diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:17:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:17:27 +0000 |
commit | f215e02bf85f68d3a6106c2a1f4f7f063f819064 (patch) | |
tree | 6bb5b92c046312c4e95ac2620b10ddf482d3fa8b /src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib | |
parent | Initial commit. (diff) | |
download | virtualbox-f215e02bf85f68d3a6106c2a1f4f7f063f819064.tar.xz virtualbox-f215e02bf85f68d3a6106c2a1f4f7f063f819064.zip |
Adding upstream version 7.0.14-dfsg.upstream/7.0.14-dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib')
15 files changed, 6338 insertions, 0 deletions
diff --git a/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c new file mode 100644 index 00000000..359446fc --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c @@ -0,0 +1,543 @@ +/** @file + Main file for connect shell Driver1 function. + + (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR> + Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +/** + Create all handles associate with every device path node. + + @param DevicePathToConnect The device path which will be connected. + + @retval EFI_SUCCESS All handles associate with every device path node + have been created. + @retval EFI_INVALID_PARAMETER DevicePathToConnect is NULL. + @retval EFI_NOT_FOUND Create the handle associate with one device path + node failed + +**/ +EFI_STATUS +ShellConnectDevicePath ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect + ) +{ + EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath; + EFI_STATUS Status; + EFI_HANDLE Handle; + EFI_HANDLE PreviousHandle; + + if (DevicePathToConnect == NULL) { + return EFI_INVALID_PARAMETER; + } + + PreviousHandle = NULL; + do{ + RemainingDevicePath = DevicePathToConnect; + Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle); + + if (!EFI_ERROR (Status) && (Handle != NULL)) { + if (PreviousHandle == Handle) { + Status = EFI_NOT_FOUND; + } else { + PreviousHandle = Handle; + Status = gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE); + } + } + + } while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath) ); + + return Status; + +} + +/** + Connect drivers for PCI root bridge. + + @retval EFI_SUCCESS Connect drivers successfully. + @retval EFI_NOT_FOUND Cannot find PCI root bridge device. + +**/ +EFI_STATUS +ShellConnectPciRootBridge ( + VOID + ) +{ + UINTN RootBridgeHandleCount; + EFI_HANDLE *RootBridgeHandleBuffer; + UINTN RootBridgeIndex; + EFI_STATUS Status; + + RootBridgeHandleCount = 0; + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciRootBridgeIoProtocolGuid, + NULL, + &RootBridgeHandleCount, + &RootBridgeHandleBuffer + ); + if (EFI_ERROR (Status)) { + return Status; + } + + for (RootBridgeIndex = 0; RootBridgeIndex < RootBridgeHandleCount; RootBridgeIndex++) { + gBS->ConnectController (RootBridgeHandleBuffer[RootBridgeIndex], NULL, NULL, FALSE); + } + + FreePool (RootBridgeHandleBuffer); + + return EFI_SUCCESS; +} + + +/** + Connect controller(s) and driver(s). + + @param[in] ControllerHandle The handle to the controller. Should have driver binding on it. + @param[in] DriverHandle The handle to the driver. Should have driver binding. + @param[in] Recursive TRUE to connect recursively, FALSE otherwise. + @param[in] Output TRUE to have info on the screen, FALSE otherwise. + @param[in] AlwaysOutput Override Output for errors. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +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 = AllocateZeroPool(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); +} + +/** + Do a connect from an EFI variable via it's key name. + + @param[in] Key The name of the EFI Variable. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +ShellConnectFromDevPaths ( + IN CONST CHAR16 *Key + ) +{ + EFI_DEVICE_PATH_PROTOCOL *DevPath; + EFI_DEVICE_PATH_PROTOCOL *CopyOfDevPath; + EFI_DEVICE_PATH_PROTOCOL *Instance; + EFI_DEVICE_PATH_PROTOCOL *Next; + UINTN Length; + UINTN Index; + UINTN HandleArrayCount; + UINTN Size; + EFI_HANDLE *HandleArray; + EFI_STATUS Status; + BOOLEAN AtLeastOneConnected; + EFI_PCI_IO_PROTOCOL *PciIo; + UINT8 Class[3]; + + DevPath = NULL; + Length = 0; + AtLeastOneConnected = FALSE; + + // + // 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 = AllocateZeroPool(Length); + if (DevPath == NULL) { + return EFI_OUT_OF_RESOURCES; + } + Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath); + if (EFI_ERROR (Status)) { + if (DevPath != NULL) { + FreePool (DevPath); + } + return Status; + } + } else if (EFI_ERROR (Status)) { + return Status; + } + + Status = EFI_NOT_FOUND; + + CopyOfDevPath = DevPath; + // + // walk the list of devices and connect them + // + do { + // + // Check every instance of the console variable + // + Instance = GetNextDevicePathInstance (&CopyOfDevPath, &Size); + if (Instance == NULL) { + if (DevPath != NULL) { + FreePool (DevPath); + } + return EFI_UNSUPPORTED; + } + + Next = Instance; + while (!IsDevicePathEndType (Next)) { + Next = NextDevicePathNode (Next); + } + + SetDevicePathEndNode (Next); + // + // connect short form device path + // + if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) && + ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP) + || (DevicePathSubType (Instance) == MSG_USB_WWID_DP) + )) { + + Status = ShellConnectPciRootBridge (); + if (EFI_ERROR(Status)) { + FreePool(Instance); + FreePool(DevPath); + return Status; + } + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciIoProtocolGuid, + NULL, + &HandleArrayCount, + &HandleArray + ); + + if (!EFI_ERROR (Status)) { + for (Index = 0; Index < HandleArrayCount; Index++) { + Status = gBS->HandleProtocol ( + HandleArray[Index], + &gEfiPciIoProtocolGuid, + (VOID **)&PciIo + ); + + if (!EFI_ERROR (Status)) { + Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class); + if (!EFI_ERROR (Status)) { + if ((PCI_CLASS_SERIAL == Class[2]) && + (PCI_CLASS_SERIAL_USB == Class[1])) { + Status = gBS->ConnectController ( + HandleArray[Index], + NULL, + Instance, + FALSE + ); + if (!EFI_ERROR(Status)) { + AtLeastOneConnected = TRUE; + } + } + } + } + } + } + + if (HandleArray != NULL) { + FreePool (HandleArray); + } + } else { + // + // connect the entire device path + // + Status = ShellConnectDevicePath (Instance); + if (!EFI_ERROR (Status)) { + AtLeastOneConnected = TRUE; + } + } + FreePool (Instance); + + } while (CopyOfDevPath != NULL); + + if (DevPath != NULL) { + FreePool(DevPath); + } + + if (AtLeastOneConnected) { + return EFI_SUCCESS; + } else { + return EFI_NOT_FOUND; + } + +} + +/** + Convert the handle identifiers from strings and then connect them. + + One of them should have driver binding and either can be NULL. + + @param[in] Handle1 The first handle. + @param[in] Handle2 The second handle. + @param[in] Recursive TRUE to do connect recursively. FALSE otherwise. + @param[in] Output TRUE to have output to screen. FALSE otherwise. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +ConvertAndConnectControllers ( + IN EFI_HANDLE Handle1 OPTIONAL, + IN EFI_HANDLE Handle2 OPTIONAL, + IN CONST BOOLEAN Recursive, + IN CONST BOOLEAN Output + ) +{ + // + // 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, (BOOLEAN)(Handle2 != NULL && Handle1 != NULL))); +} + +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; + EFI_HANDLE Handle1; + EFI_HANDLE Handle2; + UINT64 Intermediate; + + 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, L"connect", 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 + // + Count = (gInReconnect?0x4:0x3); + if ((ShellCommandLineGetCount(Package) > Count) + ||(ShellCommandLineGetFlag(Package, L"-c") && ShellCommandLineGetCount(Package)>1) + ||(ShellCommandLineGetFlag(Package, L"-r") && ShellCommandLineGetCount(Package)>2) + ||(ShellCommandLineGetFlag(Package, L"-r") && ShellCommandLineGetFlag(Package, L"-c") ) + ){ + // + // error for too many parameters + // + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"connect"); + 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 = ShellConnectFromDevPaths(L"ConInDev"); + if (EFI_ERROR(Status)) { + ShellConnectFromDevPaths(L"ConOutDev"); + } else { + Status = ShellConnectFromDevPaths(L"ConOutDev"); + } + if (EFI_ERROR(Status)) { + ShellConnectFromDevPaths(L"ErrOutDev"); + } else { + Status = ShellConnectFromDevPaths(L"ErrOutDev"); + } + if (EFI_ERROR(Status)) { + ShellConnectFromDevPaths(L"ErrOut"); + } else { + Status = ShellConnectFromDevPaths(L"ErrOut"); + } + if (EFI_ERROR(Status)) { + ShellConnectFromDevPaths(L"ConIn"); + } else { + Status = ShellConnectFromDevPaths(L"ConIn"); + } + if (EFI_ERROR(Status)) { + ShellConnectFromDevPaths(L"ConOut"); + } else { + Status = ShellConnectFromDevPaths(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) { + Status = ShellConvertStringToUint64(Param1, &Intermediate, TRUE, FALSE); + Handle1 = ConvertHandleIndexToHandle((UINTN)Intermediate); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param1); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } else { + Handle1 = NULL; + } + + if (Param2 != NULL) { + Status = ShellConvertStringToUint64(Param2, &Intermediate, TRUE, FALSE); + Handle2 = ConvertHandleIndexToHandle((UINTN)Intermediate); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param2); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } else { + Handle2 = NULL; + } + + if (ShellStatus == SHELL_SUCCESS) { + if (Param1 != NULL && Handle1 == NULL){ + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param1); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (Param2 != NULL && Handle2 == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param2); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (Handle2 != NULL && Handle1 != NULL && EFI_ERROR(gBS->OpenProtocol(Handle2, &gEfiDriverBindingProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param2); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = ConvertAndConnectControllers(Handle1, Handle2, ShellCommandLineGetFlag(Package, L"-r"), (BOOLEAN)(Count!=0)); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CONNECT_NONE), gShellDriver1HiiHandle); + ShellStatus = SHELL_DEVICE_ERROR; + } + } + } + } + + ShellCommandLineFreeVarList (Package); + } + return (ShellStatus); +} + diff --git a/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/DevTree.c b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/DevTree.c new file mode 100644 index 00000000..82321a4d --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/DevTree.c @@ -0,0 +1,271 @@ +/** @file + Main file for DevTree shell Driver1 function. + + (C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR> + Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-d", TypeFlag}, + {L"-l", TypeValue}, + {NULL, TypeMax} + }; + +/** + Display a tree starting from this handle. + + @param[in] TheHandle The handle to start with. + @param[in] Lang Optionally, a UEFI defined language code. + @param[in] UseDevPaths TRUE to display info from DevPath as identifiers. + FALSE will use component name protocol instead. + @param[in] IndentCharCount How many characters to indent (allows for recursion). + @param[in] HiiString The string from HII to use for output. + + @retval SHELL_SUCCESS The operation was successful. +**/ +SHELL_STATUS +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); + ASSERT (HiiString != NULL); + + if (ShellGetExecutionBreakFlag()) { + ShellStatus = SHELL_ABORTED; + return ShellStatus; + } + + // + // 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; + } + + FormatString = AllocateZeroPool(StrSize(HiiString) + (10)*sizeof(FormatString[0])); + if (FormatString == NULL) { + return SHELL_OUT_OF_RESOURCES; + } + + // + // 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 (ShellStatus == SHELL_ABORTED) { + break; + } + } + + 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; + UINT64 Intermediate; + UINTN ParentControllerHandleCount; + EFI_HANDLE *ParentControllerHandleBuffer; + + 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, L"devtree", 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, L"devtree"); + 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"devtree", 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; + } + + // + // Skip handles that do not have device path protocol + // + Status = gBS->OpenProtocol ( + TheHandle, + &gEfiDevicePathProtocolGuid, + NULL, + NULL, + NULL, + EFI_OPEN_PROTOCOL_TEST_PROTOCOL + ); + if (EFI_ERROR (Status)) { + continue; + } + + // + // Skip handles that do have parents + // + ParentControllerHandleBuffer = NULL; + Status = PARSE_HANDLE_DATABASE_PARENTS ( + TheHandle, + &ParentControllerHandleCount, + &ParentControllerHandleBuffer + ); + SHELL_FREE_NON_NULL (ParentControllerHandleBuffer); + if (ParentControllerHandleCount > 0) { + continue; + } + + // + // Start a devtree from TheHandle that has a device path and no parents + // + ShellStatus = DoDevTreeForHandle(TheHandle, Language, FlagD, 0, HiiString); + } + } else { + Status = ShellConvertStringToUint64(Lang, &Intermediate, TRUE, FALSE); + if (EFI_ERROR(Status) || ConvertHandleIndexToHandle((UINTN)Intermediate) == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"devtree", Lang); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ShellStatus = DoDevTreeForHandle(ConvertHandleIndexToHandle((UINTN)Intermediate), Language, FlagD, 0, HiiString); + } + } + + if (HiiString != NULL) { + FreePool(HiiString); + } + SHELL_FREE_NON_NULL(Language); + ShellCommandLineFreeVarList (Package); + } + + return (ShellStatus); +} diff --git a/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c new file mode 100644 index 00000000..2851c3d6 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c @@ -0,0 +1,263 @@ +/** @file + Main file for devices shell Driver1 function. + + (C) Copyright 2012-2015 Hewlett-Packard Development Company, L.P.<BR> + Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +/** + Get lots of info about a device from its handle. + + @param[in] TheHandle The device handle to get info on. + @param[in, out] Type On successful return R, B, or D (root, bus, or + device) will be placed in this buffer. + @param[in, out] Cfg On successful return this buffer will be + TRUE if the handle has configuration, FALSE + otherwise. + @param[in, out] Diag On successful return this buffer will be + TRUE if the handle has disgnostics, FALSE + otherwise. + @param[in, out] Parents On successful return this buffer will be + contain the number of parent handles. + @param[in, out] Devices On successful return this buffer will be + contain the number of devices controlled. + @param[in, out] Children On successful return this buffer will be + contain the number of child handles. + @param[out] Name The pointer to a buffer that will be allocated + and contain the string name of the handle. + The caller must free this memory. + @param[in] Language The language code as defined by the UEFI spec. + + @retval EFI_SUCCESS The info is there. + @retval EFI_INVALID_PARAMETER A parameter was invalid. +**/ +EFI_STATUS +GetDeviceHandleInfo ( + IN EFI_HANDLE TheHandle, + IN OUT CHAR16 *Type, + IN OUT BOOLEAN *Cfg, + IN OUT BOOLEAN *Diag, + IN OUT UINTN *Parents, + IN OUT UINTN *Devices, + IN OUT 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"-sfo", TypeFlag}, + {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; + BOOLEAN SfoFlag; + + ShellStatus = SHELL_SUCCESS; + Language = NULL; + SfoFlag = FALSE; + + // + // 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, L"devices", 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, L"devices"); + 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"devices", L"-l"); + ShellCommandLineFreeVarList (Package); + return (SHELL_INVALID_PARAMETER); + } + + + // + // Print Header + + // + if (ShellCommandLineGetFlag (Package, L"-sfo")) { + ShellPrintHiiEx (-1, -1, Language, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDriver1HiiHandle, L"devices"); + SfoFlag = TRUE; + } else { + 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 (Name != NULL && (Parents != 0 || Devices != 0 || Children != 0)) { + ShellPrintHiiEx ( + -1, + -1, + Language, + SfoFlag?STRING_TOKEN (STR_DEVICES_ITEM_LINE_SFO):STRING_TOKEN (STR_DEVICES_ITEM_LINE), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex (*HandleListWalker), + Type, + Cfg?(SfoFlag?L'Y':L'X'):(SfoFlag?L'N':L'-'), + Diag?(SfoFlag?L'Y':L'X'):(SfoFlag?L'N':L'-'), + Parents, + Devices, + Children, + Name!=NULL?Name:L"<UNKNOWN>"); + } + if (Name != NULL) { + FreePool(Name); + } + if (ShellGetExecutionBreakFlag ()) { + ShellStatus = SHELL_ABORTED; + break; + } + + } + + if (HandleList != NULL) { + FreePool(HandleList); + } + + } + SHELL_FREE_NON_NULL(Language); + ShellCommandLineFreeVarList (Package); + } + return (ShellStatus); +} + diff --git a/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Dh.c b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Dh.c new file mode 100644 index 00000000..11b0f301 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Dh.c @@ -0,0 +1,1191 @@ +/** @file + Main file for Dh shell Driver1 function. + + (C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR> + Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR> + (C) Copyright 2017 Hewlett Packard Enterprise Development LP<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#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 +}; + +UINTN mGuidDataLen[] = {8, 4, 4, 4, 12}; +/** + Function to determine if the string can convert to a GUID. + The string must be restricted as "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" format. + + @param[in] String The string to test. + + @retval TRUE The string can convert to a GUID. + @retval FALSE The string can't convert to a GUID. +**/ +BOOLEAN +IsValidGuidString( + IN CONST CHAR16 *String + ) +{ + CONST CHAR16 *Walker; + CONST CHAR16 *PrevWalker; + UINTN Index; + + if (String == NULL) { + return FALSE; + } + + Walker = String; + PrevWalker = String; + Index = 0; + + while (Walker != NULL && *Walker != CHAR_NULL) { + if ( (*Walker >= '0' && *Walker <= '9') || + (*Walker >= 'a' && *Walker <= 'f') || + (*Walker >= 'A' && *Walker <= 'F') + ) { + Walker++; + } else { + if (*Walker == L'-' && (((UINTN)Walker - (UINTN)PrevWalker) / sizeof (CHAR16)) == mGuidDataLen[Index]) { + Walker++; + PrevWalker = Walker; + Index++; + } else { + return FALSE; + } + } + } + + if ((((UINTN)Walker - (UINTN)PrevWalker) / sizeof (CHAR16)) == mGuidDataLen[Index]) { + return TRUE; + } else { + return FALSE; + } +} + +/** + Convert a hex-character to decimal value. + + This internal function only deal with Unicode character + which maps to a valid hexadecimal ASII character, i.e. + L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other + Unicode character, the value returned does not make sense. + + @param[in] Char The character to convert. + + @retval The numerical value converted. +**/ +UINTN +HexCharToDecimal( + IN CHAR16 Char + ) +{ + if (Char >= '0' && Char <= '9') { + return Char - L'0'; + } else if (Char >= 'a' && Char <= 'f') { + return Char - L'a' + 10; + } else { + return Char - L'A' + 10; + } +} + +/** + Function try to convert a string to GUID format. + + @param[in] String The string will be converted. + @param[out] Guid Save the result convert from string. + + @retval EFI_SUCCESS The string was successfully converted to a GUID. + @retval EFI_UNSUPPORTED The input string is not in registry format. +**/ +EFI_STATUS +ConvertStrToGuid( + IN CONST CHAR16 *String, + OUT GUID *Guid + ) +{ + CONST CHAR16 *Walker; + UINT8 TempValue; + UINTN Index; + + if (String == NULL || !IsValidGuidString (String)) { + return EFI_UNSUPPORTED; + } + + Index = 0; + + Walker = String; + Guid->Data1 = (UINT32)StrHexToUint64 (Walker); + + Walker += 9; + Guid->Data2 = (UINT16)StrHexToUint64 (Walker); + + Walker += 5; + Guid->Data3 = (UINT16)StrHexToUint64 (Walker); + + Walker += 5; + while (Walker != NULL && *Walker != CHAR_NULL) { + if (*Walker == L'-') { + Walker++; + } else { + TempValue = (UINT8)HexCharToDecimal (*Walker); + TempValue = (UINT8)LShiftU64 (TempValue, 4); + Walker++; + + TempValue += (UINT8)HexCharToDecimal (*Walker); + Walker++; + + Guid->Data4[Index] = TempValue; + Index++; + } + } + + return EFI_SUCCESS; +} + +/** + Get the name of a driver by it's handle. + + If a name is found the memory must be callee freed. + + @param[in] TheHandle The driver's handle. + @param[in] Language The language to use. + @param[in] NameFound Upon a successful return the name found. + + @retval EFI_SUCCESS The name was found. +**/ +EFI_STATUS +GetDriverName ( + IN EFI_HANDLE TheHandle, + IN CONST CHAR8 *Language, + IN CHAR16 **NameFound + ) +{ + CHAR8 *Lang; + EFI_STATUS Status; + EFI_COMPONENT_NAME2_PROTOCOL *CompName2; + CHAR16 *NameToReturn; + // + // Go through those handles until we get one that passes for GetComponentName + // + Status = gBS->OpenProtocol( + TheHandle, + &gEfiComponentName2ProtocolGuid, + (VOID**)&CompName2, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (EFI_ERROR(Status)) { + Status = gBS->OpenProtocol( + TheHandle, + &gEfiComponentNameProtocolGuid, + (VOID**)&CompName2, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + } + + if (EFI_ERROR(Status)) { + return (EFI_NOT_FOUND); + } + Lang = GetBestLanguageForDriver (CompName2->SupportedLanguages, Language, FALSE); + Status = CompName2->GetDriverName(CompName2, Lang, &NameToReturn); + FreePool(Lang); + + if (!EFI_ERROR(Status) && NameToReturn != NULL) { + *NameFound = NULL; + StrnCatGrow(NameFound, NULL, NameToReturn, 0); + } + return (Status); +} + +/** + Discover if a protocol guid is one of the UEFI Driver Model Protocols. + + @param[in] Guid The guid to test. + + @retval TRUE The guid does represent a driver model protocol. + @retval FALSE The guid does not represent a driver model protocol. +**/ +BOOLEAN +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); +} + +/** + Get information for a handle. + + @param[in] TheHandle The handles to show info on. + @param[in] Language Language string per UEFI specification. + @param[in] Separator Separator string between information blocks. + @param[in] Verbose TRUE for extra info, FALSE otherwise. + @param[in] ExtraInfo TRUE for extra info, FALSE otherwise. + + @retval SHELL_SUCCESS The operation was successful. + @retval SHELL_INVALID_PARAMETER ProtocolName was NULL or invalid. +**/ +CHAR16* +GetProtocolInfoString( + IN CONST EFI_HANDLE TheHandle, + IN CONST CHAR8 *Language, + IN CONST CHAR16 *Separator, + IN CONST BOOLEAN Verbose, + IN CONST BOOLEAN ExtraInfo + ) +{ + EFI_GUID **ProtocolGuidArray; + UINTN ArrayCount; + UINTN ProtocolIndex; + EFI_STATUS Status; + CHAR16 *RetVal; + UINTN Size; + CHAR16 *Temp; + CHAR16 GuidStr[40]; + VOID *Instance; + CHAR16 InstanceStr[17]; + + ProtocolGuidArray = NULL; + RetVal = NULL; + Size = 0; + + Status = gBS->ProtocolsPerHandle ( + TheHandle, + &ProtocolGuidArray, + &ArrayCount + ); + if (!EFI_ERROR (Status)) { + for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) { + Temp = GetStringNameFromGuid(ProtocolGuidArray[ProtocolIndex], Language); + ASSERT((RetVal == NULL && Size == 0) || (RetVal != NULL)); + if (Size != 0) { + StrnCatGrow(&RetVal, &Size, Separator, 0); + } + StrnCatGrow(&RetVal, &Size, L"%H", 0); + if (Temp == NULL) { + UnicodeSPrint (GuidStr, sizeof (GuidStr), L"%g", ProtocolGuidArray[ProtocolIndex]); + StrnCatGrow (&RetVal, &Size, GuidStr, 0); + } else { + StrnCatGrow(&RetVal, &Size, Temp, 0); + FreePool(Temp); + } + StrnCatGrow(&RetVal, &Size, L"%N", 0); + + if(Verbose) { + Status = gBS->HandleProtocol (TheHandle, ProtocolGuidArray[ProtocolIndex], &Instance); + if (!EFI_ERROR (Status)) { + StrnCatGrow (&RetVal, &Size, L"(%H", 0); + UnicodeSPrint (InstanceStr, sizeof (InstanceStr), L"%x", Instance); + StrnCatGrow (&RetVal, &Size, InstanceStr, 0); + StrnCatGrow (&RetVal, &Size, L"%N)", 0); + } + } + + 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, Separator, 0); + StrnCatGrow(&RetVal, &Size, Temp, 0); + } + FreePool(Temp); + } + } + } + } + + SHELL_FREE_NON_NULL(ProtocolGuidArray); + + if (RetVal == NULL) { + return (NULL); + } + + ASSERT((RetVal == NULL && Size == 0) || (RetVal != NULL)); + StrnCatGrow(&RetVal, &Size, Separator, 0); + return (RetVal); +} + +/** + Gets the name of the loaded image. + + @param[in] TheHandle The handle of the driver to get info on. + @param[out] Name The pointer to the pointer. Valid upon a successful return. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +GetDriverImageName ( + IN EFI_HANDLE TheHandle, + OUT CHAR16 **Name + ) +{ + // get loaded image and devicepathtotext on image->Filepath + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + + if (TheHandle == NULL || Name == NULL) { + return (EFI_INVALID_PARAMETER); + } + + Status = gBS->OpenProtocol ( + TheHandle, + &gEfiLoadedImageProtocolGuid, + (VOID **) &LoadedImage, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR(Status)) { + return (Status); + } + DevicePath = LoadedImage->FilePath; + *Name = ConvertDevicePathToText(DevicePath, TRUE, TRUE); + return (EFI_SUCCESS); +} + +/** + Display driver model information for a given handle. + + @param[in] Handle The handle to display info on. + @param[in] BestName Use the best name? + @param[in] Language The language to output in. +**/ +EFI_STATUS +DisplayDriverModelHandle ( + IN EFI_HANDLE Handle, + IN BOOLEAN BestName, + IN CONST CHAR8 *Language OPTIONAL + ) +{ + EFI_STATUS Status; + BOOLEAN ConfigurationStatus; + BOOLEAN DiagnosticsStatus; + UINTN DriverBindingHandleCount; + EFI_HANDLE *DriverBindingHandleBuffer; + UINTN ParentControllerHandleCount; + EFI_HANDLE *ParentControllerHandleBuffer; + UINTN ChildControllerHandleCount; + EFI_HANDLE *ChildControllerHandleBuffer; + CHAR16 *TempStringPointer; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + UINTN Index; + CHAR16 *DriverName; + EFI_DRIVER_BINDING_PROTOCOL *DriverBinding; + UINTN NumberOfChildren; + UINTN HandleIndex; + UINTN ControllerHandleCount; + EFI_HANDLE *ControllerHandleBuffer; + UINTN ChildIndex; + BOOLEAN Image; + + DriverName = NULL; + + // + // See if Handle is a device handle and display its details. + // + DriverBindingHandleBuffer = NULL; + Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS ( + Handle, + &DriverBindingHandleCount, + &DriverBindingHandleBuffer + ); + + ParentControllerHandleBuffer = NULL; + Status = PARSE_HANDLE_DATABASE_PARENTS ( + Handle, + &ParentControllerHandleCount, + &ParentControllerHandleBuffer + ); + + ChildControllerHandleBuffer = NULL; + Status = ParseHandleDatabaseForChildControllers ( + Handle, + &ChildControllerHandleCount, + &ChildControllerHandleBuffer + ); + + DiagnosticsStatus = FALSE; + ConfigurationStatus = FALSE; + + if (!EFI_ERROR(gBS->OpenProtocol(Handle, &gEfiDriverConfigurationProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + ConfigurationStatus = TRUE; + } + if (!EFI_ERROR(gBS->OpenProtocol(Handle, &gEfiDriverConfiguration2ProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + ConfigurationStatus = TRUE; + } + if (!EFI_ERROR(gBS->OpenProtocol(Handle, &gEfiDriverDiagnosticsProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + DiagnosticsStatus = TRUE; + } + if (!EFI_ERROR(gBS->OpenProtocol(Handle, &gEfiDriverDiagnostics2ProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + DiagnosticsStatus = TRUE; + } + + Status = EFI_SUCCESS; + + if (DriverBindingHandleCount > 0 || ParentControllerHandleCount > 0 || ChildControllerHandleCount > 0) { + + + + DevicePath = NULL; + TempStringPointer = NULL; + Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID**)&DevicePath); + + Status = gEfiShellProtocol->GetDeviceName(Handle, EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Language, &TempStringPointer); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DH_OUTPUT_DRIVER1), gShellDriver1HiiHandle, TempStringPointer!=NULL?TempStringPointer:L"<Unknown>"); + SHELL_FREE_NON_NULL(TempStringPointer); + + TempStringPointer = ConvertDevicePathToText(DevicePath, TRUE, FALSE); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER2), + gShellDriver1HiiHandle, + TempStringPointer!=NULL?TempStringPointer:L"<None>", + ParentControllerHandleCount == 0?L"ROOT":(ChildControllerHandleCount > 0)?L"BUS":L"DEVICE", + ConfigurationStatus?L"YES":L"NO", + DiagnosticsStatus?L"YES":L"NO" + ); + + SHELL_FREE_NON_NULL(TempStringPointer); + + if (DriverBindingHandleCount == 0) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER3), + gShellDriver1HiiHandle, + L"<None>" + ); + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER3), + gShellDriver1HiiHandle, + L"" + ); + for (Index = 0; Index < DriverBindingHandleCount; Index++) { + Image = FALSE; + Status = GetDriverName ( + DriverBindingHandleBuffer[Index], + Language, + &DriverName + ); + if (EFI_ERROR (Status)) { + Status = GetDriverImageName ( + DriverBindingHandleBuffer[Index], + &DriverName + ); + if (EFI_ERROR (Status)) { + DriverName = NULL; + } + } + + if (Image) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER4A), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex (DriverBindingHandleBuffer[Index]), + DriverName!=NULL?DriverName:L"<Unknown>" + ); + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER4B), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex (DriverBindingHandleBuffer[Index]), + DriverName!=NULL?DriverName:L"<Unknown>" + ); + } + SHELL_FREE_NON_NULL(DriverName); + } + } + + if (ParentControllerHandleCount == 0) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER5), + gShellDriver1HiiHandle, + L"<None>" + ); + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER5), + gShellDriver1HiiHandle, + L"" + ); + for (Index = 0; Index < ParentControllerHandleCount; Index++) { + Status = gEfiShellProtocol->GetDeviceName(ParentControllerHandleBuffer[Index], EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Language, &TempStringPointer); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER5B), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex (ParentControllerHandleBuffer[Index]), + TempStringPointer!=NULL?TempStringPointer:L"<Unknown>" + ); + SHELL_FREE_NON_NULL(TempStringPointer); + } + } + + if (ChildControllerHandleCount == 0) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER6), + gShellDriver1HiiHandle, + L"<None>" + ); + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER6), + gShellDriver1HiiHandle, + L"" + ); + for (Index = 0; Index < ChildControllerHandleCount; Index++) { + Status = gEfiShellProtocol->GetDeviceName(ChildControllerHandleBuffer[Index], EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Language, &TempStringPointer); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER6B), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex (ChildControllerHandleBuffer[Index]), + TempStringPointer!=NULL?TempStringPointer:L"<Unknown>" + ); + SHELL_FREE_NON_NULL(TempStringPointer); + } + } + } + + SHELL_FREE_NON_NULL(DriverBindingHandleBuffer); + + SHELL_FREE_NON_NULL(ParentControllerHandleBuffer); + + SHELL_FREE_NON_NULL(ChildControllerHandleBuffer); + + if (EFI_ERROR (Status)) { + return Status; + } + // + // See if Handle is a driver binding handle and display its details. + // + Status = gBS->OpenProtocol ( + Handle, + &gEfiDriverBindingProtocolGuid, + (VOID **) &DriverBinding, + NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return EFI_SUCCESS; + } + + NumberOfChildren = 0; + ControllerHandleBuffer = NULL; + Status = PARSE_HANDLE_DATABASE_DEVICES ( + Handle, + &ControllerHandleCount, + &ControllerHandleBuffer + ); + if (ControllerHandleCount > 0) { + for (HandleIndex = 0; HandleIndex < ControllerHandleCount; HandleIndex++) { + Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN ( + Handle, + ControllerHandleBuffer[HandleIndex], + &ChildControllerHandleCount, + NULL + ); + NumberOfChildren += ChildControllerHandleCount; + } + } + + Status = GetDriverName (Handle, Language, &DriverName); + if (EFI_ERROR (Status)) { + DriverName = NULL; + } + + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER7), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex(Handle), + DriverName!=NULL?DriverName:L"<Unknown>" + ); + SHELL_FREE_NON_NULL(DriverName); + Status = GetDriverImageName ( + Handle, + &DriverName + ); + if (EFI_ERROR (Status)) { + DriverName = NULL; + } + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER7B), + gShellDriver1HiiHandle, + DriverName!=NULL?DriverName:L"<Unknown>" + ); + SHELL_FREE_NON_NULL(DriverName); + + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER8), + gShellDriver1HiiHandle, + DriverBinding->Version, + NumberOfChildren > 0?L"Bus":ControllerHandleCount > 0?L"Device":L"<Unknown>", + ConfigurationStatus?L"YES":L"NO", + DiagnosticsStatus?L"YES":L"NO" + ); + + if (ControllerHandleCount == 0) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER9), + gShellDriver1HiiHandle, + L"None" + ); + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER9), + gShellDriver1HiiHandle, + L"" + ); + for (HandleIndex = 0; HandleIndex < ControllerHandleCount; HandleIndex++) { + Status = gEfiShellProtocol->GetDeviceName(ControllerHandleBuffer[HandleIndex], EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Language, &TempStringPointer); + + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER9B), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex(ControllerHandleBuffer[HandleIndex]), + TempStringPointer!=NULL?TempStringPointer:L"<Unknown>" + ); + SHELL_FREE_NON_NULL(TempStringPointer); + + Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN ( + Handle, + ControllerHandleBuffer[HandleIndex], + &ChildControllerHandleCount, + &ChildControllerHandleBuffer + ); + if (!EFI_ERROR (Status)) { + for (ChildIndex = 0; ChildIndex < ChildControllerHandleCount; ChildIndex++) { + Status = gEfiShellProtocol->GetDeviceName(ChildControllerHandleBuffer[ChildIndex], EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Language, &TempStringPointer); + + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_DRIVER6C), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex(ChildControllerHandleBuffer[ChildIndex]), + TempStringPointer!=NULL?TempStringPointer:L"<Unknown>" + ); + SHELL_FREE_NON_NULL(TempStringPointer); + } + + SHELL_FREE_NON_NULL (ChildControllerHandleBuffer); + } + } + + SHELL_FREE_NON_NULL (ControllerHandleBuffer); + } + + return EFI_SUCCESS; +} + +/** + Display information for a handle. + + @param[in] TheHandle The handles to show info on. + @param[in] Verbose TRUE for extra info, FALSE otherwise. + @param[in] Sfo TRUE to output in standard format output (spec). + @param[in] Language Language string per UEFI specification. + @param[in] DriverInfo TRUE to show all info about the handle. + @param[in] Multiple TRUE indicates more than will be output, + FALSE for a single one. +**/ +VOID +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; + + ProtocolInfoString = NULL; + + if (!Sfo) { + if (Multiple) { + ProtocolInfoString = GetProtocolInfoString(TheHandle, Language, L" ", Verbose, TRUE); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex(TheHandle), + ProtocolInfoString==NULL?L"":ProtocolInfoString + ); + } else { + ProtocolInfoString = GetProtocolInfoString(TheHandle, Language, Verbose ? L"\r\n" : L" ", Verbose, TRUE); + if (Verbose) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_SINGLE), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex(TheHandle), + TheHandle, + ProtocolInfoString==NULL?L"":ProtocolInfoString + ); + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DH_OUTPUT_SINGLE_D), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex(TheHandle), + ProtocolInfoString==NULL?L"":ProtocolInfoString + ); + } + } + + if (DriverInfo) { + DisplayDriverModelHandle ((EFI_HANDLE)TheHandle, TRUE, Language); + } + } else { + ProtocolInfoString = GetProtocolInfoString(TheHandle, Language, L";", 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); + } +} + +/** + Display information for all handles on a list. + + @param[in] HandleList The NULL-terminated list of handles. + @param[in] Verbose TRUE for extra info, FALSE otherwise. + @param[in] Sfo TRUE to output in standard format output (spec). + @param[in] Language Language string per UEFI specification. + @param[in] DriverInfo TRUE to show all info about the handle. + + @retval SHELL_SUCCESS The operation was successful. + @retval SHELL_ABORTED The operation was aborted. +**/ +SHELL_STATUS +DoDhForHandleList( + IN CONST EFI_HANDLE *HandleList, + IN CONST BOOLEAN Verbose, + 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; HandleWalker++) { + DoDhByHandle (*HandleWalker, Verbose, Sfo, Language, DriverInfo, TRUE); + if (ShellGetExecutionBreakFlag ()) { + ShellStatus = SHELL_ABORTED; + break; + } + } + return (ShellStatus); +} + +/** + Display information for a GUID of protocol. + + @param[in] Guid The pointer to the name of the protocol. + @param[in] Verbose TRUE for extra info, FALSE otherwise. + @param[in] Sfo TRUE to output in standard format output (spec). + @param[in] Language Language string per UEFI specification. + @param[in] DriverInfo TRUE to show all info about the handle. + + @retval SHELL_SUCCESS The operation was successful. + @retval SHELL_NOT_FOUND The GUID was not found. + @retval SHELL_INVALID_PARAMETER ProtocolName was NULL or invalid. +**/ +SHELL_STATUS +DoDhByProtocolGuid( + IN CONST GUID *Guid, + IN CONST BOOLEAN Verbose, + IN CONST BOOLEAN Sfo, + IN CONST CHAR8 *Language, + IN CONST BOOLEAN DriverInfo + ) +{ + CHAR16 *Name; + SHELL_STATUS ShellStatus; + EFI_HANDLE *HandleList; + + if (!Sfo) { + if (Guid == NULL) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DH_OUTPUT_ALL_HEADER), gShellDriver1HiiHandle); + } else { + Name = GetStringNameFromGuid (Guid, NULL); + if (Name == NULL) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DH_OUTPUT_GUID_HEADER), gShellDriver1HiiHandle, Guid); + } else { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DH_OUTPUT_NAME_HEADER), gShellDriver1HiiHandle, Name); + } + } + } + HandleList = GetHandleListByProtocol(Guid); + ShellStatus = DoDhForHandleList(HandleList, Verbose, Sfo, Language, DriverInfo); + SHELL_FREE_NON_NULL(HandleList); + + return ShellStatus; +} + +/** + Function to determine use which method to print information. + If Protocol is NULL, The function will print all information. + + @param[in] Protocol The pointer to the name or GUID of protocol or NULL. + @param[in] Verbose TRUE for extra info, FALSE otherwise. + @param[in] Sfo TRUE to output in standard format output (spec). + @param[in] Language Language string per UEFI specification. + @param[in] DriverInfo TRUE to show all info about the handle. + + @retval SHELL_SUCCESS The operation was successful. + @retval SHELL_NOT_FOUND The protocol was not found. + @retval SHELL_INVALID_PARAMETER Protocol is invalid parameter. +**/ +SHELL_STATUS +DoDhByProtocol ( + IN CONST CHAR16 *Protocol, + IN CONST BOOLEAN Verbose, + IN CONST BOOLEAN Sfo, + IN CONST CHAR8 *Language, + IN CONST BOOLEAN DriverInfo + ) +{ + EFI_GUID Guid; + EFI_GUID *GuidPtr; + EFI_STATUS Status; + + if (Protocol == NULL) { + return DoDhByProtocolGuid (NULL, Verbose, Sfo, Language, DriverInfo); + } else { + Status = ConvertStrToGuid (Protocol, &Guid); + if (!EFI_ERROR (Status)) { + GuidPtr = &Guid; + } else { + // + // Protocol is a Name, convert it to GUID + // + Status = GetGuidFromStringName (Protocol, Language, &GuidPtr); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DH_NO_NAME_FOUND), gShellDriver1HiiHandle, Protocol); + return (SHELL_NOT_FOUND); + } + } + + return DoDhByProtocolGuid (GuidPtr, Verbose, Sfo, Language, DriverInfo); + } +} + +/** + Function to display decode information by Protocol. + The parameter Protocol is either a GUID or the name of protocol. + If the parameter Protocol is NULL, the function will print all + decode information. + + @param[in] Protocol The pointer to the name or GUID of protocol. + @param[in] Language Language string per UEFI specification. + + @retval SHELL_SUCCESS The operation was successful. + @retval SHELL_OUT_OT_RESOURCES A memory allocation failed. +**/ +SHELL_STATUS +DoDecodeByProtocol( + IN CONST CHAR16 *Protocol, + IN CONST CHAR8 *Language + ) +{ + EFI_STATUS Status; + EFI_GUID *Guids; + EFI_GUID Guid; + UINTN Counts; + UINTN Index; + CHAR16 *Name; + + if (Protocol == NULL) { + Counts = 0; + Status = GetAllMappingGuids (NULL, &Counts); + if (Status == EFI_BUFFER_TOO_SMALL) { + Guids = AllocatePool (Counts * sizeof(EFI_GUID)); + if (Guids == NULL) { + return SHELL_OUT_OF_RESOURCES; + } + + Status = GetAllMappingGuids (Guids, &Counts); + if (Status == EFI_SUCCESS) { + for (Index = 0; Index < Counts; Index++) { + Name = GetStringNameFromGuid (&Guids[Index], Language); + if (Name != NULL) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DH_OUTPUT_DECODE), gShellDriver1HiiHandle, Name, &Guids[Index]); + } else { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DH_NO_GUID_FOUND), gShellDriver1HiiHandle, &Guids[Index]); + } + SHELL_FREE_NON_NULL (Name); + } + } + FreePool (Guids); + } + } else { + if (ConvertStrToGuid (Protocol, &Guid) == EFI_SUCCESS) { + Name = GetStringNameFromGuid (&Guid, Language); + if (Name != NULL) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DH_OUTPUT_DECODE), gShellDriver1HiiHandle, Name, &Guid); + } else { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DH_NO_GUID_FOUND), gShellDriver1HiiHandle, &Guid); + } + SHELL_FREE_NON_NULL(Name); + } else { + Status = GetGuidFromStringName (Protocol, Language, &Guids); + if (Status == EFI_SUCCESS) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DH_OUTPUT_DECODE), gShellDriver1HiiHandle, Protocol, Guids); + } else { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DH_NO_NAME_FOUND), gShellDriver1HiiHandle, Protocol); + } + } + } + + return SHELL_SUCCESS; +} + +/** + 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 + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + CHAR8 *Language; + CONST CHAR16 *Lang; + CONST CHAR16 *RawValue; + CONST CHAR16 *ProtocolVal; + BOOLEAN SfoFlag; + BOOLEAN DriverFlag; + BOOLEAN VerboseFlag; + UINT64 Intermediate; + EFI_HANDLE Handle; + + 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, L"dh", 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, L"dh"); + ShellCommandLineFreeVarList (Package); + return (SHELL_INVALID_PARAMETER); + } + + if (ShellCommandLineGetFlag(Package, L"-l")) { + Lang = ShellCommandLineGetValue(Package, L"-l"); + if (Lang != NULL) { + Language = AllocateZeroPool(StrSize(Lang)); + AsciiSPrint(Language, StrSize(Lang), "%S", Lang); + } else { + ASSERT(Language == NULL); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"dh", L"-l"); + ShellCommandLineFreeVarList(Package); + return (SHELL_INVALID_PARAMETER); + } + } else { + Language = AllocateZeroPool(10); + AsciiSPrint(Language, 10, "en-us"); + } + + SfoFlag = ShellCommandLineGetFlag (Package, L"-sfo"); + DriverFlag = ShellCommandLineGetFlag (Package, L"-d"); + VerboseFlag = (BOOLEAN)(ShellCommandLineGetFlag (Package, L"-v") || ShellCommandLineGetFlag (Package, L"-verbose")); + RawValue = ShellCommandLineGetRawValue (Package, 1); + ProtocolVal = ShellCommandLineGetValue (Package, L"-p"); + + if (RawValue == NULL) { + if (ShellCommandLineGetFlag (Package, L"-p") && (ProtocolVal == NULL)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"dh", L"-p"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + // + // Print information by protocol, The ProtocolVal maybe is name or GUID or NULL. + // + ShellStatus = DoDhByProtocol (ProtocolVal, VerboseFlag, SfoFlag, Language, DriverFlag); + } + } else if ((RawValue != NULL) && + (gUnicodeCollation->StriColl(gUnicodeCollation, L"decode", (CHAR16 *) RawValue) == 0)) { + if (ShellCommandLineGetFlag (Package, L"-p") && (ProtocolVal == NULL)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"dh", L"-p"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + // + // Print decode informatino by protocol. + // + ShellStatus = DoDecodeByProtocol (ProtocolVal, Language); + } + } else { + if (ShellCommandLineGetFlag (Package, L"-p")) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"dh"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = ShellConvertStringToUint64 (RawValue, &Intermediate, TRUE, FALSE); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"dh", RawValue); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Handle = ConvertHandleIndexToHandle ((UINTN) Intermediate); + if (Handle == NULL) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"dh", RawValue); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + // + // Print information by handle. + // + DoDhByHandle (Handle, VerboseFlag, SfoFlag, Language, DriverFlag, FALSE); + } + } + } + } + + ShellCommandLineFreeVarList (Package); + SHELL_FREE_NON_NULL(Language); + } + + return (ShellStatus); +} diff --git a/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c new file mode 100644 index 00000000..e209db89 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c @@ -0,0 +1,198 @@ +/** @file + Main file for Disconnect shell Driver1 function. + + (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR> + (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR> + Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-r", TypeFlag}, + {L"-nc", TypeFlag}, + {NULL, TypeMax} + }; + +/** + Disconnect everything. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +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); +} + +/** + 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 + ) +{ + 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; + UINT64 Intermediate1; + UINT64 Intermediate2; + UINT64 Intermediate3; + + 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, L"disconnect", 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, L"disconnect"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount(Package) < 1) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"disconnect"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = DisconnectAll (); + // + // Reconnect all consoles if -nc is not provided + // + if (!ShellCommandLineGetFlag (Package, L"-nc")){ + ShellConnectFromDevPaths (L"ConInDev"); + ShellConnectFromDevPaths (L"ConOutDev"); + ShellConnectFromDevPaths (L"ErrOutDev"); + ShellConnectFromDevPaths (L"ErrOut"); + ShellConnectFromDevPaths (L"ConIn"); + ShellConnectFromDevPaths (L"ConOut"); + } + } + } else if (ShellCommandLineGetFlag (Package, L"-nc")) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"disconnect"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + if (ShellCommandLineGetCount(Package) > 4){ + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"disconnect"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount(Package) < 2) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"disconnect"); + 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); + ShellConvertStringToUint64(Param1, &Intermediate1, TRUE, FALSE); + Handle1 = Param1!=NULL?ConvertHandleIndexToHandle((UINTN)Intermediate1):NULL; + ShellConvertStringToUint64(Param2, &Intermediate2, TRUE, FALSE); + Handle2 = Param2!=NULL?ConvertHandleIndexToHandle((UINTN)Intermediate2):NULL; + ShellConvertStringToUint64(Param3, &Intermediate3, TRUE, FALSE); + Handle3 = Param3!=NULL?ConvertHandleIndexToHandle((UINTN)Intermediate3):NULL; + + if (Param1 != NULL && Handle1 == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"disconnect", Param1); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (Param2 != NULL && Handle2 == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"disconnect", Param2); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (Param3 != NULL && Handle3 == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"disconnect", Param3); + 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, L"disconnect", ShellStrToUintn(Param2), L"driver handle"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(Param1 != NULL); + Status = gBS->DisconnectController(Handle1, Handle2, Handle3); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_3P_RESULT), gShellDriver1HiiHandle, L"Disconnect", (UINTN)Intermediate1, (UINTN)Intermediate2, (UINTN)Intermediate3, 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/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Drivers.c b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Drivers.c new file mode 100644 index 00000000..cf8d3d32 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Drivers.c @@ -0,0 +1,423 @@ +/** @file + Main file for Drivers shell Driver1 function. + + (C) Copyright 2012-2015 Hewlett-Packard Development Company, L.P.<BR> + Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +#define MAX_LEN_DRIVER_NAME 35 + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-sfo", TypeFlag}, + {L"-l", TypeValue}, + {NULL, TypeMax} + }; + +/** + Get a device path (in text format) for a given handle. + + @param[in] TheHandle The handle to get the device path for. + + @retval NULL An error occurred. + @return A pointer to the driver path as a string. The callee must + free this memory. +**/ +CHAR16* +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 = ConvertDevicePathToText(FinalPath, TRUE, TRUE); + } + FreePool(FinalPath); + return (RetVal); +} + +/** + Determine if the given handle has Driver Configuration protocol. + + @param[in] TheHandle The handle to the driver to test. + + @retval TRUE The driver does have Driver Configuration. + @retval FALSE The driver does not have Driver Configuration. +**/ +BOOLEAN +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); +} + +/** + Determine if the given handle has DriverDiagnostics protocol. + + @param[in] TheHandle The handle to the driver to test. + + @retval TRUE The driver does have Driver Diasgnostics. + @retval FALSE The driver does not have Driver Diagnostics. +**/ +BOOLEAN +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); +} + +/** + Finds and returns the version of the driver specified by TheHandle. + + @param[in] TheHandle The driver handle to get the version of. + + @return The version of the driver. + @retval 0xFFFFFFFF An error ocurred. +**/ +UINT32 +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); +} + +/** + Get image name from Image Handle. + + @param[in] Handle Image Handle + + @return A pointer to the image name as a string. +**/ +CHAR16 * +GetImageNameFromHandle ( + IN CONST EFI_HANDLE Handle + ) +{ + EFI_STATUS Status; + EFI_DRIVER_BINDING_PROTOCOL *DriverBinding; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + EFI_DEVICE_PATH_PROTOCOL *DevPathNode; + EFI_GUID *NameGuid; + CHAR16 *ImageName; + UINTN BufferSize; + UINT32 AuthenticationStatus; + EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv2; + + LoadedImage = NULL; + DriverBinding = NULL; + ImageName = NULL; + + Status = gBS->OpenProtocol ( + Handle, + &gEfiDriverBindingProtocolGuid, + (VOID **) &DriverBinding, + NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return NULL; + } + Status = gBS->OpenProtocol ( + DriverBinding->ImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID**)&LoadedImage, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR (Status)) { + DevPathNode = LoadedImage->FilePath; + if (DevPathNode == NULL) { + return NULL; + } + while (!IsDevicePathEnd (DevPathNode)) { + NameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)DevPathNode); + if (NameGuid != NULL) { + Status = gBS->HandleProtocol ( + LoadedImage->DeviceHandle, + &gEfiFirmwareVolume2ProtocolGuid, + (VOID **)&Fv2 + ); + if (!EFI_ERROR (Status)) { + Status = Fv2->ReadSection ( + Fv2, + NameGuid, + EFI_SECTION_USER_INTERFACE, + 0, + (VOID **)&ImageName, + &BufferSize, + &AuthenticationStatus + ); + if (!EFI_ERROR (Status)) { + break; + } + ImageName = NULL; + } + } + // + // Next device path node + // + DevPathNode = NextDevicePathNode (DevPathNode); + } + if (ImageName == NULL) { + ImageName = ConvertDevicePathToText (LoadedImage->FilePath, TRUE, TRUE); + } + } + return ImageName; +} + +/** + 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 + ) +{ + 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 ChildCountStr[21]; + CHAR16 DeviceCountStr[21]; + CHAR16 *Temp2; + CONST CHAR16 *FullDriverName; + CHAR16 *TruncatedDriverName; + CHAR16 *ImageName; + CHAR16 *FormatString; + UINT32 DriverVersion; + BOOLEAN DriverConfig; + BOOLEAN DriverDiag; + BOOLEAN SfoFlag; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + Language = NULL; + FormatString = NULL; + SfoFlag = FALSE; + + // + // 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, L"drivers", 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, L"drivers"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + if (ShellCommandLineGetFlag(Package, L"-l")){ + Lang = ShellCommandLineGetValue(Package, L"-l"); + if (Lang != NULL) { + Language = AllocateZeroPool(StrSize(Lang)); + AsciiSPrint(Language, StrSize(Lang), "%S", Lang); + } else { + ASSERT(Language == NULL); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"drivers", L"-l"); + ShellCommandLineFreeVarList (Package); + return (SHELL_INVALID_PARAMETER); + } + } + + if (ShellCommandLineGetFlag (Package, L"-sfo")) { + SfoFlag = TRUE; + FormatString = HiiGetString (gShellDriver1HiiHandle, STRING_TOKEN (STR_DRIVERS_ITEM_LINE_SFO), Language); + // + // print the SFO header + // + ShellPrintHiiEx ( + -1, + -1, + Language, + STRING_TOKEN (STR_GEN_SFO_HEADER), + gShellDriver1HiiHandle, + L"drivers"); + } 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); + FullDriverName = GetStringNameFromHandle(*HandleWalker, Language); + ImageName = GetImageNameFromHandle (*HandleWalker); + + UnicodeValueToStringS (ChildCountStr, sizeof (ChildCountStr), 0, ChildCount, 0); + UnicodeValueToStringS (DeviceCountStr, sizeof (DeviceCountStr), 0, DeviceCount, 0); + TruncatedDriverName = NULL; + if (!SfoFlag && (FullDriverName != NULL)) { + TruncatedDriverName = AllocateZeroPool ((MAX_LEN_DRIVER_NAME + 1) * sizeof (CHAR16)); + StrnCpyS (TruncatedDriverName, MAX_LEN_DRIVER_NAME + 1, FullDriverName, MAX_LEN_DRIVER_NAME); + } + + if (!SfoFlag) { + ShellPrintEx ( + -1, + -1, + FormatString, + ConvertHandleToHandleIndex (*HandleWalker), + DriverVersion, + ChildCount > 0 ? L'B' : (DeviceCount > 0 ? L'D' : L'?'), + DriverConfig ? L'X' : L'-', + DriverDiag ? L'X' : L'-', + DeviceCount > 0 ? DeviceCountStr : L"-", + ChildCount > 0 ? ChildCountStr : L"-", + TruncatedDriverName, + ImageName == NULL ? L"" : ImageName + ); + } else { + 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, + FullDriverName, + Temp2 == NULL ? L"" : Temp2 + ); + } + if (TruncatedDriverName != NULL) { + FreePool (TruncatedDriverName); + } + if (Temp2 != NULL) { + FreePool(Temp2); + } + if (ImageName != NULL) { + FreePool (ImageName); + } + + if (ShellGetExecutionBreakFlag ()) { + ShellStatus = SHELL_ABORTED; + break; + } + } + } + SHELL_FREE_NON_NULL(Language); + ShellCommandLineFreeVarList (Package); + SHELL_FREE_NON_NULL(FormatString); + } + + return (ShellStatus); +} diff --git a/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c new file mode 100644 index 00000000..4259f451 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c @@ -0,0 +1,1406 @@ +/** @file + Main file for DrvCfg shell Driver1 function. + + (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR> + Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UefiShellDriver1CommandsLib.h" +#include <Protocol/HiiConfigAccess.h> +#include <Protocol/HiiDatabase.h> + +STATIC CONST EFI_GUID *CfgGuidList[] = {&gEfiDriverConfigurationProtocolGuid, &gEfiDriverConfiguration2ProtocolGuid, NULL}; + +/** + Find the EFI_HII_HANDLE by device path. + + @param[in] DevPath1 The Device Path to match. + @param[out] HiiHandle The EFI_HII_HANDLE after the converstion. + @param[in] HiiDb The Hii database protocol + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_NOT_FOUND There was no EFI_HII_HANDLE found for that deviec path. +**/ +EFI_STATUS +FindHiiHandleViaDevPath( + IN CONST EFI_DEVICE_PATH_PROTOCOL *DevPath1, + OUT EFI_HII_HANDLE *HiiHandle, + IN EFI_HII_DATABASE_PROTOCOL *HiiDb + ) +{ + EFI_HII_HANDLE *HandleBuffer; + UINTN HandleBufferSize; + VOID *MainBuffer; + UINTN MainBufferSize; + EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; + EFI_HII_PACKAGE_HEADER *PackageHeader; + UINTN LoopVariable; + EFI_DEVICE_PATH_PROTOCOL *DevPath2; + EFI_STATUS Status; + + ASSERT(DevPath1 != NULL); + ASSERT(HiiHandle != NULL); + ASSERT(*HiiHandle == NULL); + ASSERT(HiiDb != NULL); + + HandleBufferSize = 0; + HandleBuffer = NULL; + Status = HiiDb->ListPackageLists(HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer); + if (Status == EFI_BUFFER_TOO_SMALL) { + HandleBuffer = AllocateZeroPool(HandleBufferSize); + if (HandleBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + Status = HiiDb->ListPackageLists (HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer); + } + } + if (EFI_ERROR(Status)) { + SHELL_FREE_NON_NULL(HandleBuffer); + return (Status); + } + + if (HandleBuffer == NULL) { + return EFI_NOT_FOUND; + } + + for (LoopVariable = 0 ; LoopVariable < (HandleBufferSize/sizeof(HandleBuffer[0])) && *HiiHandle == NULL ; LoopVariable++) { + MainBufferSize = 0; + MainBuffer = NULL; + Status = HiiDb->ExportPackageLists(HiiDb, HandleBuffer[LoopVariable], &MainBufferSize, MainBuffer); + if (Status == EFI_BUFFER_TOO_SMALL) { + MainBuffer = AllocateZeroPool(MainBufferSize); + if (MainBuffer != NULL) { + Status = HiiDb->ExportPackageLists (HiiDb, HandleBuffer[LoopVariable], &MainBufferSize, MainBuffer); + } + } + if (EFI_ERROR (Status)) { + continue; + } + // + // Enumerate through the block of returned memory. + // This should actually be a small block, but we need to be sure. + // + for (PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)MainBuffer + ; PackageListHeader != NULL && ((CHAR8*)PackageListHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) && *HiiHandle == NULL + ; PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)(((CHAR8*)(PackageListHeader)) + PackageListHeader->PackageLength )) { + for (PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageListHeader))+sizeof(EFI_HII_PACKAGE_LIST_HEADER)) + ; PackageHeader != NULL && ((CHAR8*)PackageHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) && PackageHeader->Type != EFI_HII_PACKAGE_END && *HiiHandle == NULL + ; PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageHeader))+PackageHeader->Length)) { + if (PackageHeader->Type == EFI_HII_PACKAGE_DEVICE_PATH) { + DevPath2 = (EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)); + if (DevicePathCompare(&DevPath1, &DevPath2) == 0) { + *HiiHandle = HandleBuffer[LoopVariable]; + break; + } + } + } + } + SHELL_FREE_NON_NULL(MainBuffer); + } + SHELL_FREE_NON_NULL(HandleBuffer); + + if (*HiiHandle == NULL) { + return (EFI_NOT_FOUND); + } + return (EFI_SUCCESS); +} + +/** + Convert a EFI_HANDLE to a EFI_HII_HANDLE. + + @param[in] Handle The EFI_HANDLE to convert. + @param[out] HiiHandle The EFI_HII_HANDLE after the converstion. + @param[in] HiiDb The Hii database protocol + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +ConvertHandleToHiiHandle( + IN CONST EFI_HANDLE Handle, + OUT EFI_HII_HANDLE *HiiHandle, + IN EFI_HII_DATABASE_PROTOCOL *HiiDb + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevPath1; + + if (HiiHandle == NULL || HiiDb == NULL) { + return (EFI_INVALID_PARAMETER); + } + *HiiHandle = NULL; + + if (Handle == NULL) { + return (EFI_SUCCESS); + } + + DevPath1 = NULL; + Status = gBS->OpenProtocol(Handle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath1, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (EFI_ERROR(Status) || DevPath1 == NULL) { + return (EFI_NOT_FOUND); + } + + return (FindHiiHandleViaDevPath(DevPath1, HiiHandle, HiiDb)); +} + +/** + Function to print out all HII configuration information to a file. + + @param[in] Handle The handle to get info on. NULL to do all handles. + @param[in] FileName The filename to rwite the info to. +**/ +SHELL_STATUS +ConfigToFile( + IN CONST EFI_HANDLE Handle, + IN CONST CHAR16 *FileName + ) +{ + EFI_HII_DATABASE_PROTOCOL *HiiDatabase; + EFI_STATUS Status; + VOID *MainBuffer; + UINTN MainBufferSize; + EFI_HII_HANDLE HiiHandle; + SHELL_FILE_HANDLE FileHandle; + + HiiDatabase = NULL; + MainBufferSize = 0; + MainBuffer = NULL; + FileHandle = NULL; + + Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_GEN_FILE_OPEN_FAIL), + gShellDriver1HiiHandle, + L"drvcfg", + FileName, + Status); + return (SHELL_DEVICE_ERROR); + } + + // + // Locate HII Database protocol + // + Status = gBS->LocateProtocol ( + &gEfiHiiDatabaseProtocolGuid, + NULL, + (VOID **) &HiiDatabase + ); + + if (EFI_ERROR(Status) || HiiDatabase == NULL) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_GEN_PROTOCOL_NF), + gShellDriver1HiiHandle, + L"drvcfg", + L"EfiHiiDatabaseProtocol", + &gEfiHiiDatabaseProtocolGuid); + ShellCloseFile(&FileHandle); + return (SHELL_NOT_FOUND); + } + + HiiHandle = NULL; + Status = ConvertHandleToHiiHandle(Handle, &HiiHandle, HiiDatabase); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_GEN_HANDLE_NOT), + gShellDriver1HiiHandle, + L"drvcfg", + ConvertHandleToHandleIndex(Handle), + L"Device"); + ShellCloseFile(&FileHandle); + return (SHELL_DEVICE_ERROR); + } + + Status = HiiDatabase->ExportPackageLists(HiiDatabase, HiiHandle, &MainBufferSize, MainBuffer); + if (Status == EFI_BUFFER_TOO_SMALL) { + MainBuffer = AllocateZeroPool(MainBufferSize); + Status = HiiDatabase->ExportPackageLists(HiiDatabase, HiiHandle, &MainBufferSize, MainBuffer); + } + + Status = ShellWriteFile(FileHandle, &MainBufferSize, MainBuffer); + + ShellCloseFile(&FileHandle); + SHELL_FREE_NON_NULL(MainBuffer); + + if (EFI_ERROR(Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_FILE_WRITE_FAIL), + gShellDriver1HiiHandle, + L"drvcfg", + FileName); + return (SHELL_DEVICE_ERROR); + } + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_DRVCFG_COMP), + gShellDriver1HiiHandle); + + return (SHELL_SUCCESS); +} + +/** + Function to read in HII configuration information from a file. + + @param[in] Handle The handle to get info for. + @param[in] FileName The filename to read the info from. +**/ +SHELL_STATUS +ConfigFromFile( + IN EFI_HANDLE Handle, + IN CONST CHAR16 *FileName + ) +{ + EFI_HII_DATABASE_PROTOCOL *HiiDatabase; + EFI_STATUS Status; + VOID *MainBuffer; + UINT64 Temp; + UINTN MainBufferSize; + EFI_HII_HANDLE HiiHandle; + SHELL_FILE_HANDLE FileHandle; + CHAR16 *TempDevPathString; + EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; + EFI_HII_PACKAGE_HEADER *PackageHeader; + EFI_DEVICE_PATH_PROTOCOL *DevPath; + UINTN HandleIndex; + + HiiDatabase = NULL; + MainBufferSize = 0; + MainBuffer = NULL; + FileHandle = NULL; + + Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_GEN_FILE_OPEN_FAIL), + gShellDriver1HiiHandle, + L"drvcfg", + FileName, + Status); + return (SHELL_DEVICE_ERROR); + } + + // + // Locate HII Database protocol + // + Status = gBS->LocateProtocol ( + &gEfiHiiDatabaseProtocolGuid, + NULL, + (VOID **) &HiiDatabase + ); + + if (EFI_ERROR(Status) || HiiDatabase == NULL) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_GEN_PROTOCOL_NF), + gShellDriver1HiiHandle, + L"drvcfg", + L"EfiHiiDatabaseProtocol", + &gEfiHiiDatabaseProtocolGuid); + ShellCloseFile(&FileHandle); + return (SHELL_NOT_FOUND); + } + + Status = ShellGetFileSize(FileHandle, &Temp); + MainBufferSize = (UINTN)Temp; + if (EFI_ERROR(Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_FILE_READ_FAIL), + gShellDriver1HiiHandle, + L"drvcfg", + FileName); + + ShellCloseFile(&FileHandle); + return (SHELL_DEVICE_ERROR); + } + MainBuffer = AllocateZeroPool((UINTN)MainBufferSize); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_GEN_OUT_MEM), + gShellDriver1HiiHandle, L"drvcfg"); + ShellCloseFile(&FileHandle); + return (SHELL_DEVICE_ERROR); + } + Status = ShellReadFile(FileHandle, &MainBufferSize, MainBuffer); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_FILE_READ_FAIL), + gShellDriver1HiiHandle, + L"drvcfg", + FileName); + + ShellCloseFile(&FileHandle); + SHELL_FREE_NON_NULL(MainBuffer); + return (SHELL_DEVICE_ERROR); + } + + ShellCloseFile(&FileHandle); + + if (Handle != NULL) { + // + // User override in place. Just do it. + // + HiiHandle = NULL; + Status = ConvertHandleToHiiHandle(Handle, &HiiHandle, HiiDatabase); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_GEN_HANDLE_NOT), + gShellDriver1HiiHandle, L"drvcfg", + ConvertHandleToHandleIndex(Handle), + L"Device"); + ShellCloseFile(&FileHandle); + return (SHELL_DEVICE_ERROR); + } + Status = HiiDatabase->UpdatePackageList(HiiDatabase, HiiHandle, MainBuffer); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_GEN_UEFI_FUNC_WARN), + gShellDriver1HiiHandle, + L"drvcfg", + L"HiiDatabase->UpdatePackageList", + Status); + return (SHELL_DEVICE_ERROR); + } + } else { + // + // we need to parse the buffer and try to match the device paths for each item to try to find it's device path. + // + + for (PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)MainBuffer + ; PackageListHeader != NULL && ((CHAR8*)PackageListHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) + ; PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)(((CHAR8*)(PackageListHeader)) + PackageListHeader->PackageLength )) { + for (PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageListHeader))+sizeof(EFI_HII_PACKAGE_LIST_HEADER)) + ; PackageHeader != NULL && ((CHAR8*)PackageHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) && PackageHeader->Type != EFI_HII_PACKAGE_END + ; PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageHeader))+PackageHeader->Length)) { + if (PackageHeader->Type == EFI_HII_PACKAGE_DEVICE_PATH) { + HiiHandle = NULL; + Status = FindHiiHandleViaDevPath((EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)), &HiiHandle, HiiDatabase); + if (EFI_ERROR(Status)) { + // + // print out an error. + // + TempDevPathString = ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)), TRUE, TRUE); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_DRVCFG_IN_FILE_NF), + gShellDriver1HiiHandle, + TempDevPathString); + SHELL_FREE_NON_NULL(TempDevPathString); + } else { + Status = HiiDatabase->UpdatePackageList(HiiDatabase, HiiHandle, PackageListHeader); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_GEN_UEFI_FUNC_WARN), + gShellDriver1HiiHandle, + L"drvcfg", + L"HiiDatabase->UpdatePackageList", + Status); + return (SHELL_DEVICE_ERROR); + } else { + DevPath = (EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)); + gBS->LocateDevicePath(&gEfiHiiConfigAccessProtocolGuid, &DevPath, &Handle); + HandleIndex = ConvertHandleToHandleIndex(Handle); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_DRVCFG_DONE_HII), + gShellDriver1HiiHandle, + HandleIndex); + } + } + } + } + } + } + + SHELL_FREE_NON_NULL(MainBuffer); + + + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_DRVCFG_COMP), + gShellDriver1HiiHandle); + return (SHELL_SUCCESS); +} + +/** + Present a requested action to the user. + + @param[in] DriverImageHandle The handle for the driver to configure. + @param[in] ControllerHandle The handle of the device being managed by the Driver specified. + @param[in] ChildHandle The handle of a child device of the specified device. + @param[in] ActionRequired The required HII action. + + @retval SHELL_INVALID_PARAMETER A parameter has a invalid value. +**/ +EFI_STATUS +ShellCmdDriverConfigurationProcessActionRequired ( + EFI_HANDLE DriverImageHandle, + EFI_HANDLE ControllerHandle, + EFI_HANDLE ChildHandle, + EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED ActionRequired + ) +{ + EFI_HANDLE ConnectControllerContextOverride[2]; + + switch (ActionRequired) { + case EfiDriverConfigurationActionNone: + ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_NONE), gShellDriver1HiiHandle); + break; + + case EfiDriverConfigurationActionStopController: + ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_STOP), gShellDriver1HiiHandle); + ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_ENTER_S), gShellDriver1HiiHandle, L"stop controller"); + ShellPromptForResponse(ShellPromptResponseTypeEnterContinue, NULL, NULL); + + gBS->DisconnectController (ControllerHandle, DriverImageHandle, ChildHandle); + ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_CTLR_S), gShellDriver1HiiHandle, L"stopped"); + break; + + case EfiDriverConfigurationActionRestartController: + ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_RESTART_S), gShellDriver1HiiHandle, L"controller"); + ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_ENTER_S), gShellDriver1HiiHandle, L"restart controller"); + ShellPromptForResponse(ShellPromptResponseTypeEnterContinue, NULL, NULL); + + gBS->DisconnectController (ControllerHandle, DriverImageHandle, ChildHandle); + ConnectControllerContextOverride[0] = DriverImageHandle; + ConnectControllerContextOverride[1] = NULL; + gBS->ConnectController (ControllerHandle, ConnectControllerContextOverride, NULL, TRUE); + ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_CTLR_S), gShellDriver1HiiHandle, L"restarted"); + break; + + case EfiDriverConfigurationActionRestartPlatform: + ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_RESTART_S), gShellDriver1HiiHandle, L"platform"); + ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_ENTER_S), gShellDriver1HiiHandle, L"restart platform"); + ShellPromptForResponse(ShellPromptResponseTypeEnterContinue, NULL, NULL); + + gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL); + break; + + default: + return (EFI_INVALID_PARAMETER); + } + + return EFI_SUCCESS; +} + +/** + Do the configuration in an environment without HII. + + @param[in] Language The language code. + @param[in] ForceDefaults TRUE to force defaults, FALSE otherwise. + @param[in] DefaultType If ForceDefaults is TRUE, specifies the default type. + @param[in] AllChildren TRUE to configure all children, FALSE otherwise. + @param[in] ValidateOptions TRUE to validate existing options, FALSE otherwise. + @param[in] SetOptions TRUE to set options, FALSE otherwise. + @param[in] DriverImageHandle The handle for the driver to configure. + @param[in] DeviceHandle The handle of the device being managed by the Driver specified. + @param[in] ChildHandle The handle of a child device of the specified device. + + @retval SHELL_NOT_FOUND A specified handle could not be found. + @retval SHELL_INVALID_PARAMETER A parameter has a invalid value. +**/ +SHELL_STATUS +PreHiiDrvCfg ( + IN CONST CHAR8 *Language, + IN BOOLEAN ForceDefaults, + IN UINT32 DefaultType, + IN BOOLEAN AllChildren, + IN BOOLEAN ValidateOptions, + IN BOOLEAN SetOptions, + IN EFI_HANDLE DriverImageHandle, + IN EFI_HANDLE DeviceHandle, + IN EFI_HANDLE ChildHandle + ) +{ + EFI_STATUS Status; + SHELL_STATUS ShellStatus; + UINTN OuterLoopCounter; + CHAR8 *BestLanguage; + UINTN DriverImageHandleCount; + EFI_HANDLE *DriverImageHandleBuffer; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + UINTN *HandleType; + UINTN LoopCounter; + UINTN ChildIndex; + UINTN ChildHandleCount; + EFI_HANDLE *ChildHandleBuffer; + UINTN *ChildHandleType; + EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED ActionRequired; + EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration; + BOOLEAN Iso639Language; + UINTN HandleIndex1; + UINTN HandleIndex2; + UINTN HandleIndex3; + + ShellStatus = SHELL_SUCCESS; + + if (ChildHandle == NULL && AllChildren) { + SetOptions = FALSE; + } + + if (ForceDefaults) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_FORCE_D), + gShellDriver1HiiHandle, + DefaultType); + } else if (ValidateOptions) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_VALIDATE), + gShellDriver1HiiHandle); + } else if (SetOptions) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_SET), + gShellDriver1HiiHandle); + } + + if (DriverImageHandle == 0) { + DriverImageHandleBuffer = GetHandleListByProtocolList(CfgGuidList); + if (DriverImageHandleBuffer == NULL) { + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } + for ( + HandleBuffer = DriverImageHandleBuffer, DriverImageHandleCount = 0 + ; HandleBuffer != NULL && *HandleBuffer != NULL + ; HandleBuffer++,DriverImageHandleCount++); + } else { + DriverImageHandleCount = 1; + // + // Allocate buffer to hold the image handle so as to + // keep consistent with the above clause + // + DriverImageHandleBuffer = AllocatePool (sizeof (EFI_HANDLE)); + ASSERT (DriverImageHandleBuffer); + DriverImageHandleBuffer[0] = DriverImageHandle; + } + + for (OuterLoopCounter = 0; OuterLoopCounter < DriverImageHandleCount; OuterLoopCounter++) { + Iso639Language = FALSE; + Status = gBS->OpenProtocol ( + DriverImageHandleBuffer[OuterLoopCounter], + &gEfiDriverConfiguration2ProtocolGuid, + (VOID **) &DriverConfiguration, + NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + Iso639Language = TRUE; + Status = gBS->OpenProtocol ( + DriverImageHandleBuffer[OuterLoopCounter], + &gEfiDriverConfigurationProtocolGuid, + (VOID **) &DriverConfiguration, + NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + } + if (EFI_ERROR (Status)) { +// ShellPrintHiiEx( +// -1, +// -1, +// NULL, +// STRING_TOKEN (STR_DRVCFG_NOT_SUPPORT), +// gShellDriver1HiiHandle, +// ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]) +// ); + ShellStatus = SHELL_UNSUPPORTED; + continue; + } + + BestLanguage = GetBestLanguage ( + DriverConfiguration->SupportedLanguages, + Iso639Language, + Language!=NULL?Language:"", + DriverConfiguration->SupportedLanguages, + NULL + ); + if (BestLanguage == NULL) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_GEN_NO_VALUE), + gShellDriver1HiiHandle, + L"drvcfg", + L"-l" + ); + ShellStatus = SHELL_INVALID_PARAMETER; + continue; + } + + Status = ParseHandleDatabaseByRelationshipWithType ( + DriverImageHandleBuffer[OuterLoopCounter], + NULL, + &HandleCount, + &HandleBuffer, + &HandleType + ); + if (EFI_ERROR (Status)) { + continue; + } + + if (SetOptions && DeviceHandle == NULL) { + + gST->ConOut->ClearScreen (gST->ConOut); + Status = DriverConfiguration->SetOptions ( + DriverConfiguration, + NULL, + NULL, + BestLanguage, + &ActionRequired + ); + gST->ConOut->ClearScreen (gST->ConOut); + + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_ALL_LANG), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]), + DriverConfiguration->SupportedLanguages + ); + if (!EFI_ERROR (Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_OPTIONS_SET), + gShellDriver1HiiHandle); + for (LoopCounter = 0; LoopCounter < HandleCount; LoopCounter++) { + if ((HandleType[LoopCounter] & HR_CONTROLLER_HANDLE) == HR_CONTROLLER_HANDLE) { + ShellCmdDriverConfigurationProcessActionRequired ( + DriverImageHandleBuffer[OuterLoopCounter], + HandleBuffer[LoopCounter], + NULL, + ActionRequired + ); + } + } + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_NOT_SET), + gShellDriver1HiiHandle, + Status); + } + continue; + } + + for (LoopCounter = 0; LoopCounter < HandleCount; LoopCounter++) { + if ((HandleType[LoopCounter] & HR_CONTROLLER_HANDLE) != HR_CONTROLLER_HANDLE) { + continue; + } + if (DeviceHandle != NULL && DeviceHandle != HandleBuffer[LoopCounter]) { + continue; + } + if (ChildHandle == NULL) { + HandleIndex1 = ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]); + HandleIndex2 = ConvertHandleToHandleIndex (HandleBuffer[LoopCounter]); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_CTRL_LANG), + gShellDriver1HiiHandle, + HandleIndex1, + HandleIndex2, + DriverConfiguration->SupportedLanguages + ); + + if (ForceDefaults) { + Status = DriverConfiguration->ForceDefaults ( + DriverConfiguration, + HandleBuffer[LoopCounter], + NULL, + DefaultType, + &ActionRequired + ); + + if (!EFI_ERROR (Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_DEF_FORCED), + gShellDriver1HiiHandle); + ShellCmdDriverConfigurationProcessActionRequired ( + DriverImageHandleBuffer[OuterLoopCounter], + HandleBuffer[LoopCounter], + NULL, + ActionRequired + ); + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_FORCE_FAILED), + gShellDriver1HiiHandle, + Status); + ShellStatus = SHELL_DEVICE_ERROR; + } + } else if (ValidateOptions) { + Status = DriverConfiguration->OptionsValid ( + DriverConfiguration, + HandleBuffer[LoopCounter], + NULL + ); + + if (!EFI_ERROR (Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_OPTIONS_VALID), + gShellDriver1HiiHandle); + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_OPTIONS_INV), + gShellDriver1HiiHandle, + Status); + ShellStatus = SHELL_DEVICE_ERROR; + } + } else if (SetOptions) { + gST->ConOut->ClearScreen (gST->ConOut); + Status = DriverConfiguration->SetOptions ( + DriverConfiguration, + HandleBuffer[LoopCounter], + NULL, + BestLanguage, + &ActionRequired + ); + gST->ConOut->ClearScreen (gST->ConOut); + HandleIndex1 = ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]); + HandleIndex2 = ConvertHandleToHandleIndex (HandleBuffer[LoopCounter]); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_CTRL_LANG), + gShellDriver1HiiHandle, + HandleIndex1, + HandleIndex2, + DriverConfiguration->SupportedLanguages + ); + if (!EFI_ERROR (Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_OPTIONS_SET), + gShellDriver1HiiHandle); + + ShellCmdDriverConfigurationProcessActionRequired ( + DriverImageHandleBuffer[OuterLoopCounter], + HandleBuffer[LoopCounter], + NULL, + ActionRequired + ); + + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_NOT_SET), + gShellDriver1HiiHandle, + Status); + ShellStatus = SHELL_DEVICE_ERROR; + } + } else { + Print (L"\n"); + } + } + + if (ChildHandle == NULL && !AllChildren) { + continue; + } + + Status = ParseHandleDatabaseByRelationshipWithType ( + DriverImageHandleBuffer[OuterLoopCounter], + HandleBuffer[LoopCounter], + &ChildHandleCount, + &ChildHandleBuffer, + &ChildHandleType + ); + if (EFI_ERROR (Status)) { + continue; + } + + for (ChildIndex = 0; ChildIndex < ChildHandleCount; ChildIndex++) { + + if ((ChildHandleType[ChildIndex] & HR_CHILD_HANDLE) != HR_CHILD_HANDLE) { + continue; + } + + if (ChildHandle != NULL && ChildHandle != ChildHandleBuffer[ChildIndex]) { + continue; + } + + HandleIndex1 = ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]); + HandleIndex2 = ConvertHandleToHandleIndex (HandleBuffer[LoopCounter]); + HandleIndex3 = ConvertHandleToHandleIndex (ChildHandleBuffer[ChildIndex]); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_CHILD_LANG), + gShellDriver1HiiHandle, + HandleIndex1, + HandleIndex2, + HandleIndex3, + DriverConfiguration->SupportedLanguages); + + if (ForceDefaults) { + Status = DriverConfiguration->ForceDefaults ( + DriverConfiguration, + HandleBuffer[LoopCounter], + ChildHandleBuffer[ChildIndex], + DefaultType, + &ActionRequired + ); + + if (!EFI_ERROR (Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_DEF_FORCED), + gShellDriver1HiiHandle); + + ShellCmdDriverConfigurationProcessActionRequired ( + DriverImageHandleBuffer[OuterLoopCounter], + HandleBuffer[LoopCounter], + ChildHandleBuffer[ChildIndex], + ActionRequired + ); + + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_FORCE_FAILED), + gShellDriver1HiiHandle, + Status); + ShellStatus = SHELL_DEVICE_ERROR; + } + } else if (ValidateOptions) { + Status = DriverConfiguration->OptionsValid ( + DriverConfiguration, + HandleBuffer[LoopCounter], + ChildHandleBuffer[ChildIndex] + ); + + if (!EFI_ERROR (Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_OPTIONS_VALID), + gShellDriver1HiiHandle); + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_OPTIONS_INV), + gShellDriver1HiiHandle, + Status); + ShellStatus = SHELL_DEVICE_ERROR; + } + } else if (SetOptions) { + gST->ConOut->ClearScreen (gST->ConOut); + Status = DriverConfiguration->SetOptions ( + DriverConfiguration, + HandleBuffer[LoopCounter], + ChildHandleBuffer[ChildIndex], + BestLanguage, + &ActionRequired + ); + gST->ConOut->ClearScreen (gST->ConOut); + HandleIndex1 = ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]); + HandleIndex2 = ConvertHandleToHandleIndex (HandleBuffer[LoopCounter]); + HandleIndex3 = ConvertHandleToHandleIndex (ChildHandleBuffer[ChildIndex]); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_CHILD_LANG), + gShellDriver1HiiHandle, + HandleIndex1, + HandleIndex2, + HandleIndex3, + DriverConfiguration->SupportedLanguages + ); + if (!EFI_ERROR (Status)) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_OPTIONS_SET), + gShellDriver1HiiHandle); + + ShellCmdDriverConfigurationProcessActionRequired ( + DriverImageHandleBuffer[OuterLoopCounter], + HandleBuffer[LoopCounter], + ChildHandleBuffer[ChildIndex], + ActionRequired + ); + + } else { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_NOT_SET), + gShellDriver1HiiHandle, + Status); + ShellStatus = SHELL_DEVICE_ERROR; + } + } else { + Print (L"\n"); + } + } + + FreePool (ChildHandleBuffer); + FreePool (ChildHandleType); + } + + FreePool (BestLanguage); + FreePool (HandleBuffer); + FreePool (HandleType); + } + + if (DriverImageHandle != NULL && DriverImageHandleCount != 0) { + FreePool (DriverImageHandleBuffer); + } + +Done: + return ShellStatus; +} + +/** + Function to print out configuration information on all configurable handles. + + @param[in] ChildrenToo TRUE to tewst for children. + @param[in] Language ASCII string for language code. + @param[in] UseHii TRUE to check for Hii and DPC, FALSE for DCP only. + + @retval SHELL_SUCCESS The operation was successful. +**/ +SHELL_STATUS +PrintConfigInfoOnAll( + IN CONST BOOLEAN ChildrenToo, + IN CONST CHAR8 *Language, + IN CONST BOOLEAN UseHii + ) +{ + EFI_HANDLE *HandleList; + EFI_HANDLE *CurrentHandle; + BOOLEAN Found; + UINTN Index2; + + + Found = FALSE; + HandleList = NULL; + CurrentHandle = NULL; + + if (UseHii) { + // + // HII method + // + HandleList = GetHandleListByProtocol(&gEfiHiiConfigAccessProtocolGuid); + for (CurrentHandle = HandleList ; CurrentHandle != NULL && *CurrentHandle != NULL; CurrentHandle++){ + Found = TRUE; + Index2 = *CurrentHandle == NULL ? 0 : ConvertHandleToHandleIndex(*CurrentHandle); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_LINE_HII), + gShellDriver1HiiHandle, + Index2 + ); + } + SHELL_FREE_NON_NULL(HandleList); + } + + if (PreHiiDrvCfg ( + Language, + FALSE, + 0, + ChildrenToo, + FALSE, + FALSE, + 0, + 0, + 0) == SHELL_SUCCESS) { + Found = TRUE; + } + + if (!Found) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_NONE_FOUND), gShellDriver1HiiHandle); + return (SHELL_SUCCESS); + } + + return (SHELL_SUCCESS); +} + +STATIC CONST SHELL_PARAM_ITEM ParamListHii[] = { + {L"-s", TypeFlag}, + {L"-l", TypeValue}, + {L"-f", TypeValue}, + {L"-o", TypeValue}, + {L"-i", TypeValue}, + {NULL, TypeMax} + }; +STATIC CONST SHELL_PARAM_ITEM ParamListPreHii[] = { + {L"-c", TypeFlag}, + {L"-s", TypeFlag}, + {L"-v", TypeFlag}, + {L"-l", TypeValue}, + {L"-f", TypeValue}, + {NULL, TypeMax} + }; + +/** + 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 + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + CHAR8 *Language; + CONST CHAR16 *Lang; + CONST CHAR16 *HandleIndex1; + CONST CHAR16 *HandleIndex2; + CONST CHAR16 *HandleIndex3; + CONST CHAR16 *ForceTypeString; + BOOLEAN Force; + BOOLEAN Set; + BOOLEAN Validate; + BOOLEAN InFromFile; + BOOLEAN OutToFile; + BOOLEAN AllChildren; + BOOLEAN UseHii; + UINT32 ForceType; + UINT64 Intermediate; + EFI_HANDLE Handle1; + EFI_HANDLE Handle2; + EFI_HANDLE Handle3; + CONST CHAR16 *FileName; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + Language = NULL; + UseHii = TRUE; + ProblemParam = 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 (ParamListHii, &Package, &ProblemParam, TRUE); + if (EFI_ERROR(Status) || ShellCommandLineGetCount(Package) > 2) { + UseHii = FALSE; + if (Package != NULL) { + ShellCommandLineFreeVarList (Package); + } + SHELL_FREE_NON_NULL(ProblemParam); + Status = ShellCommandLineParse (ParamListPreHii, &Package, &ProblemParam, TRUE); + if (EFI_ERROR(Status)) { + if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"drvcfg", ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } else { + ASSERT(FALSE); + } + } + } + if (ShellStatus == SHELL_SUCCESS) { + if (ShellCommandLineGetCount(Package) > 4) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"drvcfg"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + Lang = ShellCommandLineGetValue(Package, L"-l"); + if (Lang != NULL) { + Language = AllocateZeroPool(StrSize(Lang)); + AsciiSPrint(Language, StrSize(Lang), "%S", Lang); + } else if (ShellCommandLineGetFlag(Package, L"-l")){ + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"drvcfg", L"-l"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + Set = ShellCommandLineGetFlag (Package, L"-s"); + Validate = ShellCommandLineGetFlag (Package, L"-v"); + InFromFile = ShellCommandLineGetFlag (Package, L"-i"); + OutToFile = ShellCommandLineGetFlag (Package, L"-o"); + AllChildren = ShellCommandLineGetFlag (Package, L"-c"); + Force = ShellCommandLineGetFlag (Package, L"-f"); + ForceTypeString = ShellCommandLineGetValue(Package, L"-f"); + + if (OutToFile) { + FileName = ShellCommandLineGetValue(Package, L"-o"); + } else if (InFromFile) { + FileName = ShellCommandLineGetValue(Package, L"-i"); + } else { + FileName = NULL; + } + + if (InFromFile && EFI_ERROR(ShellFileExists(FileName))) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FIND_FAIL), gShellDriver1HiiHandle, L"drvcfg", FileName); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + if (OutToFile && !EFI_ERROR(ShellFileExists(FileName))) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_EXIST), gShellDriver1HiiHandle, L"drvcfg", FileName); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + if (Force && ForceTypeString == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"drvcfg", L"-f"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + if (Force) { + Status = ShellConvertStringToUint64(ForceTypeString, &Intermediate, FALSE, FALSE); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDriver1HiiHandle, L"drvcfg", ForceTypeString, L"-f"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + ForceType = (UINT32)Intermediate; + } else { + ForceType = 0; + } + HandleIndex1 = ShellCommandLineGetRawValue(Package, 1); + Handle1 = NULL; + if (HandleIndex1 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex1, &Intermediate, TRUE, FALSE))) { + Handle1 = ConvertHandleIndexToHandle((UINTN)Intermediate); + if (Handle1 == NULL || (UINT64)(UINTN)Intermediate != Intermediate) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"drvcfg", HandleIndex1); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } + HandleIndex2 = ShellCommandLineGetRawValue(Package, 2); + Handle2 = NULL; + if (HandleIndex2 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex2, &Intermediate, TRUE, FALSE))) { + Handle2 = ConvertHandleIndexToHandle((UINTN)Intermediate); + if (Handle2 == NULL || (UINT64)(UINTN)Intermediate != Intermediate) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"drvcfg", HandleIndex2); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } + HandleIndex3 = ShellCommandLineGetRawValue(Package, 3); + Handle3 = NULL; + if (HandleIndex3 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex3, &Intermediate, TRUE, FALSE))) { + Handle3 = ConvertHandleIndexToHandle((UINTN)Intermediate); + if (Handle3 == NULL || (UINT64)(UINTN)Intermediate != Intermediate) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"drvcfg", HandleIndex3); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } + + if ((InFromFile || OutToFile) && (FileName == NULL)) { + if (FileName == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"drvcfg", InFromFile?L"-i":L"-o"); + } else { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_REQ), gShellDriver1HiiHandle, L"drvcfg"); + } + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + if (!UseHii && (InFromFile || OutToFile)) { + if (InFromFile) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDriver1HiiHandle, L"drvcfg", L"-i"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + if (OutToFile) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDriver1HiiHandle, L"drvcfg", L"-o"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } + if (Validate && Force) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDriver1HiiHandle, L"drvcfg", L"-v", L"-f"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + if (Validate && Set) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDriver1HiiHandle, L"drvcfg", L"-v", L"-s"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + if (Set && Force) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDriver1HiiHandle, L"drvcfg", L"-s", L"-f"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + if (OutToFile && InFromFile) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDriver1HiiHandle, L"drvcfg", L"-i", L"-o"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + // + // We do HII first. + // + if (UseHii) { + if (Handle1 != NULL && EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiHiiConfigAccessProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + // + // no HII on this handle. + // + ShellStatus = SHELL_UNSUPPORTED; + } else if (Validate) { + } else if (Force) { + } else if (Set) { + } else if (InFromFile) { + ShellStatus = ConfigFromFile(Handle1, FileName); + if (Handle1 != NULL && ShellStatus == SHELL_SUCCESS) { + goto Done; + } + } else if (OutToFile) { + ShellStatus = ConfigToFile(Handle1, FileName); + if (Handle1 != NULL && ShellStatus == SHELL_SUCCESS) { + goto Done; + } + } else if (HandleIndex1 == NULL) { + // + // display all that are configurable + // + ShellStatus = PrintConfigInfoOnAll(AllChildren, Language, UseHii); + goto Done; + } else { + if (!EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiHiiConfigAccessProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_LINE_HII), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex(Handle1) + ); + goto Done; + } + } + } + + // + // We allways need to do this one since it does both by default. + // + if (!InFromFile && !OutToFile) { + ShellStatus = PreHiiDrvCfg ( + Language, + Force, + ForceType, + AllChildren, + Validate, + Set, + Handle1, + Handle2, + Handle3); + } + + if (ShellStatus == SHELL_UNSUPPORTED) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_DRVCFG_NOT_SUPPORT), + gShellDriver1HiiHandle, + ConvertHandleToHandleIndex(Handle1) + ); + } + } + +Done: + ShellCommandLineFreeVarList (Package); + SHELL_FREE_NON_NULL(Language); + return (ShellStatus); +} diff --git a/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvDiag.c b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvDiag.c new file mode 100644 index 00000000..8db442bf --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvDiag.c @@ -0,0 +1,457 @@ +/** @file + Main file for DrvDiag shell Driver1 function. + + (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR> + Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +STATIC CONST EFI_GUID *DiagGuidList[] = {&gEfiDriverDiagnosticsProtocolGuid, &gEfiDriverDiagnostics2ProtocolGuid, NULL}; +// +// We need 1 more item on the list... +// +typedef enum { + TestModeStandard = EfiDriverDiagnosticTypeStandard, + TestModeExtended = EfiDriverDiagnosticTypeExtended, + TestModeManufacturing = EfiDriverDiagnosticTypeManufacturing, + TestModeList, + TestModeMax +} DRV_DIAG_TEST_MODE; + +/** + Do the diagnostics call for some set of handles. + + @param[in] Mode The type of diagnostic test to run. + @param[in] Lang The language code to use. + @param[in] AllChilds Should the test be on all children. + @param[in] DriverHandle The driver handle to test with. + @param[in] ControllerHandle The specific controller handle to test. + @param[in] ChildHandle The specific child handle to test. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_INVALID_PARAMETER A parameter had an invalid value. + @retval EFI_NOT_FOUND No diagnostic handle could be found. +**/ +EFI_STATUS +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; + CHAR8 *Language; + BOOLEAN Found; + + if ((ChildHandle != NULL && AllChilds) || (Mode >= TestModeMax)){ + return (EFI_INVALID_PARAMETER); + } + + DriverDiagnostics = NULL; + DriverDiagnostics2 = NULL; + Status = EFI_SUCCESS; + Status2 = EFI_SUCCESS; + DriverHandleList = NULL; + ControllerHandleList = NULL; + ChildHandleList = NULL; + Language = NULL; + OutBuffer = NULL; + ErrorType = NULL; + DriverHandleListCount = 0; + ControllerHandleListCount = 0; + ChildHandleListCount = 0; + + if (DriverHandle != NULL) { + DriverHandleList = AllocateZeroPool(2*sizeof(EFI_HANDLE)); + if (DriverHandleList == NULL) { + return EFI_OUT_OF_RESOURCES; + } + DriverHandleList[0] = DriverHandle; + DriverHandleListCount = 1; + } else { + DriverHandleList = GetHandleListByProtocolList(DiagGuidList); + if (DriverHandleList == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROTOCOL_NF), gShellDriver1HiiHandle, L"drvdiag", L"gEfiDriverDiagnosticsProtocolGuid", &gEfiDriverDiagnosticsProtocolGuid); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROTOCOL_NF), gShellDriver1HiiHandle, L"drvdiag", L"gEfiDriverDiagnostics2ProtocolGuid", &gEfiDriverDiagnostics2ProtocolGuid); + return (EFI_NOT_FOUND); + } + for (Walker = DriverHandleList ; Walker != NULL && *Walker != NULL ; DriverHandleListCount++, Walker++); + } + + if (ControllerHandle != NULL) { + ControllerHandleList = AllocateZeroPool(2*sizeof(EFI_HANDLE)); + if (ControllerHandleList == NULL) { + SHELL_FREE_NON_NULL (DriverHandleList); + return EFI_OUT_OF_RESOURCES; + } + ControllerHandleList[0] = ControllerHandle; + ControllerHandleListCount = 1; + } else { + ControllerHandleList = NULL; + } + + if (ChildHandle != NULL) { + ChildHandleList = AllocateZeroPool(2*sizeof(EFI_HANDLE)); + if (ChildHandleList == NULL) { + SHELL_FREE_NON_NULL (ControllerHandleList); + SHELL_FREE_NON_NULL (DriverHandleList); + return EFI_OUT_OF_RESOURCES; + } + ChildHandleList[0] = ChildHandle; + ChildHandleListCount = 1; + } else if (AllChilds) { + ChildHandleList = NULL; + // + // This gets handled in the loop below. + // + } else { + ChildHandleList = NULL; + } + + if (Mode == TestModeList) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVDIAG_HEADER), gShellDriver1HiiHandle); + } + for (DriverHandleListLoop = 0 + ; DriverHandleListLoop < DriverHandleListCount + ; DriverHandleListLoop++ + ){ + if (Mode == TestModeList) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVDIAG_DRIVER_HEADER), gShellDriver1HiiHandle, ConvertHandleToHandleIndex(DriverHandleList[DriverHandleListLoop])); + } + if (ControllerHandle == NULL) { + PARSE_HANDLE_DATABASE_DEVICES(DriverHandleList[DriverHandleListLoop], &ControllerHandleListCount, &ControllerHandleList); + } + if (ControllerHandleListCount == 0) { + if (Mode == TestModeList) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVDIAG_DRIVER_NO_HANDLES), gShellDriver1HiiHandle); + } + } else { + if (Mode == TestModeList) { + ShellPrintEx(-1, -1, L"\r\n"); + } + 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++ + ){ + Found = FALSE; + if (Mode != TestModeList) { + if (Lang == NULL || 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) && (DriverDiagnostics2 != NULL)) { + Language = GetBestLanguageForDriver(DriverDiagnostics2->SupportedLanguages, Lang, FALSE); + Found = TRUE; + Status = DriverDiagnostics2->RunDiagnostics( + DriverDiagnostics2, + ControllerHandleList[ControllerHandleListLoop], + ChildHandleList == NULL?NULL:ChildHandleList[ChildHandleListLoop], + (EFI_DRIVER_DIAGNOSTIC_TYPE)Mode, + Language, + &ErrorType, + &OutBufferSize, + &OutBuffer); + FreePool(Language); + } + } + if (!Found && (Lang == NULL||(Lang!=NULL&&(Lang[2]!='-')))){ + Status = gBS->OpenProtocol( + DriverHandleList[DriverHandleListLoop], + &gEfiDriverDiagnosticsProtocolGuid, + (VOID**)&DriverDiagnostics, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (!EFI_ERROR(Status)) { + Language = GetBestLanguageForDriver(DriverDiagnostics->SupportedLanguages, Lang, FALSE); + Status = DriverDiagnostics->RunDiagnostics( + DriverDiagnostics, + ControllerHandleList[ControllerHandleListLoop], + ChildHandleList == NULL?NULL:ChildHandleList[ChildHandleListLoop], + (EFI_DRIVER_DIAGNOSTIC_TYPE)Mode, + Language, + &ErrorType, + &OutBufferSize, + &OutBuffer); + FreePool(Language); + } + } + 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} + }; + +/** + 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 + ) +{ + 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; + UINT64 Intermediate; + + ShellStatus = SHELL_SUCCESS; + Mode = TestModeMax; + 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, L"drvdiag", 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, L"drvdiag"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if ((ShellCommandLineGetFlag(Package, L"-s")) + || (ShellCommandLineGetFlag(Package, L"-e")) + || (ShellCommandLineGetFlag(Package, L"-m")) + ){ + // + // Run the appropriate test + // + if (ShellCommandLineGetFlag(Package, L"-s")) { + Mode = TestModeStandard; + } else if (ShellCommandLineGetFlag(Package, L"-e")) { + Mode = TestModeExtended; + } else if (ShellCommandLineGetFlag(Package, L"-m")) { + Mode = TestModeManufacturing; + } else { + ASSERT(FALSE); + } + } else { + // + // Do a listing of what's available to test + // + Mode = TestModeList; + } + + Lang = ShellCommandLineGetValue(Package, L"-l"); + if (ShellCommandLineGetFlag(Package, L"-l") && Lang == NULL) { + ASSERT(Language == NULL); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"drvdiag", L"-l"); + ShellCommandLineFreeVarList (Package); + return (SHELL_INVALID_PARAMETER); + } else if (Lang != NULL) { + Language = AllocateZeroPool(StrSize(Lang)); + AsciiSPrint(Language, StrSize(Lang), "%S", Lang); + } + + DriverHandleStr = ShellCommandLineGetRawValue(Package, 1); + ControllerHandleStr = ShellCommandLineGetRawValue(Package, 2); + ChildHandleStr = ShellCommandLineGetRawValue(Package, 3); + + if (DriverHandleStr == NULL) { + Handle1 = NULL; + } else { + ShellConvertStringToUint64(DriverHandleStr, &Intermediate, TRUE, FALSE); + Handle1 = ConvertHandleIndexToHandle((UINTN)Intermediate); + } + if (ControllerHandleStr == NULL) { + Handle2 = NULL; + } else { + ShellConvertStringToUint64(ControllerHandleStr, &Intermediate, TRUE, FALSE); + Handle2 = ConvertHandleIndexToHandle((UINTN)Intermediate); + } + if (ChildHandleStr == NULL) { + Handle3 = NULL; + } else { + ShellConvertStringToUint64(ChildHandleStr, &Intermediate, TRUE, FALSE); + Handle3 = ConvertHandleIndexToHandle((UINTN)Intermediate); + } + + 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/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c new file mode 100644 index 00000000..e84f426b --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c @@ -0,0 +1,210 @@ +/** @file + Main file for OpenInfo shell Driver1 function. + + (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR> + Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#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 "; + +/** + Open the database and print out all the info about TheHandle. + + @param[in] TheHandle The handle to print info on. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_INVALID_PARAMETER TheHandle was NULL. +**/ +EFI_STATUS +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; + UINTN ControllerIndex; + + if (TheHandle == NULL) { + return (EFI_INVALID_PARAMETER); + } + + // + // 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, NULL); + ControllerIndex = ConvertHandleToHandleIndex(OpenInfo[OpenInfoIndex].ControllerHandle); + if (ControllerIndex != 0) { + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN(STR_OPENINFO_LINE), + gShellDriver1HiiHandle, + HandleIndex, + ControllerIndex, + 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; + UINT64 Intermediate; + + 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, L"openinfo", 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, L"openinfo"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount(Package) == 0) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"openinfo"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Param1 = ShellCommandLineGetRawValue(Package, 1); + Status = ShellConvertStringToUint64(Param1, &Intermediate, TRUE, FALSE); + if (EFI_ERROR(Status) || Param1 == NULL || ConvertHandleIndexToHandle((UINTN)Intermediate) == NULL){ + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"openinfo", Param1); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + TheHandle = ConvertHandleIndexToHandle((UINTN)Intermediate); + ASSERT(TheHandle != NULL); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_OPENINFO_HEADER_LINE), gShellDriver1HiiHandle, (UINTN)Intermediate, TheHandle); + + Status = TraverseHandleDatabase (TheHandle); + if (!EFI_ERROR(Status)) { + } else { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"openinfo", Param1); + ShellStatus = SHELL_NOT_FOUND; + } + } + } + } + return (ShellStatus); +} diff --git a/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Reconnect.c b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Reconnect.c new file mode 100644 index 00000000..8c3740a9 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Reconnect.c @@ -0,0 +1,93 @@ +/** @file + Main file for Reconnect shell Driver1 function. + + Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR> + (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR> + (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + {L"-r", TypeFlag}, + {NULL, TypeMax} + }; + +/** + Connect all the possible console devices. + +**/ +VOID +ConnectAllConsoles ( + VOID + ) +{ + ShellConnectFromDevPaths(L"ConInDev"); + ShellConnectFromDevPaths(L"ConOutDev"); + ShellConnectFromDevPaths(L"ErrOutDev"); + + ShellConnectFromDevPaths(L"ErrOut"); + ShellConnectFromDevPaths(L"ConIn"); + ShellConnectFromDevPaths(L"ConOut"); +} + + +/** + 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 + ) +{ + SHELL_STATUS ShellStatus; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + EFI_STATUS Status; + + gInReconnect = TRUE; + 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, L"reconnect", ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { + ShellStatus = ShellCommandRunDisconnect(ImageHandle, SystemTable); + if (ShellStatus == SHELL_SUCCESS) { + if (ShellCommandLineGetFlag(Package, L"-r")) { + ConnectAllConsoles(); + } + ShellStatus = ShellCommandRunConnect(ImageHandle, SystemTable); + } + } + + gInReconnect = FALSE; + + return (ShellStatus); +} + diff --git a/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.c b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.c new file mode 100644 index 00000000..53033321 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.c @@ -0,0 +1,98 @@ +/** @file + Main file for NULL named library for level 1 shell command functions. + + Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +STATIC CONST CHAR16 mFileName[] = L"Driver1Commands"; +EFI_HII_HANDLE gShellDriver1HiiHandle = NULL; +BOOLEAN gInReconnect = FALSE; + +/** + Function to return the name of the file containing help if HII will not be used. + + @return The filename. +**/ +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_SUCCESS); + } + + // + // 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. + + @param ImageHandle The image handle of the process. + @param SystemTable The EFI System Table pointer. +**/ +EFI_STATUS +EFIAPI +UefiShellDriver1CommandsLibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + if (gShellDriver1HiiHandle != NULL) { + HiiRemovePackages(gShellDriver1HiiHandle); + } + return (EFI_SUCCESS); +} + + + diff --git a/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.h b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.h new file mode 100644 index 00000000..21360b26 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.h @@ -0,0 +1,222 @@ +/** @file + Main file for NULL named library for Profile1 shell command functions. + + Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _UEFI_SHELL_DRIVER1_COMMANDS_LIB_H_ +#define _UEFI_SHELL_DRIVER1_COMMANDS_LIB_H_ + +#include <Uefi.h> + +#include <Guid/GlobalVariable.h> +#include <Guid/ConsoleInDevice.h> +#include <Guid/ConsoleOutDevice.h> +#include <Guid/ShellLibHiiGuid.h> + +#include <IndustryStandard/Pci.h> + +#include <Pi/PiFirmwareVolume.h> +#include <Pi/PiFirmwareFile.h> +#include <Protocol/FirmwareVolume2.h> + +#include <Protocol/Shell.h> +#include <Protocol/ShellParameters.h> +#include <Protocol/DevicePath.h> +#include <Protocol/LoadedImage.h> +#include <Protocol/UnicodeCollation.h> +#include <Protocol/DriverDiagnostics2.h> +#include <Protocol/DriverDiagnostics.h> +#include <Protocol/PlatformDriverOverride.h> +#include <Protocol/BusSpecificDriverOverride.h> +#include <Protocol/PlatformToDriverConfiguration.h> +#include <Protocol/DriverSupportedEfiVersion.h> +#include <Protocol/DriverFamilyOverride.h> +#include <Protocol/DriverHealth.h> +#include <Protocol/PciIo.h> +#include <Protocol/PciRootBridgeIo.h> + +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/PcdLib.h> +#include <Library/ShellCommandLib.h> +#include <Library/ShellLib.h> +#include <Library/SortLib.h> +#include <Library/UefiLib.h> +#include <Library/UefiRuntimeServicesTableLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/HiiLib.h> +#include <Library/FileHandleLib.h> +#include <Library/DevicePathLib.h> +#include <Library/PrintLib.h> +#include <Library/HandleParsingLib.h> +#include <Library/PeCoffGetEntryPointLib.h> +#include <Library/HandleParsingLib.h> + + +extern EFI_HII_HANDLE gShellDriver1HiiHandle; +extern BOOLEAN gInReconnect; + +/** + 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 + ); + +/** + Do a connect from an EFI variable via it's key name. + + @param[in] Key The name of the EFI Variable. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +ShellConnectFromDevPaths ( + IN CONST CHAR16 *Key + ); + + + +#endif + diff --git a/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf new file mode 100644 index 00000000..75f46225 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf @@ -0,0 +1,68 @@ +## @file +# Provides shell driver1 profile functions +# +# Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## +[Defines] + INF_VERSION = 0x00010006 + BASE_NAME = UefiShellDriver1CommandsLib + FILE_GUID = 313D3674-3ED4-48fd-BF97-7DB35D4190D1 + MODULE_TYPE = UEFI_APPLICATION + 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 ## CONSUMES + +[Protocols] + gEfiDriverHealthProtocolGuid ## UNDEFINED + gEfiDriverFamilyOverrideProtocolGuid ## UNDEFINED + gEfiHiiConfigAccessProtocolGuid ## SOMETIMES_CONSUMES + gEfiHiiDatabaseProtocolGuid ## CONSUMES + +[Guids] + gEfiGlobalVariableGuid ## SOMETIMES_CONSUMES ## GUID + gEfiConsoleInDeviceGuid ## CONSUMES ## GUID + gEfiConsoleOutDeviceGuid ## CONSUMES ## GUID + gShellDriver1HiiGuid ## PRODUCES ## HII diff --git a/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.uni b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.uni new file mode 100644 index 00000000..0e6799d0 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.uni @@ -0,0 +1,753 @@ +// /**
+//
+// (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP<BR>
+// (C) Copyright 2012-2015 Hewlett-Packard Development Company, L.P.<BR>
+// Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// Module Name:
+//
+// UefiShellDriver1CommandsLib.uni
+//
+// Abstract:
+//
+// String definitions for UEFI Shell 2.0 driver1 profile commands
+//
+//
+// **/
+
+/=#
+
+#langdef en-US "english"
+
+#string STR_GEN_PROBLEM #language en-US "%H%s%N: Unknown flag - '%H%s%N'\r\n"
+#string STR_GEN_PROBLEM_VAL #language en-US "%H%s%N: Bad value - '%H%s%N' for flag - '%H%s%N'\r\n"
+#string STR_GEN_PARAM_INV #language en-US "%H%s%N: Invalid argument - '%H%s%N'\r\n"
+#string STR_GEN_TOO_FEW #language en-US "%H%s%N: Too few arguments\r\n"
+#string STR_GEN_TOO_MANY #language en-US "%H%s%N: Too many arguments\r\n"
+#string STR_GEN_INV_HANDLE #language en-US "%H%s%N: Handle - '%H%s%N' not found\r\n"
+#string STR_GEN_PARAM_CONFLICT #language en-US "%H%s%N: Flags conflict with - '%H%s%N' and '%H%s%N'\r\n"
+#string STR_GEN_NO_VALUE #language en-US "%H%s%N: Missing argument for flag - '%H%s%N'\r\n"
+#string STR_GEN_HANDLE_NOT #language en-US "%H%s%N: Handle [%H%02x%N] is not a valid %s\r\n"
+#string STR_GEN_HANDLE_REQ #language en-US "%H%s%N: Handle required with the specified options\r\n"
+#string STR_GEN_PROTOCOL_NF #language en-US "%H%s%N: The protocol '%H%s%N' is required and not found (%g)\r\n"
+#string STR_GEN_FIND_FAIL #language en-US "%H%s%N: File not found - '%H%s%N'\r\n"
+#string STR_GEN_FILE_EXIST #language en-US "%H%s%N: File already exists - '%H%s%N'\r\n"
+#string STR_GEN_FILE_OPEN_FAIL #language en-US "%H%s%N: Cannot open file - '%H%s%N'\r\n"
+#string STR_FILE_WRITE_FAIL #language en-US "%H%s%N: Write file error - '%H%s%N'\r\n"
+#string STR_FILE_READ_FAIL #language en-US "%H%s%N: Read file error - '%H%s%N'\r\n"
+#string STR_GEN_OUT_MEM #language en-US "%H%s%N: Memory allocation was not successful\r\n"
+#string STR_GEN_UEFI_FUNC_ERROR #language en-US "%H%s%N: UEFI function '%H%s%N' returned an incorrect value for: %s (%x)\r\n"
+#string STR_GEN_UEFI_FUNC_WARN #language en-US "%H%s%N: UEFI function '%H%s%N' returned: %r\r\n"
+#string STR_GEN_SFO_HEADER #language en-US "ShellCommand,"%s"\r\n"
+
+#string STR_DRVDIAG_HEADER #language en-US "%EAvailable Diagnostics%N.\r\n"
+#string STR_DRVDIAG_DRIVER_HEADER #language en-US "Driver [%H%02x%N]: "
+#string STR_DRVDIAG_DRIVER_NO_HANDLES #language en-US "No controller handles found.\r\n"
+
+#string STR_HANDLE_RESULT #language en-US "%H%s%N - Handle [%H%02x%N] Result %r.\r\n"
+#string STR_3P_RESULT #language en-US "%H%s%N - (%H%02x%N,%H%02x%N,%H%02x%N) Result %r.\r\n"
+#string STR_CONNECT_NONE #language en-US "%HConnect%N No drivers could be connected.\r\n"
+
+#string STR_DRVCFG_NONE_FOUND #language en-US "%HDrvCfg%N No configurable devices were found.\r\n"
+#string STR_DRVCFG_COMP #language en-US "%HDrvCfg%N - operation complete.\r\n"
+#string STR_DRVCFG_DONE_HII #language en-US "Handle[%H%02x%N] successfully updated from file.\r\n"
+#string STR_DRVCFG_LINE_HII #language en-US "Handle[%H%02x%N] HII Config Access\r\n"
+#string STR_DRVCFG_ALL_LANG #language en-US "Driver[%H%02x%N] Ctrl[--] Lang[%H%a%N] Driver Configuration"
+#string STR_DRVCFG_CTRL_LANG #language en-US "Driver[%H%02x%N] Ctrl[%H%02x%N] Lang[%H%a%N] Driver Configuration"
+#string STR_DRVCFG_CHILD_LANG #language en-US "Driver[%H%02x%N] Ctrl[%H%02x%N] Child[%H%02x%N] Lang[%H%a%N] Driver Configuration"
+#string STR_DRVCFG_RESTART_S #language en-US "Restart %s\r\n"
+#string STR_DRVCFG_STOP #language en-US "Stop Controller\n"
+#string STR_DRVCFG_ENTER_S #language en-US "\nPress [ENTER] to %s"
+#string STR_DRVCFG_NONE #language en-US "None\n"
+#string STR_DRVCFG_CTLR_S #language en-US "Controller %s\n"
+#string STR_DRVCFG_FORCE_D #language en-US "Force Default Configuration to DefaultType %08x\n"
+#string STR_DRVCFG_VALIDATE #language en-US "Validate Configuration Options\n"
+#string STR_DRVCFG_SET #language en-US "Set Configuration Options\n"
+#string STR_DRVCFG_NOT_SUPPORT #language en-US "Handle [%H%02x%N] does not support configuration.\n"
+#string STR_DRVCFG_OPTIONS_SET #language en-US " - Options set. Action Required is "
+#string STR_DRVCFG_NOT_SET #language en-US " - Options not set. Status = %r\n"
+#string STR_DRVCFG_DEF_FORCED #language en-US " - Defaults forced. Action Required is "
+#string STR_DRVCFG_FORCE_FAILED #language en-US " - Force of defaults failed. Status = %r\n"
+#string STR_DRVCFG_OPTIONS_VALID #language en-US " - Options valid\n"
+#string STR_DRVCFG_OPTIONS_INV #language en-US " - Options not valid. Status = %r\n"
+#string STR_DRVCFG_IN_FILE_NF #language en-US "DevicePath '%B%s%N' from file not found in HII DB. Skipped.\r\n"
+
+
+#string STR_DEVICES_HEADER_LINES #language en-US "%N"
+" T D\r\n"
+" Y C I\r\n"
+" P F A\r\n"
+"CTRL E G G #P #D #C Device Name\r\n"
+"==== = = = == == === =========================================================\r\n"
+#string STR_DEVICES_ITEM_LINE #language en-US "%H%4x%N %1c %1c %1c %2d %2d %3d %s\r\n"
+#string STR_DEVICES_ITEM_LINE_SFO #language en-US "DevicesInfo,"%x","%c","%c","%c","%d","%d","%d","%s"\r\n"
+
+#string STR_DRIVERS_HEADER_LINES #language en-US "%N"
+"%H T D%N\r\n"
+"%HD Y C I%N\r\n"
+"%HR P F A%N\r\n"
+"%HV VERSION E G G #D #C DRIVER NAME IMAGE NAME%N\r\n"
+"== ======== = = = == == =================================== ==========\r\n"
+#string STR_DRIVERS_ITEM_LINE #language en-US "%H%2x%N %08x %1c %1c %1c %2s %2s %-35s %s\r\n"
+#string STR_DRIVERS_ITEM_LINE_SFO #language en-US "DriversInfo,"%x","%x","%c","%c","%c","%d","%d","%s","%s"\r\n"
+
+#string STR_DH_OUTPUT_DECODE #language en-US "%s: %g\r\n"
+#string STR_DH_NO_NAME_FOUND #language en-US "Protocol Name '%s' could not be identified.\r\n"
+#string STR_DH_NO_GUID_FOUND #language en-US "Protocol GUID '%g' could not be identified.\r\n"
+#string STR_DH_SFO_OUTPUT #language en-US "%s, %s, %H%02x%N, %s, &s\r\n"
+#string STR_DH_OUTPUT #language en-US "%H%02x%N: %s\r\n"
+#string STR_DH_OUTPUT_ALL_HEADER #language en-US "Handle dump\r\n"
+#string STR_DH_OUTPUT_GUID_HEADER #language en-US "Handle dump by protocol '%g'\r\n"
+#string STR_DH_OUTPUT_NAME_HEADER #language en-US "Handle dump by protocol '%s'\r\n"
+#string STR_DH_OUTPUT_SINGLE_D #language en-US "%H%02x%N: %s\r\n"
+#string STR_DH_OUTPUT_SINGLE #language en-US "%H%02x%N: %x\r\n%s"
+#string STR_DH_OUTPUT_SFO #language en-US "%s, %s, %s, %H%02x%N, %s, %s\r\n"
+#string STR_DH_OUTPUT_DRIVER1 #language en-US " Controller Name : %H%s%N\r\n"
+#string STR_DH_OUTPUT_DRIVER2 #language en-US " Device Path : %H%s%N\r\n"
+ " Controller Type : %H%s%N\r\n"
+ " Configuration : %H%s%N\r\n"
+ " Diagnostics : %H%s%N\r\n"
+#string STR_DH_OUTPUT_DRIVER3 #language en-US " Managed by : %H%s%N\r\n"
+#string STR_DH_OUTPUT_DRIVER4A #language en-US " Drv[%H%02x%N] : Image(%H%s%N)r\n"
+#string STR_DH_OUTPUT_DRIVER4B #language en-US " Drv[%H%02x%N] : %H%s%N\r\n"
+#string STR_DH_OUTPUT_DRIVER5 #language en-US " Parent Controllers : %H%s%N\r\n"
+#string STR_DH_OUTPUT_DRIVER5B #language en-US " Parent[%H%02x%N] : %H%s%N\r\n"
+#string STR_DH_OUTPUT_DRIVER6 #language en-US " Child Controllers : %H%s%N\r\n"
+#string STR_DH_OUTPUT_DRIVER6B #language en-US " Child[%H%02x%N] : %H%s%N\r\n"
+#string STR_DH_OUTPUT_DRIVER6C #language en-US " Child[%H%02x%N] : %H%s%N\r\n"
+#string STR_DH_OUTPUT_DRIVER7 #language en-US " Driver Name [%H%02x%N] : %H%s%N\r\n"
+#string STR_DH_OUTPUT_DRIVER7B #language en-US " Driver Image Name : %H%s%N\r\n"
+#string STR_DH_OUTPUT_DRIVER8 #language en-US " Driver Version : %H%08x%N\r\n"
+ " Driver Type : %H%s%N\r\n"
+ " Configuration : %H%s%N\r\n"
+ " Diagnostics : %H%s%N\r\n"
+#string STR_DH_OUTPUT_DRIVER9 #language en-US " Managing : %H%s%N\r\n"
+#string STR_DH_OUTPUT_DRIVER9B #language en-US " Ctrl[%H%02x%N] : %H%s%N\r\n"
+
+#string STR_DEV_TREE_OUTPUT #language en-US "Ctrl[%H%02x%N] %s\r\n"
+
+#string STR_UNLOAD_CONF #language en-US "%HUnload%N - Handle [%H%02x%N]. [y/n]?\r\n"
+#string STR_UNLOAD_VERBOSE #language en-US ""
+"Handle [%H%02x%N] (%08x)\r\n"
+" Image (%08x)\r\n"
+" ParentHandle..: %08x\r\n"
+" SystemTable...: %08x\r\n"
+" DeviceHandle..: %08x\r\n"
+" FilePath......: %s\r\n"
+" PDBFileName...: %a\r\n"
+" ImageBase.....: %08x\r\n"
+" ImageSize.....: %Ld\r\n"
+" CodeType......: %s\r\n"
+" DataType......: %s\r\n"
+
+#string STR_OPENINFO_HEADER_LINE #language en-US "Handle %H%02x%N (%H%0p%N)\r\n"
+#string STR_OPENINFO_LINE #language en-US " Drv[%H%02x%N] Ctrl[%H%02x%N] Cnt(%H%02x%N) %H%s Image%N(%s)\r\n"
+#string STR_OPENINFO_MIN_LINE #language en-US " Drv[%H%02x%N] Ctrl[ ] Cnt(%H%02x%N) %H%s Image%N(%s)\r\n"
+
+#string STR_DRV_DIAG_ITEM_LINE #language en-US " Drv[%H%02x%N] Ctrl[%H%02x%N] Child[%H%02x%N]\r\n"
+
+#string STR_GET_HELP_DRVCFG #language en-US ""
+".TH drvcfg 0 "configure a UEFI driver."\r\n"
+".SH NAME\r\n"
+"Invokes the driver configuration.\r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"DRVCFG [-l XXX] [-c] [-f <Type>|-v|-s] \r\n"
+" [DriverHandle [DeviceHandle [ChildHandle]]] [-i filename] [-o filename]\r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" -c - Configures all child devices.\r\n"
+" -l - Configures using the ISO 3066 language specified by XXX.\r\n"
+" -f - Forces defaults.\r\n"
+" -v - Validates options.\r\n"
+" -s - Sets options.\r\n"
+" -i - Receives configuration updates from an input file.\r\n"
+" -o - Exports the settings of the specified driver instance to a\r\n"
+" file.\r\n"
+" Type - Specifies the type of default configuration options to force on the\r\n"
+" controller.\r\n"
+" 0 - Standard Defaults.\r\n"
+" 1 - Manufacturing Defaults.\r\n"
+" 2 - Safe Defaults.\r\n"
+" 4000-FFFF - Custom Defaults.\r\n"
+" DriverHandle - Specifies the the handle of the driver to configure.\r\n"
+" DeviceHandle - Specifies the handle of a device that the DriverHandle is managing.\r\n"
+" ChildHandle - Specifies the handle of a device that is a child of the DeviceHandle. \r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. Default Type:\r\n"
+" 0 - Safe Defaults. Places a controller in a safe configuration with\r\n"
+" the greatest probability of functioning correctly in a platform.\r\n"
+" 1 - Manufacturing Defaults. Optional type that places the controller in\r\n"
+" a configuration suitable for a manufacturing and test environment.\r\n"
+" 2 - Custom Defaults. Optional type that places the controller in a\r\n"
+" custom configuration.\r\n"
+" 3 - Performance Defaults. Optional type that places the controller in a\r\n"
+" configuration that maximizes the controller's performance in a \r\n"
+" platform. \r\n"
+" Other Value - Depends on the driver's implementation.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * To display the list of devices that are available for configuration:\r\n"
+" Shell> drvcfg\r\n"
+" \r\n"
+" * To display the list of devices and child devices that are available for\r\n"
+" configuration:\r\n"
+" Shell> drvcfg -c\r\n"
+" \r\n"
+" * To force defaults on all devices:\r\n"
+" Shell> drvcfg -f 0\r\n"
+" \r\n"
+" * To force defaults on all devices that are managed by driver 0x17:\r\n"
+" Shell> drvcfg -f 0 17\r\n"
+" \r\n"
+" * To force defaults on device 0x28 that is managed by driver 0x17:\r\n"
+" Shell> drvcfg -f 0 17 28\r\n"
+" \r\n"
+" * To force defaults on all child devices of device 0x28 that is managed by\r\n"
+" driver 0x17:\r\n"
+" Shell> drvcfg -f 0 17 28 -c\r\n"
+" \r\n"
+" * To force defaults on child device 0x30 of device 0x28 that is managed by\r\n"
+" driver 0x17:\r\n"
+" Shell> drvcfg -f 0 17 28 30\r\n"
+" \r\n"
+" * To validate options on all devices:\r\n"
+" Shell> drvcfg -v\r\n"
+" \r\n"
+" * To validate options on all devices that are managed by driver 0x17:\r\n"
+" Shell> drvcfg -v 17\r\n"
+" \r\n"
+" * To validate options on device 0x28 that is managed by driver 0x17:\r\n"
+" Shell> drvcfg -v 17 28\r\n"
+" \r\n"
+" * To validate options on all child devices of device 0x28 that is managed by\r\n"
+" driver 0x17:\r\n"
+" Shell> drvcfg -v 17 28 -c\r\n"
+" \r\n"
+" * To validate options on child device 0x30 of device 0x28 that is managed by\r\n"
+" driver 0x17:\r\n"
+" Shell> drvcfg -v 17 28 30\r\n"
+" \r\n"
+" * To set options on device 0x28 that is managed by driver 0x17: \r\n"
+" Shell> drvcfg -s 17 28\r\n"
+" \r\n"
+" * To set options on child device 0x30 of device 0x28 that is managed by\r\n"
+" driver 0x17:\r\n"
+" Shell> drvcfg -s 17 28 30\r\n"
+" \r\n"
+" * To set options on device 0x28 that is managed by driver 0x17 in English:\r\n"
+" Shell> drvcfg -s 17 28 -l eng\r\n"
+" \r\n"
+" * To set options on device 0x28 that is managed by driver 0x17 in Spanish:\r\n"
+" Shell> drvcfg -s 17 28 -l spa\r\n"
+".SH RETURNVALUES\r\n"
+" \r\n"
+"RETURN VALUES:\r\n"
+" SHELL_SUCCESS The action was completed as requested.\r\n"
+" SHELL_SECURITY_VIOLATION This function was not performed due to a security\r\n"
+" violation.\r\n"
+" SHELL_UNSUPPORTED The action as requested was unsupported.\r\n"
+" SHELL_INVALID_PARAMETER One of the passed in parameters was incorrectly\r\n"
+" formatted or its value was out of bounds.\r\n"
+
+#string STR_GET_HELP_DRIVERS #language en-US ""
+".TH drivers 0 "display a list of drivers"\r\n"
+".SH NAME\r\n"
+"Displays the UEFI driver list.\r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"DRIVERS [-l XXX] [-sfo] \r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" -l - Displays drivers using the specified language (e.g. ISO 639-2) \r\n"
+" -sfo - Displays information as described in Standard-Format Output.\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. This command displays a list of information for drivers that follow the\r\n"
+" UEFI Driver Model in the UEFI environment. The list includes:\r\n"
+" DRV - The handle number of the UEFI driver.\r\n"
+" VERSION - The version number of the UEFI driver.\r\n"
+" TYPE - The driver type:\r\n"
+" [B] - Bus Driver\r\n"
+" [D] - Device Driver\r\n"
+" CFG - Driver supports the Driver Configuration Protocol.\r\n"
+" DIAG - Driver supports the Driver Diagnostics Protocol.\r\n"
+" #D - The number of devices that this driver is managing.\r\n"
+" #C - The number of child devices that this driver has produced.\r\n"
+" DRIVER NAME - The name of the driver from the Component Name Protocol.\r\n"
+" IMAGE PATH - The file path from which the driver was loaded.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * To display the list:\r\n"
+" Shell> drivers\r\n"
+".SH RETURNVALUES\r\n"
+" \r\n"
+"RETURN VALUES:\r\n"
+" SHELL_SUCCESS The action was completed as requested.\r\n"
+" SHELL_SECURITY_VIOLATION This function was not performed due to a security\r\n"
+" violation.\r\n"
+" SHELL_INVALID_PARAMETER One of the passed in parameters was incorrectly\r\n"
+" formatted or its value was out of bounds.\r\n"
+
+#string STR_GET_HELP_DISCONNECT #language en-US ""
+".TH disconnect 0 "disconnect a driver"\r\n"
+".SH NAME\r\n"
+"Disconnects one or more drivers from the specified devices. \r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"DISCONNECT DeviceHandle [DriverHandle [ChildHandle]] \r\n"
+"DISCONNECT -r [-nc] \r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+"NOTES:\r\n"
+" -r - Disconnects all drivers from all devices, then reconnect\r\n"
+" consoles.\r\n"
+" -nc - Do not reconnect the console devices.\r\n"
+" DeviceHandle - Specifies a device handle (a hexadecimal number). If not\r\n"
+" specified, then disconnect DriverHandle.\r\n"
+" DriverHandle - Specifies a driver handle (a hexadecimal number).\r\n"
+" ChildHandle - Specifies a child handle of a device (a hexadecimal number).\r\n"
+" If not specified, then all child handles of DeviceHandle are\r\n"
+" disconnected.\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. If the 'DriverHandle' parameter is not specified, the default is to\r\n"
+" disconnect 'DeviceHandle'.\r\n"
+" 2. If the 'ChildHandle' parameter is not specified, the default is to\r\n"
+" disconnect all child handles of the 'DeviceHandle'.\r\n"
+" 3. If the '-r' option is specified, all consoles and drivers will be\r\n"
+" disconnected from all devices in the system, then consoles are\r\n"
+" reconnected. If the '-nc' option is also spcified, then console devices\r\n"
+" are not reconnected.\r\n"
+" 4. This command does not support output redirection.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * To disconnect all drivers from all devices, then reconnect console\r\n"
+" devices:\r\n"
+" Shell> disconnect -r\r\n"
+" \r\n"
+" * To disconnect all drivers from all devices, including console devices:\r\n"
+" Shell> disconnect -r -nc\r\n"
+" \r\n"
+" * To disconnect all drivers from device 0x28:\r\n"
+" fs0:\> disconnect 28\r\n"
+" \r\n"
+" * To disconnect driver 0x17 from device 0x28:\r\n"
+" fs0:\> disconnect 28 17\r\n"
+" \r\n"
+" * To disconnect driver 0x17 from controlling the child 0x32 of device 0x28:\r\n"
+" fs0:\> disconnect 28 17 32\r\n"
+".SH RETURNVALUES\r\n"
+" \r\n"
+"RETURN VALUES:\r\n"
+" SHELL_SUCCESS The action was completed as requested.\r\n"
+" SHELL_SECURITY_VIOLATION This function was not performed due to a security\r\n"
+" violation.\r\n"
+" SHELL_INVALID_PARAMETER One of the passed in parameters was incorrectly\r\n"
+" formatted or its value was out of bounds.\r\n"
+
+#string STR_GET_HELP_DH #language en-US ""
+".TH dh 0 "displays list of handles"\r\n"
+".SH NAME\r\n"
+"Displays the device handles in the UEFI environment. \r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"DH [-l <lang>] [handle | -p <prot_id>] [-d] [-v] \r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" -p - Dumps all handles of a protocol specified by the GUID.\r\n"
+" -d - Dumps UEFI Driver Model-related information.\r\n"
+" -l - Dumps information using the language codes (e.g. ISO 639-2).\r\n"
+" -sfo - Displays information as described in Standard-Format Output.\r\n"
+" -v - Dumps verbose information about a specific handle.\r\n"
+" handle - Specifies a handle to dump information about (a hexadecimal number).\r\n"
+" If not present, then all information will be dumped.\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. When neither 'handle' nor 'prot_id' is specified, a list of all the\r\n"
+" device handles in the UEFI environment is displayed. \r\n"
+" 2. The '-d' option displays UEFI Driver Model related information including\r\n"
+" parent handles, child handles, all drivers installed on the handle, etc.\r\n"
+" 3. The '-v' option displays verbose information for the specified handle\r\n"
+" including all the protocols on the handle and their details.\r\n"
+" 4. If the '-p' option is specified, all handles containing the specified\r\n"
+" protocol will be displayed. Otherwise, the 'handle' parameter has to be\r\n"
+" specified for display. In this case, the '-d' option will be enabled\r\n"
+" automatically if the '-v' option is not specified.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * To display all handles and display one screen at a time:\r\n"
+" Shell> dh -b\r\n"
+" \r\n"
+" * To display the detailed information on handle 0x30:\r\n"
+" Shell> dh 30\r\n"
+" \r\n"
+" * To display all handles with 'diskio' protocol:\r\n"
+" Shell> dh -p diskio\r\n"
+" \r\n"
+" * To display all handles with 'LoadedImage' protocol and break when the screen is\r\n"
+" full:\r\n"
+" Shell> dh -p LoadedImage -b\r\n"
+".SH RETURNVALUES\r\n"
+" \r\n"
+"RETURN VALUES:\r\n"
+" SHELL_SUCCESS The action was completed as requested.\r\n"
+" SHELL_SECURITY_VIOLATION This function was not performed due to a security\r\n"
+" violation.\r\n"
+" SHELL_INVALID_PARAMETER One of the passed in parameters was incorrectly\r\n"
+" formatted or its value was out of bounds.\r\n"
+
+#string STR_GET_HELP_DEVTREE #language en-US ""
+".TH devtree 0 "display device tree"\r\n"
+".SH NAME\r\n"
+"Displays the UEFI Driver Model compliant device tree.\r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"DEVTREE [-b] [-d] [-l XXX] [DeviceHandle] \r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" -b - Displays one screen at a time.\r\n"
+" -d - Displays the device tree using device paths.\r\n"
+" -l - Displays the device tree using the specified language.\r\n"
+" DeviceHandle - Displays the device tree below a certain handle.\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. This command prints a tree of devices that are being managed by drivers\r\n"
+" that follow the UEFI Driver Model. By default, the devices are printed in\r\n"
+" device names that are retrieved from the Component Name Protocol.\r\n"
+" 2. If the option -d is specified, the device paths will be printed instead.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * To display the tree of all devices compliant with the UEFI Driver Model:\r\n"
+" Shell> devtree\r\n"
+" \r\n"
+" * To display the tree of all devices below device 28 compliant with the UEFI\r\n"
+" Driver Model:\r\n"
+" Shell> devtree 28\r\n"
+" \r\n"
+" * To display the tree of all devices compliant with the UEFI Driver Model\r\n"
+" one screen at a time:\r\n"
+" Shell> devtree -b\r\n"
+" \r\n"
+
+#string STR_GET_HELP_DEVICES #language en-US ""
+".TH devices 0 "display a list of devices"\r\n"
+".SH NAME\r\n"
+"Displays the list of devices managed by UEFI drivers. \r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"DEVICES [-b] [-l XXX] [-sfo] \r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" -b - Display one screen at a time\r\n"
+" -l XXX - Display devices using the specified ISO 639-2 language\r\n"
+" -sfo - Displays information as described in Standard-Format Output.\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. The command prints a list of devices that are being managed by drivers\r\n"
+" that follow the UEFI Driver Model.\r\n"
+" 2. Display Format:\r\n"
+" CTRL - The handle number of the UEFI device\r\n"
+" TYPE - The device type:\r\n"
+" [R] - Root Controller\r\n"
+" [B] - Bus Controller\r\n"
+" [D] - Device Controller\r\n"
+" CFG - A managing driver supports the Driver Configuration\r\n"
+" Protocol. Yes if 'Y' or 'X'; No if 'N' or '-'.\r\n"
+" DIAG - A managing driver supports the Driver Diagnostics\r\n"
+" Protocol. Yes if 'Y' or 'X'; No if 'N' or '-'.\r\n"
+" #P - The number of parent controllers for this device\r\n"
+" #D - The number of drivers managing the device\r\n"
+" #C - The number of child controllers produced by this device\r\n"
+" DEVICE NAME - The name of the device from the Component Name Protocol\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * To display all devices compliant with the UEFI Driver Model:\r\n"
+" Shell> devices\r\n"
+" \r\n"
+
+#string STR_GET_HELP_CONNECT #language en-US ""
+".TH connect 0 "connect a driver"\r\n"
+".SH NAME\r\n"
+"Binds a driver to a specific device and starts the driver. \r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"CONNECT [[DeviceHandle] [DriverHandle] | [-c] | [-r]] \r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" -c - Connects console devices\r\n"
+" -r - Connects recursively\r\n"
+" DeviceHandle - Specifies a device handle in hexadecimal format.\r\n"
+" DriverHandle - Specifies a driver handle in hexadecimal format.\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. If no 'DeviceHandle' parameter is specified, all device handles in the\r\n"
+" current system will be the default.\r\n"
+" 2. If no 'DriverHandle' parameter is specified, all matched drivers will be\r\n"
+" bound to the specified device.\r\n"
+" 3. If 'DriverHandle' parameter is provided, the specified driver will have\r\n"
+" highest priority on connecting the device(s).\r\n"
+" 4. If the '-c' option is specified, only console devices described in the\r\n"
+" UEFI Shell environment variables and related devices will be connected.\r\n"
+" 5. If the '-r' option is specified, the command will recursively scan all\r\n"
+" handles and check to see if any loaded or embedded driver can match the\r\n"
+" specified device. If so, the driver will be bound to the device.\r\n"
+" Additionally, if more device handles are created during the binding, \r\n"
+" these handles will also be checked to see if a matching driver can bind\r\n"
+" to these devices as well. The process is repeated until no more drivers\r\n"
+" are able to connect to any devices. However, without the option, the\r\n"
+" newly created device handles will not be further bound to any\r\n"
+" drivers.\r\n"
+" 6. If only a single handle is specified and the handle has an\r\n"
+" EFI_DRIVER_BINDING_PROTOCOL on it, then the handle is assumed to be a\r\n"
+" driver handle. Otherwise, it is assumed to be a device handle.\r\n"
+" 7. If no parameters are specified, then the command will attempt to bind\r\n"
+" all proper drivers to all devices without recursion. Each connection\r\n"
+" status will be displayed.\r\n"
+" 8. Output redirection is not supported for 'connect -r' usage.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * To connect all drivers to all devices recursively:\r\n"
+" Shell> connect -r\r\n"
+" \r\n"
+" * To display all connections:\r\n"
+" Shell> connect\r\n"
+" \r\n"
+" * To connect drivers with 0x17 as highest priority to all the devices they\r\n"
+" can manage:\r\n"
+" Shell> connect 17\r\n"
+" \r\n"
+" * To connect all possible drivers to device 0x19:\r\n"
+" Shell> connect 19\r\n"
+" \r\n"
+" * To connect drivers with 0x17 as highest priority to device 0x19 they can\r\n"
+" manage:\r\n"
+" Shell> connect 19 17\r\n"
+" \r\n"
+" * To connect console devices described in the UEFI Shell environment\r\n"
+" variables:\r\n"
+" Shell> connect -c\r\n"
+".SH RETURNVALUES\r\n"
+" \r\n"
+"RETURN VALUES:\r\n"
+" SHELL_SUCCESS The action was completed as requested.\r\n"
+" SHELL_SECURITY_VIOLATION This function was not performed due to a security\r\n"
+" violation.\r\n"
+" SHELL_INVALID_PARAMETER One of the passed in parameters was incorrectly\r\n"
+" formatted or its value was out of bounds.\r\n"
+
+#string STR_GET_HELP_OPENINFO #language en-US ""
+".TH openinfo 0 "display info about a handle."\r\n"
+".SH NAME\r\n"
+"Displays the protocols and agents associated with a handle. \r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"OPENINFO Handle [-b] \r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" -b - Displays one screen at a time.\r\n"
+" Handle - Displays open protocol information for the specified handle.\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. This command is used to display the open protocols on a given handle.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * To show open protocols on handle 0x23:\r\n"
+" Shell> openinfo 23\r\n"
+" \r\n"
+
+#string STR_GET_HELP_DRVDIAG #language en-US ""
+".TH drvdiag 0 "diagnose a driver"\r\n"
+".SH NAME\r\n"
+"Invokes the Driver Diagnostics Protocol. \r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"DRVDIAG [-c] [-l XXX] [-s|-e|-m] [DriverHandle [DeviceHandle [ChildHandle]]] \r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" -c - Diagnoses all child devices.\r\n"
+" -l - Diagnoses using the ISO 639-2 language specified by XXX.\r\n"
+" -s - Runs diagnostics in standard mode.\r\n"
+" -e - Runs diagnostics in extended mode.\r\n"
+" -m - Runs diagnostics in manufacturing mode.\r\n"
+" DriverHandle - Specifies the handle of the driver to diagnose.\r\n"
+" DeviceHandle - Specifies the handle of a device that DriverHandle is managing.\r\n"
+" ChildHandle - Specifies the handle of a device that is a child of DeviceHandle.\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. This command invokes the Driver Diagnostics Protocol.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * To display the list of devices that are available for diagnostics:\r\n"
+" Shell> drvdiag\r\n"
+" \r\n"
+" * To display the list of devices and child devices that are available for\r\n"
+" diagnostics:\r\n"
+" Shell> drvdiag -c\r\n"
+" \r\n"
+" * To run diagnostics in standard mode on all devices:\r\n"
+" Shell> drvdiag -s\r\n"
+" \r\n"
+" * To run diagnostics in standard mode on all devices in English:\r\n"
+" Shell> drvdiag -s -l eng\r\n"
+" \r\n"
+" * To run diagnostics in standard mode on all devices in Spanish:\r\n"
+" Shell> drvdiag -s -l spa\r\n"
+" \r\n"
+" * To run diagnostics in standard mode on all devices and child devices:\r\n"
+" Shell> drvdiag -s -c\r\n"
+" \r\n"
+" * To run diagnostics in extended mode on all devices:\r\n"
+" Shell> drvdiag -e\r\n"
+" \r\n"
+" * To run diagnostics in manufacturing mode on all devices:\r\n"
+" Shell> drvdiag -m\r\n"
+" \r\n"
+" * To run diagnostics in standard mode on all devices managed by driver 0x17:\r\n"
+" Shell> drvdiag -s 17\r\n"
+" \r\n"
+" * To run diagnostics in standard mode on device 0x28 managed by driver 0x17:\r\n"
+" Shell> drvdiag -s 17 28\r\n"
+" \r\n"
+" * To run diagnostics in standard mode on all child devices of device 0x28\r\n"
+" managed by driver 0x17:\r\n"
+" Shell> drvdiag -s 17 28 -c\r\n"
+" \r\n"
+" * To run diagnostics in standard mode on child device 0x30 of device 0x28\r\n"
+" managed by driver 0x17:\r\n"
+" Shell> drvdiag -s 17 28 30\r\n"
+".SH RETURNVALUES\r\n"
+" \r\n"
+"RETURN VALUES:\r\n"
+" SHELL_SUCCESS The action was completed as requested.\r\n"
+" SHELL_SECURITY_VIOLATION This function was not performed due to a security\r\n"
+" violation.\r\n"
+" SHELL_INVALID_PARAMETER One of the passed in parameters was incorrectly\r\n"
+" formatted or its value was out of bounds.\r\n"
+
+#string STR_GET_HELP_RECONNECT #language en-US ""
+".TH reconnect 0 "reconnect drivers"\r\n"
+".SH NAME\r\n"
+"Reconnects drivers to the specific device. \r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"RECONNECT DeviceHandle [DriverHandle [ChildHandle]]\r\n"
+"RECONNECT -r \r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" -r - Reconnects drivers to all devices.\r\n"
+" DeviceHandle - Specifies a device handle (a hexadecimal number).\r\n"
+" DriverHandle - Specifies a driver handle (a hexadecimal number). If not specified, all\r\n"
+" drivers on the specified device will be reconnected. \r\n"
+" ChildHandle - Specifies the child handle of device (a hexadecimal number). If not\r\n"
+" specified, then all child handles of the specified device are\r\n"
+" reconnected.\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. This command reconnects drivers to the specific device. It will first\r\n"
+" disconnect the specified driver from the specified device and then connect\r\n"
+" the driver to the device recursively.\r\n"
+" 2. If the -r option is used, then all drivers will be reconnected to all\r\n"
+" devices. Any drivers that are bound to any devices will be disconnected\r\n"
+" first and then connected recursively.\r\n"
+" 3. See the connect and disconnect commands for more details. \r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * To reconnect all drivers to all devices:\r\n"
+" Shell> reconnect -r\r\n"
+" \r\n"
+" * To reconnect all drivers to device 0x28:\r\n"
+" fs0:\> reconnect 28\r\n"
+" \r\n"
+" * To disconnect 0x17 from 0x28 then reconnect drivers with 0x17 as highest\r\n"
+" priority to device 0x28:\r\n"
+" fs0:\> reconnect 28 17\r\n"
+" \r\n"
+" * To disconnect 0x17 from 0x28 destroying child 0x32 then reconnect drivers\r\n"
+" with 0x17 as highest priority to device 0x28\r\n"
+" fs0:\> reconnect 28 17 32\r\n"
+".SH RETURNVALUES\r\n"
+" \r\n"
+"RETURN VALUES:\r\n"
+" SHELL_SUCCESS The action was completed as requested.\r\n"
+" SHELL_SECURITY_VIOLATION This function was not performed due to a security\r\n"
+" violation.\r\n"
+" SHELL_INVALID_PARAMETER One of the passed in parameters was incorrectly\r\n"
+" formatted or its value was out of bounds.\r\n"
+
+#string STR_GET_HELP_UNLOAD #language en-US ""
+".TH unload 0 "unload a driver"\r\n"
+".SH NAME\r\n"
+"Unloads a driver image that was already loaded. \r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"UNLOAD [-n] [-v|-verbose] Handle \r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" -n - Skips all prompts during unloading, so that it can be used\r\n"
+" in a script file.\r\n"
+" -v, -verbose - Dumps verbose status information before the image is unloaded.\r\n"
+" Handle - Specifies the handle of driver to unload, always taken as hexadecimal number.\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. The '-n' option can be used to skip all prompts during unloading.\r\n"
+" 2. If the '-v' option is specified, verbose image information will be\r\n"
+" displayed before the image is unloaded.\r\n"
+" 3. Only drivers that support unloading can be successfully unloaded.\r\n"
+" 4. Use the 'LOAD' command to load a driver.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * To find the handle for the UEFI driver image to unload:\r\n"
+" Shell> dh -b\r\n"
+" \r\n"
+" * To unload the UEFI driver image with handle 27:\r\n"
+" Shell> unload 27\r\n"
+".SH RETURNVALUES\r\n"
+" \r\n"
+"RETURN VALUES:\r\n"
+" SHELL_SUCCESS The action was completed as requested.\r\n"
+" SHELL_SECURITY_VIOLATION This function was not performed due to a security\r\n"
+" violation.\r\n"
+" SHELL_INVALID_PARAMETER One of the passed in parameters was incorrectly\r\n"
+" formatted or its value was out of bounds.\r\n"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Unload.c b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Unload.c new file mode 100644 index 00000000..2e2220fb --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Unload.c @@ -0,0 +1,142 @@ +/** @file + Main file for Unload shell Driver1 function. + + (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR> + Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UefiShellDriver1CommandsLib.h" + +/** + 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 +DumpLoadedImageProtocolInfo ( + IN EFI_HANDLE TheHandle + ) +{ + CHAR16 *TheString; + + TheString = GetProtocolInformationDump(TheHandle, &gEfiLoadedImageProtocolGuid, TRUE); + + ShellPrintEx(-1, -1, L"%s", TheString); + + SHELL_FREE_NON_NULL(TheString); + + 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; + UINT64 Value; + + ShellStatus = SHELL_SUCCESS; + Package = NULL; + Resp = NULL; + Value = 0; + TheHandle = 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,L"unload", 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, L"unload"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount(Package) < 2) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"unload"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Param1 = ShellCommandLineGetRawValue(Package, 1); + if (Param1 != NULL) { + Status = ShellConvertStringToUint64(Param1, &Value, TRUE, FALSE); + TheHandle = ConvertHandleIndexToHandle((UINTN)Value); + } + + if (EFI_ERROR(Status) || Param1 == NULL || TheHandle == NULL){ + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"unload", Param1); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + 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, (UINTN)TheHandle); + 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", (UINTN)TheHandle, 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); +} |