[PATCH v2] emulation: fdt: Allow using U-Boot's device tree with QEMU

Simon Glass sjg at chromium.org
Thu Apr 17 23:35:44 CEST 2025


Hi Heinrich,

On Tue, 15 Apr 2025 at 23:33, Heinrich Schuchardt <xypron.glpk at gmx.de> wrote:
>
> On 4/5/25 21:07, Simon Glass wrote:
> > 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.
>
> This description looks wrong:
>
> Signatures are in FIT images.
>
> Only public keys to validate the signatures should 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].
>
> This seems to relate to
> [PATCH] hw/arm/virt: Allow additions to the generated device tree
> https://lore.kernel.org/qemu-devel/20210926183410.256484-1-sjg@chromium.org/
>
> As your describe in [1] QEMU already provides a -dtb parameter if you
> want a crafted device-tree. Your proposed change is confounding boot
> stages and and would not provide value to the QEMU project. It was
> therefore rejected for good.
>
> It remains unclear why you would disable OF_HAS_PRIOR_STAGE if you were
> using QEMU's -dtb parameter.
>
> What would be the benefit of compiling the DT into U-Boot instead of
> providing it via the -dtb parameter?

It is helpful when testing things in U-Boot, e.g. FIT validation.

>
> >
> > 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.
>
> To me the new parameter is harder to use than simply making
> CONFIG_OF_HAS_PRIOR_STAGE always editable.
>
> >
> > [1] https://docs.u-boot.org/en/latest/develop/devicetree/dt_qemu.html
>
> The instructions that you provide in [1] are incorrect.
>
> "qemu-system-arm -machine virt -machine dumpdtb=qemu.dtb"
>
> The second machine statement overrides the first one. And the second one
> will use the default machine which for instance on riscv64 is not virt.
>
> The correct invocation to download the device-tree would be:
>
> qemu-system-arm -M virt,dumpdtb=qemudtb

I didn't actually send that code in this patch, but please do a patch
if you have time.

>
>
> > Link: https://patchwork.kernel.org/project/qemu-devel/patch/20210926183410.256484-1-sjg@chromium.org/#24481799
> >
> > Signed-off-by: Simon Glass <sjg at chromium.org>
> > Suggested-by: Tom Rini <trini at konsulko.com>
> > ---
> >
> > Changes in v2:
> > - Add a new QEMU-specific Kconfig instead
> >
> >   arch/arm/Kconfig                   |  2 +-
> >   board/emulation/common/Kconfig     | 12 ++++++++++++
> >   doc/develop/devicetree/dt_qemu.rst |  5 +++++
> >   dts/Kconfig                        |  9 +++++++--
>
> This patch lacks proper documentation in doc/

OK I'll add something.

>
> >   4 files changed, 25 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> > index db8758e6dfe..b55ed61894a 100644
> > --- a/arch/arm/Kconfig
> > +++ b/arch/arm/Kconfig
> > @@ -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
> > diff --git a/board/emulation/common/Kconfig b/board/emulation/common/Kconfig
> > index 4c15c8bcb89..3f9a6ea578f 100644
> > --- a/board/emulation/common/Kconfig
> > +++ b/board/emulation/common/Kconfig
> > @@ -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
> > diff --git a/doc/develop/devicetree/dt_qemu.rst b/doc/develop/devicetree/dt_qemu.rst
> > index 8ba2b225590..c693b49d3d4 100644
> > --- a/doc/develop/devicetree/dt_qemu.rst
> > +++ b/doc/develop/devicetree/dt_qemu.rst
> > @@ -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>`_.
> > diff --git a/dts/Kconfig b/dts/Kconfig
> > index 2e88d210bb8..53f7e246a80 100644
> > --- a/dts/Kconfig
> > +++ b/dts/Kconfig
> > @@ -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
>
> %s/usiing/using/

Will fix.


>
> Best regards
>
> Heinrich
>
> > +       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"
>


More information about the U-Boot mailing list