public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Gerd Hoffmann" <kraxel@redhat.com>
To: devel@edk2.groups.io
Cc: "Jordan Justen" <jordan.l.justen@intel.com>,
	"Jiewen Yao" <jiewen.yao@intel.com>,
	"Pawel Polawski" <ppolawsk@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Ard Biesheuvel" <ardb+tianocore@kernel.org>
Subject: [PATCH v3 3/5] OvmfPkg/Microvm/fdt: add empty fdt
Date: Mon, 13 Dec 2021 09:16:56 +0100	[thread overview]
Message-ID: <20211213081658.3535809-4-kraxel@redhat.com> (raw)
In-Reply-To: <20211213081658.3535809-1-kraxel@redhat.com>

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,
thats 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.

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 | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index c9ec1d7e99fb..d0323c645162 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.33.1


  parent reply	other threads:[~2021-12-13  8:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-13  8:16 [PATCH v3 0/5] OvmfPkg/Microvm: second batch of microvm patches Gerd Hoffmann
2021-12-13  8:16 ` [PATCH v3 1/5] OvmfPkg/Microvm/fdt: add device tree support Gerd Hoffmann
2021-12-13  9:38   ` Philippe Mathieu-Daudé
2021-12-13  8:16 ` [PATCH v3 2/5] OvmfPkg/Microvm/fdt: load fdt from fw_cfg Gerd Hoffmann
2021-12-13  9:33   ` Philippe Mathieu-Daudé
2021-12-13 11:21     ` Gerd Hoffmann
2021-12-13  9:43   ` [edk2-devel] " Ard Biesheuvel
2021-12-13 11:26     ` Gerd Hoffmann
2021-12-13 11:30       ` Ard Biesheuvel
2021-12-13  8:16 ` Gerd Hoffmann [this message]
2021-12-13  9:35   ` [PATCH v3 3/5] OvmfPkg/Microvm/fdt: add empty fdt Philippe Mathieu-Daudé
2021-12-13  8:16 ` [PATCH v3 4/5] OvmfPkg/Microvm/virtio: add virtio-mmio support Gerd Hoffmann
2021-12-13  9:38   ` Philippe Mathieu-Daudé
2021-12-13  8:16 ` [PATCH v3 5/5] OvmfPkg/Microvm: add README Gerd Hoffmann
2021-12-13  9:37   ` Philippe Mathieu-Daudé
2021-12-13 12:18 ` [PATCH v3 0/5] OvmfPkg/Microvm: second batch of microvm patches Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211213081658.3535809-4-kraxel@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox