Revision: 15908 http://sourceforge.net/p/edk2/code/15908 Author: oliviermartin Date: 2014-08-26 10:21:48 +0000 (Tue, 26 Aug 2014) Log Message: ----------- EmbeddedPkg/FdtLib: Added support to load FDT from Firmware Volume
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Olivier Martin <olivier.mar...@arm.com> Modified Paths: -------------- trunk/edk2/EmbeddedPkg/Include/libfdt_env.h trunk/edk2/EmbeddedPkg/Library/FdtLib/FdtConfigurationTable.c trunk/edk2/EmbeddedPkg/Library/FdtLib/FdtLib.inf Modified: trunk/edk2/EmbeddedPkg/Include/libfdt_env.h =================================================================== --- trunk/edk2/EmbeddedPkg/Include/libfdt_env.h 2014-08-26 10:20:47 UTC (rev 15907) +++ trunk/edk2/EmbeddedPkg/Include/libfdt_env.h 2014-08-26 10:21:48 UTC (rev 15908) @@ -94,4 +94,19 @@ IN CONST CHAR16* FileName ); +/** + Load and Install FDT from Firmware Volume + + @param Filename Guid of the FDT blob to load from firmware volume + + @return EFI_SUCCESS Fdt Blob was successfully installed into the configuration table + from firmware volume + @return EFI_NOT_FOUND Failed to locate the file in firmware volume + @return EFI_OUT_OF_RESOURCES Failed to allocate memory to contain the blob +**/ +EFI_STATUS +InstallFdtFromFv ( + IN CONST EFI_GUID *FileName + ); + #endif /* _LIBFDT_ENV_H */ Modified: trunk/edk2/EmbeddedPkg/Library/FdtLib/FdtConfigurationTable.c =================================================================== --- trunk/edk2/EmbeddedPkg/Library/FdtLib/FdtConfigurationTable.c 2014-08-26 10:20:47 UTC (rev 15907) +++ trunk/edk2/EmbeddedPkg/Library/FdtLib/FdtConfigurationTable.c 2014-08-26 10:21:48 UTC (rev 15908) @@ -12,12 +12,13 @@ * **/ -#include <Uefi.h> +#include <PiDxe.h> #include <Library/DebugLib.h> #include <Library/MemoryAllocationLib.h> #include <Library/UefiBootServicesTableLib.h> #include <Protocol/DevicePath.h> +#include <Protocol/FirmwareVolume2.h> #include <Protocol/SimpleFileSystem.h> #include <Guid/Fdt.h> @@ -176,3 +177,103 @@ Fs->Close (Fs); return Status; } + +/** + Load and Install FDT from Firmware Volume + + @param Filename Guid of the FDT blob to load from firmware volume + + @return EFI_SUCCESS Fdt Blob was successfully installed into the configuration table + from firmware volume + @return EFI_NOT_FOUND Fail to locate the file in firmware volume + @return EFI_OUT_OF_RESOURCES Fail to allocate memory to contain the blob +**/ +EFI_STATUS +InstallFdtFromFv ( + IN CONST EFI_GUID *FileName + ) +{ + EFI_STATUS Status; + EFI_HANDLE *HandleBuffer; + UINTN NumberOfHandles; + UINT32 FvStatus; + UINTN Index; + EFI_FIRMWARE_VOLUME2_PROTOCOL *FvInstance; + INTN SectionInstance; + UINTN FdtSize; + VOID* FdtBlob; + EFI_PHYSICAL_ADDRESS FdtBase; + + FvStatus = 0; + SectionInstance = 0; + + // Locate all the Firmware Volume protocols. + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiFirmwareVolume2ProtocolGuid, + NULL, + &NumberOfHandles, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // Looking for FV that contains the FDT blob + for (Index = 0; Index < NumberOfHandles; Index++) { + // + // Get the protocol on this handle + // This should not fail because of LocateHandleBuffer + // + Status = gBS->HandleProtocol ( + HandleBuffer[Index], + &gEfiFirmwareVolume2ProtocolGuid, + (VOID**) &FvInstance + ); + if (EFI_ERROR (Status)) { + goto FREE_HANDLE_BUFFER; + } + + while (Status == EFI_SUCCESS) { + // FdtBlob must be allocated by ReadSection + FdtBlob = NULL; + + // See if it contains the FDT file + Status = FvInstance->ReadSection ( + FvInstance, + FileName, + EFI_SECTION_RAW, + SectionInstance, + &FdtBlob, + &FdtSize, + &FvStatus + ); + if (!EFI_ERROR (Status)) { + // When the FDT blob is attached to the Configuration Table it is recommended to load it as Runtime Service Data + // to prevent the kernel to overwrite its data + Status = gBS->AllocatePages (AllocateAnyPages, EfiRuntimeServicesData, EFI_SIZE_TO_PAGES (FdtSize), &FdtBase); + if (EFI_ERROR (Status)) { + goto FREE_HANDLE_BUFFER; + } + + // Copy the FDT to the Runtime memory + gBS->CopyMem ((VOID*)(UINTN)FdtBase, FdtBlob, FdtSize); + // Free the buffer allocated by FvInstance->ReadSection() + gBS->FreePool (FdtBlob); + + // Install the FDT as part of the UEFI Configuration Table + Status = InstallFdtIntoConfigurationTable ((VOID*)(UINTN)FdtBase, FdtSize); + if (EFI_ERROR (Status)) { + gBS->FreePages (FdtBase, EFI_SIZE_TO_PAGES (FdtSize)); + } + break; + } + } + } + +FREE_HANDLE_BUFFER: + // Free any allocated buffers + gBS->FreePool (HandleBuffer); + + return Status; +} Modified: trunk/edk2/EmbeddedPkg/Library/FdtLib/FdtLib.inf =================================================================== --- trunk/edk2/EmbeddedPkg/Library/FdtLib/FdtLib.inf 2014-08-26 10:20:47 UTC (rev 15907) +++ trunk/edk2/EmbeddedPkg/Library/FdtLib/FdtLib.inf 2014-08-26 10:21:48 UTC (rev 15908) @@ -44,6 +44,7 @@ [Protocols] gEfiDevicePathProtocolGuid gEfiSimpleFileSystemProtocolGuid + gEfiFirmwareVolume2ProtocolGuid [Guids] gEfiFileInfoGuid This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/ _______________________________________________ edk2-commits mailing list edk2-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-commits