]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmbeddedPkg/FdtPlatformDxe: Add 'setfdt' EFI Shell command
authorRonald Cron <Ronald.Cron@arm.com>
Wed, 25 Feb 2015 19:34:07 +0000 (19:34 +0000)
committeroliviermartin <oliviermartin@Edk2>
Wed, 25 Feb 2015 19:34:07 +0000 (19:34 +0000)
The 'setfdt' EFI Shell command allows to define a new FDT
as the prefered one for development purposes. It allows to
trigger the run of the FDT installation process as well.

Please refer to the README.txt file for more comprehensive
description.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ronald Cron <Ronald.Cron@arm.com>
Reviewed-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16934 6f19259b-4bc3-4df7-8a09-765794883524

EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatform.c
EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.inf
EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.uni [new file with mode: 0644]
EmbeddedPkg/Drivers/FdtPlatformDxe/README.txt
EmbeddedPkg/EmbeddedPkg.dsc

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
index ea45baa2e3a0c46a5de890cf1453690439f7dece..64d14a26e748cdfd3f6a102302a4cfb30cda9d23 100644 (file)
@@ -15,6 +15,7 @@
 [Defines]\r
   INF_VERSION     = 0x00010006\r
   BASE_NAME       = FdtPlatformDxe\r
+  MODULE_UNI_FILE = FdtPlatformDxe.uni\r
   FILE_GUID       = 6e9a4c69-57c6-4fcd-b083-4f2c3bdb6051\r
   MODULE_TYPE     = DXE_DRIVER\r
   VERSION_STRING  = 0.1\r
 \r
 [Sources.common]\r
   FdtPlatform.c\r
+  FdtPlatformDxe.uni\r
 \r
 [Packages]\r
   EmbeddedPkg/EmbeddedPkg.dec\r
   ArmPkg/ArmPkg.dec\r
   MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
 \r
 [LibraryClasses]\r
   UefiDriverEntryPoint\r
   DebugLib\r
   UefiBootServicesTableLib\r
   UefiRuntimeServicesTableLib\r
+  HiiLib\r
+  ShellLib\r
 \r
 [Protocols]\r
+  gEfiDevicePathToTextProtocolGuid\r
   gEfiDevicePathFromTextProtocolGuid\r
+  gEfiShellDynamicCommandProtocolGuid\r
 \r
 [Guids]\r
   gEfiEndOfDxeEventGroupGuid\r
diff --git a/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.uni b/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.uni
new file mode 100644 (file)
index 0000000..2f8ddc2
Binary files /dev/null and b/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.uni differ
index bf61e661af8bae8558c256a827881479d2cf89ba..a87e7db28d78edf587e1450a3df426964f0382e0 100644 (file)
@@ -15,7 +15,7 @@
 The purpose of the FdtPlatformDxe UEFI driver is to install the Flat Device
 Tree (FDT) of the platform the UEFI frimware is running on into the UEFI
 Configuration Table. The FDT is identified within the UEFI Configuration
-Table by the "gFdtTableGuid" GUID defined in EmbeddedPkg.dec.
+Table by the "gFdtTableGuid" GUID defined in "EmbeddedPkg.dec".
 
 Once installed, an UEFI application or OS boot loader can get from the UEFI
 Configuration Table the FDT of the platform from the "gFdtTableGuid" GUID.
@@ -48,3 +48,25 @@ driver tries to install it using the device path defined by the UEFI variable
 "Fdt". If the variable does not exist or the installation using the device path
 defined by the UEFI variable fails then the installation proceeds as described
 above.
+
+Furthermore and again for development purposes only, if the feature PCD
+"PcdOverridePlatformFdt" is equal to TRUE, the current driver provides the EFI
+Shell command "setfdt" to define the location of the FDT by the mean of an EFI
+Shell file path (like "fs2:\boot\fdt.dtb") or a device path.
+
+If the path passed in to the command is a valid EFI Shell file path, the
+command translates it into the corresponding device path and stores that
+device path in the "Fdt" UEFI variable asking for the variable to be non
+volatile.
+
+If the path passed in to the command is not recognised as a valid EFI
+Shell device path, the command handles it as device path and stored
+in the "Fdt" UEFI variable as it is.
+
+Finally, the "-i" option of the "setfdt" command allows to trigger the FDT
+installation process. The installation process is completed when the command
+returns. The command can be invoked with the "-i" option only and in that
+case the "Fdt" UEFI variable is not updated and the command just runs the
+FDT installation process. If the command is invoked with the "-i" option and
+an EFI Shell file path then first the "Fdt" UEFI variable is updated accordingly
+and then the FDT installation process is run.
index 8a58b9b1217c068d0b39fc87a26a3e49f65f0bef..fc42fe5128bf6e44d77b55826349c46fc9e7c5c3 100644 (file)
   AcpiLib|EmbeddedPkg/Library/AcpiLib/AcpiLib.inf\r
   FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf\r
 \r
+  # Shell libraries\r
+  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf\r
+  FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf\r
+  SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf\r
+\r
   # Networking Requirements\r
   NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf\r
   HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf\r