2 Main file for DevTree shell Driver1 function.
4 Copyright (c) 2010 - 2011, 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
)) {
88 // If we are at the begining then we want root handles they have no parents and do have device path.
90 if (IndentCharCount
== 0) {
91 Status
= gBS
->OpenProtocol (
93 &gEfiDevicePathProtocolGuid
,
97 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
99 if (EFI_ERROR (Status
)) {
100 return SHELL_SUCCESS
;
104 FormatString
= AllocateZeroPool(StrSize(HiiString
) + (10)*sizeof(FormatString
[0]));
106 ASSERT(HiiString
!= NULL
);
107 ASSERT(FormatString
!= NULL
);
110 // we generate the format string on the fly so that we can control the
111 // number of space characters that the first (empty) string has. this
112 // handles the indenting.
115 UnicodeSPrint(FormatString
, StrSize(HiiString
) + (10)*sizeof(FormatString
[0]), L
"%%%ds %s", IndentCharCount
, HiiString
);
116 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
);
118 // print out the information for ourselves
125 ConvertHandleToHandleIndex(TheHandle
),
126 Name
==NULL
?L
"Unknown":Name
);
128 FreePool(FormatString
);
134 // recurse on each child handle with IndentCharCount + 2
136 ParseHandleDatabaseForChildControllers(TheHandle
, &ChildCount
, &ChildHandleBuffer
);
137 for (LoopVar
= 0 ; LoopVar
< ChildCount
&& ShellStatus
== SHELL_SUCCESS
; LoopVar
++){
138 ShellStatus
= DoDevTreeForHandle(ChildHandleBuffer
[LoopVar
], Lang
, UseDevPaths
, IndentCharCount
+2, HiiString
);
141 if (ChildHandleBuffer
!= NULL
) {
142 FreePool(ChildHandleBuffer
);
145 return (ShellStatus
);
149 Function for 'devtree' command.
151 @param[in] ImageHandle Handle to the Image (NULL if Internal).
152 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
156 ShellCommandRunDevTree (
157 IN EFI_HANDLE ImageHandle
,
158 IN EFI_SYSTEM_TABLE
*SystemTable
163 CHAR16
*ProblemParam
;
164 SHELL_STATUS ShellStatus
;
169 EFI_HANDLE TheHandle
;
173 ShellStatus
= SHELL_SUCCESS
;
174 Status
= EFI_SUCCESS
;
178 // initialize the shell lib (we must be in non-auto-init...)
180 Status
= ShellInitialize();
181 ASSERT_EFI_ERROR(Status
);
183 Status
= CommandInit();
184 ASSERT_EFI_ERROR(Status
);
187 // parse the command line
189 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
190 if (EFI_ERROR(Status
)) {
191 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
192 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, ProblemParam
);
193 FreePool(ProblemParam
);
194 ShellStatus
= SHELL_INVALID_PARAMETER
;
199 if (ShellCommandLineGetCount(Package
) > 2) {
200 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
);
201 ShellCommandLineFreeVarList (Package
);
202 return (SHELL_INVALID_PARAMETER
);
204 Lang
= ShellCommandLineGetValue(Package
, L
"-l");
206 Language
= AllocateZeroPool(StrSize(Lang
));
207 AsciiSPrint(Language
, StrSize(Lang
), "%S", Lang
);
208 } else if (!ShellCommandLineGetFlag(Package
, L
"-l")){
209 ASSERT(Language
== NULL
);
210 // Language = AllocateZeroPool(10);
211 // AsciiSPrint(Language, 10, "en-us");
213 ASSERT(Language
== NULL
);
214 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDriver1HiiHandle
, L
"-l");
215 ShellCommandLineFreeVarList (Package
);
216 return (SHELL_INVALID_PARAMETER
);
218 FlagD
= ShellCommandLineGetFlag(Package
, L
"-d");
220 Lang
= ShellCommandLineGetRawValue(Package
, 1);
221 HiiString
= HiiGetString(gShellDriver1HiiHandle
, STRING_TOKEN (STR_DEV_TREE_OUTPUT
), Language
);
224 for (LoopVar
= 1 ; ; LoopVar
++){
225 TheHandle
= ConvertHandleIndexToHandle(LoopVar
);
226 if (TheHandle
== NULL
){
229 ShellStatus
= DoDevTreeForHandle(TheHandle
, Language
, FlagD
, 0, HiiString
);
232 Status
= ShellConvertStringToUint64(Lang
, &Intermediate
, TRUE
, FALSE
);
233 if (EFI_ERROR(Status
) || ConvertHandleIndexToHandle((UINTN
)Intermediate
) == NULL
) {
234 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, Lang
);
235 ShellStatus
= SHELL_INVALID_PARAMETER
;
237 ShellStatus
= DoDevTreeForHandle(ConvertHandleIndexToHandle((UINTN
)Intermediate
), Language
, FlagD
, 0, HiiString
);
241 if (HiiString
!= NULL
) {
244 SHELL_FREE_NON_NULL(Language
);
245 ShellCommandLineFreeVarList (Package
);
248 return (ShellStatus
);