From 2db245b3ae93b0dae3d8f4898f7f444201eac4b4 Mon Sep 17 00:00:00 2001 From: mattp Date: Sat, 19 Jul 2025 08:40:50 -0400 Subject: [PATCH 28/29] Fix Fdt and remove Uga --- Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.c | 105 +++++++++--------- .../RaspberryPi/Drivers/FdtDxe/FdtDxe.inf | 1 + .../Library/BoardInfoLib/BoardInfoLib.c | 14 +-- .../Library/FdtPlatformLib/FdtPlatformLib.c | 6 +- .../MemoryInitPeiLib/MemoryInitPeiLib.inf | 1 + .../PlatformBootManagerLib.inf | 1 - Platform/RaspberryPi/RPi5/RPi5.dsc | 8 +- 7 files changed, 66 insertions(+), 70 deletions(-) diff --git a/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.c b/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.c index d0a448df..7b7b5676 100644 --- a/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.c +++ b/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -17,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -45,13 +46,13 @@ FixEthernetAliases ( // // Look up the 'ethernet[0]' aliases // - Aliases = fdt_path_offset (mFdtImage, "/aliases"); + Aliases = FdtPathOffset (mFdtImage, "/aliases"); if (Aliases < 0) { DEBUG ((DEBUG_ERROR, "%a: failed to locate '/aliases'\n", __func__)); return EFI_NOT_FOUND; } - Ethernet = fdt_getprop (mFdtImage, Aliases, "ethernet", NULL); - Ethernet0 = fdt_getprop (mFdtImage, Aliases, "ethernet0", NULL); + Ethernet = FdtGetProp (mFdtImage, Aliases, "ethernet", NULL); + Ethernet0 = FdtGetProp (mFdtImage, Aliases, "ethernet0", NULL); Alias = Ethernet ? Ethernet : Ethernet0; if (!Alias) { DEBUG ((DEBUG_ERROR, "%a: failed to locate 'ethernet[0]' alias\n", __func__)); @@ -59,7 +60,7 @@ FixEthernetAliases ( } // - // Create copy for fdt_setprop + // Create copy for FdtSetProp // CopySize = AsciiStrSize (Alias); Copy = AllocateCopyPool (CopySize, Alias); @@ -73,7 +74,7 @@ FixEthernetAliases ( // Status = EFI_SUCCESS; if (!Ethernet) { - Retval = fdt_setprop (mFdtImage, Aliases, "ethernet", Copy, CopySize); + Retval = FdtSetProp (mFdtImage, Aliases, "ethernet", Copy, CopySize); if (Retval != 0) { Status = EFI_NOT_FOUND; DEBUG ((DEBUG_ERROR, "%a: failed to create 'ethernet' alias (%d)\n", @@ -82,7 +83,7 @@ FixEthernetAliases ( DEBUG ((DEBUG_INFO, "%a: created 'ethernet' alias '%a'\n", __func__, Copy)); } if (!Ethernet0) { - Retval = fdt_setprop (mFdtImage, Aliases, "ethernet0", Copy, CopySize); + Retval = FdtSetProp (mFdtImage, Aliases, "ethernet0", Copy, CopySize); if (Retval != 0) { Status = EFI_NOT_FOUND; DEBUG ((DEBUG_ERROR, "%a: failed to create 'ethernet0' alias (%d)\n", @@ -109,7 +110,7 @@ UpdateMacAddress ( // // Locate the node that the 'ethernet' alias refers to // - Node = fdt_path_offset (mFdtImage, "ethernet"); + Node = FdtPathOffset (mFdtImage, "ethernet"); if (Node < 0) { DEBUG ((DEBUG_ERROR, "%a: failed to locate 'ethernet' alias\n", __func__)); return EFI_NOT_FOUND; @@ -124,7 +125,7 @@ UpdateMacAddress ( return Status; } - Retval = fdt_setprop (mFdtImage, Node, "mac-address", MacAddress, + Retval = FdtSetProp (mFdtImage, Node, "mac-address", MacAddress, sizeof MacAddress); if (Retval != 0) { DEBUG ((DEBUG_ERROR, "%a: failed to create 'mac-address' property (%d)\n", @@ -157,28 +158,28 @@ AddUsbCompatibleProperty ( INTN Retval; // Locate the node that the 'usb' alias refers to - Node = fdt_path_offset (mFdtImage, "usb"); + Node = FdtPathOffset (mFdtImage, "usb"); if (Node < 0) { DEBUG ((DEBUG_ERROR, "%a: failed to locate 'usb' alias\n", __func__)); return EFI_NOT_FOUND; } // Get the property list. This is a list of NUL terminated strings. - List = fdt_getprop (mFdtImage, Node, "compatible", &ListSize); + List = FdtGetProp (mFdtImage, Node, "compatible", &ListSize); if (List == NULL) { DEBUG ((DEBUG_ERROR, "%a: failed to locate properties\n", __func__)); return EFI_NOT_FOUND; } // Check if the compatible value we plan to add is already present - if (fdt_stringlist_contains (List, ListSize, NewProp)) { + if (FdtStringListContains (List, ListSize, NewProp)) { DEBUG ((DEBUG_INFO, "%a: property '%a' is already set.\n", __func__, NewProp)); return EFI_SUCCESS; } // Make sure the compatible device is what we expect - if (!fdt_stringlist_contains (List, ListSize, Prop)) { + if (!FdtStringListContains (List, ListSize, Prop)) { DEBUG ((DEBUG_ERROR, "%a: property '%a' is missing!\n", __func__, Prop)); return EFI_NOT_FOUND; @@ -196,7 +197,7 @@ AddUsbCompatibleProperty ( CopyMem (NewList, List, ListSize); CopyMem (&NewList[ListSize], NewProp, sizeof (NewProp)); - Retval = fdt_setprop (mFdtImage, Node, "compatible", NewList, + Retval = FdtSetProp (mFdtImage, Node, "compatible", NewList, ListSize + sizeof (NewProp)); FreePool (NewList); if (Retval != 0) { @@ -217,7 +218,7 @@ CleanMemoryNodes ( INTN Node; INT32 Retval; - Node = fdt_path_offset (mFdtImage, "/memory"); + Node = FdtPathOffset (mFdtImage, "/memory"); if (Node < 0) { return EFI_SUCCESS; } @@ -227,7 +228,7 @@ CleanMemoryNodes ( * OS go crazy and ignore the UEFI map. */ DEBUG ((DEBUG_INFO, "Removing bogus /memory\n")); - Retval = fdt_del_node (mFdtImage, Node); + Retval = FdtDelNode (mFdtImage, Node); if (Retval != 0) { DEBUG ((DEBUG_ERROR, "Failed to remove /memory\n")); return EFI_NOT_FOUND; @@ -246,15 +247,15 @@ SanitizePSCI ( INTN Root; INT32 Retval; - Root = fdt_path_offset (mFdtImage, "/"); + Root = FdtPathOffset (mFdtImage, "/"); ASSERT (Root >= 0); if (Root < 0) { return EFI_NOT_FOUND; } - Node = fdt_path_offset (mFdtImage, "/psci"); + Node = FdtPathOffset (mFdtImage, "/psci"); if (Node < 0) { - Node = fdt_add_subnode (mFdtImage, Root, "psci"); + Node = FdtAddSubnode (mFdtImage, Root, "psci"); } ASSERT (Node >= 0); @@ -263,33 +264,33 @@ SanitizePSCI ( return EFI_NOT_FOUND; } - Retval = fdt_setprop_string (mFdtImage, Node, "compatible", "arm,psci-1.0"); + Retval = FdtSetPropString (mFdtImage, Node, "compatible", "arm,psci-1.0"); if (Retval != 0) { DEBUG ((DEBUG_ERROR, "Couldn't set /psci compatible property\n")); return EFI_NOT_FOUND; } - Retval = fdt_setprop_string (mFdtImage, Node, "method", "smc"); + Retval = FdtSetPropString (mFdtImage, Node, "method", "smc"); if (Retval != 0) { DEBUG ((DEBUG_ERROR, "Couldn't set /psci method property\n")); return EFI_NOT_FOUND; } - Root = fdt_path_offset (mFdtImage, "/cpus"); + Root = FdtPathOffset (mFdtImage, "/cpus"); if (Root < 0) { DEBUG ((DEBUG_ERROR, "No CPUs to update with PSCI enable-method?\n")); return EFI_NOT_FOUND; } - Node = fdt_first_subnode (mFdtImage, Root); + Node = FdtFirstSubnode (mFdtImage, Root); while (Node >= 0) { - if (fdt_setprop_string (mFdtImage, Node, "enable-method", "psci") != 0) { + if (FdtSetPropString (mFdtImage, Node, "enable-method", "psci") != 0) { DEBUG ((DEBUG_ERROR, "Failed to update enable-method for a CPU\n")); return EFI_NOT_FOUND; } - fdt_delprop (mFdtImage, Node, "cpu-release-addr"); - Node = fdt_next_subnode (mFdtImage, Node); + FdtDelProp (mFdtImage, Node, "cpu-release-addr"); + Node = FdtNextSubnode (mFdtImage, Node); } return EFI_SUCCESS; } @@ -307,7 +308,7 @@ CleanSimpleFramebuffer ( * Should look for nodes by kind and remove aliases * by matching against device. */ - Node = fdt_path_offset (mFdtImage, "display0"); + Node = FdtPathOffset (mFdtImage, "display0"); if (Node < 0) { return EFI_SUCCESS; } @@ -317,19 +318,19 @@ CleanSimpleFramebuffer ( * doesn't reflect the framebuffer built by UEFI. */ DEBUG ((DEBUG_INFO, "Removing bogus display0\n")); - Retval = fdt_del_node (mFdtImage, Node); + Retval = FdtDelNode (mFdtImage, Node); if (Retval != 0) { DEBUG ((DEBUG_ERROR, "Failed to remove display0\n")); return EFI_NOT_FOUND; } - Node = fdt_path_offset (mFdtImage, "/aliases"); + Node = FdtPathOffset (mFdtImage, "/aliases"); if (Node < 0) { DEBUG ((DEBUG_ERROR, "Couldn't find /aliases to remove display0\n")); return EFI_NOT_FOUND; } - Retval = fdt_delprop (mFdtImage, Node, "display0"); + Retval = FdtDelProp (mFdtImage, Node, "display0"); if (Retval != 0) { DEBUG ((DEBUG_ERROR, "Failed to remove display0 alias\n")); return EFI_NOT_FOUND; @@ -349,20 +350,20 @@ SyncPcie ( INTN Retval; UINT32 DmaRanges[7]; - Node = fdt_path_offset (mFdtImage, "pcie0"); + Node = FdtPathOffset (mFdtImage, "pcie0"); if (Node < 0) { DEBUG ((DEBUG_ERROR, "%a: failed to locate 'pcie0' alias\n", __func__)); return EFI_NOT_FOUND; } // non translated 32-bit DMA window with a limit of 0xc0000000 - DmaRanges[0] = cpu_to_fdt32 (0x02000000); - DmaRanges[1] = cpu_to_fdt32 (0x00000000); - DmaRanges[2] = cpu_to_fdt32 (0x00000000); - DmaRanges[3] = cpu_to_fdt32 (0x00000000); - DmaRanges[4] = cpu_to_fdt32 (0x00000000); - DmaRanges[5] = cpu_to_fdt32 (0x00000000); - DmaRanges[6] = cpu_to_fdt32 (0xc0000000); + DmaRanges[0] = CpuToFdt32 (0x02000000); + DmaRanges[1] = CpuToFdt32 (0x00000000); + DmaRanges[2] = CpuToFdt32 (0x00000000); + DmaRanges[3] = CpuToFdt32 (0x00000000); + DmaRanges[4] = CpuToFdt32 (0x00000000); + DmaRanges[5] = CpuToFdt32 (0x00000000); + DmaRanges[6] = CpuToFdt32 (0xc0000000); DEBUG ((DEBUG_INFO, "%a: Updating PCIe dma-ranges\n", __func__)); @@ -371,7 +372,7 @@ SyncPcie ( * around a failure in Linux and OpenBSD to reset the PCIe/XHCI correctly * when in DT mode. */ - Retval = fdt_setprop (mFdtImage, Node, "dma-ranges", + Retval = FdtSetProp (mFdtImage, Node, "dma-ranges", DmaRanges, sizeof DmaRanges); if (Retval != 0) { DEBUG ((DEBUG_ERROR, "%a: failed to locate PCIe 'dma-ranges' property (%d)\n", @@ -380,20 +381,20 @@ SyncPcie ( } // move the MMIO window too - DmaRanges[0] = cpu_to_fdt32 (0x02000000); // non prefetchable 32-bit - DmaRanges[1] = cpu_to_fdt32 (FixedPcdGet64 (PcdBcm27xxPciBusMmioAdr) >> 32); // bus addr @ 0x0f8000000 - DmaRanges[2] = cpu_to_fdt32 (FixedPcdGet64 (PcdBcm27xxPciBusMmioAdr) & MAX_UINT32); - DmaRanges[3] = cpu_to_fdt32 (FixedPcdGet64 (PcdBcm27xxPciCpuMmioAdr) >> 32); // cpu addr @ 0x600000000 - DmaRanges[4] = cpu_to_fdt32 (FixedPcdGet64 (PcdBcm27xxPciCpuMmioAdr) & MAX_UINT32); - DmaRanges[5] = cpu_to_fdt32 (0x00000000); - DmaRanges[6] = cpu_to_fdt32 (FixedPcdGet32 (PcdBcm27xxPciBusMmioLen) + 1); // len = 0x4000 0000 + DmaRanges[0] = CpuToFdt32 (0x02000000); // non prefetchable 32-bit + DmaRanges[1] = CpuToFdt32 (FixedPcdGet64 (PcdBcm27xxPciBusMmioAdr) >> 32); // bus addr @ 0x0f8000000 + DmaRanges[2] = CpuToFdt32 (FixedPcdGet64 (PcdBcm27xxPciBusMmioAdr) & MAX_UINT32); + DmaRanges[3] = CpuToFdt32 (FixedPcdGet64 (PcdBcm27xxPciCpuMmioAdr) >> 32); // cpu addr @ 0x600000000 + DmaRanges[4] = CpuToFdt32 (FixedPcdGet64 (PcdBcm27xxPciCpuMmioAdr) & MAX_UINT32); + DmaRanges[5] = CpuToFdt32 (0x00000000); + DmaRanges[6] = CpuToFdt32 (FixedPcdGet32 (PcdBcm27xxPciBusMmioLen) + 1); // len = 0x4000 0000 DEBUG ((DEBUG_INFO, "%a: Updating PCIe ranges\n", __func__)); /* * Match ranges (BAR/MMIO) with the EDK2+ACPI setup we are using. */ - Retval = fdt_setprop (mFdtImage, Node, "ranges", + Retval = FdtSetProp (mFdtImage, Node, "ranges", DmaRanges, sizeof DmaRanges); if (Retval != 0) { DEBUG ((DEBUG_ERROR, "%a: failed to locate PCIe MMIO 'ranges' property (%d)\n", @@ -418,12 +419,12 @@ SyncPcie ( * triggering the mailbox by removing the node. */ - Node = fdt_path_offset (mFdtImage, "/scb/pcie@7d500000/pci"); + Node = FdtPathOffset (mFdtImage, "/scb/pcie@7d500000/pci"); if (Node < 0) { // This can happen on CM4/etc which doesn't have an onboard XHCI DEBUG ((DEBUG_INFO, "%a: failed to locate /scb/pcie@7d500000/pci\n", __func__)); } else { - Retval = fdt_del_node (mFdtImage, Node); + Retval = FdtDelNode (mFdtImage, Node); if (Retval != 0) { DEBUG ((DEBUG_ERROR, "Failed to remove /scb/pcie@7d500000/pci\n")); return EFI_NOT_FOUND; @@ -483,7 +484,7 @@ FdtDxeInitialize ( return EFI_NOT_FOUND; } - FdtSize = fdt_totalsize (FdtImage); + FdtSize = FdtTotalSize (FdtImage); DEBUG ((DEBUG_INFO, "Devicetree passed via config.txt (0x%lx bytes)\n", FdtSize)); /* @@ -497,9 +498,9 @@ FdtDxeInitialize ( goto out; } - Retval = fdt_open_into (FdtImage, mFdtImage, FdtSize); + Retval = FdtOpenInto (FdtImage, mFdtImage, FdtSize); if (Retval != 0) { - DEBUG ((DEBUG_ERROR, "fdt_open_into failed: %d\n", Retval)); + DEBUG ((DEBUG_ERROR, "FdtOpenInto failed: %d\n", Retval)); goto out; } diff --git a/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf b/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf index 1ea2fe40..bcc29318 100644 --- a/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf +++ b/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf @@ -27,6 +27,7 @@ [LibraryClasses] BaseLib + BaseMemoryLib BoardInfoLib BoardRevisionHelperLib DebugLib diff --git a/Platform/RaspberryPi/Library/BoardInfoLib/BoardInfoLib.c b/Platform/RaspberryPi/Library/BoardInfoLib/BoardInfoLib.c index 514ad7fe..197cb97c 100644 --- a/Platform/RaspberryPi/Library/BoardInfoLib/BoardInfoLib.c +++ b/Platform/RaspberryPi/Library/BoardInfoLib/BoardInfoLib.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include EFI_STATUS EFIAPI @@ -27,19 +27,19 @@ BoardInfoGetRevisionCode ( return EFI_NOT_FOUND; } - Node = fdt_path_offset (Fdt, "/system"); + Node = FdtPathOffset (Fdt, "/system"); if (Node < 0) { return EFI_NOT_FOUND; } - Property = fdt_getprop (Fdt, Node, "linux,revision", &Length); + Property = FdtGetProp (Fdt, Node, "linux,revision", &Length); if (Property == NULL) { return EFI_NOT_FOUND; } else if (Length != sizeof (UINT32)) { return EFI_BAD_BUFFER_SIZE; } - *RevisionCode = fdt32_to_cpu (*(UINT32 *) Property); + *RevisionCode = Fdt32ToCpu (*(UINT32 *) Property); return EFI_SUCCESS; } @@ -60,19 +60,19 @@ BoardInfoGetSerialNumber ( return EFI_NOT_FOUND; } - Node = fdt_path_offset (Fdt, "/system"); + Node = FdtPathOffset (Fdt, "/system"); if (Node < 0) { return EFI_NOT_FOUND; } - Property = fdt_getprop (Fdt, Node, "linux,serial", &Length); + Property = FdtGetProp (Fdt, Node, "linux,serial", &Length); if (Property == NULL) { return EFI_NOT_FOUND; } else if (Length != sizeof (UINT64)) { return EFI_BAD_BUFFER_SIZE; } - *SerialNumber = fdt64_to_cpu (*(UINT64 *) Property); + *SerialNumber = Fdt64ToCpu (*(UINT64 *) Property); return EFI_SUCCESS; } diff --git a/Platform/RaspberryPi/Library/FdtPlatformLib/FdtPlatformLib.c b/Platform/RaspberryPi/Library/FdtPlatformLib/FdtPlatformLib.c index 7d148c01..af14df8c 100644 --- a/Platform/RaspberryPi/Library/FdtPlatformLib/FdtPlatformLib.c +++ b/Platform/RaspberryPi/Library/FdtPlatformLib/FdtPlatformLib.c @@ -8,7 +8,7 @@ #include #include -#include +#include VOID * EFIAPI @@ -21,10 +21,10 @@ FdtPlatformGetBase ( Fdt = (VOID *)(UINTN) PcdGet32 (PcdFdtBaseAddress); - FdtError = fdt_check_header (Fdt); + FdtError = FdtCheckHeader (Fdt); if (FdtError != 0) { DEBUG ((DEBUG_ERROR, "%a: Bad/missing FDT at 0x%p! Ret=%a\n", - __func__, Fdt, fdt_strerror (FdtError))); + __func__, Fdt, FdtStrerror (FdtError))); ASSERT (FALSE); return NULL; } diff --git a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf index d39210c7..ecb03d8c 100644 --- a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf +++ b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf @@ -25,6 +25,7 @@ ArmPkg/ArmPkg.dec ArmPlatformPkg/ArmPlatformPkg.dec Platform/RaspberryPi/RaspberryPi.dec + UefiCpuPkg/UefiCpuPkg.dec [LibraryClasses] DebugLib diff --git a/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf index 9e26828b..57280db9 100644 --- a/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -52,7 +52,6 @@ UefiLib [FeaturePcd] - gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate diff --git a/Platform/RaspberryPi/RPi5/RPi5.dsc b/Platform/RaspberryPi/RPi5/RPi5.dsc index 1cd72681..9b8a09f1 100644 --- a/Platform/RaspberryPi/RPi5/RPi5.dsc +++ b/Platform/RaspberryPi/RPi5/RPi5.dsc @@ -274,8 +274,6 @@ ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe. # It could be set FALSE to save size. gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE - gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|FALSE - gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport|FALSE [PcdsFixedAtBuild.common] gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000 @@ -384,7 +382,6 @@ [PcdsFeatureFlag.common] gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE - gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|FALSE gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol|TRUE [PcdsFixedAtBuild.common] @@ -574,10 +571,7 @@ ArmPkg/Drivers/ArmGicDxe/ArmGicV2Dxe.inf Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxe.inf - Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf { - - FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf # Map to deprecated library for this module only - } + Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf ArmPkg/Drivers/TimerDxe/TimerDxe.inf MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf MdeModulePkg/Universal/EbcDxe/EbcDxe.inf -- 2.51.2