]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatform.c
EmbeddedPkg: import Lan91x Ethernet controller driver
[mirror_edk2.git] / EmbeddedPkg / Drivers / FdtPlatformDxe / FdtPlatform.c
index 38f31005f3a59d790a23f9828fa823f5d079d98a..b4be2a078991f0deccf1aa94f1b98ca6c00aa95f 100644 (file)
@@ -20,8 +20,6 @@
 \r
 #include <Protocol/DevicePath.h>\r
 \r
-#include <libfdt.h>\r
-\r
 //\r
 // Internal variables\r
 //\r
@@ -32,6 +30,12 @@ STATIC CONST EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mShellDynCmdProtocolSetFdt = {
     ShellDynCmdSetFdtGetHelp  // GetHelp\r
 };\r
 \r
+STATIC CONST EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mShellDynCmdProtocolDumpFdt = {\r
+    L"dumpfdt",                // Name of the command\r
+    ShellDynCmdDumpFdtHandler, // Handler\r
+    ShellDynCmdDumpFdtGetHelp  // GetHelp\r
+};\r
+\r
 STATIC CONST EFI_GUID  mFdtPlatformDxeHiiGuid = {\r
                          0x8afa7610, 0x62b1, 0x46aa,\r
                          {0xb5, 0x34, 0xc3, 0xde, 0xff, 0x39, 0x77, 0x8c}\r
@@ -90,15 +94,16 @@ InstallFdt (
     goto Error;\r
   }\r
 \r
-  // Check the FDT header is valid. We only make this check in DEBUG mode in\r
-  // case the FDT header change on production device and this ASSERT() becomes\r
-  // not valid.\r
-  ASSERT (fdt_check_header ((VOID*)(UINTN)FdtBlobBase) == 0);\r
-\r
   //\r
-  // Ensure the Size of the Device Tree is smaller than the size of the read file\r
+  // Ensure that the FDT header is valid and that the Size of the Device Tree\r
+  // is smaller than the size of the read file\r
   //\r
-  ASSERT ((UINTN)fdt_totalsize ((VOID*)(UINTN)FdtBlobBase) <= FdtBlobSize);\r
+  if (fdt_check_header ((VOID*)(UINTN)FdtBlobBase) != 0 ||\r
+      (UINTN)fdt_totalsize ((VOID*)(UINTN)FdtBlobBase) > FdtBlobSize) {\r
+    DEBUG ((EFI_D_ERROR, "InstallFdt() - loaded FDT binary image seems corrupt\n"));\r
+    Status = EFI_LOAD_ERROR;\r
+    goto Error;\r
+  }\r
 \r
   //\r
   // Store the FDT as Runtime Service Data to prevent the Kernel from\r
@@ -159,23 +164,14 @@ FdtPlatformEntryPoint (
   )\r
 {\r
   EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle;\r
 \r
   //\r
   // Install the Device Tree from its expected location\r
   //\r
   Status = RunFdtInstallation (NULL);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
 \r
-  //\r
-  // If the development features are enabled, install the dynamic shell\r
-  // command "setfdt" to be able to define a device path for the FDT\r
-  // that has precedence over the device paths defined by\r
-  // "PcdFdtDevicePaths".\r
-  //\r
-\r
-  if (FeaturePcdGet (PcdOverridePlatformFdt)) {\r
+  if (FeaturePcdGet (PcdOverridePlatformFdt) || FeaturePcdGet (PcdDumpFdtShellCommand)) {\r
     //\r
     // Register the strings for the user interface in the HII Database.\r
     // This shows the way to the multi-language support, even if\r
@@ -192,10 +188,22 @@ FdtPlatformEntryPoint (
                                  FdtPlatformDxeStrings,\r
                                  NULL\r
                                  );\r
+  }\r
 \r
+  //\r
+  // If the development features are enabled, install the dynamic shell\r
+  // command "setfdt" to be able to define a device path for the FDT\r
+  // that has precedence over the device paths defined by\r
+  // "PcdFdtDevicePaths".\r
+  //\r
+\r
+  if (FeaturePcdGet (PcdOverridePlatformFdt)) {\r
     if (mFdtPlatformDxeHiiHandle != NULL) {\r
+      // We install dynamic EFI command on separate handles as we cannot register\r
+      // more than one protocol of the same protocol interface on the same handle.\r
+      Handle = NULL;\r
       Status = gBS->InstallMultipleProtocolInterfaces (\r
-                      &ImageHandle,\r
+                      &Handle,\r
                       &gEfiShellDynamicCommandProtocolGuid,\r
                       &mShellDynCmdProtocolSetFdt,\r
                       NULL\r
@@ -215,6 +223,32 @@ FdtPlatformEntryPoint (
     }\r
   }\r
 \r
+  if (FeaturePcdGet (PcdDumpFdtShellCommand)) {\r
+    if (mFdtPlatformDxeHiiHandle != NULL) {\r
+      // We install dynamic EFI command on separate handles as we cannot register\r
+      // more than one protocol of the same protocol interface on the same handle.\r
+      Handle = NULL;\r
+      Status = gBS->InstallMultipleProtocolInterfaces (\r
+                      &Handle,\r
+                      &gEfiShellDynamicCommandProtocolGuid,\r
+                      &mShellDynCmdProtocolDumpFdt,\r
+                      NULL\r
+                      );\r
+      if (EFI_ERROR (Status)) {\r
+        HiiRemovePackages (mFdtPlatformDxeHiiHandle);\r
+      }\r
+    } else {\r
+      Status = EFI_LOAD_ERROR;\r
+    }\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((\r
+        EFI_D_WARN,\r
+        "Unable to install \"dumpfdt\" EFI Shell command - %r \n",\r
+        Status\r
+        ));\r
+    }\r
+  }\r
+\r
   return Status;\r
 }\r
 \r