From 12c71010b84ac910972f738eb5fd0dfd7b688413 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Wed, 29 Mar 2017 12:05:01 +0100 Subject: [PATCH] EmbeddedPkg/DtPlatformDxe: load platform DTB via new library To give platforms some room to decide which DTB is suitable and where to load it from, load the DTB image indirectly via the new DtPlatformDtbLoaderLib library class. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- .../Drivers/DtPlatformDxe/DtPlatformDxe.c | 34 +++++++++---------- .../Drivers/DtPlatformDxe/DtPlatformDxe.inf | 2 +- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.c b/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.c index 5778633b49..1014be2281 100644 --- a/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.c +++ b/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -114,17 +114,13 @@ DtPlatformDxeEntryPoint ( UINTN BufferSize; VOID *Dtb; UINTN DtbSize; - VOID *DtbCopy; - // - // Check whether a DTB blob is included in the firmware image. - // Dtb = NULL; - Status = GetSectionFromAnyFv (&gDtPlatformDefaultDtbFileGuid, - EFI_SECTION_RAW, 0, &Dtb, &DtbSize); + Status = DtPlatformLoadDtb (&Dtb, &DtbSize); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_WARN, "%a: no DTB blob found, defaulting to ACPI\n", - __FUNCTION__)); + DEBUG ((DEBUG_WARN, + "%a: no DTB blob could be loaded, defaulting to ACPI (Status == %r)\n", + __FUNCTION__, Status)); DtAcpiPref.Pref = DT_ACPI_SELECT_ACPI; } else { // @@ -157,7 +153,7 @@ DtPlatformDxeEntryPoint ( EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, sizeof (DtAcpiPref), &DtAcpiPref); if (EFI_ERROR (Status)) { - return Status; + goto FreeDtb; } } @@ -172,23 +168,18 @@ DtPlatformDxeEntryPoint ( DEBUG ((DEBUG_ERROR, "%a: failed to install gEdkiiPlatformHasAcpiGuid as a protocol\n", __FUNCTION__)); - return Status; + goto FreeDtb; } } else if (DtAcpiPref.Pref == DT_ACPI_SELECT_DT) { // // DT was selected: copy the blob into newly allocated memory and install // a reference to it as the FDT configuration table. // - DtbCopy = AllocateCopyPool (DtbSize, Dtb); - if (DtbCopy == NULL) { - return EFI_OUT_OF_RESOURCES; - } - Status = gBS->InstallConfigurationTable (&gFdtTableGuid, DtbCopy); + Status = gBS->InstallConfigurationTable (&gFdtTableGuid, Dtb); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: failed to install FDT configuration table\n", __FUNCTION__)); - FreePool (DtbCopy); - return Status; + goto FreeDtb; } } else { ASSERT (FALSE); @@ -210,4 +201,11 @@ DtPlatformDxeEntryPoint ( // installed in that case. // return InstallHiiPages (); + +FreeDtb: + if (Dtb != NULL) { + FreePool (Dtb); + } + + return Status; } diff --git a/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.inf b/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.inf index b73877a608..45dfd9088b 100644 --- a/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.inf +++ b/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.inf @@ -40,7 +40,7 @@ [LibraryClasses] BaseLib DebugLib - DxeServicesLib + DtPlatformDtbLoaderLib HiiLib MemoryAllocationLib UefiBootServicesTableLib -- 2.39.2