]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmbeddedPkg/DtPlatformDxe: load platform DTB via new library
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 29 Mar 2017 11:05:01 +0000 (12:05 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 31 Mar 2017 12:19:29 +0000 (13:19 +0100)
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>
EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.c
EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.inf

index 5778633b4985f0dc864a09ffe6c7410f94dff548..1014be2281d428de82fff139c5d2fde883eb4ba6 100644 (file)
@@ -15,7 +15,7 @@
 #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
@@ -114,17 +114,13 @@ DtPlatformDxeEntryPoint (
   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
@@ -157,7 +153,7 @@ DtPlatformDxeEntryPoint (
                     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
@@ -172,23 +168,18 @@ DtPlatformDxeEntryPoint (
       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
@@ -210,4 +201,11 @@ DtPlatformDxeEntryPoint (
   // 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
index b73877a6086be744de8f46b1dad7b93df2bd85eb..45dfd9088bf0a6feba83cd1fa64592f1d0d4cf16 100644 (file)
@@ -40,7 +40,7 @@
 [LibraryClasses]\r
   BaseLib\r
   DebugLib\r
-  DxeServicesLib\r
+  DtPlatformDtbLoaderLib\r
   HiiLib\r
   MemoryAllocationLib\r
   UefiBootServicesTableLib\r