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 <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
Ard Biesheuvel 2017-03-29 12:05:01 +01:00
parent 4c725c8959
commit 12c71010b8
2 changed files with 17 additions and 19 deletions

View File

@ -15,7 +15,7 @@
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/DevicePathLib.h> #include <Library/DevicePathLib.h>
#include <Library/DxeServicesLib.h> #include <Library/DtPlatformDtbLoaderLib.h>
#include <Library/HiiLib.h> #include <Library/HiiLib.h>
#include <Library/MemoryAllocationLib.h> #include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
@ -114,17 +114,13 @@ DtPlatformDxeEntryPoint (
UINTN BufferSize; UINTN BufferSize;
VOID *Dtb; VOID *Dtb;
UINTN DtbSize; UINTN DtbSize;
VOID *DtbCopy;
//
// Check whether a DTB blob is included in the firmware image.
//
Dtb = NULL; Dtb = NULL;
Status = GetSectionFromAnyFv (&gDtPlatformDefaultDtbFileGuid, Status = DtPlatformLoadDtb (&Dtb, &DtbSize);
EFI_SECTION_RAW, 0, &Dtb, &DtbSize);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "%a: no DTB blob found, defaulting to ACPI\n", DEBUG ((DEBUG_WARN,
__FUNCTION__)); "%a: no DTB blob could be loaded, defaulting to ACPI (Status == %r)\n",
__FUNCTION__, Status));
DtAcpiPref.Pref = DT_ACPI_SELECT_ACPI; DtAcpiPref.Pref = DT_ACPI_SELECT_ACPI;
} else { } else {
// //
@ -157,7 +153,7 @@ DtPlatformDxeEntryPoint (
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (DtAcpiPref), &DtAcpiPref); sizeof (DtAcpiPref), &DtAcpiPref);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto FreeDtb;
} }
} }
@ -172,23 +168,18 @@ DtPlatformDxeEntryPoint (
DEBUG ((DEBUG_ERROR, DEBUG ((DEBUG_ERROR,
"%a: failed to install gEdkiiPlatformHasAcpiGuid as a protocol\n", "%a: failed to install gEdkiiPlatformHasAcpiGuid as a protocol\n",
__FUNCTION__)); __FUNCTION__));
return Status; goto FreeDtb;
} }
} else if (DtAcpiPref.Pref == DT_ACPI_SELECT_DT) { } else if (DtAcpiPref.Pref == DT_ACPI_SELECT_DT) {
// //
// DT was selected: copy the blob into newly allocated memory and install // DT was selected: copy the blob into newly allocated memory and install
// a reference to it as the FDT configuration table. // a reference to it as the FDT configuration table.
// //
DtbCopy = AllocateCopyPool (DtbSize, Dtb); Status = gBS->InstallConfigurationTable (&gFdtTableGuid, Dtb);
if (DtbCopy == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Status = gBS->InstallConfigurationTable (&gFdtTableGuid, DtbCopy);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to install FDT configuration table\n", DEBUG ((DEBUG_ERROR, "%a: failed to install FDT configuration table\n",
__FUNCTION__)); __FUNCTION__));
FreePool (DtbCopy); goto FreeDtb;
return Status;
} }
} else { } else {
ASSERT (FALSE); ASSERT (FALSE);
@ -210,4 +201,11 @@ DtPlatformDxeEntryPoint (
// installed in that case. // installed in that case.
// //
return InstallHiiPages (); return InstallHiiPages ();
FreeDtb:
if (Dtb != NULL) {
FreePool (Dtb);
}
return Status;
} }

View File

@ -40,7 +40,7 @@
[LibraryClasses] [LibraryClasses]
BaseLib BaseLib
DebugLib DebugLib
DxeServicesLib DtPlatformDtbLoaderLib
HiiLib HiiLib
MemoryAllocationLib MemoryAllocationLib
UefiBootServicesTableLib UefiBootServicesTableLib