On 2015/11/30 14:24, Ard Biesheuvel wrote: > On 29 November 2015 at 07:31, Shannon Zhao <[email protected]> wrote: >> > From: Shannon Zhao <[email protected]> >> > >> > If there are more than one /memory nodes in FDT, it needs to find the >> > lowest one, and set PcdSystemMemorySize with thes size of this node. >> > >> > Contributed-under: TianoCore Contribution Agreement 1.0 >> > Signed-off-by: Shannon Zhao <[email protected]> >> > --- >> > ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c | 30 >> > ++++++++++++++++------------ >> > 1 file changed, 17 insertions(+), 13 deletions(-) >> > >> > diff --git a/ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c >> > b/ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c >> > index 17f2686..7a0fc0e 100644 >> > --- a/ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c >> > +++ b/ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c >> > @@ -72,8 +72,8 @@ ArmPlatformInitializeSystemMemory ( >> > { >> > VOID *DeviceTreeBase; >> > INT32 Node, Prev; >> > - UINT64 NewBase; >> > - UINT64 NewSize; >> > + UINT64 NewBase, CurBase; >> > + UINT64 NewSize, CurSize; >> > CONST CHAR8 *Type; >> > INT32 Len; >> > CONST UINT64 *RegProp; >> > @@ -90,7 +90,7 @@ ArmPlatformInitializeSystemMemory ( >> > ASSERT (fdt_check_header (DeviceTreeBase) == 0); >> > >> > // >> > - // Look for a memory node >> > + // Look for the lowest memory node >> > // >> > for (Prev = 0;; Prev = Node) { >> > Node = fdt_next_node (DeviceTreeBase, Prev, NULL); >> > @@ -110,26 +110,30 @@ ArmPlatformInitializeSystemMemory ( >> > RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len); >> > if (RegProp != 0 && Len == (2 * sizeof (UINT64))) { >> > >> > - NewBase = fdt64_to_cpu (ReadUnaligned64 (RegProp)); >> > - NewSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1)); >> > - >> > - // >> > - // Make sure the start of DRAM matches our expectation >> > - // >> > - ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == NewBase); >> > - PcdSet64 (PcdSystemMemorySize, NewSize); >> > + CurBase = fdt64_to_cpu (ReadUnaligned64 (RegProp)); >> > + CurSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1)); >> > >> > DEBUG ((EFI_D_INFO, "%a: System RAM @ 0x%lx - 0x%lx\n", >> > - __FUNCTION__, NewBase, NewBase + NewSize - 1)); >> > + __FUNCTION__, CurBase, CurBase + CurSize - 1)); >> > + >> > + if (NewBase > CurBase || NewBase == 0) { >> > + NewBase = CurBase; >> > + NewSize = CurSize; >> > + } > I wonder if it would not make more sense to search for the memory node > whose base == FixedPcdGet64 (PcdSystemMemoryBase) directly, rather > than find the lowest one and ASSERT() that it is the one we are > looking for. > Yeah, but if there is a (wrong) memory node with a base address lower than FixedPcdGet64 (PcdSystemMemoryBase), does this work for UEFI or OS?
Thanks, -- Shannon _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

