1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
/** @file
Main file for Dh shell Driver1 function.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "UefiShellDriver1CommandsLib.h"
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-p", TypeValue},
{L"-d", TypeFlag},
{L"-v", TypeFlag},
{L"-verbose", TypeFlag},
{L"-sfo", TypeFlag},
{L"-l", TypeValue},
{NULL, TypeMax}
};
STATIC CONST EFI_GUID *UefiDriverModelProtocolsGuidArray[] = {
&gEfiDriverBindingProtocolGuid,
&gEfiPlatformDriverOverrideProtocolGuid,
&gEfiBusSpecificDriverOverrideProtocolGuid,
&gEfiDriverDiagnosticsProtocolGuid,
&gEfiDriverDiagnostics2ProtocolGuid,
&gEfiComponentNameProtocolGuid,
&gEfiComponentName2ProtocolGuid,
&gEfiPlatformToDriverConfigurationProtocolGuid,
&gEfiDriverSupportedEfiVersionProtocolGuid,
&gEfiDriverFamilyOverrideProtocolGuid,
&gEfiDriverHealthProtocolGuid,
&gEfiLoadedImageProtocolGuid,
NULL
};
BOOLEAN
EFIAPI
IsDriverProt (
IN CONST EFI_GUID *Guid
)
{
CONST EFI_GUID **GuidWalker;
BOOLEAN GuidFound;
GuidFound = FALSE;
for (GuidWalker = UefiDriverModelProtocolsGuidArray
; GuidWalker != NULL && *GuidWalker != NULL
; GuidWalker++
){
if (CompareGuid(*GuidWalker, Guid)) {
GuidFound = TRUE;
break;
}
}
return (GuidFound);
}
CHAR16*
EFIAPI
GetProtocolInfoString(
IN CONST EFI_HANDLE TheHandle,
IN CONST CHAR8 *Language,
IN CONST CHAR16 *Seperator,
IN CONST BOOLEAN DriverInfo,
IN CONST BOOLEAN Verbose,
IN CONST BOOLEAN ExtraInfo
)
{
EFI_GUID **ProtocolGuidArray;
UINTN ArrayCount;
UINTN ProtocolIndex;
EFI_STATUS Status;
CHAR16 *RetVal;
UINTN Size;
CHAR16 *Temp;
ProtocolGuidArray = NULL;
Status = gBS->ProtocolsPerHandle (
TheHandle,
&ProtocolGuidArray,
&ArrayCount
);
if (!EFI_ERROR (Status)) {
RetVal = NULL;
Size = 0;
for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
Temp = GetStringNameFromGuid(ProtocolGuidArray[ProtocolIndex], Language);
if (Temp != NULL) {
ASSERT((RetVal == NULL && Size == 0) || (RetVal != NULL));
if (Size != 0) {
StrnCatGrow(&RetVal, &Size, Seperator, 0);
}
StrnCatGrow(&RetVal, &Size, L"%H", 0);
StrnCatGrow(&RetVal, &Size, Temp, 0);
StrnCatGrow(&RetVal, &Size, L"%N", 0);
FreePool(Temp);
}
if (ExtraInfo) {
Temp = GetProtocolInformationDump(TheHandle, ProtocolGuidArray[ProtocolIndex], Verbose);
if (Temp != NULL) {
ASSERT((RetVal == NULL && Size == 0) || (RetVal != NULL));
if (!Verbose) {
StrnCatGrow(&RetVal, &Size, L"(", 0);
StrnCatGrow(&RetVal, &Size, Temp, 0);
StrnCatGrow(&RetVal, &Size, L")", 0);
} else {
StrnCatGrow(&RetVal, &Size, Seperator, 0);
StrnCatGrow(&RetVal, &Size, Temp, 0);
}
FreePool(Temp);
}
}
}
} else {
return (NULL);
}
if (ProtocolGuidArray != NULL) {
FreePool(ProtocolGuidArray);
}
ASSERT((RetVal == NULL && Size == 0) || (RetVal != NULL));
StrnCatGrow(&RetVal, &Size, Seperator, 0);
return (RetVal);
}
SHELL_STATUS
EFIAPI
DoDhByHandle(
IN CONST EFI_HANDLE TheHandle,
IN CONST BOOLEAN Verbose,
IN CONST BOOLEAN Sfo,
IN CONST CHAR8 *Language,
IN CONST BOOLEAN DriverInfo,
IN CONST BOOLEAN Multiple
)
{
CHAR16 *ProtocolInfoString;
SHELL_STATUS ShellStatus;
EFI_STATUS Status;
Status = EFI_SUCCESS;
ShellStatus = SHELL_SUCCESS;
ProtocolInfoString = NULL;
if (!Sfo) {
if (Multiple) {
ProtocolInfoString = GetProtocolInfoString(TheHandle, Language, L" ", DriverInfo, Verbose, TRUE);
ShellPrintHiiEx(
-1,
-1,
NULL,
STRING_TOKEN (STR_DH_OUTPUT),
gShellDriver1HiiHandle,
ConvertHandleToHandleIndex(TheHandle),
ProtocolInfoString==NULL?L"":ProtocolInfoString);
} else {
ProtocolInfoString = GetProtocolInfoString(TheHandle, Language, L"\r\n", DriverInfo, Verbose, TRUE);
ShellPrintHiiEx(
-1,
-1,
NULL,
STRING_TOKEN (STR_DH_OUTPUT_SINGLE),
gShellDriver1HiiHandle,
ConvertHandleToHandleIndex(TheHandle),
TheHandle,
ProtocolInfoString==NULL?L"":ProtocolInfoString);
}
} else {
//#string STR_DH_OUTPUT_SFO #language en-US "%s, %s, %s, %H%02x%N, %s, %s\r\n"
ProtocolInfoString = GetProtocolInfoString(TheHandle, Language, L";", DriverInfo, FALSE, FALSE);
ShellPrintHiiEx(
-1,
-1,
NULL,
STRING_TOKEN (STR_DH_OUTPUT_SFO),
gShellDriver1HiiHandle,
Multiple ?L"HandlesInfo":L"HandleInfo",
L"DriverName",
L"ControllerName",
ConvertHandleToHandleIndex(TheHandle),
L"DevPath",
ProtocolInfoString==NULL?L"":ProtocolInfoString);
}
if (ProtocolInfoString != NULL) {
FreePool(ProtocolInfoString);
}
return (ShellStatus);
}
SHELL_STATUS
EFIAPI
DoDhForHandleList(
IN CONST EFI_HANDLE *HandleList,
IN CONST BOOLEAN Sfo,
IN CONST CHAR8 *Language,
IN CONST BOOLEAN DriverInfo
)
{
CONST EFI_HANDLE *HandleWalker;
SHELL_STATUS ShellStatus;
ShellStatus = SHELL_SUCCESS;
for (HandleWalker = HandleList ; HandleWalker != NULL && *HandleWalker != NULL && ShellStatus == SHELL_SUCCESS; HandleWalker++) {
ShellStatus = DoDhByHandle(
*HandleWalker,
FALSE,
Sfo,
Language,
DriverInfo,
TRUE
);
}
return (ShellStatus);
}
SHELL_STATUS
EFIAPI
DoDhForAll(
IN CONST BOOLEAN Sfo,
IN CONST CHAR8 *Language,
IN CONST BOOLEAN DriverInfo
)
{
EFI_HANDLE *HandleList;
SHELL_STATUS ShellStatus;
HandleList = GetHandleListByProtocol(NULL);
ShellStatus = DoDhForHandleList(
HandleList,
Sfo,
Language,
DriverInfo);
FreePool(HandleList);
return (ShellStatus);
}
SHELL_STATUS
EFIAPI
DoDhByProtocol(
IN CONST CHAR16 *ProtocolName,
IN CONST BOOLEAN Sfo,
IN CONST CHAR8 *Language,
IN CONST BOOLEAN DriverInfo
)
{
EFI_GUID *Guid;
EFI_STATUS Status;
EFI_HANDLE *HandleList;
SHELL_STATUS ShellStatus;
ASSERT(ProtocolName != NULL);
Status = GetGuidFromStringName(ProtocolName, Language, &Guid);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DH_NO_GUID_FOUND), gShellDriver1HiiHandle, ProtocolName);
return (SHELL_INVALID_PARAMETER);
}
HandleList = GetHandleListByProtocol(Guid);
ShellStatus = DoDhForHandleList(
HandleList,
Sfo,
Language,
DriverInfo);
SHELL_FREE_NON_NULL(HandleList);
return (ShellStatus);
}
SHELL_STATUS
EFIAPI
ShellCommandRunDh (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
CHAR8 *Language;
CONST CHAR16 *Lang;
CONST CHAR16 *Temp2;
BOOLEAN SfoMode;
BOOLEAN FlagD;
BOOLEAN Verbose;
ShellStatus = SHELL_SUCCESS;
Status = EFI_SUCCESS;
Language = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
if (ShellCommandLineGetCount(Package) > 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle);
ShellCommandLineFreeVarList (Package);
return (SHELL_INVALID_PARAMETER);
}
Lang = ShellCommandLineGetValue(Package, L"-l");
if (Lang != NULL) {
Language = AllocateZeroPool(StrSize(Lang));
AsciiSPrint(Language, StrSize(Lang), "%S", Lang);
} else if (!ShellCommandLineGetFlag(Package, L"-l")){
Language = AllocateZeroPool(10);
AsciiSPrint(Language, 10, "en-us");
} else {
ASSERT(Language == NULL);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l");
ShellCommandLineFreeVarList (Package);
return (SHELL_INVALID_PARAMETER);
}
SfoMode = ShellCommandLineGetFlag(Package, L"-sfo");
FlagD = ShellCommandLineGetFlag(Package, L"-d");
if (ShellCommandLineGetFlag(Package, L"-v") || ShellCommandLineGetFlag(Package, L"-verbose")) {
Verbose = TRUE;
} else {
Verbose = FALSE;
}
if (ShellCommandLineGetFlag(Package, L"-p")) {
if (ShellCommandLineGetCount(Package) > 1) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetValue(Package, L"-p") == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-p");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// print by protocol
//
ShellStatus = DoDhByProtocol(
ShellCommandLineGetValue(Package, L"-p"),
SfoMode,
Lang==NULL?NULL:Language,
FlagD
);
}
} else {
Temp2 = ShellCommandLineGetRawValue(Package, 1);
if (Temp2 == NULL) {
//
// Print everything
//
ShellStatus = DoDhForAll(
SfoMode,
Lang==NULL?NULL:Language,
FlagD
);
} else {
if (!ShellIsHexOrDecimalNumber(Temp2, TRUE, FALSE) || ConvertHandleIndexToHandle(StrHexToUintn(Temp2)) == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Temp2);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// print 1 handle
//
ShellStatus = DoDhByHandle(
ConvertHandleIndexToHandle(StrHexToUintn(Temp2)),
Verbose,
SfoMode,
Lang==NULL?NULL:Language,
FlagD,
FALSE
);
}
}
}
ShellCommandLineFreeVarList (Package);
SHELL_FREE_NON_NULL(Language);
}
return (ShellStatus);
}
|