FdtClient is unhappy without a device tree, so add an empty fdt
which we can use in case etc/fdt is not present in fw_cfg.
https://bugzilla.tianocore.org/show_bug.cgi?id=3689
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
OvmfPkg/PlatformPei/Platform.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index 3c0cdba67c83..5071389c1fb4 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -16,6 +16,7 @@
//
// The Library classes this module consumes
//
+#include <Library/BaseMemoryLib.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
@@ -321,6 +322,18 @@ PciExBarInitialization (
);
}
+static const UINT8 EmptyFdt[] = {
+ 0xd0, 0x0d, 0xfe, 0xed, 0x00, 0x00, 0x00, 0x48,
+ 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x48,
+ 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x11,
+ 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x09,
+};
+
VOID
MicrovmInitialization (
VOID
@@ -335,8 +348,9 @@ MicrovmInitialization (
Status = QemuFwCfgFindFile ("etc/fdt", &FdtItem, &FdtSize);
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_INFO, "%a: no etc/fdt found in fw_cfg\n", __FUNCTION__));
- return;
+ DEBUG ((DEBUG_INFO, "%a: no etc/fdt found in fw_cfg, using dummy\n", __FUNCTION__));
+ FdtItem = 0;
+ FdtSize = sizeof(EmptyFdt);
}
FdtPages = EFI_SIZE_TO_PAGES (FdtSize);
@@ -346,8 +360,12 @@ MicrovmInitialization (
return;
}
- QemuFwCfgSelectItem (FdtItem);
- QemuFwCfgReadBytes (FdtSize, NewBase);
+ if (FdtItem) {
+ QemuFwCfgSelectItem (FdtItem);
+ QemuFwCfgReadBytes (FdtSize, NewBase);
+ } else {
+ CopyMem(NewBase, EmptyFdt, FdtSize);
+ }
FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof (*FdtHobData));
if (FdtHobData == NULL) {
--
2.31.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#82038): https://edk2.groups.io/g/devel/message/82038
Mute This Topic: https://groups.io/mt/86316755/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Hi
I am not sure where the problem is. "FdtClient is unhappy without a device tree, so add an empty fdt"
Do we have option 2 to fix the issue?
If no device tree, why we need FdtClient? Why we need make it happy?
Thank you
Yao Jiewen
> -----Original Message-----
> From: Gerd Hoffmann <kraxel@redhat.com>
> Sent: Thursday, October 14, 2021 11:30 PM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>; Justen, Jordan L
> <jordan.l.justen@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>; Gerd
> Hoffmann <kraxel@redhat.com>
> Subject: [PATCH 3/5] OvmfPkg/Microvm/fdt: add empty fdt
>
> FdtClient is unhappy without a device tree, so add an empty fdt
> which we can use in case etc/fdt is not present in fw_cfg.
>
> https://bugzilla.tianocore.org/show_bug.cgi?id=3689
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> OvmfPkg/PlatformPei/Platform.c | 26 ++++++++++++++++++++++----
> 1 file changed, 22 insertions(+), 4 deletions(-)
>
> diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
> index 3c0cdba67c83..5071389c1fb4 100644
> --- a/OvmfPkg/PlatformPei/Platform.c
> +++ b/OvmfPkg/PlatformPei/Platform.c
> @@ -16,6 +16,7 @@
> //
> // The Library classes this module consumes
> //
> +#include <Library/BaseMemoryLib.h>
> #include <Library/BaseLib.h>
> #include <Library/DebugLib.h>
> #include <Library/HobLib.h>
> @@ -321,6 +322,18 @@ PciExBarInitialization (
> );
> }
>
> +static const UINT8 EmptyFdt[] = {
> + 0xd0, 0x0d, 0xfe, 0xed, 0x00, 0x00, 0x00, 0x48,
> + 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x48,
> + 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x11,
> + 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x09,
> +};
> +
> VOID
> MicrovmInitialization (
> VOID
> @@ -335,8 +348,9 @@ MicrovmInitialization (
>
> Status = QemuFwCfgFindFile ("etc/fdt", &FdtItem, &FdtSize);
> if (EFI_ERROR (Status)) {
> - DEBUG ((DEBUG_INFO, "%a: no etc/fdt found in fw_cfg\n",
> __FUNCTION__));
> - return;
> + DEBUG ((DEBUG_INFO, "%a: no etc/fdt found in fw_cfg, using dummy\n",
> __FUNCTION__));
> + FdtItem = 0;
> + FdtSize = sizeof(EmptyFdt);
> }
>
> FdtPages = EFI_SIZE_TO_PAGES (FdtSize);
> @@ -346,8 +360,12 @@ MicrovmInitialization (
> return;
> }
>
> - QemuFwCfgSelectItem (FdtItem);
> - QemuFwCfgReadBytes (FdtSize, NewBase);
> + if (FdtItem) {
> + QemuFwCfgSelectItem (FdtItem);
> + QemuFwCfgReadBytes (FdtSize, NewBase);
> + } else {
> + CopyMem(NewBase, EmptyFdt, FdtSize);
> + }
>
> FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof (*FdtHobData));
> if (FdtHobData == NULL) {
> --
> 2.31.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#82079): https://edk2.groups.io/g/devel/message/82079
Mute This Topic: https://groups.io/mt/86316755/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
On Fri, Oct 15, 2021 at 03:54:19AM +0000, Yao, Jiewen wrote: > Hi > I am not sure where the problem is. "FdtClient is unhappy without a device tree, so add an empty fdt" FdtClient throws an assert() in case no device tree is present. > Do we have option 2 to fix the issue? > If no device tree, why we need FdtClient? Why we need make it happy? Well, if all goes as planned the microvm in qemu 6.2+ will provide the fdt but older qemu versions don't. So I want use the fdt if present to detect virtio-mmio devices. On older qemu versions without fdt I do *not* want abort the boot though, the firmware still works with reduced functionality (no storage/network, but direct kernel boot works). The microvm situation is a bit special here. On arm systems the fdt is rather essential for hardware bringup, which is probably the reason for the assert(). For microvm this is not the case though. take care, Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#82083): https://edk2.groups.io/g/devel/message/82083 Mute This Topic: https://groups.io/mt/86316755/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
OK. I recommend to add those background info in comments. Thank you Yao Jiewen > -----Original Message----- > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Gerd > Hoffmann > Sent: Friday, October 15, 2021 12:53 PM > To: devel@edk2.groups.io; Yao, Jiewen <jiewen.yao@intel.com> > Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>; Justen, Jordan L > <jordan.l.justen@intel.com> > Subject: Re: [edk2-devel] [PATCH 3/5] OvmfPkg/Microvm/fdt: add empty fdt > > On Fri, Oct 15, 2021 at 03:54:19AM +0000, Yao, Jiewen wrote: > > Hi > > I am not sure where the problem is. "FdtClient is unhappy without a device tree, > so add an empty fdt" > > FdtClient throws an assert() in case no device tree is present. > > > Do we have option 2 to fix the issue? > > If no device tree, why we need FdtClient? Why we need make it happy? > > Well, if all goes as planned the microvm in qemu 6.2+ will provide the > fdt but older qemu versions don't. So I want use the fdt if present to > detect virtio-mmio devices. On older qemu versions without fdt I do > *not* want abort the boot though, the firmware still works with reduced > functionality (no storage/network, but direct kernel boot works). > > The microvm situation is a bit special here. On arm systems the fdt is > rather essential for hardware bringup, which is probably the reason for > the assert(). For microvm this is not the case though. > > take care, > Gerd > > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#82145): https://edk2.groups.io/g/devel/message/82145 Mute This Topic: https://groups.io/mt/86316755/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2026 Red Hat, Inc.