Compare commits

..

1 Commits

Author SHA1 Message Date
Simon Glass
42d12fa98b emulation: fdt: Allow using U-Boot's device tree with QEMU
At present it is impossible to change the qemu_arm64 defconfig to
obtain a devicetree from the U-Boot build.

This is necessary for FIT validation, for example, where the signature
node must be compiled into U-Boot.

A proposed change to QEMU to allow device tree additions has been
blocked for several years. The only known workaround is to use QEMU's
dumpdtb option, merge in the signature node manually, disable
OF_HAS_PRIOR_STAGE and then start QEMU with special arguments. This is
complicated enough that it is documented in U-Boot[1].

Unfortunately the only way to disable OF_HAS_PRIOR_STAGE at present is
to hack the Kconfig.

Add a new QEMU_MANUAL_DTB Kconfig option which makes OF_HAS_PRIOR_STAGE
optional, thus avoiding needing to patch U-Boot to get this working.

This seems a clearer solution than just making OF_HAS_PRIOR_STAGE
visible, since that symbol is intended to be set automatically by each
platform.

Series-to: u-boot
Series-cc: trini
Series-cc: Peter Maydell <peter.maydell@linaro.org>
Series-cc: Andrew Phelps <andrew.phelps@canonical.com>
Series-cc: ilias
Series-version: 2
Series-changes: 2
- Add a new QEMU-specific Kconfig instead

[1] https://docs.u-boot.org/en/latest/develop/devicetree/dt_qemu.html
Link: https://patchwork.kernel.org/project/qemu-devel/patch/20210926183410.256484-1-sjg@chromium.org/#24481799

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Tom Rini <trini@konsulko.com>
2025-04-06 07:04:52 +12:00
23 changed files with 129 additions and 164 deletions

View File

@@ -551,7 +551,7 @@ config SYS_LOAD_ADDR
default 0x12000000 if ARCH_MX6 && !(MX6SL || MX6SLL || MX6SX || MX6UL || MX6ULL)
default 0x80800000 if ARCH_MX7
default 0x90000000 if FSL_LSCH2 || FSL_LSCH3
default 0 if ARCH_EFI
default 0x02000000 if ARCH_EFI
default 0x0 if ARCH_SC5XX
help
Address in memory to use as the default safe load address.

View File

@@ -1055,7 +1055,7 @@ config ARCH_QEMU
imply DM_RNG
imply DM_RTC
imply RTC_PL031
imply OF_HAS_PRIOR_STAGE if !TARGET_QEMU_ARM_SBSA
imply OF_HAS_PRIOR_STAGE if !TARGET_QEMU_ARM_SBSA && !QEMU_MANUAL_DTB
imply VIDEO
imply VIDEO_BOCHS
imply SYS_WHITE_ON_BLACK

View File

@@ -28,7 +28,7 @@ choice
config TARGET_VEXPRESS64_BASE_FVP
bool "Support Versatile Express ARMv8a FVP BASE model"
select VEXPRESS64_BASE_MODEL
imply OF_HAS_PRIOR_STAGE if !BLOBLIST
imply OF_HAS_PRIOR_STAGE
config TARGET_VEXPRESS64_BASER_FVP
bool "Support Versatile Express ARMv8r64 FVP BASE model"

View File

@@ -3,8 +3,5 @@
# (C) Copyright 2000-2004
# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
obj-y := vexpress64.o
obj-$(CONFIG_OF_HAS_PRIOR_STAGE) += lowlevel_init.o
obj-y := vexpress64.o lowlevel_init.o
obj-$(CONFIG_TARGET_VEXPRESS64_JUNO) += pcie.o

View File

@@ -100,9 +100,7 @@ int dram_init_banksize(void)
* Push the variable into the .data section so that it
* does not get cleared later.
*/
#ifdef CONFIG_OF_HAS_PRIOR_STAGE
unsigned long __section(".data") prior_stage_fdt_address[2];
#endif
#ifdef CONFIG_OF_BOARD
@@ -153,7 +151,6 @@ static phys_addr_t find_dtb_in_nor_flash(const char *partname)
}
#endif
#ifdef CONFIG_OF_HAS_PRIOR_STAGE
/*
* Filter for a valid DTB, as TF-A happens to provide a pointer to some
* data structure using the DTB format, which we cannot use.
@@ -204,7 +201,6 @@ int board_fdt_blob_setup(void **fdtp)
return -ENXIO;
}
#endif
#endif
/* Actual reset is done via PSCI. */
void reset_cpu(void)

View File

@@ -17,7 +17,7 @@ config TARGET_EFI_X86_APP32
help
This target is used for running U-Boot on top of EFI. In
this case EFI does the early initialisation, and U-Boot
starts once the RAM, video and CPU are fully running.
takes over once the RAM, video and CPU are fully running.
U-Boot is loaded as an application from EFI.
config TARGET_EFI_X86_APP64
@@ -27,7 +27,7 @@ config TARGET_EFI_X86_APP64
help
This target is used for running U-Boot on top of EFI in 64-bit mode.
In this case EFI does the early initialisation, and U-Boot
starts once the RAM, video and CPU are fully running.
takes over once the RAM, video and CPU are fully running.
U-Boot is loaded as an application from EFI.
config TARGET_EFI_X86_PAYLOAD
@@ -59,7 +59,7 @@ config TARGET_EFI_ARM_APP64
help
This target is used for running U-Boot on top of EFI in 64-bit mode.
In this case EFI does the early initialisation, and U-Boot
starts once the RAM, video and CPU are fully running.
takes over once the RAM, video and CPU are fully running.
U-Boot is loaded as an application from EFI.
endchoice

View File

@@ -1,3 +1,10 @@
EFI-ARM_APP32 BOARD
M: Simon Glass <sjg@chromium.org>
S: Maintained
F: board/efi/Kconfig
F: board/efi/efi-arm_app/
F: configs/efi-arm_app32_defconfig
EFI-ARM_APP64 BOARD
M: Simon Glass <sjg@chromium.org>
S: Maintained

View File

@@ -13,3 +13,15 @@ config MTDPARTS_NOR1
help
This define the partition of nor1 used to build mtparts dynamically
for the u-boot env stored on nor1.
config QEMU_MANUAL_DTB
bool "Manually provide a device tree to QEMU"
help
For some use cases, such as FIT validation where a public key must be
placed in U-Boot's device tree, we need to override the device tree
that QEMU would normally provide to us.
Note: this work-around is necessary since Linaro has blocked
addition of a feature to support additions to the QEMU devicetree:
Link: https://patchwork.kernel.org/project/qemu-devel/patch/20210926183410.256484-1-sjg@chromium.org/#24481799

View File

@@ -1185,39 +1185,6 @@ int bootm_run(struct bootm_info *bmi)
int bootz_run(struct bootm_info *bmi)
{
struct bootm_headers *images = bmi->images;
ulong zi_start, zi_end;
int ret;
ret = bootm_run_states(bmi, BOOTM_STATE_START);
if (ret)
return ret;
images->ep = bmi->addr_img ? hextoul(bmi->addr_img, NULL) :
image_load_addr;
ret = bootz_setup(images->ep, &zi_start, &zi_end);
if (ret)
return ret;
lmb_reserve(images->ep, zi_end - zi_start);
/*
* Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
* have a header that provide this informaiton.
*/
if (bootm_find_images(images->ep, bmi->conf_ramdisk, bmi->conf_fdt,
images->ep, zi_end - zi_start))
return -EINVAL;
/*
* We are doing the BOOTM_STATE_LOADOS state ourselves, so must
* disable interrupts ourselves
*/
bootm_disable_interrupts();
images->os.os = IH_OS_LINUX;
return boot_run(bmi, "bootz", 0);
}

View File

@@ -20,6 +20,56 @@ int __weak bootz_setup(ulong image, ulong *start, ulong *end)
return -1;
}
/*
* zImage booting support
*/
static int bootz_start(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[], struct bootm_headers *images)
{
ulong zi_start, zi_end;
struct bootm_info bmi;
int ret;
bootm_init(&bmi);
if (argc)
bmi.addr_img = argv[0];
if (argc > 1)
bmi.conf_ramdisk = argv[1];
if (argc > 2)
bmi.conf_fdt = argv[2];
/* do not set up argc and argv[] since nothing uses them */
ret = bootm_run_states(&bmi, BOOTM_STATE_START);
/* Setup Linux kernel zImage entry point */
if (!argc) {
images->ep = image_load_addr;
debug("* kernel: default image load address = 0x%08lx\n",
image_load_addr);
} else {
images->ep = hextoul(argv[0], NULL);
debug("* kernel: cmdline image address = 0x%08lx\n",
images->ep);
}
ret = bootz_setup(images->ep, &zi_start, &zi_end);
if (ret != 0)
return 1;
lmb_reserve(images->ep, zi_end - zi_start);
/*
* Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
* have a header that provide this informaiton.
*/
if (bootm_find_images(image_load_addr, cmd_arg1(argc, argv),
cmd_arg2(argc, argv), images->ep,
zi_end - zi_start))
return 1;
return 0;
}
int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
struct bootm_info bmi;
@@ -28,6 +78,17 @@ int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
/* Consume 'bootz' */
argc--; argv++;
if (bootz_start(cmdtp, flag, argc, argv, &images))
return 1;
/*
* We are doing the BOOTM_STATE_LOADOS state ourselves, so must
* disable interrupts ourselves
*/
bootm_disable_interrupts();
images.os.os = IH_OS_LINUX;
bootm_init(&bmi);
if (argc)
bmi.addr_img = argv[0];
@@ -38,10 +99,8 @@ int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
bmi.cmd_name = "bootz";
ret = bootz_run(&bmi);
if (ret)
return CMD_RET_FAILURE;
return 0;
return ret;
}
U_BOOT_LONGHELP(bootz,

View File

@@ -1055,8 +1055,8 @@ choice
config BLOBLIST_FIXED
bool "Place bloblist at a fixed address in memory"
help
Select this to use a fixed memory address for the bloblist. If the
bloblist exists at this address from a previous phase, it is used as is.
Select this to used a fixed memory address for the bloblist. If the
bloblist exists at this address from a previous phase, it used as is.
If not it is created at this address in U-Boot.
config BLOBLIST_ALLOC
@@ -1066,12 +1066,6 @@ config BLOBLIST_ALLOC
specify a fixed address on systems where this is unknown or can
change at runtime.
config BLOBLIST_PASSAGE
bool "Use bloblist in-place"
help
Use a bloblist in the incoming standard passage. The size is detected
automatically so CONFIG_BLOBLIST_SIZE can be 0.
endchoice
config BLOBLIST_ADDR
@@ -1086,17 +1080,17 @@ config BLOBLIST_ADDR
config BLOBLIST_SIZE
hex "Size of bloblist"
default 0x0 if BLOBLIST_PASSAGE
default 0x400
help
Sets the size of the bloblist in bytes. This must include all
overhead (alignment, bloblist header, record header). The bloblist
is set up in the first part of U-Boot to run (TPL, SPL or U-Boot
proper), and this same bloblist is used for subsequent phases.
proper), and this sane bloblist is used for subsequent phases.
config BLOBLIST_SIZE_RELOC
hex "Size of bloblist after relocation"
default BLOBLIST_SIZE if BLOBLIST_FIXED || BLOBLIST_ALLOC
default 0x0 if BLOBLIST_PASSAGE
default 0x20000 if (ARM && EFI_LOADER && GENERATE_ACPI_TABLE)
help
Sets the size of the bloblist in bytes after relocation. Since U-Boot

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: GPL-2.0+
// SPDX-License-Identifier: GPL-2.0+ BSD-3-Clause
/*
* Copyright 2018 Google, Inc
* Written by Simon Glass <sjg@chromium.org>
@@ -489,9 +489,6 @@ int bloblist_reloc(void *to, uint to_size)
{
struct bloblist_hdr *hdr;
if (!to_size)
return 0;
if (to_size < gd->bloblist->total_size)
return -ENOSPC;
@@ -522,6 +519,13 @@ int bloblist_init(void)
* at a fixed address.
*/
bool from_addr = fixed && !xpl_is_first_phase();
/*
* If U-Boot is in the first phase that an arch custom routine should
* install the bloblist passed from previous loader to this fixed
* address.
*/
bool from_boot_arg = fixed && xpl_is_first_phase();
if (xpl_prev_phase() == PHASE_TPL && !IS_ENABLED(CONFIG_TPL_BLOBLIST))
from_addr = false;
if (fixed)
@@ -529,13 +533,7 @@ int bloblist_init(void)
CONFIG_BLOBLIST_ADDR);
size = CONFIG_BLOBLIST_SIZE;
/*
* If the current boot stage is the first phase of U-Boot, then an
* architecture-specific routine should be used to handle the bloblist
* passed from the previous boot loader
*/
if (xpl_is_first_phase() && !IS_ENABLED(CONFIG_BLOBLIST_ALLOC))
if (from_boot_arg)
ret = xferlist_from_boot_arg(addr, size);
else if (from_addr)
ret = bloblist_check(addr, size);

View File

@@ -1,5 +0,0 @@
#include <configs/vexpress_fvp_defconfig>
CONFIG_BLOBLIST=y
CONFIG_BLOBLIST_PASSAGE=y
CONFIG_BLOBLIST_SIZE_RELOC=0x10000

View File

@@ -43,22 +43,6 @@ Juno is an Arm development board with the following features:
More details can be found in the board documentation [3]_.
Bloblist Support
----------------
The ``vexpress_fvp_bloblist_defconfig`` configures U-Boot to be compiled for
Vexpress64 with Bloblist as the primary method for information handoff between
boot stages. U-Boot offers three methods to set up a bloblist: using a
predefined bloblist at a specified address, dynamically allocating memory for a
bloblist, or utilizing a standard passage-provided bloblist with automatic size
detection.
By default, ``vexpress_fvp_bloblist_defconfig`` uses the standard passage method
(CONFIG_BLOBLIST_PASSAGE) because TF-A provides a Transfer List in non-secure
memory that U-Boot can utilise. This Bloblist, which is referred to as a Transfer List in
TF-A, contains all necessary data for the handoff process, including DT and ACPI
tables.
References
----------

View File

@@ -46,3 +46,8 @@ You can then run qemu with the merged devicetree, e.g.::
Note that there seems to be a bug in some versions of qemu where the output of
dumpdtb does not quite match what is provided to U-Boot.
See also the
`rejected QEMU patch <https://patchwork.kernel.org/project/qemu-devel/patch/20231117021840.117874-1-sjg@chromium.org>`_
and
`discussion <https://patchwork.kernel.org/project/qemu-devel/patch/20210926183410.256484-1-sjg@chromium.org>`_.

View File

@@ -205,8 +205,13 @@ config OF_HAS_PRIOR_STAGE
development purposes, but it is not recommended, and likely will not
even work, for production systems.
Note: This option must be set in Kconfig and cannot be enabled or
disabled in the board's defconfig file.
Note: This option can be disabled for QEMU usiing QEMU_MANUAL_DTB thus
allowing QEMU to support FIT validation, where the devicetree must
include a public key.
See also this for context:
https://patchwork.kernel.org/project/qemu-devel/patch/20210926183410.256484-1-sjg@chromium.org/#24481799
config OF_OMIT_DTB
bool "Omit the device tree output when building"

View File

@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: GPL-2.0+ */
/* SPDX-License-Identifier: GPL-2.0+ BSD-3-Clause */
/*
* This provides a standard way of passing information between boot phases
* (TPL -> SPL -> U-Boot proper.)
@@ -475,7 +475,7 @@ int bloblist_init(void);
/**
* bloblist_maybe_init() - Init the bloblist system if not already done
*
* Calls bloblist_init() if the GD_FLG_BLOBLIST_READY flag is not set
* Calls bloblist_init() if the GD_FLG_BLOBLIST_READY flag is not et
*
* Return: 0 if OK, -ve on error
*/

View File

@@ -169,14 +169,12 @@
" if load hostfs - ${kernel_addr_r} ${kernel_name}; then" \
" setenv fdt_high 0xffffffffffffffff;" \
" setenv initrd_high 0xffffffffffffffff;" \
" if test -n load hostfs - ${fdt_addr_r} ${fdtfile}; then" \
" fdt move $fdtcontroladdr $fdt_addr_r;" \
" fi;" \
" load hostfs - ${fdt_addr_r} ${fdtfile};" \
" load hostfs - ${ramdisk_addr_r} ${ramdisk_name};" \
" fdt addr ${fdt_addr_r};" \
" fdt resize;" \
" fdt chosen ${ramdisk_addr_r} ${filesize};" \
" booti $kernel_addr_r - ${fdt_addr_r};" \
" booti $kernel_addr_r - $fdt_addr_r;" \
" fi;" \
"fi\0"
#define BOOTENV_DEV_NAME_SMH(devtypeu, devtypel, instance) "smh "

View File

@@ -4,6 +4,8 @@
#define __NET_COMMON_H__
#include <asm/cache.h>
#include <command.h>
#include <env.h>
#include <hexdump.h>
#include <linux/if_ether.h>
#include <linux/sizes.h>
@@ -11,8 +13,6 @@
#include <rand.h>
#include <time.h>
struct cmd_tbl;
#define DEBUG_NET_PKT_TRACE 0 /* Trace all packet data */
/*
@@ -463,7 +463,10 @@ int update_tftp(ulong addr, char *interface, char *devstring);
* 0 to 255
* Return: IP address, or 0 if invalid
*/
struct in_addr env_get_ip(char *var);
static inline struct in_addr env_get_ip(char *var)
{
return string_to_ip(env_get(var));
}
int net_init(void);

View File

@@ -1,5 +1,4 @@
// SPDX-License-Identifier: GPL-2.0
#include <env.h>
#include <net-common.h>
void copy_filename(char *dst, const char *src, int size)
@@ -26,8 +25,3 @@ int wget_request(ulong dst_addr, char *uri, struct wget_http_info *info)
wget_info = info ? info : &default_wget_info;
return wget_with_dns(dst_addr, uri);
}
struct in_addr env_get_ip(char *var)
{
return string_to_ip(env_get(var));
}

View File

@@ -63,8 +63,7 @@ def prepare_patches(col, branch, count, start, end, ignore_binary, signoff,
branch, start, to_do, ignore_binary, series, signoff)
# Fix up the patch files to our liking, and insert the cover letter
patchstream.fix_patches(series, patch_files, keep_change_id,
insert_base_commit=not cover_fname)
patchstream.fix_patches(series, patch_files, keep_change_id)
if cover_fname and series.get('cover'):
patchstream.insert_cover_letter(cover_fname, series, to_do)
return series, cover_fname, patch_files

View File

@@ -357,31 +357,6 @@ Changes in v2:
expected = expected.splitlines()
self.assertEqual(expected, lines[start:(start+len(expected))])
def test_base_commit(self):
"""Test adding a base commit with no cover letter"""
orig_text = self._get_text('test01.txt')
pos = orig_text.index('commit 5ab48490f03051875ab13d288a4bf32b507d76fd')
text = orig_text[:pos]
series = patchstream.get_metadata_for_test(text)
series.base_commit = Commit('1a44532')
series.branch = 'mybranch'
cover_fname, args = self._create_patches_for_test(series)
self.assertFalse(cover_fname)
with capture_sys_output() as out:
patchstream.fix_patches(series, args, insert_base_commit=True)
self.assertEqual('Cleaned 1 patch\n', out[0].getvalue())
lines = tools.read_file(args[0], binary=False).splitlines()
pos = lines.index('-- ')
# We expect these lines at the end:
# -- (with trailing space)
# 2.7.4
# (empty)
# base-commit: xxx
# branch: xxx
self.assertEqual('base-commit: 1a44532', lines[pos + 3])
self.assertEqual('branch: mybranch', lines[pos + 4])
def make_commit_with_file(self, subject, body, fname, text):
"""Create a file and add it to the git repo with a new commit
@@ -552,11 +527,6 @@ complicated as possible''')
self.assertEqual(f'base-commit: {base}', lines[0])
self.assertEqual('branch: second', lines[1])
# Make sure that the base-commit is not present when it is in the
# cover letter
for fname in patch_files:
self.assertNotIn(b'base-commit:', tools.read_file(fname))
# Check that it can skip patches at the end
with capture_sys_output() as _:
_, cover_fname, patch_files = control.prepare_patches(

View File

@@ -76,13 +76,8 @@ class PatchStream:
are interested in. We can also process a patch file in order to remove
unwanted tags or inject additional ones. These correspond to the two
phases of processing.
Args:
keep_change_id (bool): Keep the Change-Id tag
insert_base_commit (bool): True to add the base commit to the end
"""
def __init__(self, series, is_log=False, keep_change_id=False,
insert_base_commit=False):
def __init__(self, series, is_log=False, keep_change_id=False):
self.skip_blank = False # True to skip a single blank line
self.found_test = False # Found a TEST= line
self.lines_after_test = 0 # Number of lines found after TEST=
@@ -108,7 +103,6 @@ class PatchStream:
self.recent_quoted = collections.deque([], 5)
self.recent_unquoted = queue.Queue()
self.was_quoted = None
self.insert_base_commit = insert_base_commit
@staticmethod
def process_text(text, is_comment=False):
@@ -664,13 +658,6 @@ class PatchStream:
outfd.write(line + '\n')
self.blank_count = 0
self.finalise()
if self.insert_base_commit:
if self.series.base_commit:
print(f'base-commit: {self.series.base_commit.hash}',
file=outfd)
if self.series.branch:
print(f'branch: {self.series.branch}', file=outfd)
def insert_tags(msg, tags_to_emit):
"""Add extra tags to a commit message
@@ -791,8 +778,7 @@ def get_metadata_for_test(text):
pst.finalise()
return series
def fix_patch(backup_dir, fname, series, cmt, keep_change_id=False,
insert_base_commit=False):
def fix_patch(backup_dir, fname, series, cmt, keep_change_id=False):
"""Fix up a patch file, by adding/removing as required.
We remove our tags from the patch file, insert changes lists, etc.
@@ -806,7 +792,6 @@ def fix_patch(backup_dir, fname, series, cmt, keep_change_id=False,
series (Series): Series information about this patch set
cmt (Commit): Commit object for this patch file
keep_change_id (bool): Keep the Change-Id tag.
insert_base_commit (bool): True to add the base commit to the end
Return:
list: A list of errors, each str, or [] if all ok.
@@ -814,8 +799,7 @@ def fix_patch(backup_dir, fname, series, cmt, keep_change_id=False,
handle, tmpname = tempfile.mkstemp()
outfd = os.fdopen(handle, 'w', encoding='utf-8')
infd = open(fname, 'r', encoding='utf-8')
pst = PatchStream(series, keep_change_id=keep_change_id,
insert_base_commit=insert_base_commit)
pst = PatchStream(series, keep_change_id=keep_change_id)
pst.commit = cmt
pst.process_stream(infd, outfd)
infd.close()
@@ -827,7 +811,7 @@ def fix_patch(backup_dir, fname, series, cmt, keep_change_id=False,
shutil.move(tmpname, fname)
return cmt.warn
def fix_patches(series, fnames, keep_change_id=False, insert_base_commit=False):
def fix_patches(series, fnames, keep_change_id=False):
"""Fix up a list of patches identified by filenames
The patch files are processed in place, and overwritten.
@@ -836,7 +820,6 @@ def fix_patches(series, fnames, keep_change_id=False, insert_base_commit=False):
series (Series): The Series object
fnames (:type: list of str): List of patch files to process
keep_change_id (bool): Keep the Change-Id tag.
insert_base_commit (bool): True to add the base commit to the end
"""
# Current workflow creates patches, so we shouldn't need a backup
backup_dir = None #tempfile.mkdtemp('clean-patch')
@@ -846,8 +829,7 @@ def fix_patches(series, fnames, keep_change_id=False, insert_base_commit=False):
cmt.patch = fname
cmt.count = count
result = fix_patch(backup_dir, fname, series, cmt,
keep_change_id=keep_change_id,
insert_base_commit=insert_base_commit)
keep_change_id=keep_change_id)
if result:
print('%d warning%s for %s:' %
(len(result), 's' if len(result) > 1 else '', fname))