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