2 Main file for DevTree 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 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "UefiShellDriver1CommandsLib.h"
12 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
19 Display a tree starting from this handle.
21 @param[in] TheHandle The handle to start with.
22 @param[in] Lang Optionally, a UEFI defined language code.
23 @param[in] UseDevPaths TRUE to display info from DevPath as identifiers.
24 FALSE will use component name protocol instead.
25 @param[in] IndentCharCount How many characters to indent (allows for recursion).
26 @param[in] HiiString The string from HII to use for output.
28 @retval SHELL_SUCCESS The operation was successful.
32 IN CONST EFI_HANDLE TheHandle
,
33 IN CONST CHAR8
*Lang OPTIONAL
,
34 IN CONST BOOLEAN UseDevPaths
,
35 IN CONST UINTN IndentCharCount
,
36 IN CONST CHAR16
*HiiString
39 SHELL_STATUS ShellStatus
;
43 EFI_HANDLE
*ChildHandleBuffer
;
48 ShellStatus
= SHELL_SUCCESS
;
50 ChildHandleBuffer
= NULL
;
53 ASSERT (TheHandle
!= NULL
);
54 ASSERT (HiiString
!= NULL
);
56 if (ShellGetExecutionBreakFlag()) {
57 ShellStatus
= SHELL_ABORTED
;
62 // We want controller handles. they will not have LoadedImage or DriverBinding (or others...)
64 Status
= gBS
->OpenProtocol (
66 &gEfiDriverBindingProtocolGuid
,
70 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
72 if (!EFI_ERROR (Status
)) {
76 Status
= gBS
->OpenProtocol (
78 &gEfiLoadedImageProtocolGuid
,
82 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
84 if (!EFI_ERROR (Status
)) {
88 FormatString
= AllocateZeroPool(StrSize(HiiString
) + (10)*sizeof(FormatString
[0]));
89 if (FormatString
== NULL
) {
90 return SHELL_OUT_OF_RESOURCES
;
94 // we generate the format string on the fly so that we can control the
95 // number of space characters that the first (empty) string has. this
96 // handles the indenting.
99 UnicodeSPrint(FormatString
, StrSize(HiiString
) + (10)*sizeof(FormatString
[0]), L
"%%%ds %s", IndentCharCount
, HiiString
);
100 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
);
102 // print out the information for ourselves
109 ConvertHandleToHandleIndex(TheHandle
),
110 Name
==NULL
?L
"Unknown":Name
);
112 FreePool(FormatString
);
118 // recurse on each child handle with IndentCharCount + 2
120 ParseHandleDatabaseForChildControllers(TheHandle
, &ChildCount
, &ChildHandleBuffer
);
121 for (LoopVar
= 0 ; LoopVar
< ChildCount
&& ShellStatus
== SHELL_SUCCESS
; LoopVar
++){
122 ShellStatus
= DoDevTreeForHandle(ChildHandleBuffer
[LoopVar
], Lang
, UseDevPaths
, IndentCharCount
+2, HiiString
);
123 if (ShellStatus
== SHELL_ABORTED
) {
128 if (ChildHandleBuffer
!= NULL
) {
129 FreePool(ChildHandleBuffer
);
132 return (ShellStatus
);
136 Function for 'devtree' command.
138 @param[in] ImageHandle Handle to the Image (NULL if Internal).
139 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
143 ShellCommandRunDevTree (
144 IN EFI_HANDLE ImageHandle
,
145 IN EFI_SYSTEM_TABLE
*SystemTable
150 CHAR16
*ProblemParam
;
151 SHELL_STATUS ShellStatus
;
156 EFI_HANDLE TheHandle
;
159 UINTN ParentControllerHandleCount
;
160 EFI_HANDLE
*ParentControllerHandleBuffer
;
162 ShellStatus
= SHELL_SUCCESS
;
163 Status
= EFI_SUCCESS
;
167 // initialize the shell lib (we must be in non-auto-init...)
169 Status
= ShellInitialize();
170 ASSERT_EFI_ERROR(Status
);
172 Status
= CommandInit();
173 ASSERT_EFI_ERROR(Status
);
176 // parse the command line
178 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
179 if (EFI_ERROR(Status
)) {
180 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
181 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, L
"devtree", ProblemParam
);
182 FreePool(ProblemParam
);
183 ShellStatus
= SHELL_INVALID_PARAMETER
;
188 if (ShellCommandLineGetCount(Package
) > 2) {
189 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
, L
"devtree");
190 ShellCommandLineFreeVarList (Package
);
191 return (SHELL_INVALID_PARAMETER
);
193 Lang
= ShellCommandLineGetValue(Package
, L
"-l");
195 Language
= AllocateZeroPool(StrSize(Lang
));
196 AsciiSPrint(Language
, StrSize(Lang
), "%S", Lang
);
197 } else if (!ShellCommandLineGetFlag(Package
, L
"-l")){
198 ASSERT(Language
== NULL
);
199 // Language = AllocateZeroPool(10);
200 // AsciiSPrint(Language, 10, "en-us");
202 ASSERT(Language
== NULL
);
203 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDriver1HiiHandle
, L
"devtree", L
"-l");
204 ShellCommandLineFreeVarList (Package
);
205 return (SHELL_INVALID_PARAMETER
);
207 FlagD
= ShellCommandLineGetFlag(Package
, L
"-d");
209 Lang
= ShellCommandLineGetRawValue(Package
, 1);
210 HiiString
= HiiGetString(gShellDriver1HiiHandle
, STRING_TOKEN (STR_DEV_TREE_OUTPUT
), Language
);
213 for (LoopVar
= 1 ; ; LoopVar
++){
214 TheHandle
= ConvertHandleIndexToHandle(LoopVar
);
215 if (TheHandle
== NULL
){
220 // Skip handles that do not have device path protocol
222 Status
= gBS
->OpenProtocol (
224 &gEfiDevicePathProtocolGuid
,
228 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
230 if (EFI_ERROR (Status
)) {
235 // Skip handles that do have parents
237 ParentControllerHandleBuffer
= NULL
;
238 Status
= PARSE_HANDLE_DATABASE_PARENTS (
240 &ParentControllerHandleCount
,
241 &ParentControllerHandleBuffer
243 SHELL_FREE_NON_NULL (ParentControllerHandleBuffer
);
244 if (ParentControllerHandleCount
> 0) {
249 // Start a devtree from TheHandle that has a device path and no parents
251 ShellStatus
= DoDevTreeForHandle(TheHandle
, Language
, FlagD
, 0, HiiString
);
254 Status
= ShellConvertStringToUint64(Lang
, &Intermediate
, TRUE
, FALSE
);
255 if (EFI_ERROR(Status
) || ConvertHandleIndexToHandle((UINTN
)Intermediate
) == NULL
) {
256 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, L
"devtree", Lang
);
257 ShellStatus
= SHELL_INVALID_PARAMETER
;
259 ShellStatus
= DoDevTreeForHandle(ConvertHandleIndexToHandle((UINTN
)Intermediate
), Language
, FlagD
, 0, HiiString
);
263 if (HiiString
!= NULL
) {
266 SHELL_FREE_NON_NULL(Language
);
267 ShellCommandLineFreeVarList (Package
);
270 return (ShellStatus
);