Skip to content

Commit 4dea748

Browse files
committed
QemuSbsa: Switch from EmbeddedPkg's libfdt to MdePkg FdtLib
Switch the Sbsa libraries to use the MdePkg's FdtLib. EmebeddedPkg fdtlib has been removed in 202511.
1 parent 11d8829 commit 4dea748

File tree

4 files changed

+56
-51
lines changed

4 files changed

+56
-51
lines changed

Platforms/QemuSbsaPkg/Library/FdtHelperLib/FdtHelperLib.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
**/
1010

1111
#include <Uefi.h>
12+
#include <Library/BaseLib.h>
1213
#include <Library/DebugLib.h>
1314
#include <Library/FdtHelperLib.h>
1415
#include <Library/PcdLib.h>
15-
#include <libfdt.h>
16+
#include <Library/FdtLib.h>
1617

1718
STATIC INT32 mFdtFirstCpuOffset;
1819
STATIC INT32 mFdtCpuNodeSize;
@@ -29,25 +30,25 @@ FdtHelperGetMpidr (
2930
IN UINTN CpuId
3031
)
3132
{
32-
VOID *DeviceTreeBase;
33-
CONST UINT64 *RegVal;
34-
INT32 Len;
33+
VOID *DeviceTreeBase;
34+
CONST FDT_PROPERTY *PropertyPtr;
35+
INT32 Len;
3536

3637
DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
3738
ASSERT (DeviceTreeBase != NULL);
3839

39-
RegVal = fdt_getprop (
40-
DeviceTreeBase,
41-
mFdtFirstCpuOffset + (CpuId * mFdtCpuNodeSize),
42-
"reg",
43-
&Len
44-
);
45-
if (!RegVal) {
40+
PropertyPtr = FdtGetProperty (
41+
DeviceTreeBase,
42+
mFdtFirstCpuOffset + (CpuId * mFdtCpuNodeSize),
43+
"reg",
44+
&Len
45+
);
46+
if (!PropertyPtr) {
4647
DEBUG ((DEBUG_ERROR, "Couldn't find reg property for CPU:%d\n", CpuId));
4748
return 0;
4849
}
4950

50-
return (fdt64_to_cpu (ReadUnaligned64 (RegVal)));
51+
return (Fdt64ToCpu (ReadUnaligned64 ((UINT64 *)PropertyPtr->Data)));
5152
}
5253

5354
/** Walks through the Device Tree created by Qemu and counts the number
@@ -71,9 +72,9 @@ FdtHelperCountCpus (
7172
ASSERT (DeviceTreeBase != NULL);
7273

7374
// Make sure we have a valid device tree blob
74-
ASSERT (fdt_check_header (DeviceTreeBase) == 0);
75+
ASSERT (FdtCheckHeader (DeviceTreeBase) == 0);
7576

76-
CpuNode = fdt_path_offset (DeviceTreeBase, "/cpus");
77+
CpuNode = FdtPathOffset (DeviceTreeBase, "/cpus");
7778
if (CpuNode <= 0) {
7879
DEBUG ((DEBUG_ERROR, "Unable to locate /cpus in device tree\n"));
7980
return 0;
@@ -84,11 +85,11 @@ FdtHelperCountCpus (
8485
// Walk through /cpus node and count the number of subnodes.
8586
// The count of these subnodes corresponds to the number of
8687
// CPUs created by Qemu.
87-
Prev = fdt_first_subnode (DeviceTreeBase, CpuNode);
88+
Prev = FdtFirstSubnode (DeviceTreeBase, CpuNode);
8889
mFdtFirstCpuOffset = Prev;
8990
while (1) {
9091
CpuCount++;
91-
Node = fdt_next_subnode (DeviceTreeBase, Prev);
92+
Node = FdtNextSubnode (DeviceTreeBase, Prev);
9293
if (Node < 0) {
9394
break;
9495
}

Platforms/QemuSbsaPkg/Library/OemMiscLib/OemMiscLib.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <Library/PcdLib.h>
2020
#include <Library/SerialPortLib.h>
2121
#include <Library/TimerLib.h>
22-
#include <libfdt.h>
2322

2423
/** Returns whether the specified processor is present or not.
2524

Platforms/QemuSbsaPkg/Library/SbsaQemuLib/SbsaQemuMem.c

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
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

Platforms/QemuSbsaPkg/QemuSbsaPkg.dsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
DebugAgentTimerLib|EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLibNull.inf
184184

185185
# Flattened Device Tree (FDT) access library
186-
FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf
186+
FdtLib|MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
187187

188188
# PCI Libraries
189189
PciLib|MdePkg/Library/BasePciLibPciExpress/BasePciLibPciExpress.inf

0 commit comments

Comments
 (0)