2 Tools of clarify the content of the smbios table.
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
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 "../UefiShellDebug1CommandsLib.h"
16 #include "LibSmbiosView.h"
17 #include "smbiosview.h"
18 #include "PrintInfo.h"
19 #include "QueryTable.h"
21 UINT8 gShowType
= SHOW_DETAIL
;
22 STATIC STRUCTURE_STATISTICS
*mStatisticsTable
= NULL
;
24 UINT8 SmbiosMajorVersion
;
25 UINT8 SmbiosMinorVersion
;
27 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
37 ShellCommandRunSmbiosView (
38 IN EFI_HANDLE ImageHandle
,
39 IN EFI_SYSTEM_TABLE
*SystemTable
48 SHELL_STATUS ShellStatus
;
51 mStatisticsTable
= NULL
;
53 ShellStatus
= SHELL_SUCCESS
;
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
;
65 if (ShellCommandLineGetCount(Package
) > 1) {
66 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
);
67 ShellStatus
= SHELL_INVALID_PARAMETER
;
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"))
76 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
);
77 ShellStatus
= SHELL_INVALID_PARAMETER
;
83 Status
= LibSmbiosInit ();
84 if (EFI_ERROR (Status
)) {
85 ShellStatus
= SHELL_NOT_FOUND
;
89 // build statistics table
91 Status
= InitSmbiosTableStatistics ();
92 if (EFI_ERROR (Status
)) {
93 ShellStatus
= SHELL_NOT_FOUND
;
97 StructType
= STRUCTURE_TYPE_RANDOM
;
100 // Initialize the StructHandle to be the first handle
102 StructHandle
= STRUCTURE_HANDLE_INVALID
;
103 LibGetSmbiosStructure (&StructHandle
, NULL
, NULL
);
105 Temp
= ShellCommandLineGetValue(Package
, L
"-t");
107 StructType
= (UINT8
) ShellStrToUintn (Temp
);
110 Temp
= ShellCommandLineGetValue(Package
, L
"-h");
113 StructHandle
= (UINT16
) ShellStrToUintn(Temp
);
116 if (ShellCommandLineGetFlag(Package
, L
"-s")) {
117 Status
= DisplayStatisticsTable (SHOW_DETAIL
);
118 if (EFI_ERROR(Status
)) {
119 ShellStatus
= SHELL_NOT_FOUND
;
124 if (ShellCommandLineGetFlag(Package
, L
"-a")) {
125 gShowType
= SHOW_ALL
;
128 // Show SMBIOS structure information
130 Status
= SMBiosView (StructType
, StructHandle
, gShowType
, RandomView
);
131 if (EFI_ERROR(Status
)) {
132 ShellStatus
= SHELL_NOT_FOUND
;
140 if (mStatisticsTable
!= NULL
) {
142 // Release statistics table
144 FreePool (mStatisticsTable
);
145 mStatisticsTable
= NULL
;
148 if (Package
!= NULL
) {
149 ShellCommandLineFreeVarList (Package
);
158 Query all structures Data from SMBIOS table and Display
159 the information to users as required display option.
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.
166 @retval EFI_SUCCESS print is successful.
167 @retval EFI_BAD_BUFFER_SIZE structure is out of the range of SMBIOS table.
173 IN UINT16 QueryHandle
,
175 IN BOOLEAN RandomView
181 // bigger than SMBIOS_STRUCTURE_TABLE.MaxStructureSize
187 // address offset from structure table head.
191 // structure table head.
194 SMBIOS_STRUCTURE_POINTER pStruct
;
195 SMBIOS_STRUCTURE_TABLE
*SMBiosTable
;
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
;
204 if (CompareMem (SMBiosTable
->AnchorString
, "_SM_", 4) == 0) {
206 // Have get SMBIOS table
208 SmbiosPrintEPSInfo (SMBiosTable
, Option
);
210 SmbiosMajorVersion
= SMBiosTable
->MajorVersion
;
211 SmbiosMinorVersion
= SMBiosTable
->MinorVersion
;
213 ShellPrintEx(-1,-1,L
"=========================================================\n");
214 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND
), gShellDebug1HiiHandle
);
216 if (QueryType
== STRUCTURE_TYPE_RANDOM
) {
217 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM
), gShellDebug1HiiHandle
);
219 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE
), gShellDebug1HiiHandle
, QueryType
);
223 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM
), gShellDebug1HiiHandle
);
225 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE
), gShellDebug1HiiHandle
, QueryHandle
);
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");
234 // Get internal commands, such as change options.
236 Status = WaitEnter ();
237 if (EFI_ERROR (Status)) {
238 if (Status == EFI_ABORTED) {
247 // Searching and display structure info
249 Handle
= QueryHandle
;
250 TableHead
= SMBiosTable
->TableAddress
;
252 for (Index
= 0; Index
< SMBiosTable
->NumberOfSmbiosStructures
; Index
++) {
254 // if reach the end of table, break..
256 if (Handle
== STRUCTURE_HANDLE_INVALID
) {
260 // handle then point to the next!
262 if (LibGetSmbiosStructure (&Handle
, Buffer
, &Length
) != DMI_SUCCESS
) {
265 Offset
= (UINT16
) (Offset
+ Length
);
266 pStruct
.Raw
= Buffer
;
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.
273 if (QueryType
!= STRUCTURE_TYPE_RANDOM
&& pStruct
.Hdr
->Type
!= QueryType
) {
277 ShellPrintEx(-1,-1,L
"\n=========================================================\n");
278 ShellPrintHiiEx(-1,-1,NULL
,
279 STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE_HANDLE_DUMP_STRUCT
),
280 gShellDebug1HiiHandle
,
284 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH
), gShellDebug1HiiHandle
, Index
, Length
);
286 // Addr of structure in structure in table
288 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR
), gShellDebug1HiiHandle
, TableHead
+ Offset
);
289 DumpHex (0, 0, Length
, Buffer
);
293 // Get internal commands, such as change options.
295 Status = WaitEnter ();
296 if (EFI_ERROR (Status)) {
297 if (Status == EFI_ABORTED) {
305 if (gShowType
!= SHOW_NONE
) {
307 // check structure legality
309 SmbiosCheckStructure (&pStruct
);
312 // Print structure information
314 SmbiosPrintStructure (&pStruct
, gShowType
);
315 ShellPrintEx(-1,-1,L
"\n");
319 // Get internal commands, such as change options.
321 Status = WaitEnter ();
322 if (EFI_ERROR (Status)) {
323 if (Status == EFI_ABORTED) {
336 ShellPrintEx(-1,-1,L
"\n=========================================================\n");
340 return EFI_BAD_BUFFER_SIZE
;
344 Function to initialize the global mStatisticsTable object.
346 @retval EFI_SUCCESS print is successful.
350 InitSmbiosTableStatistics (
360 SMBIOS_STRUCTURE_POINTER pStruct
;
361 SMBIOS_STRUCTURE_TABLE
*SMBiosTable
;
362 STRUCTURE_STATISTICS
*pStatistics
;
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
;
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
;
376 // Allocate memory to mStatisticsTable
378 if (mStatisticsTable
!= NULL
) {
379 FreePool (mStatisticsTable
);
380 mStatisticsTable
= NULL
;
383 mStatisticsTable
= (STRUCTURE_STATISTICS
*) AllocateZeroPool (SMBiosTable
->NumberOfSmbiosStructures
* sizeof (STRUCTURE_STATISTICS
));
385 if (mStatisticsTable
== NULL
) {
386 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM
), gShellDebug1HiiHandle
);
387 return EFI_OUT_OF_RESOURCES
;
391 pStatistics
= mStatisticsTable
;
394 // search from the first one
396 Handle
= STRUCTURE_HANDLE_INVALID
;
397 LibGetSmbiosStructure (&Handle
, NULL
, NULL
);
398 for (Index
= 1; Index
<= SMBiosTable
->NumberOfSmbiosStructures
; Index
++) {
400 // If reach the end of table, break..
402 if (Handle
== STRUCTURE_HANDLE_INVALID
) {
406 // After LibGetSmbiosStructure(), handle then point to the next!
408 if (LibGetSmbiosStructure (&Handle
, Buffer
, &Length
) != DMI_SUCCESS
) {
412 pStruct
.Raw
= Buffer
;
413 Offset
= (UINT16
) (Offset
+ Length
);
416 // general statistics
418 pStatistics
->Index
= Index
;
419 pStatistics
->Type
= pStruct
.Hdr
->Type
;
420 pStatistics
->Handle
= pStruct
.Hdr
->Handle
;
421 pStatistics
->Length
= Length
;
422 pStatistics
->Addr
= Offset
;
424 pStatistics
= &mStatisticsTable
[Index
];
431 Function to display the global mStatisticsTable object.
433 @param[in] Option ECHO, NORMAL, or DETAIL control the amount of detail displayed.
435 @retval EFI_SUCCESS print is successful.
439 DisplayStatisticsTable (
445 STRUCTURE_STATISTICS
*pStatistics
;
446 SMBIOS_STRUCTURE_TABLE
*SMBiosTable
;
449 if (Option
< SHOW_OUTLINE
) {
453 // display EPS information firstly
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
;
461 ShellPrintEx(-1,-1,L
"\n============================================================\n");
462 SmbiosPrintEPSInfo (SMBiosTable
, Option
);
464 if (Option
< SHOW_NORMAL
) {
468 if (mStatisticsTable
== NULL
) {
469 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS
), gShellDebug1HiiHandle
);
470 return EFI_NOT_FOUND
;
473 ShellPrintEx(-1,-1,L
"============================================================\n");
474 pStatistics
= &mStatisticsTable
[0];
475 Num
= SMBiosTable
->NumberOfSmbiosStructures
;
477 // display statistics table content
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
);
488 ShellPrintEx(-1,-1,L
"\n");
489 pStatistics
= &mStatisticsTable
[Index
];
492 // Display 20 lines and wait for a page break
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) {
512 function to return a string of the detail level.
514 @param[in] ShowType The detail level whose name is desired in clear text.
516 @return A pointer to a string representing the ShowType (or 'undefined type' if not known).
533 return L
"SHOW_OUTLINE";
536 return L
"SHOW_NORMAL";
539 return L
"SHOW_DETAIL";
545 return L
"Undefined type";
551 InitializeSmbiosViewApplicationGetLineHelp (
555 return LibCmdGetStringByToken (STRING_ARRAY_NAME, &EfiSmbiosViewGuid, STRING_TOKEN (STR_SMBIOSVIEW_LINE_HELP), Str);