2 Main file for Dh shell Driver1 function.
4 (C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
6 (C) Copyright 2017 Hewlett Packard Enterprise Development LP<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "UefiShellDriver1CommandsLib.h"
13 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
17 { L
"-verbose", TypeFlag
},
18 { L
"-sfo", TypeFlag
},
23 STATIC CONST EFI_GUID
*UefiDriverModelProtocolsGuidArray
[] = {
24 &gEfiDriverBindingProtocolGuid
,
25 &gEfiPlatformDriverOverrideProtocolGuid
,
26 &gEfiBusSpecificDriverOverrideProtocolGuid
,
27 &gEfiDriverDiagnosticsProtocolGuid
,
28 &gEfiDriverDiagnostics2ProtocolGuid
,
29 &gEfiComponentNameProtocolGuid
,
30 &gEfiComponentName2ProtocolGuid
,
31 &gEfiPlatformToDriverConfigurationProtocolGuid
,
32 &gEfiDriverSupportedEfiVersionProtocolGuid
,
33 &gEfiDriverFamilyOverrideProtocolGuid
,
34 &gEfiDriverHealthProtocolGuid
,
35 &gEfiLoadedImageProtocolGuid
,
39 UINTN mGuidDataLen
[] = { 8, 4, 4, 4, 12 };
42 Function to determine if the string can convert to a GUID.
43 The string must be restricted as "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" format.
45 @param[in] String The string to test.
47 @retval TRUE The string can convert to a GUID.
48 @retval FALSE The string can't convert to a GUID.
52 IN CONST CHAR16
*String
56 CONST CHAR16
*PrevWalker
;
67 while (Walker
!= NULL
&& *Walker
!= CHAR_NULL
) {
68 if (((*Walker
>= '0') && (*Walker
<= '9')) ||
69 ((*Walker
>= 'a') && (*Walker
<= 'f')) ||
70 ((*Walker
>= 'A') && (*Walker
<= 'F'))
75 if ((*Walker
== L
'-') && ((((UINTN
)Walker
- (UINTN
)PrevWalker
) / sizeof (CHAR16
)) == mGuidDataLen
[Index
])) {
85 if ((((UINTN
)Walker
- (UINTN
)PrevWalker
) / sizeof (CHAR16
)) == mGuidDataLen
[Index
]) {
93 Convert a hex-character to decimal value.
95 This internal function only deal with Unicode character
96 which maps to a valid hexadecimal ASII character, i.e.
97 L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other
98 Unicode character, the value returned does not make sense.
100 @param[in] Char The character to convert.
102 @retval The numerical value converted.
109 if ((Char
>= '0') && (Char
<= '9')) {
111 } else if ((Char
>= 'a') && (Char
<= 'f')) {
112 return Char
- L
'a' + 10;
114 return Char
- L
'A' + 10;
119 Function try to convert a string to GUID format.
121 @param[in] String The string will be converted.
122 @param[out] Guid Save the result convert from string.
124 @retval EFI_SUCCESS The string was successfully converted to a GUID.
125 @retval EFI_UNSUPPORTED The input string is not in registry format.
129 IN CONST CHAR16
*String
,
133 CONST CHAR16
*Walker
;
137 if ((String
== NULL
) || !IsValidGuidString (String
)) {
138 return EFI_UNSUPPORTED
;
144 Guid
->Data1
= (UINT32
)StrHexToUint64 (Walker
);
147 Guid
->Data2
= (UINT16
)StrHexToUint64 (Walker
);
150 Guid
->Data3
= (UINT16
)StrHexToUint64 (Walker
);
153 while (Walker
!= NULL
&& *Walker
!= CHAR_NULL
) {
154 if (*Walker
== L
'-') {
157 TempValue
= (UINT8
)HexCharToDecimal (*Walker
);
158 TempValue
= (UINT8
)LShiftU64 (TempValue
, 4);
161 TempValue
+= (UINT8
)HexCharToDecimal (*Walker
);
164 Guid
->Data4
[Index
] = TempValue
;
173 Get the name of a driver by it's handle.
175 If a name is found the memory must be callee freed.
177 @param[in] TheHandle The driver's handle.
178 @param[in] Language The language to use.
179 @param[in] NameFound Upon a successful return the name found.
181 @retval EFI_SUCCESS The name was found.
185 IN EFI_HANDLE TheHandle
,
186 IN CONST CHAR8
*Language
,
187 IN CHAR16
**NameFound
192 EFI_COMPONENT_NAME2_PROTOCOL
*CompName2
;
193 CHAR16
*NameToReturn
;
196 // Go through those handles until we get one that passes for GetComponentName
198 Status
= gBS
->OpenProtocol (
200 &gEfiComponentName2ProtocolGuid
,
204 EFI_OPEN_PROTOCOL_GET_PROTOCOL
206 if (EFI_ERROR (Status
)) {
207 Status
= gBS
->OpenProtocol (
209 &gEfiComponentNameProtocolGuid
,
213 EFI_OPEN_PROTOCOL_GET_PROTOCOL
217 if (EFI_ERROR (Status
)) {
218 return (EFI_NOT_FOUND
);
221 Lang
= GetBestLanguageForDriver (CompName2
->SupportedLanguages
, Language
, FALSE
);
222 Status
= CompName2
->GetDriverName (CompName2
, Lang
, &NameToReturn
);
225 if (!EFI_ERROR (Status
) && (NameToReturn
!= NULL
)) {
227 StrnCatGrow (NameFound
, NULL
, NameToReturn
, 0);
234 Discover if a protocol guid is one of the UEFI Driver Model Protocols.
236 @param[in] Guid The guid to test.
238 @retval TRUE The guid does represent a driver model protocol.
239 @retval FALSE The guid does not represent a driver model protocol.
243 IN CONST EFI_GUID
*Guid
246 CONST EFI_GUID
**GuidWalker
;
250 for (GuidWalker
= UefiDriverModelProtocolsGuidArray
251 ; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
255 if (CompareGuid (*GuidWalker
, Guid
)) {
265 Get information for a handle.
267 @param[in] TheHandle The handles to show info on.
268 @param[in] Language Language string per UEFI specification.
269 @param[in] Separator Separator string between information blocks.
270 @param[in] Verbose TRUE for extra info, FALSE otherwise.
271 @param[in] ExtraInfo TRUE for extra info, FALSE otherwise.
273 @retval SHELL_SUCCESS The operation was successful.
274 @retval SHELL_INVALID_PARAMETER ProtocolName was NULL or invalid.
277 GetProtocolInfoString (
278 IN CONST EFI_HANDLE TheHandle
,
279 IN CONST CHAR8
*Language
,
280 IN CONST CHAR16
*Separator
,
281 IN CONST BOOLEAN Verbose
,
282 IN CONST BOOLEAN ExtraInfo
285 EFI_GUID
**ProtocolGuidArray
;
294 CHAR16 InstanceStr
[17];
296 ProtocolGuidArray
= NULL
;
300 Status
= gBS
->ProtocolsPerHandle (
305 if (!EFI_ERROR (Status
)) {
306 for (ProtocolIndex
= 0; ProtocolIndex
< ArrayCount
; ProtocolIndex
++) {
307 Temp
= GetStringNameFromGuid (ProtocolGuidArray
[ProtocolIndex
], Language
);
308 ASSERT ((RetVal
== NULL
&& Size
== 0) || (RetVal
!= NULL
));
310 StrnCatGrow (&RetVal
, &Size
, Separator
, 0);
313 StrnCatGrow (&RetVal
, &Size
, L
"%H", 0);
315 UnicodeSPrint (GuidStr
, sizeof (GuidStr
), L
"%g", ProtocolGuidArray
[ProtocolIndex
]);
316 StrnCatGrow (&RetVal
, &Size
, GuidStr
, 0);
318 StrnCatGrow (&RetVal
, &Size
, Temp
, 0);
322 StrnCatGrow (&RetVal
, &Size
, L
"%N", 0);
325 Status
= gBS
->HandleProtocol (TheHandle
, ProtocolGuidArray
[ProtocolIndex
], &Instance
);
326 if (!EFI_ERROR (Status
)) {
327 StrnCatGrow (&RetVal
, &Size
, L
"(%H", 0);
328 UnicodeSPrint (InstanceStr
, sizeof (InstanceStr
), L
"%x", Instance
);
329 StrnCatGrow (&RetVal
, &Size
, InstanceStr
, 0);
330 StrnCatGrow (&RetVal
, &Size
, L
"%N)", 0);
335 Temp
= GetProtocolInformationDump (TheHandle
, ProtocolGuidArray
[ProtocolIndex
], Verbose
);
337 ASSERT ((RetVal
== NULL
&& Size
== 0) || (RetVal
!= NULL
));
339 StrnCatGrow (&RetVal
, &Size
, L
"(", 0);
340 StrnCatGrow (&RetVal
, &Size
, Temp
, 0);
341 StrnCatGrow (&RetVal
, &Size
, L
")", 0);
343 StrnCatGrow (&RetVal
, &Size
, Separator
, 0);
344 StrnCatGrow (&RetVal
, &Size
, Temp
, 0);
353 SHELL_FREE_NON_NULL (ProtocolGuidArray
);
355 if (RetVal
== NULL
) {
359 ASSERT ((RetVal
== NULL
&& Size
== 0) || (RetVal
!= NULL
));
360 StrnCatGrow (&RetVal
, &Size
, Separator
, 0);
365 Gets the name of the loaded image.
367 @param[in] TheHandle The handle of the driver to get info on.
368 @param[out] Name The pointer to the pointer. Valid upon a successful return.
370 @retval EFI_SUCCESS The operation was successful.
374 IN EFI_HANDLE TheHandle
,
378 // get loaded image and devicepathtotext on image->Filepath
379 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
381 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
383 if ((TheHandle
== NULL
) || (Name
== NULL
)) {
384 return (EFI_INVALID_PARAMETER
);
387 Status
= gBS
->OpenProtocol (
389 &gEfiLoadedImageProtocolGuid
,
390 (VOID
**)&LoadedImage
,
393 EFI_OPEN_PROTOCOL_GET_PROTOCOL
395 if (EFI_ERROR (Status
)) {
399 DevicePath
= LoadedImage
->FilePath
;
400 *Name
= ConvertDevicePathToText (DevicePath
, TRUE
, TRUE
);
401 return (EFI_SUCCESS
);
405 Display driver model information for a given handle.
407 @param[in] Handle The handle to display info on.
408 @param[in] BestName Use the best name?
409 @param[in] Language The language to output in.
412 DisplayDriverModelHandle (
413 IN EFI_HANDLE Handle
,
415 IN CONST CHAR8
*Language OPTIONAL
419 BOOLEAN ConfigurationStatus
;
420 BOOLEAN DiagnosticsStatus
;
421 UINTN DriverBindingHandleCount
;
422 EFI_HANDLE
*DriverBindingHandleBuffer
;
423 UINTN ParentControllerHandleCount
;
424 EFI_HANDLE
*ParentControllerHandleBuffer
;
425 UINTN ChildControllerHandleCount
;
426 EFI_HANDLE
*ChildControllerHandleBuffer
;
427 CHAR16
*TempStringPointer
;
428 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
431 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
432 UINTN NumberOfChildren
;
434 UINTN ControllerHandleCount
;
435 EFI_HANDLE
*ControllerHandleBuffer
;
442 // See if Handle is a device handle and display its details.
444 DriverBindingHandleBuffer
= NULL
;
445 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
447 &DriverBindingHandleCount
,
448 &DriverBindingHandleBuffer
451 ParentControllerHandleBuffer
= NULL
;
452 Status
= PARSE_HANDLE_DATABASE_PARENTS (
454 &ParentControllerHandleCount
,
455 &ParentControllerHandleBuffer
458 ChildControllerHandleBuffer
= NULL
;
459 Status
= ParseHandleDatabaseForChildControllers (
461 &ChildControllerHandleCount
,
462 &ChildControllerHandleBuffer
465 DiagnosticsStatus
= FALSE
;
466 ConfigurationStatus
= FALSE
;
468 if (!EFI_ERROR (gBS
->OpenProtocol (Handle
, &gEfiDriverConfigurationProtocolGuid
, NULL
, NULL
, gImageHandle
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
))) {
469 ConfigurationStatus
= TRUE
;
472 if (!EFI_ERROR (gBS
->OpenProtocol (Handle
, &gEfiDriverConfiguration2ProtocolGuid
, NULL
, NULL
, gImageHandle
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
))) {
473 ConfigurationStatus
= TRUE
;
476 if (!EFI_ERROR (gBS
->OpenProtocol (Handle
, &gEfiDriverDiagnosticsProtocolGuid
, NULL
, NULL
, gImageHandle
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
))) {
477 DiagnosticsStatus
= TRUE
;
480 if (!EFI_ERROR (gBS
->OpenProtocol (Handle
, &gEfiDriverDiagnostics2ProtocolGuid
, NULL
, NULL
, gImageHandle
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
))) {
481 DiagnosticsStatus
= TRUE
;
484 Status
= EFI_SUCCESS
;
486 if ((DriverBindingHandleCount
> 0) || (ParentControllerHandleCount
> 0) || (ChildControllerHandleCount
> 0)) {
488 TempStringPointer
= NULL
;
489 Status
= gBS
->HandleProtocol (Handle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&DevicePath
);
491 Status
= gEfiShellProtocol
->GetDeviceName (Handle
, EFI_DEVICE_NAME_USE_COMPONENT_NAME
|EFI_DEVICE_NAME_USE_DEVICE_PATH
, (CHAR8
*)Language
, &TempStringPointer
);
492 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DH_OUTPUT_DRIVER1
), gShellDriver1HiiHandle
, TempStringPointer
!= NULL
? TempStringPointer
: L
"<Unknown>");
493 SHELL_FREE_NON_NULL (TempStringPointer
);
495 TempStringPointer
= ConvertDevicePathToText (DevicePath
, TRUE
, FALSE
);
500 STRING_TOKEN (STR_DH_OUTPUT_DRIVER2
),
501 gShellDriver1HiiHandle
,
502 TempStringPointer
!= NULL
? TempStringPointer
: L
"<None>",
503 ParentControllerHandleCount
== 0 ? L
"ROOT" : (ChildControllerHandleCount
> 0) ? L
"BUS" : L
"DEVICE",
504 ConfigurationStatus
? L
"YES" : L
"NO",
505 DiagnosticsStatus
? L
"YES" : L
"NO"
508 SHELL_FREE_NON_NULL (TempStringPointer
);
510 if (DriverBindingHandleCount
== 0) {
515 STRING_TOKEN (STR_DH_OUTPUT_DRIVER3
),
516 gShellDriver1HiiHandle
,
524 STRING_TOKEN (STR_DH_OUTPUT_DRIVER3
),
525 gShellDriver1HiiHandle
,
528 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
530 Status
= GetDriverName (
531 DriverBindingHandleBuffer
[Index
],
535 if (EFI_ERROR (Status
)) {
536 Status
= GetDriverImageName (
537 DriverBindingHandleBuffer
[Index
],
540 if (EFI_ERROR (Status
)) {
550 STRING_TOKEN (STR_DH_OUTPUT_DRIVER4A
),
551 gShellDriver1HiiHandle
,
552 ConvertHandleToHandleIndex (DriverBindingHandleBuffer
[Index
]),
553 DriverName
!= NULL
? DriverName
: L
"<Unknown>"
560 STRING_TOKEN (STR_DH_OUTPUT_DRIVER4B
),
561 gShellDriver1HiiHandle
,
562 ConvertHandleToHandleIndex (DriverBindingHandleBuffer
[Index
]),
563 DriverName
!= NULL
? DriverName
: L
"<Unknown>"
567 SHELL_FREE_NON_NULL (DriverName
);
571 if (ParentControllerHandleCount
== 0) {
576 STRING_TOKEN (STR_DH_OUTPUT_DRIVER5
),
577 gShellDriver1HiiHandle
,
585 STRING_TOKEN (STR_DH_OUTPUT_DRIVER5
),
586 gShellDriver1HiiHandle
,
589 for (Index
= 0; Index
< ParentControllerHandleCount
; Index
++) {
590 Status
= gEfiShellProtocol
->GetDeviceName (ParentControllerHandleBuffer
[Index
], EFI_DEVICE_NAME_USE_COMPONENT_NAME
|EFI_DEVICE_NAME_USE_DEVICE_PATH
, (CHAR8
*)Language
, &TempStringPointer
);
595 STRING_TOKEN (STR_DH_OUTPUT_DRIVER5B
),
596 gShellDriver1HiiHandle
,
597 ConvertHandleToHandleIndex (ParentControllerHandleBuffer
[Index
]),
598 TempStringPointer
!= NULL
? TempStringPointer
: L
"<Unknown>"
600 SHELL_FREE_NON_NULL (TempStringPointer
);
604 if (ChildControllerHandleCount
== 0) {
609 STRING_TOKEN (STR_DH_OUTPUT_DRIVER6
),
610 gShellDriver1HiiHandle
,
618 STRING_TOKEN (STR_DH_OUTPUT_DRIVER6
),
619 gShellDriver1HiiHandle
,
622 for (Index
= 0; Index
< ChildControllerHandleCount
; Index
++) {
623 Status
= gEfiShellProtocol
->GetDeviceName (ChildControllerHandleBuffer
[Index
], EFI_DEVICE_NAME_USE_COMPONENT_NAME
|EFI_DEVICE_NAME_USE_DEVICE_PATH
, (CHAR8
*)Language
, &TempStringPointer
);
628 STRING_TOKEN (STR_DH_OUTPUT_DRIVER6B
),
629 gShellDriver1HiiHandle
,
630 ConvertHandleToHandleIndex (ChildControllerHandleBuffer
[Index
]),
631 TempStringPointer
!= NULL
? TempStringPointer
: L
"<Unknown>"
633 SHELL_FREE_NON_NULL (TempStringPointer
);
638 SHELL_FREE_NON_NULL (DriverBindingHandleBuffer
);
640 SHELL_FREE_NON_NULL (ParentControllerHandleBuffer
);
642 SHELL_FREE_NON_NULL (ChildControllerHandleBuffer
);
644 if (EFI_ERROR (Status
)) {
649 // See if Handle is a driver binding handle and display its details.
651 Status
= gBS
->OpenProtocol (
653 &gEfiDriverBindingProtocolGuid
,
654 (VOID
**)&DriverBinding
,
657 EFI_OPEN_PROTOCOL_GET_PROTOCOL
659 if (EFI_ERROR (Status
)) {
663 NumberOfChildren
= 0;
664 ControllerHandleBuffer
= NULL
;
665 Status
= PARSE_HANDLE_DATABASE_DEVICES (
667 &ControllerHandleCount
,
668 &ControllerHandleBuffer
670 if (ControllerHandleCount
> 0) {
671 for (HandleIndex
= 0; HandleIndex
< ControllerHandleCount
; HandleIndex
++) {
672 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
674 ControllerHandleBuffer
[HandleIndex
],
675 &ChildControllerHandleCount
,
678 NumberOfChildren
+= ChildControllerHandleCount
;
682 Status
= GetDriverName (Handle
, Language
, &DriverName
);
683 if (EFI_ERROR (Status
)) {
691 STRING_TOKEN (STR_DH_OUTPUT_DRIVER7
),
692 gShellDriver1HiiHandle
,
693 ConvertHandleToHandleIndex (Handle
),
694 DriverName
!= NULL
? DriverName
: L
"<Unknown>"
696 SHELL_FREE_NON_NULL (DriverName
);
697 Status
= GetDriverImageName (
701 if (EFI_ERROR (Status
)) {
709 STRING_TOKEN (STR_DH_OUTPUT_DRIVER7B
),
710 gShellDriver1HiiHandle
,
711 DriverName
!= NULL
? DriverName
: L
"<Unknown>"
713 SHELL_FREE_NON_NULL (DriverName
);
719 STRING_TOKEN (STR_DH_OUTPUT_DRIVER8
),
720 gShellDriver1HiiHandle
,
721 DriverBinding
->Version
,
722 NumberOfChildren
> 0 ? L
"Bus" : ControllerHandleCount
> 0 ? L
"Device" : L
"<Unknown>",
723 ConfigurationStatus
? L
"YES" : L
"NO",
724 DiagnosticsStatus
? L
"YES" : L
"NO"
727 if (ControllerHandleCount
== 0) {
732 STRING_TOKEN (STR_DH_OUTPUT_DRIVER9
),
733 gShellDriver1HiiHandle
,
741 STRING_TOKEN (STR_DH_OUTPUT_DRIVER9
),
742 gShellDriver1HiiHandle
,
745 for (HandleIndex
= 0; HandleIndex
< ControllerHandleCount
; HandleIndex
++) {
746 Status
= gEfiShellProtocol
->GetDeviceName (ControllerHandleBuffer
[HandleIndex
], EFI_DEVICE_NAME_USE_COMPONENT_NAME
|EFI_DEVICE_NAME_USE_DEVICE_PATH
, (CHAR8
*)Language
, &TempStringPointer
);
752 STRING_TOKEN (STR_DH_OUTPUT_DRIVER9B
),
753 gShellDriver1HiiHandle
,
754 ConvertHandleToHandleIndex (ControllerHandleBuffer
[HandleIndex
]),
755 TempStringPointer
!= NULL
? TempStringPointer
: L
"<Unknown>"
757 SHELL_FREE_NON_NULL (TempStringPointer
);
759 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
761 ControllerHandleBuffer
[HandleIndex
],
762 &ChildControllerHandleCount
,
763 &ChildControllerHandleBuffer
765 if (!EFI_ERROR (Status
)) {
766 for (ChildIndex
= 0; ChildIndex
< ChildControllerHandleCount
; ChildIndex
++) {
767 Status
= gEfiShellProtocol
->GetDeviceName (ChildControllerHandleBuffer
[ChildIndex
], EFI_DEVICE_NAME_USE_COMPONENT_NAME
|EFI_DEVICE_NAME_USE_DEVICE_PATH
, (CHAR8
*)Language
, &TempStringPointer
);
773 STRING_TOKEN (STR_DH_OUTPUT_DRIVER6C
),
774 gShellDriver1HiiHandle
,
775 ConvertHandleToHandleIndex (ChildControllerHandleBuffer
[ChildIndex
]),
776 TempStringPointer
!= NULL
? TempStringPointer
: L
"<Unknown>"
778 SHELL_FREE_NON_NULL (TempStringPointer
);
781 SHELL_FREE_NON_NULL (ChildControllerHandleBuffer
);
785 SHELL_FREE_NON_NULL (ControllerHandleBuffer
);
792 Display information for a handle.
794 @param[in] TheHandle The handles to show info on.
795 @param[in] Verbose TRUE for extra info, FALSE otherwise.
796 @param[in] Sfo TRUE to output in standard format output (spec).
797 @param[in] Language Language string per UEFI specification.
798 @param[in] DriverInfo TRUE to show all info about the handle.
799 @param[in] Multiple TRUE indicates more than will be output,
800 FALSE for a single one.
804 IN CONST EFI_HANDLE TheHandle
,
805 IN CONST BOOLEAN Verbose
,
806 IN CONST BOOLEAN Sfo
,
807 IN CONST CHAR8
*Language
,
808 IN CONST BOOLEAN DriverInfo
,
809 IN CONST BOOLEAN Multiple
812 CHAR16
*ProtocolInfoString
;
814 ProtocolInfoString
= NULL
;
818 ProtocolInfoString
= GetProtocolInfoString (TheHandle
, Language
, L
" ", Verbose
, TRUE
);
823 STRING_TOKEN (STR_DH_OUTPUT
),
824 gShellDriver1HiiHandle
,
825 ConvertHandleToHandleIndex (TheHandle
),
826 ProtocolInfoString
== NULL
? L
"" : ProtocolInfoString
829 ProtocolInfoString
= GetProtocolInfoString (TheHandle
, Language
, Verbose
? L
"\r\n" : L
" ", Verbose
, TRUE
);
835 STRING_TOKEN (STR_DH_OUTPUT_SINGLE
),
836 gShellDriver1HiiHandle
,
837 ConvertHandleToHandleIndex (TheHandle
),
839 ProtocolInfoString
== NULL
? L
"" : ProtocolInfoString
846 STRING_TOKEN (STR_DH_OUTPUT_SINGLE_D
),
847 gShellDriver1HiiHandle
,
848 ConvertHandleToHandleIndex (TheHandle
),
849 ProtocolInfoString
== NULL
? L
"" : ProtocolInfoString
855 DisplayDriverModelHandle ((EFI_HANDLE
)TheHandle
, TRUE
, Language
);
858 ProtocolInfoString
= GetProtocolInfoString (TheHandle
, Language
, L
";", FALSE
, FALSE
);
863 STRING_TOKEN (STR_DH_OUTPUT_SFO
),
864 gShellDriver1HiiHandle
,
865 Multiple
? L
"HandlesInfo" : L
"HandleInfo",
868 ConvertHandleToHandleIndex (TheHandle
),
870 ProtocolInfoString
== NULL
? L
"" : ProtocolInfoString
874 if (ProtocolInfoString
!= NULL
) {
875 FreePool (ProtocolInfoString
);
880 Display information for all handles on a list.
882 @param[in] HandleList The NULL-terminated list of handles.
883 @param[in] Verbose TRUE for extra info, FALSE otherwise.
884 @param[in] Sfo TRUE to output in standard format output (spec).
885 @param[in] Language Language string per UEFI specification.
886 @param[in] DriverInfo TRUE to show all info about the handle.
888 @retval SHELL_SUCCESS The operation was successful.
889 @retval SHELL_ABORTED The operation was aborted.
893 IN CONST EFI_HANDLE
*HandleList
,
894 IN CONST BOOLEAN Verbose
,
895 IN CONST BOOLEAN Sfo
,
896 IN CONST CHAR8
*Language
,
897 IN CONST BOOLEAN DriverInfo
900 CONST EFI_HANDLE
*HandleWalker
;
901 SHELL_STATUS ShellStatus
;
903 ShellStatus
= SHELL_SUCCESS
;
904 for (HandleWalker
= HandleList
; HandleWalker
!= NULL
&& *HandleWalker
!= NULL
; HandleWalker
++) {
905 DoDhByHandle (*HandleWalker
, Verbose
, Sfo
, Language
, DriverInfo
, TRUE
);
906 if (ShellGetExecutionBreakFlag ()) {
907 ShellStatus
= SHELL_ABORTED
;
912 return (ShellStatus
);
916 Display information for a GUID of protocol.
918 @param[in] Guid The pointer to the name of the protocol.
919 @param[in] Verbose TRUE for extra info, FALSE otherwise.
920 @param[in] Sfo TRUE to output in standard format output (spec).
921 @param[in] Language Language string per UEFI specification.
922 @param[in] DriverInfo TRUE to show all info about the handle.
924 @retval SHELL_SUCCESS The operation was successful.
925 @retval SHELL_NOT_FOUND The GUID was not found.
926 @retval SHELL_INVALID_PARAMETER ProtocolName was NULL or invalid.
931 IN CONST BOOLEAN Verbose
,
932 IN CONST BOOLEAN Sfo
,
933 IN CONST CHAR8
*Language
,
934 IN CONST BOOLEAN DriverInfo
938 SHELL_STATUS ShellStatus
;
939 EFI_HANDLE
*HandleList
;
943 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DH_OUTPUT_ALL_HEADER
), gShellDriver1HiiHandle
);
945 Name
= GetStringNameFromGuid (Guid
, NULL
);
947 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DH_OUTPUT_GUID_HEADER
), gShellDriver1HiiHandle
, Guid
);
949 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DH_OUTPUT_NAME_HEADER
), gShellDriver1HiiHandle
, Name
);
954 HandleList
= GetHandleListByProtocol (Guid
);
955 ShellStatus
= DoDhForHandleList (HandleList
, Verbose
, Sfo
, Language
, DriverInfo
);
956 SHELL_FREE_NON_NULL (HandleList
);
962 Function to determine use which method to print information.
963 If Protocol is NULL, The function will print all information.
965 @param[in] Protocol The pointer to the name or GUID of protocol or NULL.
966 @param[in] Verbose TRUE for extra info, FALSE otherwise.
967 @param[in] Sfo TRUE to output in standard format output (spec).
968 @param[in] Language Language string per UEFI specification.
969 @param[in] DriverInfo TRUE to show all info about the handle.
971 @retval SHELL_SUCCESS The operation was successful.
972 @retval SHELL_NOT_FOUND The protocol was not found.
973 @retval SHELL_INVALID_PARAMETER Protocol is invalid parameter.
977 IN CONST CHAR16
*Protocol
,
978 IN CONST BOOLEAN Verbose
,
979 IN CONST BOOLEAN Sfo
,
980 IN CONST CHAR8
*Language
,
981 IN CONST BOOLEAN DriverInfo
988 if (Protocol
== NULL
) {
989 return DoDhByProtocolGuid (NULL
, Verbose
, Sfo
, Language
, DriverInfo
);
991 Status
= ConvertStrToGuid (Protocol
, &Guid
);
992 if (!EFI_ERROR (Status
)) {
996 // Protocol is a Name, convert it to GUID
998 Status
= GetGuidFromStringName (Protocol
, Language
, &GuidPtr
);
999 if (EFI_ERROR (Status
)) {
1000 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DH_NO_NAME_FOUND
), gShellDriver1HiiHandle
, Protocol
);
1001 return (SHELL_NOT_FOUND
);
1005 return DoDhByProtocolGuid (GuidPtr
, Verbose
, Sfo
, Language
, DriverInfo
);
1010 Function to display decode information by Protocol.
1011 The parameter Protocol is either a GUID or the name of protocol.
1012 If the parameter Protocol is NULL, the function will print all
1015 @param[in] Protocol The pointer to the name or GUID of protocol.
1016 @param[in] Language Language string per UEFI specification.
1018 @retval SHELL_SUCCESS The operation was successful.
1019 @retval SHELL_OUT_OT_RESOURCES A memory allocation failed.
1022 DoDecodeByProtocol (
1023 IN CONST CHAR16
*Protocol
,
1024 IN CONST CHAR8
*Language
1034 if (Protocol
== NULL
) {
1036 Status
= GetAllMappingGuids (NULL
, &Counts
);
1037 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1038 Guids
= AllocatePool (Counts
* sizeof (EFI_GUID
));
1039 if (Guids
== NULL
) {
1040 return SHELL_OUT_OF_RESOURCES
;
1043 Status
= GetAllMappingGuids (Guids
, &Counts
);
1044 if (Status
== EFI_SUCCESS
) {
1045 for (Index
= 0; Index
< Counts
; Index
++) {
1046 Name
= GetStringNameFromGuid (&Guids
[Index
], Language
);
1048 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DH_OUTPUT_DECODE
), gShellDriver1HiiHandle
, Name
, &Guids
[Index
]);
1050 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DH_NO_GUID_FOUND
), gShellDriver1HiiHandle
, &Guids
[Index
]);
1053 SHELL_FREE_NON_NULL (Name
);
1060 if (ConvertStrToGuid (Protocol
, &Guid
) == EFI_SUCCESS
) {
1061 Name
= GetStringNameFromGuid (&Guid
, Language
);
1063 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DH_OUTPUT_DECODE
), gShellDriver1HiiHandle
, Name
, &Guid
);
1065 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DH_NO_GUID_FOUND
), gShellDriver1HiiHandle
, &Guid
);
1068 SHELL_FREE_NON_NULL (Name
);
1070 Status
= GetGuidFromStringName (Protocol
, Language
, &Guids
);
1071 if (Status
== EFI_SUCCESS
) {
1072 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DH_OUTPUT_DECODE
), gShellDriver1HiiHandle
, Protocol
, Guids
);
1074 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DH_NO_NAME_FOUND
), gShellDriver1HiiHandle
, Protocol
);
1079 return SHELL_SUCCESS
;
1083 Function for 'dh' command.
1085 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1086 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1091 IN EFI_HANDLE ImageHandle
,
1092 IN EFI_SYSTEM_TABLE
*SystemTable
1096 LIST_ENTRY
*Package
;
1097 CHAR16
*ProblemParam
;
1098 SHELL_STATUS ShellStatus
;
1101 CONST CHAR16
*RawValue
;
1102 CONST CHAR16
*ProtocolVal
;
1105 BOOLEAN VerboseFlag
;
1106 UINT64 Intermediate
;
1109 ShellStatus
= SHELL_SUCCESS
;
1110 Status
= EFI_SUCCESS
;
1114 // initialize the shell lib (we must be in non-auto-init...)
1116 Status
= ShellInitialize ();
1117 ASSERT_EFI_ERROR (Status
);
1119 Status
= CommandInit ();
1120 ASSERT_EFI_ERROR (Status
);
1123 // parse the command line
1125 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
1126 if (EFI_ERROR (Status
)) {
1127 if ((Status
== EFI_VOLUME_CORRUPTED
) && (ProblemParam
!= NULL
)) {
1128 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, L
"dh", ProblemParam
);
1129 FreePool (ProblemParam
);
1130 ShellStatus
= SHELL_INVALID_PARAMETER
;
1135 if (ShellCommandLineGetCount (Package
) > 2) {
1136 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
, L
"dh");
1137 ShellCommandLineFreeVarList (Package
);
1138 return (SHELL_INVALID_PARAMETER
);
1141 if (ShellCommandLineGetFlag (Package
, L
"-l")) {
1142 Lang
= ShellCommandLineGetValue (Package
, L
"-l");
1144 Language
= AllocateZeroPool (StrSize (Lang
));
1145 AsciiSPrint (Language
, StrSize (Lang
), "%S", Lang
);
1147 ASSERT (Language
== NULL
);
1148 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDriver1HiiHandle
, L
"dh", L
"-l");
1149 ShellCommandLineFreeVarList (Package
);
1150 return (SHELL_INVALID_PARAMETER
);
1153 Language
= AllocateZeroPool (10);
1154 AsciiSPrint (Language
, 10, "en-us");
1157 SfoFlag
= ShellCommandLineGetFlag (Package
, L
"-sfo");
1158 DriverFlag
= ShellCommandLineGetFlag (Package
, L
"-d");
1159 VerboseFlag
= (BOOLEAN
)(ShellCommandLineGetFlag (Package
, L
"-v") || ShellCommandLineGetFlag (Package
, L
"-verbose"));
1160 RawValue
= ShellCommandLineGetRawValue (Package
, 1);
1161 ProtocolVal
= ShellCommandLineGetValue (Package
, L
"-p");
1163 if (RawValue
== NULL
) {
1164 if (ShellCommandLineGetFlag (Package
, L
"-p") && (ProtocolVal
== NULL
)) {
1165 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDriver1HiiHandle
, L
"dh", L
"-p");
1166 ShellStatus
= SHELL_INVALID_PARAMETER
;
1169 // Print information by protocol, The ProtocolVal maybe is name or GUID or NULL.
1171 ShellStatus
= DoDhByProtocol (ProtocolVal
, VerboseFlag
, SfoFlag
, Language
, DriverFlag
);
1173 } else if ((RawValue
!= NULL
) &&
1174 (gUnicodeCollation
->StriColl (gUnicodeCollation
, L
"decode", (CHAR16
*)RawValue
) == 0))
1176 if (ShellCommandLineGetFlag (Package
, L
"-p") && (ProtocolVal
== NULL
)) {
1177 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDriver1HiiHandle
, L
"dh", L
"-p");
1178 ShellStatus
= SHELL_INVALID_PARAMETER
;
1181 // Print decode informatino by protocol.
1183 ShellStatus
= DoDecodeByProtocol (ProtocolVal
, Language
);
1186 if (ShellCommandLineGetFlag (Package
, L
"-p")) {
1187 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
, L
"dh");
1188 ShellStatus
= SHELL_INVALID_PARAMETER
;
1190 Status
= ShellConvertStringToUint64 (RawValue
, &Intermediate
, TRUE
, FALSE
);
1191 if (EFI_ERROR (Status
)) {
1192 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, L
"dh", RawValue
);
1193 ShellStatus
= SHELL_INVALID_PARAMETER
;
1195 Handle
= ConvertHandleIndexToHandle ((UINTN
)Intermediate
);
1196 if (Handle
== NULL
) {
1197 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, L
"dh", RawValue
);
1198 ShellStatus
= SHELL_INVALID_PARAMETER
;
1201 // Print information by handle.
1203 DoDhByHandle (Handle
, VerboseFlag
, SfoFlag
, Language
, DriverFlag
, FALSE
);
1209 ShellCommandLineFreeVarList (Package
);
1210 SHELL_FREE_NON_NULL (Language
);
1213 return (ShellStatus
);