From 4ba49616416ad8ce57c61d0bb0a80c7b5dbf434b Mon Sep 17 00:00:00 2001 From: jcarsey Date: Fri, 12 Nov 2010 19:40:21 +0000 Subject: Adding Driver1 profile commands to the UEFI Shell 2.0. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11050 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Library/UefiShellDriver1CommandsLib/Connect.c | 334 +++++++++++++++++ .../Library/UefiShellDriver1CommandsLib/DevTree.c | 235 ++++++++++++ .../Library/UefiShellDriver1CommandsLib/Devices.c | 229 ++++++++++++ ShellPkg/Library/UefiShellDriver1CommandsLib/Dh.c | 414 +++++++++++++++++++++ .../UefiShellDriver1CommandsLib/Disconnect.c | 177 +++++++++ .../Library/UefiShellDriver1CommandsLib/Drivers.c | 252 +++++++++++++ .../Library/UefiShellDriver1CommandsLib/DrvCfg.c | 406 ++++++++++++++++++++ .../Library/UefiShellDriver1CommandsLib/DrvDiag.c | 412 ++++++++++++++++++++ .../Library/UefiShellDriver1CommandsLib/OpenInfo.c | 202 ++++++++++ .../UefiShellDriver1CommandsLib/Reconnect.c | 31 ++ .../UefiShellDriver1CommandsLib.c | 99 +++++ .../UefiShellDriver1CommandsLib.h | 201 ++++++++++ .../UefiShellDriver1CommandsLib.inf | 73 ++++ .../UefiShellDriver1CommandsLib.uni | Bin 0 -> 60700 bytes .../Library/UefiShellDriver1CommandsLib/Unload.c | 220 +++++++++++ 15 files changed, 3285 insertions(+) create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/DevTree.c create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/Dh.c create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/Drivers.c create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/DrvDiag.c create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/Reconnect.c create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.c create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.h create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.uni create mode 100644 ShellPkg/Library/UefiShellDriver1CommandsLib/Unload.c (limited to 'ShellPkg') diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c new file mode 100644 index 0000000000..47818f7d88 --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c @@ -0,0 +1,334 @@ +/** @file + Main file for connect shell Driver1 function. + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +/** +**/ +EFI_STATUS +EFIAPI +ConnectControllers ( + IN CONST EFI_HANDLE ControllerHandle OPTIONAL, + IN CONST EFI_HANDLE DriverHandle OPTIONAL, + IN CONST BOOLEAN Recursive, + IN CONST BOOLEAN Output, + IN CONST BOOLEAN AlwaysOutput + ) +{ + EFI_STATUS Status; + EFI_STATUS Status2; + EFI_HANDLE *ControllerHandleList; + EFI_HANDLE *DriverHandleList; + EFI_HANDLE *HandleWalker; + + ControllerHandleList = NULL; + Status = EFI_NOT_FOUND; + Status2 = EFI_NOT_FOUND; + + // + // If we have a single handle to connect make that a 'list' + // + if (DriverHandle == NULL) { + DriverHandleList = NULL; + } else { + DriverHandleList = AllocatePool(2*sizeof(EFI_HANDLE)); + if (DriverHandleList == NULL) { + return (EFI_OUT_OF_RESOURCES); + } + DriverHandleList[0] = DriverHandle; + DriverHandleList[1] = NULL; + } + + // + // do we connect all controllers (with a loop) or a single one... + // This is where we call the gBS->ConnectController function. + // + if (ControllerHandle == NULL) { + ControllerHandleList = GetHandleListByProtocol(&gEfiDevicePathProtocolGuid); + for (HandleWalker = ControllerHandleList + ; HandleWalker != NULL && *HandleWalker != NULL + ; HandleWalker++ + ){ + Status = gBS->ConnectController(*HandleWalker, DriverHandleList, NULL, Recursive); + if (!EFI_ERROR(Status)) { + Status2 = EFI_SUCCESS; + } + if ((Output && !EFI_ERROR(Status)) || AlwaysOutput) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_HANDLE_RESULT), gShellDriver1HiiHandle, L"Connect", ConvertHandleToHandleIndex(*HandleWalker), Status); + } + } + } else { + Status = gBS->ConnectController(ControllerHandle, DriverHandleList, NULL, Recursive); + if (!EFI_ERROR(Status)) { + Status2 = EFI_SUCCESS; + } + if ((Output && !EFI_ERROR(Status)) || AlwaysOutput) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_HANDLE_RESULT), gShellDriver1HiiHandle, L"Connect", ConvertHandleToHandleIndex(ControllerHandle), Status); + } + } + + // + // Free any memory we allocated. + // + if (ControllerHandleList != NULL) { + FreePool(ControllerHandleList); + } + if (DriverHandleList != NULL) { + FreePool(DriverHandleList); + } + return (Status2); +} + +EFI_STATUS +EFIAPI +ConnectFromDevPaths ( + IN CONST CHAR16 *Key + ) +{ + EFI_DEVICE_PATH_PROTOCOL *DevPath; + EFI_DEVICE_PATH_PROTOCOL *DevPathWalker; + UINTN Length; + EFI_HANDLE Handle; + EFI_STATUS Status; + + DevPath = NULL; + Length = 0; + + // + // Get the DevicePath buffer from the variable... + // + Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath); + if (Status == EFI_BUFFER_TOO_SMALL) { + DevPath = AllocatePool(Length); + Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath); + } + + Status = EFI_NOT_FOUND; + // + // walk the list of devices and connect them + // + for (DevPathWalker = DevPath + ; DevPathWalker < (DevPath + Length) && EFI_ERROR(Status) && DevPath != NULL + ; DevPathWalker += GetDevicePathSize(DevPathWalker) + ){ + // + // get the correct handle from a given device path + // + if ((StrCmp(Key, L"ConInDev") == 0) + ||(StrCmp(Key, L"ConIn") == 0) + ){ + Status = gBS->LocateDevicePath((EFI_GUID*)&gEfiConsoleInDeviceGuid, &DevPathWalker, &Handle); + if (!EFI_ERROR(Status)) { + Status = ConnectControllers(NULL, Handle, FALSE, TRUE, FALSE); + } + } else if ((StrCmp(Key, L"ConOutDev") == 0) + || (StrCmp(Key, L"ConErrDev") == 0) + || (StrCmp(Key, L"ConOut") == 0) + || (StrCmp(Key, L"ConErr") == 0) + ){ + Status = gBS->LocateDevicePath((EFI_GUID*)&gEfiConsoleOutDeviceGuid, &DevPathWalker, &Handle); + if (!EFI_ERROR(Status)) { + Status = ConnectControllers(NULL, Handle, FALSE, TRUE, FALSE); + } + } + } + + if (DevPath != NULL) { + FreePool(DevPath); + } + return (Status); +} + +EFI_STATUS +EFIAPI +ConvertAndConnectControllers ( + IN CONST CHAR16 *StringHandle1 OPTIONAL, + IN CONST CHAR16 *StringHandle2 OPTIONAL, + IN CONST BOOLEAN Recursive, + IN CONST BOOLEAN Output + ) +{ + EFI_HANDLE Handle1; + EFI_HANDLE Handle2; + + // + // Convert the command line parameters to HANDLES. They must be in HEX according to spec. + // + if (StringHandle1 != NULL) { + Handle1 = ConvertHandleIndexToHandle(StrHexToUintn(StringHandle1)); + } else { + Handle1 = NULL; + } + if (StringHandle2 != NULL) { + Handle2 = ConvertHandleIndexToHandle(StrHexToUintn(StringHandle2)); + } else { + Handle2 = NULL; + } + + // + // if only one is NULL verify it's the proper one... + // + if ( (Handle1 == NULL && Handle2 != NULL) + || (Handle1 != NULL && Handle2 == NULL) + ){ + // + // Figure out which one should be NULL and move the handle to the right place. + // If Handle1 is NULL then test Handle2 and vise versa. + // The one that DOES has driver binding must be Handle2 + // + if (Handle1 == NULL) { + if (EFI_ERROR(gBS->OpenProtocol(Handle2, &gEfiDriverBindingProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + // swap + Handle1 = Handle2; + Handle2 = NULL; + } else { + // We're all good... + } + } else { + if (EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiDriverBindingProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + // We're all good... + } else { + // swap + Handle2 = Handle1; + Handle1 = NULL; + } + } + } + + return (ConnectControllers(Handle1, Handle2, Recursive, Output, FALSE)); +} + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-c", TypeFlag}, + {L"-r", TypeFlag}, + {NULL, TypeMax} + }; + +/** + Function for 'connect' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunConnect ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + CONST CHAR16 *Param1; + CONST CHAR16 *Param2; + UINTN Count; + + ShellStatus = SHELL_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize(); + ASSERT_EFI_ERROR(Status); + + Status = CommandInit(); + ASSERT_EFI_ERROR(Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR(Status)) { + if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { + // + // if more than 2 'value' parameters (plus the name one) or either -r or -c with any value parameters we have too many parameters + // + if ((ShellCommandLineGetCount(Package) > 3) + ||((ShellCommandLineGetFlag(Package, L"-r") || ShellCommandLineGetFlag(Package, L"-c")) && ShellCommandLineGetCount(Package)>1) + ||(ShellCommandLineGetFlag(Package, L"-r") && ShellCommandLineGetFlag(Package, L"-c") ) + ){ + // + // error for too many parameters + // + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetFlag(Package, L"-c")) { + // + // do the conin and conout from EFI variables + // if the first fails dont 'loose' the error + // + Status = ConnectFromDevPaths(L"ConInDev"); + if (EFI_ERROR(Status)) { + ConnectFromDevPaths(L"ConOutDev"); + } else { + Status = ConnectFromDevPaths(L"ConOutDev"); + } + if (EFI_ERROR(Status)) { + ConnectFromDevPaths(L"ConErrDev"); + } else { + Status = ConnectFromDevPaths(L"ConErrDev"); + } + if (EFI_ERROR(Status)) { + ConnectFromDevPaths(L"ConErr"); + } else { + Status = ConnectFromDevPaths(L"ConErr"); + } + if (EFI_ERROR(Status)) { + ConnectFromDevPaths(L"ConIn"); + } else { + Status = ConnectFromDevPaths(L"ConIn"); + } + if (EFI_ERROR(Status)) { + ConnectFromDevPaths(L"ConOut"); + } else { + Status = ConnectFromDevPaths(L"ConOut"); + } + if (EFI_ERROR(Status)) { + ShellStatus = SHELL_DEVICE_ERROR; + } + } else { + // + // 0, 1, or 2 specific handles and possibly recursive + // + Param1 = ShellCommandLineGetRawValue(Package, 1); + Param2 = ShellCommandLineGetRawValue(Package, 2); + Count = ShellCommandLineGetCount(Package); + if (Param1 != NULL && ConvertHandleIndexToHandle(StrHexToUintn(Param1)) == NULL){ + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param1); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (Param2 != NULL && ConvertHandleIndexToHandle(StrHexToUintn(Param2)) == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param2); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = ConvertAndConnectControllers(Param1, Param2, ShellCommandLineGetFlag(Package, L"-r"), (BOOLEAN)(Count!=0)); + if (EFI_ERROR(Status)) { + ShellStatus = SHELL_DEVICE_ERROR; + } + } + } + + ShellCommandLineFreeVarList (Package); + } + return (ShellStatus); +} + diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/DevTree.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/DevTree.c new file mode 100644 index 0000000000..8a5c79b8cb --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/DevTree.c @@ -0,0 +1,235 @@ +/** @file + Main file for DevTree shell Driver1 function. + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-d", TypeFlag}, + {L"-l", TypeValue}, + {NULL, TypeMax} + }; + +SHELL_STATUS +EFIAPI +DoDevTreeForHandle( + IN CONST EFI_HANDLE TheHandle, + IN CONST CHAR8 *Lang OPTIONAL, + IN CONST BOOLEAN UseDevPaths, + IN CONST UINTN IndentCharCount, + IN CONST CHAR16 *HiiString + ) +{ + SHELL_STATUS ShellStatus; + EFI_STATUS Status; + CHAR16 *FormatString; + CHAR16 *Name; + EFI_HANDLE *ChildHandleBuffer; + UINTN ChildCount; + UINTN LoopVar; + + Status = EFI_SUCCESS; + ShellStatus = SHELL_SUCCESS; + Name = NULL; + ChildHandleBuffer = NULL; + ChildCount = 0; + + ASSERT(TheHandle != NULL); + // + // We want controller handles. they will not have LoadedImage or DriverBinding (or others...) + // + Status = gBS->OpenProtocol ( + TheHandle, + &gEfiDriverBindingProtocolGuid, + NULL, + NULL, + NULL, + EFI_OPEN_PROTOCOL_TEST_PROTOCOL + ); + if (!EFI_ERROR (Status)) { + return SHELL_SUCCESS; + } + + Status = gBS->OpenProtocol ( + TheHandle, + &gEfiLoadedImageProtocolGuid, + NULL, + NULL, + NULL, + EFI_OPEN_PROTOCOL_TEST_PROTOCOL + ); + if (!EFI_ERROR (Status)) { + return SHELL_SUCCESS; + } + + // + // If we are at the begining then we want root handles they have no parents and do have device path. + // + if (IndentCharCount == 0) { + Status = gBS->OpenProtocol ( + TheHandle, + &gEfiDevicePathProtocolGuid, + NULL, + NULL, + NULL, + EFI_OPEN_PROTOCOL_TEST_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return SHELL_SUCCESS; + } + } + + FormatString = AllocateZeroPool(StrSize(HiiString) + (10)*sizeof(FormatString[0])); + + ASSERT(HiiString != NULL); + ASSERT(FormatString != NULL); + + // + // we generate the format string on the fly so that we can control the + // number of space characters that the first (empty) string has. this + // handles the indenting. + // + + UnicodeSPrint(FormatString, StrSize(HiiString) + (10)*sizeof(FormatString[0]), L"%%%ds %s", IndentCharCount, HiiString); + gEfiShellProtocol->GetDeviceName((EFI_HANDLE)TheHandle, !UseDevPaths?EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH:EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Lang, &Name); + // + // print out the information for ourselves + // + ShellPrintEx( + -1, + -1, + FormatString, + L"", + ConvertHandleToHandleIndex(TheHandle), + Name==NULL?L"Unknown":Name); + + FreePool(FormatString); + if (Name != NULL) { + FreePool(Name); + } + + // + // recurse on each child handle with IndentCharCount + 2 + // + ParseHandleDatabaseForChildControllers(TheHandle, &ChildCount, &ChildHandleBuffer); + for (LoopVar = 0 ; LoopVar < ChildCount && ShellStatus == SHELL_SUCCESS; LoopVar++){ + ShellStatus = DoDevTreeForHandle(ChildHandleBuffer[LoopVar], Lang, UseDevPaths, IndentCharCount+2, HiiString); + } + + if (ChildHandleBuffer != NULL) { + FreePool(ChildHandleBuffer); + } + + return (ShellStatus); +} + +/** + Function for 'devtree' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunDevTree ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + CHAR8 *Language; + CONST CHAR16 *Lang; + CHAR16 *HiiString; + UINTN LoopVar; + EFI_HANDLE TheHandle; + BOOLEAN FlagD; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + Language = NULL; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize(); + ASSERT_EFI_ERROR(Status); + + Status = CommandInit(); + ASSERT_EFI_ERROR(Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR(Status)) { + if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { + if (ShellCommandLineGetCount(Package) > 2) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); + ShellCommandLineFreeVarList (Package); + return (SHELL_INVALID_PARAMETER); + } + Lang = ShellCommandLineGetValue(Package, L"-l"); + if (Lang != NULL) { + Language = AllocateZeroPool(StrSize(Lang)); + AsciiSPrint(Language, StrSize(Lang), "%S", Lang); + } else if (!ShellCommandLineGetFlag(Package, L"-l")){ + ASSERT(Language == NULL); +// Language = AllocateZeroPool(10); +// AsciiSPrint(Language, 10, "en-us"); + } else { + ASSERT(Language == NULL); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l"); + ShellCommandLineFreeVarList (Package); + return (SHELL_INVALID_PARAMETER); + } + FlagD = ShellCommandLineGetFlag(Package, L"-d"); + + Lang = ShellCommandLineGetRawValue(Package, 1); + HiiString = HiiGetString(gShellDriver1HiiHandle, STRING_TOKEN (STR_DEV_TREE_OUTPUT), Language); + + if (Lang == NULL) { + for (LoopVar = 1 ; ; LoopVar++){ + TheHandle = ConvertHandleIndexToHandle(LoopVar); + if (TheHandle == NULL){ + break; + } + ShellStatus = DoDevTreeForHandle(TheHandle, Language, FlagD, 0, HiiString); + } + } else { + if (!ShellIsHexOrDecimalNumber(Lang, TRUE, FALSE) || ConvertHandleIndexToHandle(StrHexToUintn(Lang)) == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Lang); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ShellStatus = DoDevTreeForHandle(ConvertHandleIndexToHandle(StrHexToUintn(Lang)), Language, FlagD, 0, HiiString); + } + } + + if (HiiString != NULL) { + FreePool(HiiString); + } + SHELL_FREE_NON_NULL(Language); + ShellCommandLineFreeVarList (Package); + } + + return (ShellStatus); +} diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c new file mode 100644 index 0000000000..1af1773849 --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c @@ -0,0 +1,229 @@ +/** @file + Main file for devices shell Driver1 function. + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +EFI_STATUS +EFIAPI +GetDeviceHandleInfo ( + IN EFI_HANDLE TheHandle, + IN CHAR16 *Type, + IN BOOLEAN *Cfg, + IN BOOLEAN *Diag, + IN UINTN *Parents, + IN UINTN *Devices, + IN UINTN *Children, + OUT CHAR16 **Name, + IN CONST CHAR8 *Language + ) +{ + EFI_STATUS Status; + EFI_HANDLE *HandleBuffer; + UINTN Count; + + if (TheHandle == NULL + || Type == NULL + || Cfg == NULL + || Diag == NULL + || Parents == NULL + || Devices == NULL + || Children == NULL + || Name == NULL ) { + return (EFI_INVALID_PARAMETER); + } + + *Cfg = FALSE; + *Diag = FALSE; + *Children = 0; + *Parents = 0; + *Devices = 0; + *Type = L' '; + *Name = CHAR_NULL; + HandleBuffer = NULL; + Status = EFI_SUCCESS; + + gEfiShellProtocol->GetDeviceName(TheHandle, EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Language, Name); + + Status = ParseHandleDatabaseForChildControllers(TheHandle, Children, NULL); + if (!EFI_ERROR(Status)) { + Status = PARSE_HANDLE_DATABASE_PARENTS(TheHandle, Parents, NULL); + if (/*!EFI_ERROR(Status) && */Parents != NULL && Children != NULL) { + if (*Parents == 0) { + *Type = L'R'; + } else if (*Children > 0) { + *Type = L'B'; + } else { + *Type = L'D'; + } + } + } + Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS(TheHandle, Devices, &HandleBuffer); + if (!EFI_ERROR(Status) && Devices != NULL && HandleBuffer != NULL) { + for (Count = 0 ; Count < *Devices ; Count++) { + if (!EFI_ERROR(gBS->OpenProtocol(HandleBuffer[Count], &gEfiDriverConfigurationProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + *Cfg = TRUE; + } + if (!EFI_ERROR(gBS->OpenProtocol(HandleBuffer[Count], &gEfiDriverDiagnosticsProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + *Diag = TRUE; + } + if (!EFI_ERROR(gBS->OpenProtocol(HandleBuffer[Count], &gEfiDriverDiagnostics2ProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + *Diag = TRUE; + } + } + SHELL_FREE_NON_NULL(HandleBuffer); + } + + return (Status); +} + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-l", TypeValue}, + {NULL, TypeMax} + }; + +/** + Function for 'devices' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunDevices ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + CHAR8 *Language; + EFI_HANDLE *HandleList; + EFI_HANDLE *HandleListWalker; + CHAR16 Type; + BOOLEAN Cfg; + BOOLEAN Diag; + UINTN Parents; + UINTN Devices; + UINTN Children; + CHAR16 *Name; + CONST CHAR16 *Lang; + + ShellStatus = SHELL_SUCCESS; + Language = NULL; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize(); + ASSERT_EFI_ERROR(Status); + + Status = CommandInit(); + ASSERT_EFI_ERROR(Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR(Status)) { + if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { + // + // if more than 0 'value' parameters we have too many parameters + // + if (ShellCommandLineGetRawValue(Package, 1) != NULL){ + // + // error for too many parameters + // + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + // + // get the language if necessary + // + Lang = ShellCommandLineGetValue(Package, L"-l"); + if (Lang != NULL) { + Language = AllocateZeroPool(StrSize(Lang)); + AsciiSPrint(Language, StrSize(Lang), "%S", Lang); + } else if (!ShellCommandLineGetFlag(Package, L"-l")){ + ASSERT(Language == NULL); +// Language = AllocateZeroPool(10); +// AsciiSPrint(Language, 10, "en-us"); + } else { + ASSERT(Language == NULL); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l"); + ShellCommandLineFreeVarList (Package); + return (SHELL_INVALID_PARAMETER); + } + + + // + // Print Header + // + ShellPrintHiiEx(-1, -1, Language, STRING_TOKEN (STR_DEVICES_HEADER_LINES), gShellDriver1HiiHandle); + + // + // loop through each handle + // + HandleList = GetHandleListByProtocol(NULL); + ASSERT(HandleList != NULL); + for (HandleListWalker = HandleList + ; HandleListWalker != NULL && *HandleListWalker != NULL /*&& !EFI_ERROR(Status)*/ + ; HandleListWalker++ + ){ + + // + // get all the info on each handle + // + Name = NULL; + Status = GetDeviceHandleInfo(*HandleListWalker, &Type, &Cfg, &Diag, &Parents, &Devices, &Children, &Name, Language); + if (Parents != 0 || Devices != 0 || Children != 0) { + ShellPrintHiiEx( + -1, + -1, + Language, + STRING_TOKEN (STR_DEVICES_ITEM_LINE), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex(*HandleListWalker), + Type, + Cfg?L'X':L'-', + Diag?L'X':L'-', + Parents, + Devices, + Children, + Name!=NULL?Name:L""); + } + if (Name != NULL) { + FreePool(Name); + } + } + + if (HandleList != NULL) { + FreePool(HandleList); + } + + } + SHELL_FREE_NON_NULL(Language); + ShellCommandLineFreeVarList (Package); + } + return (ShellStatus); +} + diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Dh.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Dh.c new file mode 100644 index 0000000000..3d3f1b19f4 --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Dh.c @@ -0,0 +1,414 @@ +/** @file + Main file for Dh shell Driver1 function. + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-p", TypeValue}, + {L"-d", TypeFlag}, + {L"-v", TypeFlag}, + {L"-verbose", TypeFlag}, + {L"-sfo", TypeFlag}, + {L"-l", TypeValue}, + {NULL, TypeMax} + }; + +STATIC CONST EFI_GUID *UefiDriverModelProtocolsGuidArray[] = { + &gEfiDriverBindingProtocolGuid, + &gEfiPlatformDriverOverrideProtocolGuid, + &gEfiBusSpecificDriverOverrideProtocolGuid, + &gEfiDriverDiagnosticsProtocolGuid, + &gEfiDriverDiagnostics2ProtocolGuid, + &gEfiComponentNameProtocolGuid, + &gEfiComponentName2ProtocolGuid, + &gEfiPlatformToDriverConfigurationProtocolGuid, + &gEfiDriverSupportedEfiVersionProtocolGuid, + &gEfiDriverFamilyOverrideProtocolGuid, + &gEfiDriverHealthProtocolGuid, + &gEfiLoadedImageProtocolGuid, + NULL +}; + +BOOLEAN +EFIAPI +IsDriverProt ( + IN CONST EFI_GUID *Guid + ) +{ + CONST EFI_GUID **GuidWalker; + BOOLEAN GuidFound; + GuidFound = FALSE; + for (GuidWalker = UefiDriverModelProtocolsGuidArray + ; GuidWalker != NULL && *GuidWalker != NULL + ; GuidWalker++ + ){ + if (CompareGuid(*GuidWalker, Guid)) { + GuidFound = TRUE; + break; + } + } + return (GuidFound); +} + +CHAR16* +EFIAPI +GetProtocolInfoString( + IN CONST EFI_HANDLE TheHandle, + IN CONST CHAR8 *Language, + IN CONST CHAR16 *Seperator, + IN CONST BOOLEAN DriverInfo, + IN CONST BOOLEAN Verbose, + IN CONST BOOLEAN ExtraInfo + ) +{ + EFI_GUID **ProtocolGuidArray; + UINTN ArrayCount; + UINTN ProtocolIndex; + EFI_STATUS Status; + CHAR16 *RetVal; + UINTN Size; + CHAR16 *Temp; + + ProtocolGuidArray = NULL; + + Status = gBS->ProtocolsPerHandle ( + TheHandle, + &ProtocolGuidArray, + &ArrayCount + ); + if (!EFI_ERROR (Status)) { + RetVal = NULL; + Size = 0; + for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) { + Temp = GetStringNameFromGuid(ProtocolGuidArray[ProtocolIndex], Language); + if (Temp != NULL) { + ASSERT((RetVal == NULL && Size == 0) || (RetVal != NULL)); + if (Size != 0) { + StrnCatGrow(&RetVal, &Size, Seperator, 0); + } + StrnCatGrow(&RetVal, &Size, L"%H", 0); + StrnCatGrow(&RetVal, &Size, Temp, 0); + StrnCatGrow(&RetVal, &Size, L"%N", 0); + FreePool(Temp); + } + if (ExtraInfo) { + Temp = GetProtocolInformationDump(TheHandle, ProtocolGuidArray[ProtocolIndex], Verbose); + if (Temp != NULL) { + ASSERT((RetVal == NULL && Size == 0) || (RetVal != NULL)); + if (!Verbose) { + StrnCatGrow(&RetVal, &Size, L"(", 0); + StrnCatGrow(&RetVal, &Size, Temp, 0); + StrnCatGrow(&RetVal, &Size, L")", 0); + } else { + StrnCatGrow(&RetVal, &Size, Seperator, 0); + StrnCatGrow(&RetVal, &Size, Temp, 0); + } + FreePool(Temp); + } + } + } + } else { + return (NULL); + } + + if (ProtocolGuidArray != NULL) { + FreePool(ProtocolGuidArray); + } + ASSERT((RetVal == NULL && Size == 0) || (RetVal != NULL)); + StrnCatGrow(&RetVal, &Size, Seperator, 0); + return (RetVal); +} + +SHELL_STATUS +EFIAPI +DoDhByHandle( + IN CONST EFI_HANDLE TheHandle, + IN CONST BOOLEAN Verbose, + IN CONST BOOLEAN Sfo, + IN CONST CHAR8 *Language, + IN CONST BOOLEAN DriverInfo, + IN CONST BOOLEAN Multiple + ) +{ + CHAR16 *ProtocolInfoString; + SHELL_STATUS ShellStatus; + EFI_STATUS Status; + + Status = EFI_SUCCESS; + ShellStatus = SHELL_SUCCESS; + ProtocolInfoString = NULL; + + if (!Sfo) { + if (Multiple) { + ProtocolInfoString = GetProtocolInfoString(TheHandle, Language, L" ", DriverInfo, Verbose, TRUE); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex(TheHandle), + ProtocolInfoString==NULL?L"":ProtocolInfoString); + } else { + ProtocolInfoString = GetProtocolInfoString(TheHandle, Language, L"\r\n", DriverInfo, Verbose, TRUE); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_SINGLE), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex(TheHandle), + TheHandle, + ProtocolInfoString==NULL?L"":ProtocolInfoString); + } + } else { +//#string STR_DH_OUTPUT_SFO #language en-US "%s, %s, %s, %H%02x%N, %s, %s\r\n" + ProtocolInfoString = GetProtocolInfoString(TheHandle, Language, L";", DriverInfo, FALSE, FALSE); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_SFO), + gShellDriver1HiiHandle, + Multiple ?L"HandlesInfo":L"HandleInfo", + L"DriverName", + L"ControllerName", + ConvertHandleToHandleIndex(TheHandle), + L"DevPath", + ProtocolInfoString==NULL?L"":ProtocolInfoString); + + + } + + + if (ProtocolInfoString != NULL) { + FreePool(ProtocolInfoString); + } + return (ShellStatus); +} + +SHELL_STATUS +EFIAPI +DoDhForHandleList( + IN CONST EFI_HANDLE *HandleList, + IN CONST BOOLEAN Sfo, + IN CONST CHAR8 *Language, + IN CONST BOOLEAN DriverInfo + ) +{ + CONST EFI_HANDLE *HandleWalker; + SHELL_STATUS ShellStatus; + + ShellStatus = SHELL_SUCCESS; + + for (HandleWalker = HandleList ; HandleWalker != NULL && *HandleWalker != NULL && ShellStatus == SHELL_SUCCESS; HandleWalker++) { + ShellStatus = DoDhByHandle( + *HandleWalker, + FALSE, + Sfo, + Language, + DriverInfo, + TRUE + ); + } + return (ShellStatus); +} + +SHELL_STATUS +EFIAPI +DoDhForAll( + IN CONST BOOLEAN Sfo, + IN CONST CHAR8 *Language, + IN CONST BOOLEAN DriverInfo + ) +{ + EFI_HANDLE *HandleList; + SHELL_STATUS ShellStatus; + + HandleList = GetHandleListByProtocol(NULL); + + ShellStatus = DoDhForHandleList( + HandleList, + Sfo, + Language, + DriverInfo); + + FreePool(HandleList); + + return (ShellStatus); +} + +SHELL_STATUS +EFIAPI +DoDhByProtocol( + IN CONST CHAR16 *ProtocolName, + IN CONST BOOLEAN Sfo, + IN CONST CHAR8 *Language, + IN CONST BOOLEAN DriverInfo + ) +{ + EFI_GUID *Guid; + EFI_STATUS Status; + EFI_HANDLE *HandleList; + SHELL_STATUS ShellStatus; + + ASSERT(ProtocolName != NULL); + + Status = GetGuidFromStringName(ProtocolName, Language, &Guid); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DH_NO_GUID_FOUND), gShellDriver1HiiHandle, ProtocolName); + return (SHELL_INVALID_PARAMETER); + } + + HandleList = GetHandleListByProtocol(Guid); + + ShellStatus = DoDhForHandleList( + HandleList, + Sfo, + Language, + DriverInfo); + + SHELL_FREE_NON_NULL(HandleList); + + return (ShellStatus); +} + +SHELL_STATUS +EFIAPI +ShellCommandRunDh ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + CHAR8 *Language; + CONST CHAR16 *Lang; + CONST CHAR16 *Temp2; + BOOLEAN SfoMode; + BOOLEAN FlagD; + BOOLEAN Verbose; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + Language = NULL; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize(); + ASSERT_EFI_ERROR(Status); + + Status = CommandInit(); + ASSERT_EFI_ERROR(Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR(Status)) { + if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { + if (ShellCommandLineGetCount(Package) > 2) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); + ShellCommandLineFreeVarList (Package); + return (SHELL_INVALID_PARAMETER); + } + + Lang = ShellCommandLineGetValue(Package, L"-l"); + if (Lang != NULL) { + Language = AllocateZeroPool(StrSize(Lang)); + AsciiSPrint(Language, StrSize(Lang), "%S", Lang); + } else if (!ShellCommandLineGetFlag(Package, L"-l")){ + Language = AllocateZeroPool(10); + AsciiSPrint(Language, 10, "en-us"); + } else { + ASSERT(Language == NULL); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l"); + ShellCommandLineFreeVarList (Package); + return (SHELL_INVALID_PARAMETER); + } + + SfoMode = ShellCommandLineGetFlag(Package, L"-sfo"); + FlagD = ShellCommandLineGetFlag(Package, L"-d"); + if (ShellCommandLineGetFlag(Package, L"-v") || ShellCommandLineGetFlag(Package, L"-verbose")) { + Verbose = TRUE; + } else { + Verbose = FALSE; + } + + if (ShellCommandLineGetFlag(Package, L"-p")) { + if (ShellCommandLineGetCount(Package) > 1) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetValue(Package, L"-p") == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-p"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + // + // print by protocol + // + ShellStatus = DoDhByProtocol( + ShellCommandLineGetValue(Package, L"-p"), + SfoMode, + Lang==NULL?NULL:Language, + FlagD + ); + } + } else { + Temp2 = ShellCommandLineGetRawValue(Package, 1); + if (Temp2 == NULL) { + // + // Print everything + // + ShellStatus = DoDhForAll( + SfoMode, + Lang==NULL?NULL:Language, + FlagD + ); + } else { + if (!ShellIsHexOrDecimalNumber(Temp2, TRUE, FALSE) || ConvertHandleIndexToHandle(StrHexToUintn(Temp2)) == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Temp2); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + // + // print 1 handle + // + ShellStatus = DoDhByHandle( + ConvertHandleIndexToHandle(StrHexToUintn(Temp2)), + Verbose, + SfoMode, + Lang==NULL?NULL:Language, + FlagD, + FALSE + ); + } + } + } + + + ShellCommandLineFreeVarList (Package); + SHELL_FREE_NON_NULL(Language); + } + + return (ShellStatus); +} diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c new file mode 100644 index 0000000000..d10ce56806 --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c @@ -0,0 +1,177 @@ +/** @file + Main file for Disconnect shell Driver1 function. + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-r", TypeFlag}, + {NULL, TypeMax} + }; + +EFI_STATUS +EFIAPI +DisconnectAll( + VOID + ) +{ + // + // Stolen from UEFI 2.3 spec (May 2009 version) + // Pages 171/172 + // Removed gBS local definition + // + + // + // Disconnect All Handles Example + // The following example recusively disconnects all drivers from all + // controllers in a platform. + // + EFI_STATUS Status; +// EFI_BOOT_SERVICES *gBS; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + UINTN HandleIndex; + // + // Retrieve the list of all handles from the handle database + // + Status = gBS->LocateHandleBuffer ( + AllHandles, + NULL, + NULL, + &HandleCount, + &HandleBuffer + ); + if (!EFI_ERROR (Status)) { + for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) { + Status = gBS->DisconnectController ( + HandleBuffer[HandleIndex], + NULL, + NULL + ); + } + gBS->FreePool(HandleBuffer); + // + // end of stealing + // + } + return (EFI_SUCCESS); +} + +SHELL_STATUS +EFIAPI +ShellCommandRunDisconnect ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + CONST CHAR16 *Param1; + CONST CHAR16 *Param2; + CONST CHAR16 *Param3; + EFI_HANDLE Handle1; + EFI_HANDLE Handle2; + EFI_HANDLE Handle3; + + ShellStatus = SHELL_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize(); + ASSERT_EFI_ERROR(Status); + + Status = CommandInit(); + ASSERT_EFI_ERROR(Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR(Status)) { + if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { + if (ShellCommandLineGetFlag(Package, L"-r")){ + if (ShellCommandLineGetCount(Package) > 1){ + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount(Package) < 1) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = DisconnectAll(); + } + } else { + if (ShellCommandLineGetCount(Package) > 4){ + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount(Package) < 2) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + // + // must have between 1 and 3 handles passed in ... + // + Param1 = ShellCommandLineGetRawValue(Package, 1); + Param2 = ShellCommandLineGetRawValue(Package, 2); + Param3 = ShellCommandLineGetRawValue(Package, 3); + Handle1 = Param1!=NULL?ConvertHandleIndexToHandle(StrHexToUintn(Param1)):NULL; + Handle2 = Param2!=NULL?ConvertHandleIndexToHandle(StrHexToUintn(Param2)):NULL; + Handle3 = Param3!=NULL?ConvertHandleIndexToHandle(StrHexToUintn(Param3)):NULL; + + if (Param1 != NULL && Handle1 == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param1); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (Param2 != NULL && Handle2 == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param2); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (Param3 != NULL && Handle3 == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param3); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiDevicePathProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + ASSERT(Param1 != NULL); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_NOT), gShellDriver1HiiHandle, StrHexToUintn(Param1), L"controller handle"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (Handle2 != NULL && EFI_ERROR(gBS->OpenProtocol(Handle2, &gEfiDriverBindingProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + ASSERT(Param2 != NULL); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_NOT), gShellDriver1HiiHandle, StrHexToUintn(Param2), L"driver handle"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(Param1 != NULL); + ASSERT(Param2 != NULL); + ASSERT(Param3 != NULL); + Status = gBS->DisconnectController(Handle1, Handle2, Handle3); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_3P_RESULT), gShellDriver1HiiHandle, L"Disconnect", Handle1, Handle2, Handle3, Status); + } + } + } + } + if (ShellStatus == SHELL_SUCCESS) { + if (Status == EFI_SECURITY_VIOLATION) { + ShellStatus = SHELL_SECURITY_VIOLATION; + } else if (Status == EFI_INVALID_PARAMETER) { + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (EFI_ERROR(Status)) { + ShellStatus = SHELL_NOT_FOUND; + } + } + return (ShellStatus); +} diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Drivers.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Drivers.c new file mode 100644 index 0000000000..7784ca75d6 --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Drivers.c @@ -0,0 +1,252 @@ +/** @file + Main file for Drivers shell Driver1 function. + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-sfo", TypeFlag}, + {L"-l", TypeValue}, + {NULL, TypeMax} + }; + +CHAR16* +EFIAPI +GetDevicePathTextForHandle( + IN EFI_HANDLE TheHandle + ) +{ + EFI_STATUS Status; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath; + EFI_DEVICE_PATH_PROTOCOL *FinalPath; + CHAR16 *RetVal; + + FinalPath = NULL; + + Status = gBS->OpenProtocol ( + TheHandle, + &gEfiLoadedImageProtocolGuid, + (VOID**)&LoadedImage, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR (Status)) { + Status = gBS->OpenProtocol ( + LoadedImage->DeviceHandle, + &gEfiDevicePathProtocolGuid, + (VOID**)&ImageDevicePath, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR (Status)) { + FinalPath = AppendDevicePath (ImageDevicePath, LoadedImage->FilePath); + gBS->CloseProtocol( + LoadedImage->DeviceHandle, + &gEfiDevicePathProtocolGuid, + gImageHandle, + NULL); + } + gBS->CloseProtocol( + TheHandle, + &gEfiLoadedImageProtocolGuid, + gImageHandle, + NULL); + } + + if (FinalPath == NULL) { + return (NULL); + } + RetVal = gEfiShellProtocol->GetFilePathFromDevicePath(FinalPath); + if (RetVal == NULL) { + RetVal = gDevPathToText->ConvertDevicePathToText(FinalPath, TRUE, TRUE); + } + FreePool(FinalPath); + return (RetVal); +} + +BOOLEAN +EFIAPI +ReturnDriverConfig( + IN CONST EFI_HANDLE TheHandle + ) +{ + EFI_STATUS Status; + Status = gBS->OpenProtocol((EFI_HANDLE)TheHandle, &gEfiDriverConfigurationProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL); + if (EFI_ERROR(Status)) { + return (FALSE); + } + return (TRUE); +} + +BOOLEAN +EFIAPI +ReturnDriverDiag( + IN CONST EFI_HANDLE TheHandle + ) +{ + EFI_STATUS Status; + Status = gBS->OpenProtocol((EFI_HANDLE)TheHandle, &gEfiDriverDiagnostics2ProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL); + if (EFI_ERROR(Status)) { + Status = gBS->OpenProtocol((EFI_HANDLE)TheHandle, &gEfiDriverDiagnosticsProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL); + if (EFI_ERROR(Status)) { + return (FALSE); + } + } + return (TRUE); +} + +UINT32 +EFIAPI +ReturnDriverVersion( + IN CONST EFI_HANDLE TheHandle + ) +{ + EFI_DRIVER_BINDING_PROTOCOL *DriverBinding; + EFI_STATUS Status; + UINT32 RetVal; + + RetVal = (UINT32)-1; + + Status = gBS->OpenProtocol((EFI_HANDLE)TheHandle, &gEfiDriverBindingProtocolGuid, (VOID**)&DriverBinding, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (!EFI_ERROR(Status)) { + RetVal = DriverBinding->Version; + gBS->CloseProtocol(TheHandle, &gEfiDriverBindingProtocolGuid, gImageHandle, NULL); + } + return (RetVal); +} + +SHELL_STATUS +EFIAPI +ShellCommandRunDrivers ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + CHAR8 *Language; + CONST CHAR16 *Lang; + EFI_HANDLE *HandleList; + EFI_HANDLE *HandleWalker; + UINTN ChildCount; + UINTN DeviceCount; + CHAR16 *Temp2; + CHAR16 *FormatString; + UINT32 DriverVersion; + BOOLEAN DriverConfig; + BOOLEAN DriverDiag; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + Language = NULL; + FormatString = NULL; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize(); + ASSERT_EFI_ERROR(Status); + + Status = CommandInit(); + ASSERT_EFI_ERROR(Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR(Status)) { + if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { + if (ShellCommandLineGetCount(Package) > 1) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Lang = ShellCommandLineGetValue(Package, L"-l"); + if (Lang != NULL) { + Language = AllocateZeroPool(StrSize(Lang)); + AsciiSPrint(Language, StrSize(Lang), "%S", Lang); + } else if (!ShellCommandLineGetFlag(Package, L"-l")){ + ASSERT(Language == NULL); + // Language = AllocateZeroPool(10); + // AsciiSPrint(Language, 10, "en-us"); + } else { + ASSERT(Language == NULL); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l"); + ShellCommandLineFreeVarList (Package); + return (SHELL_INVALID_PARAMETER); + } + + if (ShellCommandLineGetFlag(Package, L"-sfo")) { + FormatString = HiiGetString(gShellDriver1HiiHandle, STRING_TOKEN(STR_DRIVERS_ITEM_LINE_SFO), Language); + } else { + FormatString = HiiGetString(gShellDriver1HiiHandle, STRING_TOKEN(STR_DRIVERS_ITEM_LINE), Language); + // + // print the header row + // + ShellPrintHiiEx( + -1, + -1, + Language, + STRING_TOKEN(STR_DRIVERS_HEADER_LINES), + gShellDriver1HiiHandle); + } + + HandleList = GetHandleListByProtocol(&gEfiDriverBindingProtocolGuid); + for (HandleWalker = HandleList ; HandleWalker != NULL && *HandleWalker != NULL ; HandleWalker++){ + ChildCount = 0; + DeviceCount = 0; + Status = ParseHandleDatabaseForChildDevices (*HandleWalker, &ChildCount , NULL); + Status = PARSE_HANDLE_DATABASE_DEVICES (*HandleWalker, &DeviceCount, NULL); + Temp2 = GetDevicePathTextForHandle(*HandleWalker); + DriverVersion = ReturnDriverVersion(*HandleWalker); + DriverConfig = ReturnDriverConfig(*HandleWalker); + DriverDiag = ReturnDriverDiag (*HandleWalker); + Lang = GetStringNameFromHandle(*HandleWalker, Language==NULL?"en":Language); + + ShellPrintEx( + -1, + -1, + FormatString, + ConvertHandleToHandleIndex(*HandleWalker), + DriverVersion, + ChildCount > 0?L'B':(DeviceCount > 0?L'D':L'?'), + DriverConfig?L'Y':L'N', + DriverDiag?L'Y':L'N', + DeviceCount, + ChildCount, + Lang, + Temp2==NULL?L"":Temp2 + ); + if (Temp2 != NULL) { + FreePool(Temp2); + } + } + } + SHELL_FREE_NON_NULL(Language); + ShellCommandLineFreeVarList (Package); + SHELL_FREE_NON_NULL(FormatString); + } + + return (ShellStatus); +} diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c new file mode 100644 index 0000000000..1e0456dc8e --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c @@ -0,0 +1,406 @@ +/** @file + Main file for DrvCfg shell Driver1 function. + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "UefiShellDriver1CommandsLib.h" +#include +#include + +/** + Function to validate configuration information on a configurable handle. + + @param[in] Handle The handle to validate info on. + @param[in] HiiDb A pointer to the HII Database protocol. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +EFIAPI +ValidateConfigInfoOnSingleHandleHii( + IN CONST EFI_HANDLE Handle, + IN EFI_HII_DATABASE_PROTOCOL *HiiDb + ) +{ + EFI_STATUS Status; + UINTN Size; + EFI_HII_HANDLE *HiiHandle; + EFI_HII_HANDLE *CurrentHandle; + EFI_HANDLE NormalHandle; + + if (HiiDb == NULL || Handle == NULL) { + return (EFI_INVALID_PARAMETER); + } + + Size = 0; + HiiHandle = NULL; + + Status = HiiDb->ListPackageLists( + HiiDb, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &Size, + HiiHandle); + + if (Status == EFI_BUFFER_TOO_SMALL) { + HiiHandle = AllocateZeroPool(Size); + if (HiiHandle == NULL) { + return (EFI_OUT_OF_RESOURCES); + } + Status = HiiDb->ListPackageLists( + HiiDb, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &Size, + HiiHandle); + } + if (EFI_ERROR(Status)) { + SHELL_FREE_NON_NULL(HiiHandle); + return (Status); + } + + for (CurrentHandle = HiiHandle ; CurrentHandle != NULL && *CurrentHandle != NULL ; CurrentHandle++) { + NormalHandle = NULL; + Status = HiiDb->GetPackageListHandle( + HiiDb, + *CurrentHandle, + &NormalHandle); + if (NormalHandle == Handle) { + break; + } + } + + + + + + SHELL_FREE_NON_NULL(HiiHandle); + return (Status); +} + +/** + Function to validate configuration information on all configurable handles. + + @param[in] ChildrenToo TRUE to tewst for children. + + @retval SHELL_SUCCESS The operation was successful. +**/ +SHELL_STATUS +EFIAPI +ValidOptionsOnAll( + IN CONST BOOLEAN ChildrenToo + ) +{ + EFI_HANDLE *HandleList; + EFI_HANDLE *CurrentHandle; + SHELL_STATUS ShellStatus; + EFI_STATUS Status; + BOOLEAN Found; + EFI_HII_DATABASE_PROTOCOL *HiiDb; + + Found = FALSE; + HandleList = NULL; + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + + Status = gBS->LocateProtocol(&gEfiHiiDatabaseProtocolGuid, NULL, (VOID**)&HiiDb); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROTOCOL_NF), gShellDriver1HiiHandle, L"gEfiHiiDatabaseProtocolGuid", &gEfiHiiDatabaseProtocolGuid); + return (Status); + } + + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_HEADER), gShellDriver1HiiHandle); + + // + // First do HII method + // + HandleList = GetHandleListByProtocol(&gEfiHiiConfigAccessProtocolGuid); + for (CurrentHandle = HandleList ; CurrentHandle != NULL && *CurrentHandle != NULL && ShellStatus == SHELL_SUCCESS; CurrentHandle++){ + Found = TRUE; + ///@todo VALIDATE + } + SHELL_FREE_NON_NULL(HandleList); + + // + // Now do EFI 1.10 & UEFI 2.0 drivers + // + HandleList = GetHandleListByProtocol(&gEfiDriverConfigurationProtocolGuid); + for (CurrentHandle = HandleList ; CurrentHandle != NULL && *CurrentHandle != NULL && ShellStatus == SHELL_SUCCESS; CurrentHandle++){ + Found = TRUE; + ///@todo VALIDATE + } + + if (!Found) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_NONE), gShellDriver1HiiHandle); + return (SHELL_SUCCESS); + } + + SHELL_FREE_NON_NULL(HandleList); + return (ShellStatus); +} + +/** + Function to print out configuration information on a configurable handle. + + @param[in] DriverHandle The driver handle to print info on. + @param[in] ControllerHandle The controllerHandle to print on. + @param[in] ChildrenToo TRUE to tewst for children. + @param[in] ProtocolMask BIT0 for HII, BIT1 for DirverConfiguration. + + @retval SHELL_SUCCESS The operation was successful. +**/ +SHELL_STATUS +EFIAPI +PrintConfigInfoOnSingleHandle( + IN CONST EFI_HANDLE DriverHandle, + IN CONST EFI_HANDLE ControllerHandle OPTIONAL, + IN CONST BOOLEAN ChildrenToo, + IN CONST UINT8 ProtocolMask // BIT0 - HII, BIT1 - DriverConfiguration + ) +{ + UINTN Index1; + UINTN Index2; + EFI_HANDLE *ChildHandleList; + UINTN Count; + UINTN LoopVar; + + Index1 = DriverHandle == NULL ? 0 : ConvertHandleToHandleIndex(DriverHandle ); + Index2 = ControllerHandle == NULL ? 0 : ConvertHandleToHandleIndex(ControllerHandle); + + if ((ProtocolMask & BIT0) == BIT0) { + ASSERT(Index1 == 0); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_LINE_HII), + gShellDriver1HiiHandle, + Index2 + ); + } + if ((ProtocolMask & BIT1) == BIT1) { + PARSE_HANDLE_DATABASE_MANAGED_CHILDREN(DriverHandle, ControllerHandle, &Count, &ChildHandleList); + for (LoopVar = 0 ; LoopVar <= Count ; LoopVar++) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_LINE_DRV), + gShellDriver1HiiHandle, + Index1, + Index2, + Count != 0 ? ChildHandleList[LoopVar] : 0 + ); + } + } + return (SHELL_SUCCESS); +} + +/** + Function to print out configuration information on all configurable handles. + + @param[in] ChildrenToo TRUE to tewst for children. + + @retval SHELL_SUCCESS The operation was successful. +**/ +SHELL_STATUS +EFIAPI +PrintConfigInfoOnAll( + IN CONST BOOLEAN ChildrenToo + ) +{ +// lcoate all the HII_CONFIG_ACCESS_PROTOCOL - those are all configurable +// then cross reference with EFI_DRIVER_CONFIGURATION_PROTOCOL - those are legacy configurable +// can be on chlid, but that is ok... just find the driver + EFI_HANDLE *HandleList; + EFI_HANDLE *CurrentHandle; + EFI_HANDLE *DriverHandleList; + EFI_HANDLE *ParentHandleList; + EFI_HANDLE *CurrentDriver; + UINTN Count; + SHELL_STATUS ShellStatus; + EFI_STATUS Status; + UINTN LoopVar; + BOOLEAN Found; + + Found = FALSE; + Count = 0; + HandleList = NULL; + CurrentHandle = NULL; + DriverHandleList = NULL; + CurrentDriver = NULL; + ShellStatus = SHELL_SUCCESS; + + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_HEADER), gShellDriver1HiiHandle); + // + // First do HII method + // + HandleList = GetHandleListByProtocol(&gEfiHiiConfigAccessProtocolGuid); + for (CurrentHandle = HandleList ; CurrentHandle != NULL && *CurrentHandle != NULL && ShellStatus == SHELL_SUCCESS; CurrentHandle++){ + // is this a driver handle itself? if yes print options for it. + if (!EFI_ERROR(gBS->OpenProtocol(*CurrentHandle, &gEfiDriverBindingProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + ShellStatus = PrintConfigInfoOnSingleHandle(*CurrentHandle, NULL, ChildrenToo, BIT0); + } else { + // get its driver and print options for it. + Count = 0; + Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS(*CurrentHandle, &Count, &DriverHandleList); + if (EFI_ERROR(Status)) { + Status = PARSE_HANDLE_DATABASE_PARENTS(*CurrentHandle, &Count, &ParentHandleList); + if (!EFI_ERROR(Status)) { + Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS(*ParentHandleList, &Count, &DriverHandleList); + } + } + if (Count == 0) { + Found = TRUE; + ShellStatus = PrintConfigInfoOnSingleHandle(NULL, *CurrentHandle, ChildrenToo, BIT0); + } else if (DriverHandleList != NULL) { + for (LoopVar = 0 ; LoopVar < Count ; LoopVar++) { + Found = TRUE; + ShellStatus = PrintConfigInfoOnSingleHandle(DriverHandleList[LoopVar], *CurrentHandle, ChildrenToo, BIT0); + } + } + SHELL_FREE_NON_NULL(DriverHandleList); + } + } + SHELL_FREE_NON_NULL(HandleList); + + // + // Now do EFI 1.10 & UEFI 2.0 drivers + // + HandleList = GetHandleListByProtocol(&gEfiDriverConfigurationProtocolGuid); + for (CurrentHandle = HandleList ; CurrentHandle != NULL && *CurrentHandle != NULL && ShellStatus == SHELL_SUCCESS; CurrentHandle++){ + Found = TRUE; + ShellStatus = PrintConfigInfoOnSingleHandle(*CurrentHandle, NULL, ChildrenToo, BIT1); + } + SHELL_FREE_NON_NULL(HandleList); + if (!Found) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_NONE), gShellDriver1HiiHandle); + return (SHELL_SUCCESS); + } + return (ShellStatus); +} + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-c", TypeFlag}, + {L"-s", TypeFlag}, + {L"-v", TypeFlag}, + {L"-l", TypeValue}, + {L"-f", TypeValue}, + {L"-o", TypeValue}, + {L"-i", TypeValue}, + {NULL, TypeMax} + }; + +SHELL_STATUS +EFIAPI +ShellCommandRunDrvCfg ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + CHAR8 *Language; + CONST CHAR16 *Lang; + CONST CHAR16 *Temp2; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + Language = NULL; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize(); + ASSERT_EFI_ERROR(Status); + + Status = CommandInit(); + ASSERT_EFI_ERROR(Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR(Status)) { + if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { + Lang = ShellCommandLineGetValue(Package, L"-l"); + if (Lang != NULL) { + Language = AllocateZeroPool(StrSize(Lang)); + AsciiSPrint(Language, StrSize(Lang), "%S", Lang); + } else if (!ShellCommandLineGetFlag(Package, L"-l")){ + Language = AllocateZeroPool(10); + AsciiSPrint(Language, 10, "en-us"); + } else { + ASSERT(Language == NULL); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l"); + ShellCommandLineFreeVarList (Package); + return (SHELL_INVALID_PARAMETER); + } + + // + // Should be DriverHandle + // + Temp2 = ShellCommandLineGetRawValue(Package, 1); + if (Temp2 == NULL) { + // + // no driver specified. cannot be export, inport, or set (and no specified language) + // + if (ShellCommandLineGetFlag(Package, L"-s") + ||ShellCommandLineGetFlag(Package, L"-l") + ||ShellCommandLineGetFlag(Package, L"-o") + ||ShellCommandLineGetFlag(Package, L"-i")) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_REQ), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + // + // do a loop for validation, forcing, or printing + // + if (ShellCommandLineGetFlag(Package, L"-v") && ShellCommandLineGetFlag(Package, L"-f")) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-v", L"-f"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetFlag(Package, L"-v")){ + // + // validate + // + ShellStatus = ValidOptionsOnAll(ShellCommandLineGetFlag(Package, L"-c")); + } else if (ShellCommandLineGetFlag(Package, L"-f")){ + // + // force + // +ASSERT(FALSE);// ShellStatus = ForceOptionsOnAll(ShellCommandLineGetFlag(Package, L"-c")); + } else { + // + // display all that are configurable + // + ShellStatus = PrintConfigInfoOnAll(ShellCommandLineGetFlag(Package, L"-c")); + } + } + } else { + // + // we have a driver handle, make sure it's valid then process it... + // + ASSERT(FALSE); + } + } + ShellCommandLineFreeVarList (Package); + SHELL_FREE_NON_NULL(Language); + return (ShellStatus); +} diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvDiag.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvDiag.c new file mode 100644 index 0000000000..9a8daecc9c --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvDiag.c @@ -0,0 +1,412 @@ +/** @file + Main file for DrvDiag shell Driver1 function. + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +STATIC CONST EFI_GUID *DiagGuidList[] = {&gEfiDriverDiagnosticsProtocolGuid, &gEfiDriverDiagnostics2ProtocolGuid, NULL}; +// +// We need 1 more item on the list... +// +typedef enum { + TEST_MODE_STANDARD = EfiDriverDiagnosticTypeStandard, + TEST_MODE_EXTENDED = EfiDriverDiagnosticTypeExtended, + TEST_MODE_MANUFACTURING = EfiDriverDiagnosticTypeManufacturing, + TEST_MODE_LIST, + TEST_MODE_MAX +} DRV_DIAG_TEST_MODE; + +EFI_STATUS +EFIAPI +DoDiagnostics ( + IN CONST DRV_DIAG_TEST_MODE Mode, + IN CONST CHAR8 *Lang, + IN CONST BOOLEAN AllChilds, + IN CONST EFI_HANDLE DriverHandle, + IN CONST EFI_HANDLE ControllerHandle, + IN CONST EFI_HANDLE ChildHandle + ) +{ + EFI_DRIVER_DIAGNOSTICS_PROTOCOL *DriverDiagnostics; + EFI_DRIVER_DIAGNOSTICS2_PROTOCOL *DriverDiagnostics2; + EFI_HANDLE *DriverHandleList; + EFI_HANDLE *ControllerHandleList; + EFI_HANDLE *ChildHandleList; + EFI_HANDLE *Walker; + UINTN DriverHandleListCount; + UINTN ControllerHandleListCount; + UINTN ChildHandleListCount; + UINTN DriverHandleListLoop; + UINTN ControllerHandleListLoop; + UINTN ChildHandleListLoop; + EFI_STATUS Status; + EFI_STATUS Status2; + EFI_GUID *ErrorType; + UINTN OutBufferSize; + CHAR16 *OutBuffer; + UINTN HandleIndex1; + UINTN HandleIndex2; + + if ((ChildHandle != NULL && AllChilds) || (Mode >= TEST_MODE_MAX)){ + return (EFI_INVALID_PARAMETER); + } + + if (Lang == NULL || AsciiStrLen(Lang) < 3) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"-l "); + return (EFI_INVALID_PARAMETER); + } + + DriverDiagnostics = NULL; + DriverDiagnostics2 = NULL; + Status = EFI_SUCCESS; + Status2 = EFI_SUCCESS; + DriverHandleList = NULL; + ControllerHandleList = NULL; + ChildHandleList = NULL; + OutBuffer = NULL; + ErrorType = NULL; + DriverHandleListCount = 0; + ControllerHandleListCount = 0; + ChildHandleListCount = 0; + + if (DriverHandle != NULL) { + DriverHandleList = AllocateZeroPool(2*sizeof(EFI_HANDLE)); + ASSERT(DriverHandleList!=NULL); + DriverHandleList[0] = DriverHandle; + DriverHandleListCount = 1; + } else { + DriverHandleList = GetHandleListByProtocolList(DiagGuidList); + if (DriverHandleList == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_NONE), gShellDriver1HiiHandle); + return (EFI_NOT_FOUND); + } + for (Walker = DriverHandleList ; Walker != NULL && *Walker != NULL ; DriverHandleListCount++, Walker++); + } + + if (ControllerHandle != NULL) { + ControllerHandleList = AllocateZeroPool(2*sizeof(EFI_HANDLE)); + ASSERT(ControllerHandleList!=NULL); + ControllerHandleList[0] = ControllerHandle; + ControllerHandleListCount = 1; + } else { + ControllerHandleList = NULL; + } + + if (ChildHandle != NULL) { + ChildHandleList = AllocateZeroPool(2*sizeof(EFI_HANDLE)); + ASSERT(ChildHandleList!=NULL); + ChildHandleList[0] = ChildHandle; + ChildHandleListCount = 1; + } else if (AllChilds) { + ChildHandleList = NULL; + // + // This gets handled in the loop below. + // + } else { + ChildHandleList = NULL; + } + + for (DriverHandleListLoop = 0 + ; DriverHandleListLoop < DriverHandleListCount + ; DriverHandleListLoop++ + ){ + if (ControllerHandle == NULL) { + PARSE_HANDLE_DATABASE_DEVICES(DriverHandleList[DriverHandleListLoop], &ControllerHandleListCount, &ControllerHandleList); + } + for (ControllerHandleListLoop = 0 + ; ControllerHandleListLoop < ControllerHandleListCount + ; ControllerHandleListLoop++ + ){ + if (AllChilds) { + ASSERT(ChildHandleList == NULL); + PARSE_HANDLE_DATABASE_MANAGED_CHILDREN( + DriverHandleList[DriverHandleListLoop], + ControllerHandleList[ControllerHandleListLoop], + &ChildHandleListCount, + &ChildHandleList); + } + for (ChildHandleListLoop = 0 + ; (ChildHandleListLoop < ChildHandleListCount || ChildHandleList == NULL) + ; ChildHandleListLoop++ + ){ + if (Mode != TEST_MODE_LIST) { + if (Lang[2] == '-') { + // + // Get the protocol pointer and call the function + // + Status = gBS->OpenProtocol( + DriverHandleList[DriverHandleListLoop], + &gEfiDriverDiagnostics2ProtocolGuid, + (VOID**)&DriverDiagnostics2, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (!EFI_ERROR(Status)) { + Status = DriverDiagnostics2->RunDiagnostics( + DriverDiagnostics2, + ControllerHandleList[ControllerHandleListLoop], + ChildHandleList == NULL?NULL:ChildHandleList[ChildHandleListLoop], + (EFI_DRIVER_DIAGNOSTIC_TYPE)Mode, + (CHAR8*)Lang, + &ErrorType, + &OutBufferSize, + &OutBuffer); + } + } else { + Status = gBS->OpenProtocol( + DriverHandleList[DriverHandleListLoop], + &gEfiDriverDiagnosticsProtocolGuid, + (VOID**)&DriverDiagnostics, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (!EFI_ERROR(Status)) { + Status = DriverDiagnostics->RunDiagnostics( + DriverDiagnostics, + ControllerHandleList[ControllerHandleListLoop], + ChildHandleList == NULL?NULL:ChildHandleList[ChildHandleListLoop], + (EFI_DRIVER_DIAGNOSTIC_TYPE)Mode, + (CHAR8*)Lang, + &ErrorType, + &OutBufferSize, + &OutBuffer); + } + } + if (EFI_ERROR(Status)) { + Status2 = Status; + } + HandleIndex1 = ConvertHandleToHandleIndex(DriverHandleList[DriverHandleListLoop]); + HandleIndex2 = ConvertHandleToHandleIndex(ControllerHandleList[ControllerHandleListLoop]); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_3P_RESULT), + gShellDriver1HiiHandle, + L"DrvDiag", + HandleIndex1, + HandleIndex2, + ChildHandleList == NULL?0:ConvertHandleToHandleIndex(ChildHandleList[ChildHandleListLoop]), + Status); + if (OutBuffer!=NULL) { + FreePool(OutBuffer); + OutBuffer = NULL; + } + if (ErrorType!=NULL) { + FreePool(ErrorType); + ErrorType = NULL; + } + } else { + HandleIndex1 = ConvertHandleToHandleIndex(DriverHandleList[DriverHandleListLoop]); + HandleIndex2 = ConvertHandleToHandleIndex(ControllerHandleList[ControllerHandleListLoop]); + // + // Print out the information that this set can be tested + // + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRV_DIAG_ITEM_LINE), + gShellDriver1HiiHandle, + HandleIndex1, + HandleIndex2, + ChildHandleList == NULL?0:ConvertHandleToHandleIndex(ChildHandleList[ChildHandleListLoop]) + ); + } + + // + // If we are doing a single pass with NULL child jump out after a single loop + // + if (ChildHandleList == NULL) { + break; + } + } + if (AllChilds) { + SHELL_FREE_NON_NULL(ChildHandleList); + ChildHandleList = NULL; + ChildHandleListCount = 0; + } + } + if (ControllerHandle == NULL) { + SHELL_FREE_NON_NULL(ControllerHandleList); + ControllerHandleList = NULL; + ControllerHandleListCount = 0; + } + } + + if (DriverHandleList != NULL) { + FreePool(DriverHandleList); + } + if (ControllerHandleList != NULL) { + FreePool(ControllerHandleList); + } + if (ChildHandleList != NULL) { + FreePool(ChildHandleList); + } + return (Status2); +} + + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-c", TypeFlag}, + {L"-s", TypeFlag}, + {L"-e", TypeFlag}, + {L"-m", TypeFlag}, + {L"-l", TypeValue}, + {NULL, TypeMax} + }; + +SHELL_STATUS +EFIAPI +ShellCommandRunDrvDiag ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + DRV_DIAG_TEST_MODE Mode; + CHAR8 *Language; + CONST CHAR16 *DriverHandleStr; + CONST CHAR16 *ControllerHandleStr; + CONST CHAR16 *ChildHandleStr; + CONST CHAR16 *Lang; + EFI_HANDLE Handle1; + EFI_HANDLE Handle2; + EFI_HANDLE Handle3; + + ShellStatus = SHELL_SUCCESS; + Mode = TEST_MODE_MAX; + Language = NULL; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize(); + ASSERT_EFI_ERROR(Status); + + Status = CommandInit(); + ASSERT_EFI_ERROR(Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR(Status)) { + if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { + // + // if more than 3 'value' parameters (plus the name one) or we have any 2 mode flags + // + if ((ShellCommandLineGetCount(Package) > 4) + ||(ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetFlag(Package, L"-e")) + ||(ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetFlag(Package, L"-m")) + ||(ShellCommandLineGetFlag(Package, L"-e") && ShellCommandLineGetFlag(Package, L"-m")) + ){ + // + // error for too many parameters + // + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if ((ShellCommandLineGetFlag(Package, L"-s")) + || (ShellCommandLineGetFlag(Package, L"-e")) + || (ShellCommandLineGetFlag(Package, L"-m")) + ){ + // + // Run the apropriate test + // + if (ShellCommandLineGetFlag(Package, L"-s")) { + Mode = TEST_MODE_STANDARD; + } else if (ShellCommandLineGetFlag(Package, L"-e")) { + Mode = TEST_MODE_EXTENDED; + } else if (ShellCommandLineGetFlag(Package, L"-m")) { + Mode = TEST_MODE_MANUFACTURING; + } else { + ASSERT(FALSE); + } + } else { + // + // Do a listing of what's available to test + // + Mode = TEST_MODE_LIST; + } + + Lang = ShellCommandLineGetValue(Package, L"-l"); + if (Lang != NULL) { + Language = AllocateZeroPool(StrSize(Lang)); + AsciiSPrint(Language, StrSize(Lang), "%S", Lang); + } else if (!ShellCommandLineGetFlag(Package, L"-l")){ + Language = AllocateZeroPool(10); + AsciiSPrint(Language, 10, "en-us"); + } else { + ASSERT(Language == NULL); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l"); + ShellCommandLineFreeVarList (Package); + return (SHELL_INVALID_PARAMETER); + } + + DriverHandleStr = ShellCommandLineGetRawValue(Package, 1); + ControllerHandleStr = ShellCommandLineGetRawValue(Package, 2); + ChildHandleStr = ShellCommandLineGetRawValue(Package, 3); + + if (DriverHandleStr == NULL) { + Handle1 = NULL; + } else { + Handle1 = ConvertHandleIndexToHandle(StrHexToUintn(DriverHandleStr )); + } + if (ControllerHandleStr == NULL) { + Handle2 = NULL; + } else { + Handle2 = ConvertHandleIndexToHandle(StrHexToUintn(ControllerHandleStr)); + } + if (ChildHandleStr == NULL) { + Handle3 = NULL; + } else { + Handle3 = ConvertHandleIndexToHandle(StrHexToUintn(ChildHandleStr )); + } + + Status = DoDiagnostics ( + Mode, + Language, + ShellCommandLineGetFlag(Package, L"-c"), + Handle1, + Handle2, + Handle3 + ); + + SHELL_FREE_NON_NULL(Language); + ShellCommandLineFreeVarList (Package); + + } + if (ShellStatus == SHELL_SUCCESS) { + if (Status == EFI_SECURITY_VIOLATION) { + ShellStatus = SHELL_SECURITY_VIOLATION; + } else if (Status == EFI_INVALID_PARAMETER) { + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (Status == EFI_NOT_FOUND) { + ShellStatus = SHELL_NOT_FOUND; + } else if (EFI_ERROR(Status)) { + ShellStatus = SHELL_NOT_FOUND; + } + } + + return (ShellStatus); +} diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c new file mode 100644 index 0000000000..b60cc18333 --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c @@ -0,0 +1,202 @@ +/** @file + Main file for OpenInfo shell Driver1 function. + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +STATIC CONST CHAR16 StringHandProt[] = L"HandProt "; +STATIC CONST CHAR16 StringGetProt[] = L"GetProt "; +STATIC CONST CHAR16 StringTestProt[] = L"TestProt "; +STATIC CONST CHAR16 StringChild[] = L"Child "; +STATIC CONST CHAR16 StringDriver[] = L"Driver "; +STATIC CONST CHAR16 StringExclusive[] = L"Exclusive"; +STATIC CONST CHAR16 StringDriverEx[] = L"DriverEx "; +STATIC CONST CHAR16 StringUnknown[] = L"Unknown "; + +EFI_STATUS +EFIAPI +TraverseHandleDatabase ( + IN CONST EFI_HANDLE TheHandle + ) +{ + EFI_STATUS Status; + EFI_GUID **ProtocolGuidArray; + UINTN ArrayCount; + UINTN ProtocolIndex; + EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo; + UINTN OpenInfoCount; + UINTN OpenInfoIndex; + CONST CHAR16 *OpenTypeString; + CHAR16 *TempString; + UINTN HandleIndex; + CONST CHAR16 *Name; + + ASSERT(TheHandle != NULL); + + // + // Retrieve the list of all the protocols on the handle + // + Status = gBS->ProtocolsPerHandle ( + TheHandle, + &ProtocolGuidArray, + &ArrayCount + ); + ASSERT_EFI_ERROR(Status); + if (!EFI_ERROR (Status)) { + + for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) { + // + // print out the human readable name for this one. + // + TempString = GetStringNameFromGuid(ProtocolGuidArray[ProtocolIndex], NULL); + if (TempString == NULL) { + continue; + } + ShellPrintEx(-1, -1, L"%H%s%N\r\n", TempString); + FreePool(TempString); + + // + // Retrieve the list of agents that have opened each protocol + // + Status = gBS->OpenProtocolInformation ( + TheHandle, + ProtocolGuidArray[ProtocolIndex], + &OpenInfo, + &OpenInfoCount + ); + ASSERT_EFI_ERROR(Status); + if (!EFI_ERROR (Status)) { + for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) { + switch (OpenInfo[OpenInfoIndex].Attributes) { + case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: OpenTypeString = StringHandProt; break; + case EFI_OPEN_PROTOCOL_GET_PROTOCOL: OpenTypeString = StringGetProt; break; + case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: OpenTypeString = StringTestProt; break; + case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: OpenTypeString = StringChild; break; + case EFI_OPEN_PROTOCOL_BY_DRIVER: OpenTypeString = StringDriver; break; + case EFI_OPEN_PROTOCOL_EXCLUSIVE: OpenTypeString = StringExclusive; break; + case EFI_OPEN_PROTOCOL_BY_DRIVER|EFI_OPEN_PROTOCOL_EXCLUSIVE: + OpenTypeString = StringDriverEx; break; + default: OpenTypeString = StringUnknown; break; + } + HandleIndex = ConvertHandleToHandleIndex(OpenInfo[OpenInfoIndex].AgentHandle); + Name = GetStringNameFromHandle(OpenInfo[OpenInfoIndex].AgentHandle, "en"); + if (OpenInfo[OpenInfoIndex].ControllerHandle!=NULL) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_OPENINFO_LINE), + gShellDriver1HiiHandle, + HandleIndex, + ConvertHandleToHandleIndex(OpenInfo[OpenInfoIndex].ControllerHandle), + OpenInfo[OpenInfoIndex].OpenCount, + OpenTypeString, + Name + ); + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_OPENINFO_MIN_LINE), + gShellDriver1HiiHandle, + HandleIndex, + OpenInfo[OpenInfoIndex].OpenCount, + OpenTypeString, + Name + ); + } + } + FreePool (OpenInfo); + } + } + FreePool (ProtocolGuidArray); + } + + return Status; +} + +/** + Function for 'openinfo' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunOpenInfo ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + EFI_HANDLE TheHandle; + CONST CHAR16 *Param1; + + ShellStatus = SHELL_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize(); + ASSERT_EFI_ERROR(Status); + + Status = CommandInit(); + ASSERT_EFI_ERROR(Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR(Status)) { + if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { + if (ShellCommandLineGetCount(Package) > 2){ + // + // error for too many parameters + // + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount(Package) == 0) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Param1 = ShellCommandLineGetRawValue(Package, 1); + if (Param1 == NULL || ConvertHandleIndexToHandle(StrHexToUintn(Param1)) == NULL){ + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param1); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + TheHandle = ConvertHandleIndexToHandle(StrHexToUintn(Param1)); + ASSERT(TheHandle != NULL); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_OPENINFO_HEADER_LINE), gShellDriver1HiiHandle, StrHexToUintn(Param1), TheHandle); + + Status = TraverseHandleDatabase (TheHandle); + if (!EFI_ERROR(Status)) { + } else { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param1); + ShellStatus = SHELL_NOT_FOUND; + } + } + } + } + return (ShellStatus); +} diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Reconnect.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Reconnect.c new file mode 100644 index 0000000000..723ee71141 --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Reconnect.c @@ -0,0 +1,31 @@ +/** @file + Main file for Reconnect shell Driver1 function. + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +SHELL_STATUS +EFIAPI +ShellCommandRunReconnect ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + SHELL_STATUS ShellStatus; + + ShellStatus = ShellCommandRunDisconnect(ImageHandle, SystemTable); + if (ShellStatus == SHELL_SUCCESS) { + ShellStatus = ShellCommandRunConnect(ImageHandle, SystemTable); + } + return (ShellStatus); +} diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.c new file mode 100644 index 0000000000..b0e15917d8 --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.c @@ -0,0 +1,99 @@ +/** @file + Main file for NULL named library for level 1 shell command functions. + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +STATIC CONST CHAR16 mFileName[] = L"Driver1Commands"; +EFI_HANDLE gShellDriver1HiiHandle = NULL; +CONST EFI_GUID gShellDriver1HiiGuid = \ + { \ + 0xaf0b742, 0x63ec, 0x45bd, {0x8d, 0xb6, 0x71, 0xad, 0x7f, 0x2f, 0xe8, 0xe8} \ + }; + +CONST CHAR16* +EFIAPI +ShellCommandGetManFileNameDriver1 ( + VOID + ) +{ + return (mFileName); +} + +/** + Constructor for the Shell Driver1 Commands library. + + @param ImageHandle the image handle of the process + @param SystemTable the EFI System Table pointer + + @retval EFI_SUCCESS the shell command handlers were installed sucessfully + @retval EFI_UNSUPPORTED the shell level required was not found. +**/ +EFI_STATUS +EFIAPI +UefiShellDriver1CommandsLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + // + // check our bit of the profiles mask + // + if ((PcdGet8(PcdShellProfileMask) & BIT0) == 0) { + return (EFI_UNSUPPORTED); + } + + // + // install the HII stuff. + // + gShellDriver1HiiHandle = HiiAddPackages (&gShellDriver1HiiGuid, gImageHandle, UefiShellDriver1CommandsLibStrings, NULL); + if (gShellDriver1HiiHandle == NULL) { + return (EFI_DEVICE_ERROR); + } + + // + // install our shell command handlers that are always installed + // + ShellCommandRegisterCommandName(L"connect", ShellCommandRunConnect , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE, gShellDriver1HiiHandle, STRING_TOKEN(STR_GET_HELP_CONNECT) ); + ShellCommandRegisterCommandName(L"devices", ShellCommandRunDevices , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE, gShellDriver1HiiHandle, STRING_TOKEN(STR_GET_HELP_DEVICES) ); + ShellCommandRegisterCommandName(L"openinfo", ShellCommandRunOpenInfo , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE, gShellDriver1HiiHandle, STRING_TOKEN(STR_GET_HELP_OPENINFO) ); + ShellCommandRegisterCommandName(L"disconnect", ShellCommandRunDisconnect , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE, gShellDriver1HiiHandle, STRING_TOKEN(STR_GET_HELP_DISCONNECT)); + ShellCommandRegisterCommandName(L"reconnect", ShellCommandRunReconnect , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE, gShellDriver1HiiHandle, STRING_TOKEN(STR_GET_HELP_RECONNECT) ); + ShellCommandRegisterCommandName(L"unload", ShellCommandRunUnload , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE, gShellDriver1HiiHandle, STRING_TOKEN(STR_GET_HELP_UNLOAD) ); + ShellCommandRegisterCommandName(L"drvdiag", ShellCommandRunDrvDiag , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE, gShellDriver1HiiHandle, STRING_TOKEN(STR_GET_HELP_DRVDIAG) ); + ShellCommandRegisterCommandName(L"dh", ShellCommandRunDh , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE, gShellDriver1HiiHandle, STRING_TOKEN(STR_GET_HELP_DH) ); + ShellCommandRegisterCommandName(L"drivers", ShellCommandRunDrivers , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE, gShellDriver1HiiHandle, STRING_TOKEN(STR_GET_HELP_DRIVERS) ); + ShellCommandRegisterCommandName(L"devtree", ShellCommandRunDevTree , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE, gShellDriver1HiiHandle, STRING_TOKEN(STR_GET_HELP_DEVTREE) ); + ShellCommandRegisterCommandName(L"drvcfg", ShellCommandRunDrvCfg , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE, gShellDriver1HiiHandle, STRING_TOKEN(STR_GET_HELP_DRVCFG) ); + + return (EFI_SUCCESS); +} + +/** + Destructor for the library. free any resources. +**/ +EFI_STATUS +EFIAPI +UefiShellDriver1CommandsLibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + if (gShellDriver1HiiHandle != NULL) { + HiiRemovePackages(gShellDriver1HiiHandle); + } + return (EFI_SUCCESS); +} + + + diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.h b/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.h new file mode 100644 index 0000000000..c5b6a1fbda --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.h @@ -0,0 +1,201 @@ +/** @file + Main file for NULL named library for Profile1 shell command functions. + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +extern EFI_HANDLE gShellDriver1HiiHandle; +extern CONST EFI_GUID gShellDriver1HiiGuid; + +/** + Function for 'connect' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunConnect ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + Function for 'devices' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunDevices ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + Function for 'openinfo' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunOpenInfo ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + Function for 'devtree' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunDevTree ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + Function for 'dh' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunDh ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + Function for 'disconnect' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunDisconnect ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + Function for 'drivers' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunDrivers ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + Function for 'drvcfg' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunDrvCfg ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + Function for 'drvdiag' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunDrvDiag ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + Function for 'reconnect' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunReconnect ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + Function for 'unload' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunUnload ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf b/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf new file mode 100644 index 0000000000..e6774c70e4 --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf @@ -0,0 +1,73 @@ +## @file +# Provides shell driver1 profile functions +# +# Copyright (c) 2010, Intel Corporation.All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +## +[Defines] + INF_VERSION = 0x00010006 + BASE_NAME = UefiShellDriver1CommandsLib + FILE_GUID = 313D3674-3ED4-48fd-BF97-7DB35D4190D1 + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = NULL|UEFI_APPLICATION UEFI_DRIVER + CONSTRUCTOR = UefiShellDriver1CommandsLibConstructor + DESTRUCTOR = UefiShellDriver1CommandsLibDestructor + +[Sources] + Connect.c + Devices.c + OpenInfo.c + Disconnect.c + Reconnect.c + Unload.c + DrvDiag.c + Dh.c + Drivers.c + DevTree.c + DrvCfg.c + UefiShellDriver1CommandsLib.c + UefiShellDriver1CommandsLib.h + UefiShellDriver1CommandsLib.uni + +[Packages] + MdePkg/MdePkg.dec + ShellPkg/ShellPkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + MemoryAllocationLib + BaseLib + BaseMemoryLib + DebugLib + ShellCommandLib + ShellLib + UefiLib + UefiRuntimeServicesTableLib + UefiBootServicesTableLib + SortLib + PrintLib + PeCoffGetEntryPointLib + +[Pcd] + gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask # ALWAYS_CONSUMED + +[Protocols] + gEfiDriverHealthProtocolGuid # ALWAYS_CONSUMED + gEfiDriverFamilyOverrideProtocolGuid # ALWAYS_CONSUMED + gEfiHiiConfigAccessProtocolGuid # ALWAYS_CONSUMED + gEfiHiiDatabaseProtocolGuid # ALWAYS_CONSUMED + +[Guids] + gEfiGlobalVariableGuid # ALWAYS_CONSUMED + gEfiConsoleInDeviceGuid # ALWAYS_CONSUMED + gEfiConsoleOutDeviceGuid # ALWAYS_CONSUMED + diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.uni b/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.uni new file mode 100644 index 0000000000..4a72f9f327 Binary files /dev/null and b/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.uni differ diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Unload.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Unload.c new file mode 100644 index 0000000000..239ac4aae2 --- /dev/null +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Unload.c @@ -0,0 +1,220 @@ +/** @file + Main file for Unload shell Driver1 function. + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +/** + Function to translate the EFI_MEMORY_TYPE into a string. + + @param[in] Memory The memory type. + + @retval A string representation of the type allocated from BS Pool. +**/ +CHAR16* +EFIAPI +ConvertMemoryType ( + IN CONST EFI_MEMORY_TYPE Memory + ) +{ + CHAR16 *RetVal; + RetVal = NULL; + + switch (Memory) { + case EfiReservedMemoryType: StrnCatGrow(&RetVal, NULL, L"EfiReservedMemoryType", 0); break; + case EfiLoaderCode: StrnCatGrow(&RetVal, NULL, L"EfiLoaderCode", 0); break; + case EfiLoaderData: StrnCatGrow(&RetVal, NULL, L"EfiLoaderData", 0); break; + case EfiBootServicesCode: StrnCatGrow(&RetVal, NULL, L"EfiBootServicesCode", 0); break; + case EfiBootServicesData: StrnCatGrow(&RetVal, NULL, L"EfiBootServicesData", 0); break; + case EfiRuntimeServicesCode: StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesCode", 0); break; + case EfiRuntimeServicesData: StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesData", 0); break; + case EfiConventionalMemory: StrnCatGrow(&RetVal, NULL, L"EfiConventionalMemory", 0); break; + case EfiUnusableMemory: StrnCatGrow(&RetVal, NULL, L"EfiUnusableMemory", 0); break; + case EfiACPIReclaimMemory: StrnCatGrow(&RetVal, NULL, L"EfiACPIReclaimMemory", 0); break; + case EfiACPIMemoryNVS: StrnCatGrow(&RetVal, NULL, L"EfiACPIMemoryNVS", 0); break; + case EfiMemoryMappedIO: StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIO", 0); break; + case EfiMemoryMappedIOPortSpace: StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIOPortSpace", 0); break; + case EfiPalCode: StrnCatGrow(&RetVal, NULL, L"EfiPalCode", 0); break; + case EfiMaxMemoryType: StrnCatGrow(&RetVal, NULL, L"EfiMaxMemoryType", 0); break; + default: ASSERT(FALSE); + } + return (RetVal); +} + +/** + Function to dump LoadedImage info from TheHandle. + + @param[in] TheHandle The handle to dump info from. + + @retval EFI_SUCCESS The info was dumped. + @retval EFI_INVALID_PARAMETER The handle did not have LoadedImage +**/ +EFI_STATUS +EFIAPI +DumpLoadedImageProtocolInfo ( + IN EFI_HANDLE TheHandle + ) +{ + EFI_LOADED_IMAGE_PROTOCOL *Image; + EFI_STATUS Status; + EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevicePathToText; + CHAR16 *DevicePathText; + CHAR16 *CodeTypeText; + CHAR16 *DataTypeText; + CHAR8 *PdbPointer; + + Image = NULL; + + Status = gBS->OpenProtocol(TheHandle, &gEfiLoadedImageProtocolGuid, (VOID**)&Image, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (EFI_ERROR(Status)) { + return (EFI_INVALID_PARAMETER); + } + + Status = gBS->LocateProtocol( + &gEfiDevicePathToTextProtocolGuid, + NULL, + (VOID**)&DevicePathToText); + // + // we now have the device path to text protocol + // + if (!EFI_ERROR(Status)) { + DevicePathText = DevicePathToText->ConvertDevicePathToText(Image->FilePath, TRUE, TRUE); + } else { + DevicePathText = NULL; + } + + CodeTypeText = ConvertMemoryType(Image->ImageCodeType); + DataTypeText = ConvertMemoryType(Image->ImageDataType); + PdbPointer = (CHAR8*)PeCoffLoaderGetPdbPointer(Image->ImageBase); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_UNLOAD_VERBOSE), gShellDriver1HiiHandle, + ConvertHandleToHandleIndex(TheHandle), + TheHandle, + Image, + Image->ParentHandle, + Image->SystemTable, + Image->DeviceHandle, + DevicePathText, + PdbPointer, + Image->ImageBase, + Image->ImageSize, + CodeTypeText, + DataTypeText + ); + + SHELL_FREE_NON_NULL(DevicePathText); + SHELL_FREE_NON_NULL(CodeTypeText); + SHELL_FREE_NON_NULL(DataTypeText); + + return (EFI_SUCCESS); +} + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-n", TypeFlag}, + {L"-v", TypeFlag}, + {L"-verbose", TypeFlag}, + {NULL, TypeMax} + }; + +/** + Function for 'unload' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunUnload ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + EFI_HANDLE TheHandle; + CONST CHAR16 *Param1; + SHELL_PROMPT_RESPONSE *Resp; + + ShellStatus = SHELL_SUCCESS; + Package = NULL; + Resp = NULL; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize(); + ASSERT_EFI_ERROR(Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR(Status)) { + if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { + if (ShellCommandLineGetCount(Package) > 2){ + // + // error for too many parameters + // + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount(Package) < 2) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Param1 = ShellCommandLineGetRawValue(Package, 1); + if (Param1 == NULL || ConvertHandleIndexToHandle(StrHexToUintn(Param1)) == NULL){ + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param1); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + TheHandle = ConvertHandleIndexToHandle(StrHexToUintn(Param1)); + ASSERT(TheHandle != NULL); + if (ShellCommandLineGetFlag(Package, L"-v") || ShellCommandLineGetFlag(Package, L"-verbose")) { + DumpLoadedImageProtocolInfo(TheHandle); + } + + if (!ShellCommandLineGetFlag(Package, L"-n")) { + Status = ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_UNLOAD_CONF), gShellDriver1HiiHandle, StrHexToUintn(Param1)); + Status = ShellPromptForResponse(ShellPromptResponseTypeYesNo, NULL, (VOID**)&Resp); + } + if (ShellCommandLineGetFlag(Package, L"-n") || (Resp != NULL && *Resp == ShellPromptResponseYes)) { + Status = gBS->UnloadImage(TheHandle); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HANDLE_RESULT), gShellDriver1HiiHandle, L"Unload", StrHexToUintn(Param1), Status); + } + SHELL_FREE_NON_NULL(Resp); + } + } + } + if (ShellStatus == SHELL_SUCCESS) { + if (Status == EFI_SECURITY_VIOLATION) { + ShellStatus = SHELL_SECURITY_VIOLATION; + } else if (Status == EFI_INVALID_PARAMETER) { + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (EFI_ERROR(Status)) { + ShellStatus = SHELL_NOT_FOUND; + } + } + + if (Package != NULL) { + ShellCommandLineFreeVarList(Package); + } + + return (ShellStatus); +} -- cgit v1.2.3