]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/Microvm/fdt: add empty fdt
authorGerd Hoffmann <kraxel@redhat.com>
Mon, 13 Dec 2021 08:16:56 +0000 (09:16 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 13 Dec 2021 12:16:32 +0000 (12:16 +0000)
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.

On ARM machines a device tree is mandatory for hardware detection,
that's why FdtClient fails hard.

On microvm the device tree is only used to detect virtio-mmio devices
(this patch series) and the pcie host (future series).  So edk2 can
continue with limited functionality in case no device tree is present:
no storage, no network, but serial console and direct kernel boot
works.

qemu release 6.2 & newer will provide a device tree for microvm.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3689
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
OvmfPkg/PlatformPei/Platform.c

index c9ec1d7e99fb5a4a37a2571073bcc29ce00efbc4..d0323c6451621cadfee81c712e1c4d1156d99263 100644 (file)
@@ -16,6 +16,7 @@
 //\r
 // The Library classes this module consumes\r
 //\r
+#include <Library/BaseMemoryLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/HobLib.h>\r
@@ -321,6 +322,18 @@ PciExBarInitialization (
     );\r
 }\r
 \r
+static const UINT8  EmptyFdt[] = {\r
+  0xd0, 0x0d, 0xfe, 0xed, 0x00, 0x00, 0x00, 0x48,\r
+  0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x48,\r
+  0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x11,\r
+  0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x09,\r
+};\r
+\r
 VOID\r
 MicrovmInitialization (\r
   VOID\r
@@ -335,8 +348,9 @@ MicrovmInitialization (
 \r
   Status = QemuFwCfgFindFile ("etc/fdt", &FdtItem, &FdtSize);\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((DEBUG_INFO, "%a: no etc/fdt found in fw_cfg\n", __FUNCTION__));\r
-    return;\r
+    DEBUG ((DEBUG_INFO, "%a: no etc/fdt found in fw_cfg, using dummy\n", __FUNCTION__));\r
+    FdtItem = 0;\r
+    FdtSize = sizeof (EmptyFdt);\r
   }\r
 \r
   FdtPages = EFI_SIZE_TO_PAGES (FdtSize);\r
@@ -346,8 +360,12 @@ MicrovmInitialization (
     return;\r
   }\r
 \r
-  QemuFwCfgSelectItem (FdtItem);\r
-  QemuFwCfgReadBytes (FdtSize, NewBase);\r
+  if (FdtItem) {\r
+    QemuFwCfgSelectItem (FdtItem);\r
+    QemuFwCfgReadBytes (FdtSize, NewBase);\r
+  } else {\r
+    CopyMem (NewBase, EmptyFdt, FdtSize);\r
+  }\r
 \r
   FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof (*FdtHobData));\r
   if (FdtHobData == NULL) {\r