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