2 Main file for DevTree shell Driver1 function.
4 Copyright (c) 2010, 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
[] = {
26 IN CONST EFI_HANDLE TheHandle
,
27 IN CONST CHAR8
*Lang OPTIONAL
,
28 IN CONST BOOLEAN UseDevPaths
,
29 IN CONST UINTN IndentCharCount
,
30 IN CONST CHAR16
*HiiString
33 SHELL_STATUS ShellStatus
;
37 EFI_HANDLE
*ChildHandleBuffer
;
42 ShellStatus
= SHELL_SUCCESS
;
44 ChildHandleBuffer
= NULL
;
47 ASSERT(TheHandle
!= NULL
);
49 // We want controller handles. they will not have LoadedImage or DriverBinding (or others...)
51 Status
= gBS
->OpenProtocol (
53 &gEfiDriverBindingProtocolGuid
,
57 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
59 if (!EFI_ERROR (Status
)) {
63 Status
= gBS
->OpenProtocol (
65 &gEfiLoadedImageProtocolGuid
,
69 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
71 if (!EFI_ERROR (Status
)) {
76 // If we are at the begining then we want root handles they have no parents and do have device path.
78 if (IndentCharCount
== 0) {
79 Status
= gBS
->OpenProtocol (
81 &gEfiDevicePathProtocolGuid
,
85 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
87 if (EFI_ERROR (Status
)) {
92 FormatString
= AllocateZeroPool(StrSize(HiiString
) + (10)*sizeof(FormatString
[0]));
94 ASSERT(HiiString
!= NULL
);
95 ASSERT(FormatString
!= NULL
);
98 // we generate the format string on the fly so that we can control the
99 // number of space characters that the first (empty) string has. this
100 // handles the indenting.
103 UnicodeSPrint(FormatString
, StrSize(HiiString
) + (10)*sizeof(FormatString
[0]), L
"%%%ds %s", IndentCharCount
, HiiString
);
104 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
);
106 // print out the information for ourselves
113 ConvertHandleToHandleIndex(TheHandle
),
114 Name
==NULL
?L
"Unknown":Name
);
116 FreePool(FormatString
);
122 // recurse on each child handle with IndentCharCount + 2
124 ParseHandleDatabaseForChildControllers(TheHandle
, &ChildCount
, &ChildHandleBuffer
);
125 for (LoopVar
= 0 ; LoopVar
< ChildCount
&& ShellStatus
== SHELL_SUCCESS
; LoopVar
++){
126 ShellStatus
= DoDevTreeForHandle(ChildHandleBuffer
[LoopVar
], Lang
, UseDevPaths
, IndentCharCount
+2, HiiString
);
129 if (ChildHandleBuffer
!= NULL
) {
130 FreePool(ChildHandleBuffer
);
133 return (ShellStatus
);
137 Function for 'devtree' command.
139 @param[in] ImageHandle Handle to the Image (NULL if Internal).
140 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
144 ShellCommandRunDevTree (
145 IN EFI_HANDLE ImageHandle
,
146 IN EFI_SYSTEM_TABLE
*SystemTable
151 CHAR16
*ProblemParam
;
152 SHELL_STATUS ShellStatus
;
157 EFI_HANDLE TheHandle
;
160 ShellStatus
= SHELL_SUCCESS
;
161 Status
= EFI_SUCCESS
;
165 // initialize the shell lib (we must be in non-auto-init...)
167 Status
= ShellInitialize();
168 ASSERT_EFI_ERROR(Status
);
170 Status
= CommandInit();
171 ASSERT_EFI_ERROR(Status
);
174 // parse the command line
176 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
177 if (EFI_ERROR(Status
)) {
178 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
179 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, ProblemParam
);
180 FreePool(ProblemParam
);
181 ShellStatus
= SHELL_INVALID_PARAMETER
;
186 if (ShellCommandLineGetCount(Package
) > 2) {
187 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
);
188 ShellCommandLineFreeVarList (Package
);
189 return (SHELL_INVALID_PARAMETER
);
191 Lang
= ShellCommandLineGetValue(Package
, L
"-l");
193 Language
= AllocateZeroPool(StrSize(Lang
));
194 AsciiSPrint(Language
, StrSize(Lang
), "%S", Lang
);
195 } else if (!ShellCommandLineGetFlag(Package
, L
"-l")){
196 ASSERT(Language
== NULL
);
197 // Language = AllocateZeroPool(10);
198 // AsciiSPrint(Language, 10, "en-us");
200 ASSERT(Language
== NULL
);
201 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDriver1HiiHandle
, L
"-l");
202 ShellCommandLineFreeVarList (Package
);
203 return (SHELL_INVALID_PARAMETER
);
205 FlagD
= ShellCommandLineGetFlag(Package
, L
"-d");
207 Lang
= ShellCommandLineGetRawValue(Package
, 1);
208 HiiString
= HiiGetString(gShellDriver1HiiHandle
, STRING_TOKEN (STR_DEV_TREE_OUTPUT
), Language
);
211 for (LoopVar
= 1 ; ; LoopVar
++){
212 TheHandle
= ConvertHandleIndexToHandle(LoopVar
);
213 if (TheHandle
== NULL
){
216 ShellStatus
= DoDevTreeForHandle(TheHandle
, Language
, FlagD
, 0, HiiString
);
219 if (!ShellIsHexOrDecimalNumber(Lang
, TRUE
, FALSE
) || ConvertHandleIndexToHandle(StrHexToUintn(Lang
)) == NULL
) {
220 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, Lang
);
221 ShellStatus
= SHELL_INVALID_PARAMETER
;
223 ShellStatus
= DoDevTreeForHandle(ConvertHandleIndexToHandle(StrHexToUintn(Lang
)), Language
, FlagD
, 0, HiiString
);
227 if (HiiString
!= NULL
) {
230 SHELL_FREE_NON_NULL(Language
);
231 ShellCommandLineFreeVarList (Package
);
234 return (ShellStatus
);