2 Main file for DevTree shell Driver1 function.
4 Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellDriver1CommandsLib.h"
17 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
24 Display a tree starting from this handle.
26 @param[in] TheHandle The handle to start with.
27 @param[in] Lang Optionally, a UEFI defined language code.
28 @param[in] UseDevPaths TRUE to display info from DevPath as identifiers.
29 FALSE will use component name protocol instead.
30 @param[in] IndentCharCount How many characters to indent (allows for recursion).
31 @param[in] HiiString The string from HII to use for output.
33 @retval SHELL_SUCCESS The operation was successful.
38 IN CONST EFI_HANDLE TheHandle
,
39 IN CONST CHAR8
*Lang OPTIONAL
,
40 IN CONST BOOLEAN UseDevPaths
,
41 IN CONST UINTN IndentCharCount
,
42 IN CONST CHAR16
*HiiString
45 SHELL_STATUS ShellStatus
;
49 EFI_HANDLE
*ChildHandleBuffer
;
54 ShellStatus
= SHELL_SUCCESS
;
56 ChildHandleBuffer
= NULL
;
59 ASSERT(TheHandle
!= NULL
);
61 // We want controller handles. they will not have LoadedImage or DriverBinding (or others...)
63 Status
= gBS
->OpenProtocol (
65 &gEfiDriverBindingProtocolGuid
,
69 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
71 if (!EFI_ERROR (Status
)) {
75 Status
= gBS
->OpenProtocol (
77 &gEfiLoadedImageProtocolGuid
,
81 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
83 if (!EFI_ERROR (Status
)) {
87 FormatString
= AllocateZeroPool(StrSize(HiiString
) + (10)*sizeof(FormatString
[0]));
89 ASSERT(HiiString
!= NULL
);
90 ASSERT(FormatString
!= NULL
);
93 // we generate the format string on the fly so that we can control the
94 // number of space characters that the first (empty) string has. this
95 // handles the indenting.
98 UnicodeSPrint(FormatString
, StrSize(HiiString
) + (10)*sizeof(FormatString
[0]), L
"%%%ds %s", IndentCharCount
, HiiString
);
99 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
);
101 // print out the information for ourselves
108 ConvertHandleToHandleIndex(TheHandle
),
109 Name
==NULL
?L
"Unknown":Name
);
111 FreePool(FormatString
);
117 // recurse on each child handle with IndentCharCount + 2
119 ParseHandleDatabaseForChildControllers(TheHandle
, &ChildCount
, &ChildHandleBuffer
);
120 for (LoopVar
= 0 ; LoopVar
< ChildCount
&& ShellStatus
== SHELL_SUCCESS
; LoopVar
++){
121 ShellStatus
= DoDevTreeForHandle(ChildHandleBuffer
[LoopVar
], Lang
, UseDevPaths
, IndentCharCount
+2, HiiString
);
124 if (ChildHandleBuffer
!= NULL
) {
125 FreePool(ChildHandleBuffer
);
128 return (ShellStatus
);
132 Function for 'devtree' command.
134 @param[in] ImageHandle Handle to the Image (NULL if Internal).
135 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
139 ShellCommandRunDevTree (
140 IN EFI_HANDLE ImageHandle
,
141 IN EFI_SYSTEM_TABLE
*SystemTable
146 CHAR16
*ProblemParam
;
147 SHELL_STATUS ShellStatus
;
152 EFI_HANDLE TheHandle
;
155 UINTN ParentControllerHandleCount
;
156 EFI_HANDLE
*ParentControllerHandleBuffer
;
158 ShellStatus
= SHELL_SUCCESS
;
159 Status
= EFI_SUCCESS
;
163 // initialize the shell lib (we must be in non-auto-init...)
165 Status
= ShellInitialize();
166 ASSERT_EFI_ERROR(Status
);
168 Status
= CommandInit();
169 ASSERT_EFI_ERROR(Status
);
172 // parse the command line
174 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
175 if (EFI_ERROR(Status
)) {
176 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
177 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, ProblemParam
);
178 FreePool(ProblemParam
);
179 ShellStatus
= SHELL_INVALID_PARAMETER
;
184 if (ShellCommandLineGetCount(Package
) > 2) {
185 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
);
186 ShellCommandLineFreeVarList (Package
);
187 return (SHELL_INVALID_PARAMETER
);
189 Lang
= ShellCommandLineGetValue(Package
, L
"-l");
191 Language
= AllocateZeroPool(StrSize(Lang
));
192 AsciiSPrint(Language
, StrSize(Lang
), "%S", Lang
);
193 } else if (!ShellCommandLineGetFlag(Package
, L
"-l")){
194 ASSERT(Language
== NULL
);
195 // Language = AllocateZeroPool(10);
196 // AsciiSPrint(Language, 10, "en-us");
198 ASSERT(Language
== NULL
);
199 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDriver1HiiHandle
, L
"-l");
200 ShellCommandLineFreeVarList (Package
);
201 return (SHELL_INVALID_PARAMETER
);
203 FlagD
= ShellCommandLineGetFlag(Package
, L
"-d");
205 Lang
= ShellCommandLineGetRawValue(Package
, 1);
206 HiiString
= HiiGetString(gShellDriver1HiiHandle
, STRING_TOKEN (STR_DEV_TREE_OUTPUT
), Language
);
209 for (LoopVar
= 1 ; ; LoopVar
++){
210 TheHandle
= ConvertHandleIndexToHandle(LoopVar
);
211 if (TheHandle
== NULL
){
216 // Skip handles that do not have device path protocol
218 Status
= gBS
->OpenProtocol (
220 &gEfiDevicePathProtocolGuid
,
224 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
226 if (EFI_ERROR (Status
)) {
231 // Skip handles that do have parents
233 ParentControllerHandleBuffer
= NULL
;
234 Status
= PARSE_HANDLE_DATABASE_PARENTS (
236 &ParentControllerHandleCount
,
237 &ParentControllerHandleBuffer
239 SHELL_FREE_NON_NULL (ParentControllerHandleBuffer
);
240 if (ParentControllerHandleCount
> 0) {
245 // Start a devtree from TheHandle that has a device path and no parents
247 ShellStatus
= DoDevTreeForHandle(TheHandle
, Language
, FlagD
, 0, HiiString
);
250 Status
= ShellConvertStringToUint64(Lang
, &Intermediate
, TRUE
, FALSE
);
251 if (EFI_ERROR(Status
) || ConvertHandleIndexToHandle((UINTN
)Intermediate
) == NULL
) {
252 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, Lang
);
253 ShellStatus
= SHELL_INVALID_PARAMETER
;
255 ShellStatus
= DoDevTreeForHandle(ConvertHandleIndexToHandle((UINTN
)Intermediate
), Language
, FlagD
, 0, HiiString
);
259 if (HiiString
!= NULL
) {
262 SHELL_FREE_NON_NULL(Language
);
263 ShellCommandLineFreeVarList (Package
);
266 return (ShellStatus
);