From 0ab4569c45ab23c12ca9eab42016c0e844689b7c Mon Sep 17 00:00:00 2001 From: Laszlo Ersek 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 --- .../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 +#include #include #include #include @@ -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