From 3c1e53ce8f52429067a6664576e0bd5611d4e764 Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Wed, 25 Feb 2015 19:34:07 +0000 Subject: EmbeddedPkg/FdtPlatformDxe: Add 'setfdt' EFI Shell command 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 Reviewed-by: Olivier Martin git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16934 6f19259b-4bc3-4df7-8a09-765794883524 --- EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatform.c | 108 ++++++++++++++++++++- .../Drivers/FdtPlatformDxe/FdtPlatformDxe.inf | 8 ++ .../Drivers/FdtPlatformDxe/FdtPlatformDxe.uni | Bin 0 -> 6674 bytes EmbeddedPkg/Drivers/FdtPlatformDxe/README.txt | 24 ++++- EmbeddedPkg/EmbeddedPkg.dsc | 5 + 5 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.uni diff --git a/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatform.c b/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatform.c index 8608fcf5ba..e777b0f7f7 100644 --- a/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatform.c +++ b/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatform.c @@ -20,11 +20,15 @@ #include #include #include - +#include #include +#include +#include #include #include +#include +#include #include #include @@ -34,6 +38,7 @@ // // Internal types // + STATIC VOID OnEndOfDxe ( IN EFI_EVENT Event, IN VOID *Context @@ -45,6 +50,48 @@ STATIC EFI_STATUS InstallFdt ( IN CONST CHAR16* TextDevicePath ); +STATIC SHELL_STATUS EFIAPI ShellDynCmdSetFdtHandler ( + IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This, + IN EFI_SYSTEM_TABLE *SystemTable, + IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, + IN EFI_SHELL_PROTOCOL *Shell + ); + +STATIC CHAR16* EFIAPI ShellDynCmdSetFdtGetHelp ( + IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This, + IN CONST CHAR8 *Language + ); + +STATIC SHELL_STATUS UpdateFdtTextDevicePath ( + IN EFI_SHELL_PROTOCOL *Shell, + IN CONST CHAR16 *FilePath + ); + +STATIC SHELL_STATUS EfiCodeToShellCode ( + IN EFI_STATUS Status + ); + +// +// Internal variables +// + +STATIC CONST EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mShellDynCmdProtocolSetFdt = { + L"setfdt", // Name of the command + ShellDynCmdSetFdtHandler, // Handler + ShellDynCmdSetFdtGetHelp // GetHelp +}; + +STATIC CONST EFI_GUID mFdtPlatformDxeHiiGuid = { + 0x8afa7610, 0x62b1, 0x46aa, + {0xb5, 0x34, 0xc3, 0xde, 0xff, 0x39, 0x77, 0x8c} + }; +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-i", TypeFlag }, + {NULL , TypeMax } +}; + +STATIC EFI_HANDLE mFdtPlatformDxeHiiHandle; + /** Main entry point of the FDT platform driver. @@ -53,7 +100,10 @@ STATIC EFI_STATUS InstallFdt ( @param[in] *SystemTable A pointer to the EFI System table. @retval EFI_SUCCESS The driver was initialized. - @retval EFI_OUT_OF_RESOURCES The "End of DXE" event could not be allocated. + @retval EFI_OUT_OF_RESOURCES The "End of DXE" event could not be allocated or + there was not enough memory in pool to install + the Shell Dynamic Command protocol. + @retval EFI_LOAD_ERROR Unable to add the HII package. **/ EFI_STATUS @@ -80,6 +130,57 @@ FdtPlatformEntryPoint ( &EndOfDxeEvent ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // If the development features are enabled, install the dynamic shell + // command "setfdt" to be able to define a device path for the FDT + // that has precedence over the device paths defined by + // "PcdFdtDevicePaths". + // + + if (FeaturePcdGet (PcdOverridePlatformFdt)) { + // + // Register the strings for the user interface in the HII Database. + // This shows the way to the multi-language support, even if + // only the English language is actually supported. The strings to register + // are stored in the "FdtPlatformDxeStrings[]" array. This array is + // built by the building process from the "*.uni" file associated to + // the present driver (cf. FdtPlatfromDxe.inf). Examine your Build + // folder under your package's DEBUG folder and you will find the array + // defined in a xxxStrDefs.h file. + // + mFdtPlatformDxeHiiHandle = HiiAddPackages ( + &mFdtPlatformDxeHiiGuid, + ImageHandle, + FdtPlatformDxeStrings, + NULL + ); + + if (mFdtPlatformDxeHiiHandle != NULL) { + Status = gBS->InstallMultipleProtocolInterfaces ( + &ImageHandle, + &gEfiShellDynamicCommandProtocolGuid, + &mShellDynCmdProtocolSetFdt, + NULL + ); + if (EFI_ERROR (Status)) { + HiiRemovePackages (mFdtPlatformDxeHiiHandle); + } + } else { + Status = EFI_LOAD_ERROR; + } + if (EFI_ERROR (Status)) { + DEBUG (( + EFI_D_WARN, + "Unable to install \"setfdt\" EFI Shell command - %r \n", + Status + )); + } + } + return Status; } @@ -352,8 +453,6 @@ Error : return Status; } -======= - /** This is the shell command "setfdt" handler function. This function handles the command when it is invoked in the shell. @@ -739,4 +838,3 @@ EfiCodeToShellCode ( return ShellStatus; } ->>>>>>> 4ac4fed... EmbeddedPkg/FdtPlatformDxe: Fix typo issue diff --git a/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.inf b/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.inf index ea45baa2e3..64d14a26e7 100644 --- a/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.inf +++ b/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.inf @@ -15,6 +15,7 @@ [Defines] INF_VERSION = 0x00010006 BASE_NAME = FdtPlatformDxe + MODULE_UNI_FILE = FdtPlatformDxe.uni FILE_GUID = 6e9a4c69-57c6-4fcd-b083-4f2c3bdb6051 MODULE_TYPE = DXE_DRIVER VERSION_STRING = 0.1 @@ -22,11 +23,14 @@ [Sources.common] FdtPlatform.c + FdtPlatformDxe.uni [Packages] EmbeddedPkg/EmbeddedPkg.dec ArmPkg/ArmPkg.dec MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ShellPkg/ShellPkg.dec [LibraryClasses] UefiDriverEntryPoint @@ -36,9 +40,13 @@ DebugLib UefiBootServicesTableLib UefiRuntimeServicesTableLib + HiiLib + ShellLib [Protocols] + gEfiDevicePathToTextProtocolGuid gEfiDevicePathFromTextProtocolGuid + gEfiShellDynamicCommandProtocolGuid [Guids] gEfiEndOfDxeEventGroupGuid diff --git a/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.uni b/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.uni new file mode 100644 index 0000000000..2f8ddc272a Binary files /dev/null and b/EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.uni differ diff --git a/EmbeddedPkg/Drivers/FdtPlatformDxe/README.txt b/EmbeddedPkg/Drivers/FdtPlatformDxe/README.txt index bf61e661af..a87e7db28d 100644 --- a/EmbeddedPkg/Drivers/FdtPlatformDxe/README.txt +++ b/EmbeddedPkg/Drivers/FdtPlatformDxe/README.txt @@ -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. diff --git a/EmbeddedPkg/EmbeddedPkg.dsc b/EmbeddedPkg/EmbeddedPkg.dsc index 8a58b9b121..fc42fe5128 100644 --- a/EmbeddedPkg/EmbeddedPkg.dsc +++ b/EmbeddedPkg/EmbeddedPkg.dsc @@ -101,6 +101,11 @@ AcpiLib|EmbeddedPkg/Library/AcpiLib/AcpiLib.inf FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf + # Shell libraries + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + # Networking Requirements NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf -- cgit v1.2.3