]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatform.c
EmbeddedPkg/FdtPlatformDxe: Add 'setfdt' EFI Shell command
[mirror_edk2.git] / EmbeddedPkg / Drivers / FdtPlatformDxe / FdtPlatform.c
index 8608fcf5ba271280be6e20be55021c272802a680..e777b0f7f7ed5c15073568b7b711ca3f2d6b94bd 100644 (file)
 #include <Library/PcdLib.h>\r
 #include <Library/DevicePathLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
-\r
+#include <Library/HiiLib.h>\r
 #include <Library/BdsLib.h>\r
+#include <Library/ShellLib.h>\r
 \r
+#include <Protocol/DevicePathToText.h>\r
 #include <Protocol/DevicePathFromText.h>\r
 #include <Protocol/DevicePath.h>\r
+#include <Protocol/EfiShell.h>\r
+#include <Protocol/EfiShellDynamicCommand.h>\r
 \r
 #include <Guid/EventGroup.h>\r
 #include <Guid/Fdt.h>\r
@@ -34,6 +38,7 @@
 //\r
 // Internal types\r
 //\r
+\r
 STATIC VOID OnEndOfDxe (\r
   IN EFI_EVENT  Event,\r
   IN VOID       *Context\r
@@ -45,6 +50,48 @@ STATIC EFI_STATUS InstallFdt (
   IN CONST CHAR16*  TextDevicePath\r
   );\r
 \r
+STATIC SHELL_STATUS EFIAPI ShellDynCmdSetFdtHandler (\r
+  IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL  *This,\r
+  IN EFI_SYSTEM_TABLE                    *SystemTable,\r
+  IN EFI_SHELL_PARAMETERS_PROTOCOL       *ShellParameters,\r
+  IN EFI_SHELL_PROTOCOL                  *Shell\r
+  );\r
+\r
+STATIC CHAR16* EFIAPI ShellDynCmdSetFdtGetHelp (\r
+  IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL  *This,\r
+  IN CONST CHAR8                         *Language\r
+  );\r
+\r
+STATIC SHELL_STATUS UpdateFdtTextDevicePath (\r
+  IN EFI_SHELL_PROTOCOL  *Shell,\r
+  IN CONST CHAR16        *FilePath\r
+  );\r
+\r
+STATIC SHELL_STATUS EfiCodeToShellCode (\r
+  IN EFI_STATUS  Status\r
+  );\r
+\r
+//\r
+// Internal variables\r
+//\r
+\r
+STATIC CONST EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mShellDynCmdProtocolSetFdt = {\r
+    L"setfdt",                // Name of the command\r
+    ShellDynCmdSetFdtHandler, // Handler\r
+    ShellDynCmdSetFdtGetHelp  // GetHelp\r
+};\r
+\r
+STATIC CONST EFI_GUID  mFdtPlatformDxeHiiGuid = {\r
+                         0x8afa7610, 0x62b1, 0x46aa,\r
+                         {0xb5, 0x34, 0xc3, 0xde, 0xff, 0x39, 0x77, 0x8c}\r
+                         };\r
+STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
+  {L"-i", TypeFlag },\r
+  {NULL , TypeMax  }\r
+};\r
+\r
+STATIC EFI_HANDLE  mFdtPlatformDxeHiiHandle;\r
+\r
 /**\r
   Main entry point of the FDT platform driver.\r
 \r
@@ -53,7 +100,10 @@ STATIC EFI_STATUS InstallFdt (
   @param[in]  *SystemTable  A pointer to the EFI System table.\r
 \r
   @retval  EFI_SUCCESS           The driver was initialized.\r
-  @retval  EFI_OUT_OF_RESOURCES  The "End of DXE" event could not be allocated.\r
+  @retval  EFI_OUT_OF_RESOURCES  The "End of DXE" event could not be allocated or\r
+                                 there was not enough memory in pool to install\r
+                                 the Shell Dynamic Command protocol.\r
+  @retval  EFI_LOAD_ERROR        Unable to add the HII package.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -80,6 +130,57 @@ FdtPlatformEntryPoint (
                   &EndOfDxeEvent\r
                   );\r
 \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
+    //\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
+    // only the English language is actually supported. The strings to register\r
+    // are stored in the "FdtPlatformDxeStrings[]" array. This array is\r
+    // built by the building process from the "*.uni" file associated to\r
+    // the present driver (cf. FdtPlatfromDxe.inf). Examine your Build\r
+    // folder under your package's DEBUG folder and you will find the array\r
+    // defined in a xxxStrDefs.h file.\r
+    //\r
+    mFdtPlatformDxeHiiHandle = HiiAddPackages (\r
+                                 &mFdtPlatformDxeHiiGuid,\r
+                                 ImageHandle,\r
+                                 FdtPlatformDxeStrings,\r
+                                 NULL\r
+                                 );\r
+\r
+    if (mFdtPlatformDxeHiiHandle != NULL) {\r
+      Status = gBS->InstallMultipleProtocolInterfaces (\r
+                      &ImageHandle,\r
+                      &gEfiShellDynamicCommandProtocolGuid,\r
+                      &mShellDynCmdProtocolSetFdt,\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 \"setfdt\" EFI Shell command - %r \n",\r
+        Status\r
+        ));\r
+    }\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -352,8 +453,6 @@ Error :
   return Status;\r
 }\r
 \r
-=======\r
-\r
 /**\r
   This is the shell command "setfdt" handler function. This function handles\r
   the command when it is invoked in the shell.\r
@@ -739,4 +838,3 @@ EfiCodeToShellCode (
 \r
   return ShellStatus;\r
 }\r
->>>>>>> 4ac4fed... EmbeddedPkg/FdtPlatformDxe: Fix typo issue\r