2 Main file for DevTree shell Driver1 function.
4 (C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiShellDriver1CommandsLib.h"
18 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
25 Display a tree starting from this handle.
27 @param[in] TheHandle The handle to start with.
28 @param[in] Lang Optionally, a UEFI defined language code.
29 @param[in] UseDevPaths TRUE to display info from DevPath as identifiers.
30 FALSE will use component name protocol instead.
31 @param[in] IndentCharCount How many characters to indent (allows for recursion).
32 @param[in] HiiString The string from HII to use for output.
34 @retval SHELL_SUCCESS The operation was successful.
39 IN CONST EFI_HANDLE TheHandle
,
40 IN CONST CHAR8
*Lang OPTIONAL
,
41 IN CONST BOOLEAN UseDevPaths
,
42 IN CONST UINTN IndentCharCount
,
43 IN CONST CHAR16
*HiiString
46 SHELL_STATUS ShellStatus
;
50 EFI_HANDLE
*ChildHandleBuffer
;
55 ShellStatus
= SHELL_SUCCESS
;
57 ChildHandleBuffer
= NULL
;
60 ASSERT (TheHandle
!= NULL
);
61 ASSERT (HiiString
!= NULL
);
63 if (ShellGetExecutionBreakFlag()) {
64 ShellStatus
= SHELL_ABORTED
;
69 // We want controller handles. they will not have LoadedImage or DriverBinding (or others...)
71 Status
= gBS
->OpenProtocol (
73 &gEfiDriverBindingProtocolGuid
,
77 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
79 if (!EFI_ERROR (Status
)) {
83 Status
= gBS
->OpenProtocol (
85 &gEfiLoadedImageProtocolGuid
,
89 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
91 if (!EFI_ERROR (Status
)) {
95 FormatString
= AllocateZeroPool(StrSize(HiiString
) + (10)*sizeof(FormatString
[0]));
96 if (FormatString
== NULL
) {
97 return SHELL_OUT_OF_RESOURCES
;
101 // we generate the format string on the fly so that we can control the
102 // number of space characters that the first (empty) string has. this
103 // handles the indenting.
106 UnicodeSPrint(FormatString
, StrSize(HiiString
) + (10)*sizeof(FormatString
[0]), L
"%%%ds %s", IndentCharCount
, HiiString
);
107 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
);
109 // print out the information for ourselves
116 ConvertHandleToHandleIndex(TheHandle
),
117 Name
==NULL
?L
"Unknown":Name
);
119 FreePool(FormatString
);
125 // recurse on each child handle with IndentCharCount + 2
127 ParseHandleDatabaseForChildControllers(TheHandle
, &ChildCount
, &ChildHandleBuffer
);
128 for (LoopVar
= 0 ; LoopVar
< ChildCount
&& ShellStatus
== SHELL_SUCCESS
; LoopVar
++){
129 ShellStatus
= DoDevTreeForHandle(ChildHandleBuffer
[LoopVar
], Lang
, UseDevPaths
, IndentCharCount
+2, HiiString
);
130 if (ShellStatus
== SHELL_ABORTED
) {
135 if (ChildHandleBuffer
!= NULL
) {
136 FreePool(ChildHandleBuffer
);
139 return (ShellStatus
);
143 Function for 'devtree' command.
145 @param[in] ImageHandle Handle to the Image (NULL if Internal).
146 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
150 ShellCommandRunDevTree (
151 IN EFI_HANDLE ImageHandle
,
152 IN EFI_SYSTEM_TABLE
*SystemTable
157 CHAR16
*ProblemParam
;
158 SHELL_STATUS ShellStatus
;
163 EFI_HANDLE TheHandle
;
166 UINTN ParentControllerHandleCount
;
167 EFI_HANDLE
*ParentControllerHandleBuffer
;
169 ShellStatus
= SHELL_SUCCESS
;
170 Status
= EFI_SUCCESS
;
174 // initialize the shell lib (we must be in non-auto-init...)
176 Status
= ShellInitialize();
177 ASSERT_EFI_ERROR(Status
);
179 Status
= CommandInit();
180 ASSERT_EFI_ERROR(Status
);
183 // parse the command line
185 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
186 if (EFI_ERROR(Status
)) {
187 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
188 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, L
"devtree", ProblemParam
);
189 FreePool(ProblemParam
);
190 ShellStatus
= SHELL_INVALID_PARAMETER
;
195 if (ShellCommandLineGetCount(Package
) > 2) {
196 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
, L
"devtree");
197 ShellCommandLineFreeVarList (Package
);
198 return (SHELL_INVALID_PARAMETER
);
200 Lang
= ShellCommandLineGetValue(Package
, L
"-l");
202 Language
= AllocateZeroPool(StrSize(Lang
));
203 AsciiSPrint(Language
, StrSize(Lang
), "%S", Lang
);
204 } else if (!ShellCommandLineGetFlag(Package
, L
"-l")){
205 ASSERT(Language
== NULL
);
206 // Language = AllocateZeroPool(10);
207 // AsciiSPrint(Language, 10, "en-us");
209 ASSERT(Language
== NULL
);
210 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDriver1HiiHandle
, L
"devtree", L
"-l");
211 ShellCommandLineFreeVarList (Package
);
212 return (SHELL_INVALID_PARAMETER
);
214 FlagD
= ShellCommandLineGetFlag(Package
, L
"-d");
216 Lang
= ShellCommandLineGetRawValue(Package
, 1);
217 HiiString
= HiiGetString(gShellDriver1HiiHandle
, STRING_TOKEN (STR_DEV_TREE_OUTPUT
), Language
);
220 for (LoopVar
= 1 ; ; LoopVar
++){
221 TheHandle
= ConvertHandleIndexToHandle(LoopVar
);
222 if (TheHandle
== NULL
){
227 // Skip handles that do not have device path protocol
229 Status
= gBS
->OpenProtocol (
231 &gEfiDevicePathProtocolGuid
,
235 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
237 if (EFI_ERROR (Status
)) {
242 // Skip handles that do have parents
244 ParentControllerHandleBuffer
= NULL
;
245 Status
= PARSE_HANDLE_DATABASE_PARENTS (
247 &ParentControllerHandleCount
,
248 &ParentControllerHandleBuffer
250 SHELL_FREE_NON_NULL (ParentControllerHandleBuffer
);
251 if (ParentControllerHandleCount
> 0) {
256 // Start a devtree from TheHandle that has a device path and no parents
258 ShellStatus
= DoDevTreeForHandle(TheHandle
, Language
, FlagD
, 0, HiiString
);
261 Status
= ShellConvertStringToUint64(Lang
, &Intermediate
, TRUE
, FALSE
);
262 if (EFI_ERROR(Status
) || ConvertHandleIndexToHandle((UINTN
)Intermediate
) == NULL
) {
263 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, L
"devtree", Lang
);
264 ShellStatus
= SHELL_INVALID_PARAMETER
;
266 ShellStatus
= DoDevTreeForHandle(ConvertHandleIndexToHandle((UINTN
)Intermediate
), Language
, FlagD
, 0, HiiString
);
270 if (HiiString
!= NULL
) {
273 SHELL_FREE_NON_NULL(Language
);
274 ShellCommandLineFreeVarList (Package
);
277 return (ShellStatus
);