Gerd,

On 03/04/22 11:58, Peter Maydell wrote:
> On Fri, 4 Mar 2022 at 10:52, Igor Mammedov <imamm...@redhat.com> wrote:
>> if firmware is not an option, I wouldn't opposed to printing warning
>> message from QEMU if you can detect that you are running broken edk2
>> and under condition that no new infa/hooks are invented for this.
>> (assuming it's worth all the effort at all)
> 
> I am definitely not in favour of that. QEMU should provide the
> emulated hardware and let the firmware deal with detecting if
> it's missing important stuff. It should as far as is possible
> not have special-case detection-of-broken-guests handling.
> 
> thanks
> -- PMM
> 

It's probably simplest if you replace the ASSERT()s in question; please
see the attachment. (Only smoke tested.) Gavin indicated up-thread he'd
be OK with an easier-to-understand error message.

Laszlo
From 0ab4569c45ab23c12ca9eab42016c0e844689b7c Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <ler...@redhat.com>
Date: Fri, 4 Mar 2022 15:14:25 +0100
Subject: [PATCH 1/1] ArmVirtPkg/QemuVirtMemInfoLib: improve error messages for
 MemoryInitPei

QEMU makes "virt" board configurations possible where the lowest memory
node is smaller than 128 MB. Currently we catch that with an ASSERT()
only; turn it into a hard CpuDeadLoop(), and log a more user-friendly
error message.

Convert some other ASSERT()s as well.

While at it, fix up the disorder in the [LibraryClasses] section of
"QemuVirtMemInfoPeiLib.inf".

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2041323
Signed-off-by: Laszlo Ersek <ler...@redhat.com>
---
 .../QemuVirtMemInfoPeiLib.inf                 |  3 +-
 .../QemuVirtMemInfoPeiLibConstructor.c        | 36 +++++++++++++++----
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf
index 7ecf6dfbb786..076ee24a4961 100644
--- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf
+++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf
@@ -29,11 +29,12 @@ [Packages]
 
 [LibraryClasses]
   ArmLib
+  BaseLib
   BaseMemoryLib
   DebugLib
   FdtLib
-  PcdLib
   MemoryAllocationLib
+  PcdLib
 
 [Pcd]
   gArmTokenSpaceGuid.PcdFdBaseAddress
diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c
index 33d3597d57ab..43fb38bde436 100644
--- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c
+++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c
@@ -7,6 +7,7 @@
 **/
 
 #include <Base.h>
+#include <Library/BaseLib.h>
 #include <Library/DebugLib.h>
 #include <Library/PcdLib.h>
 #include <libfdt.h>
@@ -85,7 +86,15 @@ QemuVirtMemInfoPeiLibConstructor (
   //
   // Make sure the start of DRAM matches our expectation
   //
-  ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == NewBase);
+  if (FixedPcdGet64 (PcdSystemMemoryBase) != NewBase) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: the lowest memory node must start at 0x%Lx\n",
+      __FUNCTION__,
+      FixedPcdGet64 (PcdSystemMemoryBase)
+      ));
+    CpuDeadLoop ();
+  }
   PcdStatus = PcdSet64S (PcdSystemMemorySize, NewSize);
   ASSERT_RETURN_ERROR (PcdStatus);
 
@@ -97,12 +106,25 @@ QemuVirtMemInfoPeiLibConstructor (
   // chance of marking its location as reserved or copy it to a freshly
   // allocated block in the permanent PEI RAM in the platform PEIM.
   //
-  ASSERT (NewSize >= SIZE_128MB);
-  ASSERT (
-    (((UINT64)PcdGet64 (PcdFdBaseAddress) +
-      (UINT64)PcdGet32 (PcdFdSize)) <= NewBase) ||
-    ((UINT64)PcdGet64 (PcdFdBaseAddress) >= (NewBase + NewSize))
-    );
+  if (NewSize < SIZE_128MB) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: the lowest memory node must be at least 0x%x bytes\n",
+      __FUNCTION__,
+      (UINT32)SIZE_128MB
+      ));
+    CpuDeadLoop ();
+  }
+  if ((((UINT64)PcdGet64 (PcdFdBaseAddress) +
+        (UINT64)PcdGet32 (PcdFdSize)) > NewBase) &&
+      ((UINT64)PcdGet64 (PcdFdBaseAddress) < (NewBase + NewSize))) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: the lowest memory node must not overlap the flash device\n",
+      __FUNCTION__
+      ));
+    CpuDeadLoop ();
+  }
 
   return RETURN_SUCCESS;
 }

base-commit: 589d51df260465e2561979b8a988e77b0f32a6e8
-- 
2.19.1.3.g30247aa5d201

Reply via email to