]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c
ShellPkg: Updates to 'smbiosview' command
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SmbiosView / SmbiosView.c
1 /** @file
2 Tools of clarify the content of the smbios table.
3
4 Copyright (c) 2005 - 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
9
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.
12
13 **/
14
15 #include "../UefiShellDebug1CommandsLib.h"
16 #include "LibSmbiosView.h"
17 #include "SmbiosView.h"
18 #include "PrintInfo.h"
19 #include "QueryTable.h"
20
21 UINT8 gShowType = SHOW_DETAIL;
22 STATIC STRUCTURE_STATISTICS *mStatisticsTable = NULL;
23
24 UINT8 SmbiosMajorVersion;
25 UINT8 SmbiosMinorVersion;
26
27 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
28 {L"-t", TypeValue},
29 {L"-h", TypeValue},
30 {L"-s", TypeFlag},
31 {L"-a", TypeFlag},
32 {NULL, TypeMax}
33 };
34
35 /**
36 Function for 'smbiosview' command.
37
38 @param[in] ImageHandle Handle to the Image (NULL if Internal).
39 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
40 **/
41 SHELL_STATUS
42 EFIAPI
43 ShellCommandRunSmbiosView (
44 IN EFI_HANDLE ImageHandle,
45 IN EFI_SYSTEM_TABLE *SystemTable
46 )
47 {
48 UINT8 StructType;
49 UINT16 StructHandle;
50 EFI_STATUS Status;
51 BOOLEAN RandomView;
52 LIST_ENTRY *Package;
53 CHAR16 *ProblemParam;
54 SHELL_STATUS ShellStatus;
55 CONST CHAR16 *Temp;
56
57 mStatisticsTable = NULL;
58 Package = NULL;
59 ShellStatus = SHELL_SUCCESS;
60
61 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
62 if (EFI_ERROR(Status)) {
63 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
64 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);
65 FreePool(ProblemParam);
66 ShellStatus = SHELL_INVALID_PARAMETER;
67 } else {
68 ASSERT(FALSE);
69 }
70 } else {
71 if (ShellCommandLineGetCount(Package) > 1) {
72 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
73 ShellStatus = SHELL_INVALID_PARAMETER;
74 } else if (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetValue(Package, L"-t") == NULL) {
75 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-t");
76 ShellStatus = SHELL_INVALID_PARAMETER;
77 } else if (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetValue(Package, L"-h") == NULL) {
78 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-h");
79 ShellStatus = SHELL_INVALID_PARAMETER;
80 } else if (
81 (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-h")) ||
82 (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-s")) ||
83 (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-a")) ||
84 (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetFlag(Package, L"-s")) ||
85 (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetFlag(Package, L"-a")) ||
86 (ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetFlag(Package, L"-a"))
87 ) {
88 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
89 ShellStatus = SHELL_INVALID_PARAMETER;
90 } else {
91
92 //
93 // Init Lib
94
95 Status = LibSmbiosInit ();
96 if (EFI_ERROR (Status)) {
97 ShellStatus = SHELL_NOT_FOUND;
98 goto Done;
99 }
100 //
101 // build statistics table
102 //
103 Status = InitSmbiosTableStatistics ();
104 if (EFI_ERROR (Status)) {
105 ShellStatus = SHELL_NOT_FOUND;
106 goto Done;
107 }
108
109 StructType = STRUCTURE_TYPE_RANDOM;
110 RandomView = TRUE;
111 //
112 // Initialize the StructHandle to be the first handle
113 //
114 StructHandle = INVALID_HANDLE;
115 LibGetSmbiosStructure (&StructHandle, NULL, NULL);
116
117 Temp = ShellCommandLineGetValue(Package, L"-t");
118 if (Temp != NULL) {
119 StructType = (UINT8) ShellStrToUintn (Temp);
120 }
121
122 Temp = ShellCommandLineGetValue(Package, L"-h");
123 if (Temp != NULL) {
124 RandomView = FALSE;
125 StructHandle = (UINT16) ShellStrToUintn(Temp);
126 }
127
128 if (ShellCommandLineGetFlag(Package, L"-s")) {
129 Status = DisplayStatisticsTable (SHOW_DETAIL);
130 if (EFI_ERROR(Status)) {
131 ShellStatus = SHELL_NOT_FOUND;
132 }
133 goto Done;
134 }
135
136 if (ShellCommandLineGetFlag(Package, L"-a")) {
137 gShowType = SHOW_ALL;
138 }
139 //
140 // Show SMBIOS structure information
141 //
142 Status = SMBiosView (StructType, StructHandle, gShowType, RandomView);
143 if (EFI_ERROR(Status)) {
144 ShellStatus = SHELL_NOT_FOUND;
145 }
146 }
147 }
148 Done:
149 //
150 // Release resources
151 //
152 if (mStatisticsTable != NULL) {
153 //
154 // Release statistics table
155 //
156 FreePool (mStatisticsTable);
157 mStatisticsTable = NULL;
158 }
159
160 if (Package != NULL) {
161 ShellCommandLineFreeVarList (Package);
162 }
163
164 LibSmbiosCleanup ();
165
166 return ShellStatus;
167 }
168
169 /**
170 Query all structures Data from SMBIOS table and Display
171 the information to users as required display option.
172
173 @param[in] QueryType Structure type to view.
174 @param[in] QueryHandle Structure handle to view.
175 @param[in] Option Display option: none,outline,normal,detail.
176 @param[in] RandomView Support for -h parameter.
177
178 @retval EFI_SUCCESS print is successful.
179 @retval EFI_BAD_BUFFER_SIZE structure is out of the range of SMBIOS table.
180 **/
181 EFI_STATUS
182 EFIAPI
183 SMBiosView (
184 IN UINT8 QueryType,
185 IN UINT16 QueryHandle,
186 IN UINT8 Option,
187 IN BOOLEAN RandomView
188 )
189 {
190 UINT16 Handle;
191 UINT8 *Buffer;
192 UINT16 Length;
193 UINTN Index;
194
195 SMBIOS_STRUCTURE_POINTER SmbiosStruct;
196 SMBIOS_TABLE_ENTRY_POINT *SMBiosTable;
197
198 SMBiosTable = NULL;
199 LibSmbiosGetEPS (&SMBiosTable);
200 if (SMBiosTable == NULL) {
201 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
202 return EFI_BAD_BUFFER_SIZE;
203 }
204
205 if (CompareMem (SMBiosTable->AnchorString, "_SM_", 4) == 0) {
206 //
207 // Have got SMBIOS table
208 //
209 SmbiosPrintEPSInfo (SMBiosTable, Option);
210
211 SmbiosMajorVersion = SMBiosTable->MajorVersion;
212 SmbiosMinorVersion = SMBiosTable->MinorVersion;
213
214 ShellPrintEx(-1,-1,L"=========================================================\n");
215 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND), gShellDebug1HiiHandle);
216
217 if (QueryType == STRUCTURE_TYPE_RANDOM) {
218 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM), gShellDebug1HiiHandle);
219 } else {
220 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE), gShellDebug1HiiHandle, QueryType);
221 }
222
223 if (RandomView) {
224 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM), gShellDebug1HiiHandle);
225 } else {
226 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE), gShellDebug1HiiHandle, QueryHandle);
227 }
228
229 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SHOWTYPE), gShellDebug1HiiHandle);
230 ShellPrintEx(-1,-1,GetShowTypeString (gShowType));
231 ShellPrintEx(-1,-1,L"\n\n");
232
233 /*
234 //
235 // Get internal commands, such as change options.
236 //
237 Status = WaitEnter ();
238 if (EFI_ERROR (Status)) {
239 if (Status == EFI_ABORTED) {
240 return EFI_SUCCESS;
241 }
242
243 return Status;
244 }
245 */
246
247 //
248 // Searching and display structure info
249 //
250 Handle = QueryHandle;
251 for (Index = 0; Index < SMBiosTable->NumberOfSmbiosStructures; Index++) {
252 //
253 // if reach the end of table, break..
254 //
255 if (Handle == INVALID_HANDLE) {
256 break;
257 }
258 //
259 // handle then point to the next!
260 //
261 if (LibGetSmbiosStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {
262 break;
263 }
264
265 SmbiosStruct.Raw = Buffer;
266
267 //
268 // if QueryType==Random, print this structure.
269 // if QueryType!=Random, but Hdr->Type==QueryType, also print it.
270 // only if QueryType != Random and Hdr->Type != QueryType, skiped it.
271 //
272 if (QueryType != STRUCTURE_TYPE_RANDOM && SmbiosStruct.Hdr->Type != QueryType) {
273 continue;
274 }
275
276 ShellPrintEx(-1,-1,L"\n=========================================================\n");
277 ShellPrintHiiEx(-1,-1,NULL,
278 STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE_HANDLE_DUMP_STRUCT),
279 gShellDebug1HiiHandle,
280 SmbiosStruct.Hdr->Type,
281 SmbiosStruct.Hdr->Handle
282 );
283 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH), gShellDebug1HiiHandle, Index, Length);
284 //
285 // Addr of structure in structure in table
286 //
287 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR), gShellDebug1HiiHandle, (UINTN) Buffer);
288 DumpHex (0, 0, Length, Buffer);
289
290 /*
291 //
292 // Get internal commands, such as change options.
293 //
294 Status = WaitEnter ();
295 if (EFI_ERROR (Status)) {
296 if (Status == EFI_ABORTED) {
297 return EFI_SUCCESS;
298 }
299
300 return Status;
301 }
302 */
303
304 if (gShowType != SHOW_NONE) {
305 //
306 // Print structure information
307 //
308 SmbiosPrintStructure (&SmbiosStruct, gShowType);
309 ShellPrintEx(-1,-1,L"\n");
310
311 /*
312 //
313 // Get internal commands, such as change options.
314 //
315 Status = WaitEnter ();
316 if (EFI_ERROR (Status)) {
317 if (Status == EFI_ABORTED) {
318 return EFI_SUCCESS;
319 }
320
321 return Status;
322 }
323 */
324 }
325 if (!RandomView) {
326 break;
327 }
328 //
329 // Support Execution Interrupt.
330 //
331 if (ShellGetExecutionBreakFlag ()) {
332 return EFI_ABORTED;
333 }
334 }
335
336 ShellPrintEx(-1,-1,L"\n=========================================================\n");
337 return EFI_SUCCESS;
338 }
339
340 return EFI_BAD_BUFFER_SIZE;
341 }
342
343 /**
344 Function to initialize the global mStatisticsTable object.
345
346 @retval EFI_SUCCESS print is successful.
347 **/
348 EFI_STATUS
349 EFIAPI
350 InitSmbiosTableStatistics (
351 VOID
352 )
353 {
354 UINT16 Handle;
355 UINT8 *Buffer;
356 UINT16 Length;
357 UINT16 Offset;
358 UINT16 Index;
359
360 SMBIOS_STRUCTURE_POINTER SmbiosStruct;
361 SMBIOS_TABLE_ENTRY_POINT *SMBiosTable;
362 STRUCTURE_STATISTICS *StatisticsPointer;
363
364 SMBiosTable = NULL;
365 LibSmbiosGetEPS (&SMBiosTable);
366 if (SMBiosTable == NULL) {
367 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
368 return EFI_NOT_FOUND;
369 }
370
371 if (CompareMem (SMBiosTable->AnchorString, "_SM_", 4) != 0) {
372 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SMBIOS_TABLE), gShellDebug1HiiHandle);
373 return EFI_INVALID_PARAMETER;
374 }
375 //
376 // Allocate memory to mStatisticsTable
377 //
378 if (mStatisticsTable != NULL) {
379 FreePool (mStatisticsTable);
380 mStatisticsTable = NULL;
381 }
382
383 mStatisticsTable = (STRUCTURE_STATISTICS *) AllocateZeroPool (SMBiosTable->NumberOfSmbiosStructures * sizeof (STRUCTURE_STATISTICS));
384
385 if (mStatisticsTable == NULL) {
386 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM), gShellDebug1HiiHandle);
387 return EFI_OUT_OF_RESOURCES;
388 }
389
390 Offset = 0;
391 StatisticsPointer = mStatisticsTable;
392
393 //
394 // search from the first one
395 //
396 Handle = INVALID_HANDLE;
397 LibGetSmbiosStructure (&Handle, NULL, NULL);
398 for (Index = 1; Index <= SMBiosTable->NumberOfSmbiosStructures; Index++) {
399 //
400 // If reach the end of table, break..
401 //
402 if (Handle == INVALID_HANDLE) {
403 break;
404 }
405 //
406 // After LibGetSmbiosStructure(), handle then point to the next!
407 //
408 if (LibGetSmbiosStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {
409 break;
410 }
411
412 SmbiosStruct.Raw = Buffer;
413
414 //
415 // general statistics
416 //
417 StatisticsPointer->Index = Index;
418 StatisticsPointer->Type = SmbiosStruct.Hdr->Type;
419 StatisticsPointer->Handle = SmbiosStruct.Hdr->Handle;
420 StatisticsPointer->Length = Length;
421 StatisticsPointer->Addr = Offset;
422
423 Offset = (UINT16) (Offset + Length);
424
425 StatisticsPointer = &mStatisticsTable[Index];
426 }
427
428 return EFI_SUCCESS;
429 }
430
431 /**
432 Function to display the global mStatisticsTable object.
433
434 @param[in] Option ECHO, NORMAL, or DETAIL control the amount of detail displayed.
435
436 @retval EFI_SUCCESS print is successful.
437 **/
438 EFI_STATUS
439 EFIAPI
440 DisplayStatisticsTable (
441 IN UINT8 Option
442 )
443 {
444 UINTN Index;
445 UINTN Num;
446 STRUCTURE_STATISTICS *StatisticsPointer;
447 SMBIOS_TABLE_ENTRY_POINT *SMBiosTable;
448
449 SMBiosTable = NULL;
450 if (Option < SHOW_OUTLINE) {
451 return EFI_SUCCESS;
452 }
453 //
454 // display EPS information firstly
455 //
456 LibSmbiosGetEPS (&SMBiosTable);
457 if (SMBiosTable == NULL) {
458 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
459 return EFI_UNSUPPORTED;
460 }
461
462 ShellPrintEx(-1,-1,L"\n============================================================\n");
463 SmbiosPrintEPSInfo (SMBiosTable, Option);
464
465 if (Option < SHOW_NORMAL) {
466 return EFI_SUCCESS;
467 }
468
469 if (mStatisticsTable == NULL) {
470 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS), gShellDebug1HiiHandle);
471 return EFI_NOT_FOUND;
472 }
473
474 ShellPrintEx(-1,-1,L"============================================================\n");
475 StatisticsPointer = &mStatisticsTable[0];
476 Num = SMBiosTable->NumberOfSmbiosStructures;
477 //
478 // display statistics table content
479 //
480 for (Index = 1; Index <= Num; Index++) {
481 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX), gShellDebug1HiiHandle, StatisticsPointer->Index);
482 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE), gShellDebug1HiiHandle, StatisticsPointer->Type);
483 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_HANDLE), gShellDebug1HiiHandle, StatisticsPointer->Handle);
484 if (Option >= SHOW_DETAIL) {
485 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OFFSET), gShellDebug1HiiHandle, StatisticsPointer->Addr);
486 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_LENGTH), gShellDebug1HiiHandle, StatisticsPointer->Length);
487 }
488
489 ShellPrintEx(-1,-1,L"\n");
490 StatisticsPointer = &mStatisticsTable[Index];
491 /*
492 //
493 // Display 20 lines and wait for a page break
494 //
495 if (Index % 20 == 0) {
496 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ENTER_CONTINUE), gShellDebug1HiiHandle);
497 Status = WaitEnter ();
498 if (EFI_ERROR (Status)) {
499 if (Status == EFI_ABORTED) {
500 return EFI_SUCCESS;
501 }
502
503 return Status;
504 }
505 }
506 */
507 }
508
509 return EFI_SUCCESS;
510 }
511
512 /**
513 function to return a string of the detail level.
514
515 @param[in] ShowType The detail level whose name is desired in clear text.
516
517 @return A pointer to a string representing the ShowType (or 'undefined type' if not known).
518 **/
519 CHAR16 *
520 EFIAPI
521 GetShowTypeString (
522 UINT8 ShowType
523 )
524 {
525 //
526 // show type
527 //
528 switch (ShowType) {
529
530 case SHOW_NONE:
531 return L"SHOW_NONE";
532
533 case SHOW_OUTLINE:
534 return L"SHOW_OUTLINE";
535
536 case SHOW_NORMAL:
537 return L"SHOW_NORMAL";
538
539 case SHOW_DETAIL:
540 return L"SHOW_DETAIL";
541
542 case SHOW_ALL:
543 return L"SHOW_ALL";
544
545 default:
546 return L"Undefined type";
547 }
548 }
549