1616#include <Library/MemoryAllocationLib.h>
1717#include <Library/PcdLib.h>
1818#include <Library/PanicLib.h>
19- #include <libfdt .h>
19+ #include <Library/FdtLib .h>
2020#include <Library/SecPlatformSmmuConfigLib.h>
2121
2222#include <Guid/DxeMemoryProtectionSettings.h>
@@ -66,7 +66,7 @@ InitializeMemoryConfiguration (
6666 UINT64 NewSize , CurSize ;
6767 CONST CHAR8 * Type ;
6868 INT32 Len ;
69- CONST UINT64 * RegProp ;
69+ CONST FDT_PROPERTY * PropertyPtr ;
7070 DXE_MEMORY_PROTECTION_SETTINGS DxeSettings ;
7171 UINTN FdtSize ;
7272 EFI_STATUS Status ;
@@ -110,50 +110,55 @@ InitializeMemoryConfiguration (
110110 }
111111
112112 // Make sure we have a valid device tree blob
113- if (fdt_check_header (DeviceTreeBase ) != 0 ) {
113+ if (FdtCheckHeader (DeviceTreeBase ) != 0 ) {
114114 PANIC ("Device Tree Blob header is not valid. Cannot continue without a valid Device Tree Blob.\n" );
115115 }
116116
117117 // Look for the lowest memory node
118118 for (Prev = 0 ; ; Prev = Node ) {
119- Node = fdt_next_node (DeviceTreeBase , Prev , NULL );
119+ Node = FdtNextNode (DeviceTreeBase , Prev , NULL );
120120 if (Node < 0 ) {
121121 break ;
122122 }
123123
124124 // Check for memory node
125- Type = fdt_getprop (DeviceTreeBase , Node , "device_type" , & Len );
126- if (Type && (AsciiStrnCmp (Type , "memory" , Len ) == 0 )) {
127- // Get the 'reg' property of this node. For now, we will assume
128- // two 8 byte quantities for base and size, respectively.
129- RegProp = fdt_getprop (DeviceTreeBase , Node , "reg" , & Len );
130- if ((RegProp != 0 ) && (Len == (2 * sizeof (UINT64 )))) {
131- CurBase = fdt64_to_cpu (ReadUnaligned64 (RegProp ));
132- CurSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1 ));
133-
134- DEBUG ((
135- DEBUG_INFO ,
136- "%a: System RAM @ 0x%lx - 0x%lx\n" ,
137- __FUNCTION__ ,
138- CurBase ,
139- CurBase + CurSize - 1
140- ));
141-
142- if ((NewBase > CurBase ) || (NewBase == 0 )) {
143- NewBase = CurBase ;
144- NewSize = CurSize ;
125+ PropertyPtr = FdtGetProperty (DeviceTreeBase , Node , "device_type" , & Len );
126+ if (PropertyPtr != NULL ) {
127+ Type = PropertyPtr -> Data ;
128+ if (Type && (AsciiStrnCmp (Type , "memory" , Len ) == 0 )) {
129+ // Get the 'reg' property of this node. For now, we will assume
130+ // two 8 byte quantities for base and size, respectively.
131+ PropertyPtr = FdtGetProperty (DeviceTreeBase , Node , "reg" , & Len );
132+ if (PropertyPtr != NULL ) {
133+ if (Len == (2 * sizeof (UINT64 ))) {
134+ CurBase = Fdt64ToCpu (ReadUnaligned64 ((UINT64 * )PropertyPtr -> Data ));
135+ CurSize = Fdt64ToCpu (ReadUnaligned64 ((UINT64 * )(PropertyPtr -> Data ) + 1 ));
136+
137+ DEBUG ((
138+ DEBUG_INFO ,
139+ "%a: System RAM @ 0x%lx - 0x%lx\n" ,
140+ __FUNCTION__ ,
141+ CurBase ,
142+ CurBase + CurSize - 1
143+ ));
144+
145+ if ((NewBase > CurBase ) || (NewBase == 0 )) {
146+ NewBase = CurBase ;
147+ NewSize = CurSize ;
148+ }
149+ }
150+ } else {
151+ DEBUG ((
152+ DEBUG_ERROR ,
153+ "%a: Failed to parse FDT memory node\n" ,
154+ __FUNCTION__
155+ ));
145156 }
146- } else {
147- DEBUG ((
148- DEBUG_ERROR ,
149- "%a: Failed to parse FDT memory node\n" ,
150- __FUNCTION__
151- ));
152157 }
153158 }
154159 }
155160
156- FdtSize = fdt_totalsize (DeviceTreeBase ) + PcdGet32 (PcdDeviceTreeAllocationPadding );
161+ FdtSize = FdtTotalSize (DeviceTreeBase ) + PcdGet32 (PcdDeviceTreeAllocationPadding );
157162
158163 // Create a memory allocation HOB for the device tree blob
159164 BuildMemoryAllocationHob (
@@ -278,7 +283,7 @@ ArmPlatformGetVirtualMemoryMap (
278283 );
279284
280285 if (VirtualMemoryTable == NULL ) {
281- DEBUG ((DEBUG_ERROR , "%a: Error: Failed AllocatePool()\n" , __FUNCTION__ ));
286+ DEBUG ((DEBUG_ERROR , "%a: Error: Failed AllocatePool()\n" , __func__ ));
282287 return ;
283288 }
284289
@@ -300,7 +305,7 @@ ArmPlatformGetVirtualMemoryMap (
300305 "\tPhysicalBase: 0x%lX\n"
301306 "\tVirtualBase: 0x%lX\n"
302307 "\tLength: 0x%lX\n" ,
303- __FUNCTION__ ,
308+ __func__ ,
304309 VirtualMemoryTable [0 ].PhysicalBase ,
305310 VirtualMemoryTable [0 ].VirtualBase ,
306311 VirtualMemoryTable [0 ].Length
0 commit comments