TianoCore EDK2 master
Loading...
Searching...
No Matches
DevTree.c
Go to the documentation of this file.
1
11
12STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
13 { L"-d", TypeFlag },
14 { L"-l", TypeValue },
15 { NULL, TypeMax }
16};
17
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
37 )
38{
39 SHELL_STATUS ShellStatus;
40 EFI_STATUS Status;
41 CHAR16 *FormatString;
42 CHAR16 *Name;
43 EFI_HANDLE *ChildHandleBuffer;
44 UINTN ChildCount;
45 UINTN LoopVar;
46
47 Status = EFI_SUCCESS;
48 ShellStatus = SHELL_SUCCESS;
49 Name = NULL;
50 ChildHandleBuffer = NULL;
51 ChildCount = 0;
52
53 ASSERT (TheHandle != NULL);
54 ASSERT (HiiString != NULL);
55
57 ShellStatus = SHELL_ABORTED;
58 return ShellStatus;
59 }
60
61 //
62 // We want controller handles. they will not have LoadedImage or DriverBinding (or others...)
63 //
64 Status = gBS->OpenProtocol (
65 TheHandle,
66 &gEfiDriverBindingProtocolGuid,
67 NULL,
68 NULL,
69 NULL,
70 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
71 );
72 if (!EFI_ERROR (Status)) {
73 return SHELL_SUCCESS;
74 }
75
76 Status = gBS->OpenProtocol (
77 TheHandle,
78 &gEfiLoadedImageProtocolGuid,
79 NULL,
80 NULL,
81 NULL,
82 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
83 );
84 if (!EFI_ERROR (Status)) {
85 return SHELL_SUCCESS;
86 }
87
88 FormatString = AllocateZeroPool (StrSize (HiiString) + (10)*sizeof (FormatString[0]));
89 if (FormatString == NULL) {
91 }
92
93 //
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.
97 //
98
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);
101 //
102 // print out the information for ourselves
103 //
105 -1,
106 -1,
107 FormatString,
108 L"",
109 ConvertHandleToHandleIndex (TheHandle),
110 Name == NULL ? L"Unknown" : Name
111 );
112
113 FreePool (FormatString);
114 if (Name != NULL) {
115 FreePool (Name);
116 }
117
118 //
119 // recurse on each child handle with IndentCharCount + 2
120 //
121 ParseHandleDatabaseForChildControllers (TheHandle, &ChildCount, &ChildHandleBuffer);
122 for (LoopVar = 0; LoopVar < ChildCount && ShellStatus == SHELL_SUCCESS; LoopVar++) {
123 ShellStatus = DoDevTreeForHandle (ChildHandleBuffer[LoopVar], Lang, UseDevPaths, IndentCharCount+2, HiiString);
124 if (ShellStatus == SHELL_ABORTED) {
125 break;
126 }
127 }
128
129 if (ChildHandleBuffer != NULL) {
130 FreePool (ChildHandleBuffer);
131 }
132
133 return (ShellStatus);
134}
135
143EFIAPI
145 IN EFI_HANDLE ImageHandle,
146 IN EFI_SYSTEM_TABLE *SystemTable
147 )
148{
149 EFI_STATUS Status;
150 LIST_ENTRY *Package;
151 CHAR16 *ProblemParam;
152 SHELL_STATUS ShellStatus;
153 CHAR8 *Language;
154 CONST CHAR16 *Lang;
155 CHAR16 *HiiString;
156 UINTN LoopVar;
157 EFI_HANDLE TheHandle;
158 BOOLEAN FlagD;
159 UINT64 Intermediate;
160 UINTN ParentControllerHandleCount;
161 EFI_HANDLE *ParentControllerHandleBuffer;
162
163 ShellStatus = SHELL_SUCCESS;
164 Status = EFI_SUCCESS;
165 Language = NULL;
166
167 //
168 // initialize the shell lib (we must be in non-auto-init...)
169 //
170 Status = ShellInitialize ();
171 ASSERT_EFI_ERROR (Status);
172
173 Status = CommandInit ();
174 ASSERT_EFI_ERROR (Status);
175
176 //
177 // parse the command line
178 //
179 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
180 if (EFI_ERROR (Status)) {
181 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
182 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"devtree", ProblemParam);
183 FreePool (ProblemParam);
184 ShellStatus = SHELL_INVALID_PARAMETER;
185 } else {
186 ASSERT (FALSE);
187 }
188 } else {
189 if (ShellCommandLineGetCount (Package) > 2) {
190 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"devtree");
193 }
194
195 Lang = ShellCommandLineGetValue (Package, L"-l");
196 if (Lang != NULL) {
197 Language = AllocateZeroPool (StrSize (Lang));
198 if (Language == NULL) {
199 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDriver1HiiHandle, L"devtree");
201 return (SHELL_OUT_OF_RESOURCES);
202 }
203
204 AsciiSPrint (Language, StrSize (Lang), "%S", Lang);
205 } else if (!ShellCommandLineGetFlag (Package, L"-l")) {
206 ASSERT (Language == NULL);
207 // Language = AllocateZeroPool(10);
208 // AsciiSPrint(Language, 10, "en-us");
209 } else {
210 ASSERT (Language == NULL);
211 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"devtree", L"-l");
214 }
215
216 FlagD = ShellCommandLineGetFlag (Package, L"-d");
217
218 Lang = ShellCommandLineGetRawValue (Package, 1);
219 HiiString = HiiGetString (gShellDriver1HiiHandle, STRING_TOKEN (STR_DEV_TREE_OUTPUT), Language);
220
221 if (HiiString == NULL) {
222 ASSERT (HiiString != NULL);
223 SHELL_FREE_NON_NULL (Language);
226 }
227
228 if (Lang == NULL) {
229 for (LoopVar = 1; ; LoopVar++) {
230 TheHandle = ConvertHandleIndexToHandle (LoopVar);
231 if (TheHandle == NULL) {
232 break;
233 }
234
235 //
236 // Skip handles that do not have device path protocol
237 //
238 Status = gBS->OpenProtocol (
239 TheHandle,
240 &gEfiDevicePathProtocolGuid,
241 NULL,
242 NULL,
243 NULL,
244 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
245 );
246 if (EFI_ERROR (Status)) {
247 continue;
248 }
249
250 //
251 // Skip handles that do have parents
252 //
253 ParentControllerHandleBuffer = NULL;
255 TheHandle,
256 &ParentControllerHandleCount,
257 &ParentControllerHandleBuffer
258 );
259 SHELL_FREE_NON_NULL (ParentControllerHandleBuffer);
260 if (ParentControllerHandleCount > 0) {
261 continue;
262 }
263
264 //
265 // Start a devtree from TheHandle that has a device path and no parents
266 //
267 ShellStatus = DoDevTreeForHandle (TheHandle, Language, FlagD, 0, HiiString);
268 }
269 } else {
270 Status = ShellConvertStringToUint64 (Lang, &Intermediate, TRUE, FALSE);
271 if (EFI_ERROR (Status) || (ConvertHandleIndexToHandle ((UINTN)Intermediate) == NULL)) {
272 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"devtree", Lang);
273 ShellStatus = SHELL_INVALID_PARAMETER;
274 } else {
275 ShellStatus = DoDevTreeForHandle (ConvertHandleIndexToHandle ((UINTN)Intermediate), Language, FlagD, 0, HiiString);
276 }
277 }
278
279 if (HiiString != NULL) {
280 FreePool (HiiString);
281 }
282
283 SHELL_FREE_NON_NULL (Language);
285 }
286
287 return (ShellStatus);
288}
UINT64 UINTN
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
SHELL_STATUS DoDevTreeForHandle(IN CONST EFI_HANDLE TheHandle, IN CONST CHAR8 *Lang OPTIONAL, IN CONST BOOLEAN UseDevPaths, IN CONST UINTN IndentCharCount, IN CONST CHAR16 *HiiString)
Definition: DevTree.c:31
SHELL_STATUS EFIAPI ShellCommandRunDevTree(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: DevTree.c:144
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_HANDLE EFIAPI ConvertHandleIndexToHandle(IN CONST UINTN TheIndex)
#define PARSE_HANDLE_DATABASE_PARENTS(ControllerHandle, Count, Buffer)
UINTN EFIAPI ConvertHandleToHandleIndex(IN CONST EFI_HANDLE TheHandle)
EFI_STATUS EFIAPI ParseHandleDatabaseForChildControllers(IN CONST EFI_HANDLE ControllerHandle, OUT UINTN *MatchingHandleCount, OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL)
EFI_STRING EFIAPI HiiGetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL)
Definition: HiiString.c:211
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:813
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_OUT_OF_RESOURCES
Definition: Shell.h:73
@ SHELL_ABORTED
Definition: Shell.h:128
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
EFI_STATUS EFIAPI CommandInit(VOID)
CONST CHAR16 *EFIAPI ShellCommandLineGetValue(IN CONST LIST_ENTRY *CheckPackage, IN CHAR16 *KeyString)
BOOLEAN EFIAPI ShellGetExecutionBreakFlag(VOID)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
@ TypeValue
A flag that has some data following it with a space (IE "-a 1").
Definition: ShellLib.h:700
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
EFI_STATUS EFIAPI ShellPrintEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR16 *Format,...)
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellConvertStringToUint64(IN CONST CHAR16 *String, OUT UINT64 *Value, IN CONST BOOLEAN ForceHex, IN CONST BOOLEAN StopAtSpace)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
#define STRING_TOKEN(t)