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
;
68 } else if (ShellCommandLineGetFlag(Package
, L
"-t") && ShellCommandLineGetValue(Package
, L
"-t") == NULL
) {
69 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDebug1HiiHandle
, L
"-t");
70 ShellStatus
= SHELL_INVALID_PARAMETER
;
71 } else if (ShellCommandLineGetFlag(Package
, L
"-h") && ShellCommandLineGetValue(Package
, L
"-h") == NULL
) {
72 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDebug1HiiHandle
, L
"-h");
73 ShellStatus
= SHELL_INVALID_PARAMETER
;
75 (ShellCommandLineGetFlag(Package
, L
"-t") && ShellCommandLineGetFlag(Package
, L
"-h")) ||
76 (ShellCommandLineGetFlag(Package
, L
"-t") && ShellCommandLineGetFlag(Package
, L
"-s")) ||
77 (ShellCommandLineGetFlag(Package
, L
"-t") && ShellCommandLineGetFlag(Package
, L
"-a")) ||
78 (ShellCommandLineGetFlag(Package
, L
"-h") && ShellCommandLineGetFlag(Package
, L
"-s")) ||
79 (ShellCommandLineGetFlag(Package
, L
"-h") && ShellCommandLineGetFlag(Package
, L
"-a")) ||
80 (ShellCommandLineGetFlag(Package
, L
"-s") && ShellCommandLineGetFlag(Package
, L
"-a"))
82 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
);
83 ShellStatus
= SHELL_INVALID_PARAMETER
;
89 Status
= LibSmbiosInit ();
90 if (EFI_ERROR (Status
)) {
91 ShellStatus
= SHELL_NOT_FOUND
;
95 // build statistics table
97 Status
= InitSmbiosTableStatistics ();
98 if (EFI_ERROR (Status
)) {
99 ShellStatus
= SHELL_NOT_FOUND
;
103 StructType
= STRUCTURE_TYPE_RANDOM
;
106 // Initialize the StructHandle to be the first handle
108 StructHandle
= STRUCTURE_HANDLE_INVALID
;
109 LibGetSmbiosStructure (&StructHandle
, NULL
, NULL
);
111 Temp
= ShellCommandLineGetValue(Package
, L
"-t");
113 StructType
= (UINT8
) ShellStrToUintn (Temp
);
116 Temp
= ShellCommandLineGetValue(Package
, L
"-h");
119 StructHandle
= (UINT16
) ShellStrToUintn(Temp
);
122 if (ShellCommandLineGetFlag(Package
, L
"-s")) {
123 Status
= DisplayStatisticsTable (SHOW_DETAIL
);
124 if (EFI_ERROR(Status
)) {
125 ShellStatus
= SHELL_NOT_FOUND
;
130 if (ShellCommandLineGetFlag(Package
, L
"-a")) {
131 gShowType
= SHOW_ALL
;
134 // Show SMBIOS structure information
136 Status
= SMBiosView (StructType
, StructHandle
, gShowType
, RandomView
);
137 if (EFI_ERROR(Status
)) {
138 ShellStatus
= SHELL_NOT_FOUND
;
146 if (mStatisticsTable
!= NULL
) {
148 // Release statistics table
150 FreePool (mStatisticsTable
);
151 mStatisticsTable
= NULL
;
154 if (Package
!= NULL
) {
155 ShellCommandLineFreeVarList (Package
);
164 Query all structures Data from SMBIOS table and Display
165 the information to users as required display option.
167 @param[in] QueryType Structure type to view.
168 @param[in] QueryHandle Structure handle to view.
169 @param[in] Option Display option: none,outline,normal,detail.
170 @param[in] RandomView Support for -h parameter.
172 @retval EFI_SUCCESS print is successful.
173 @retval EFI_BAD_BUFFER_SIZE structure is out of the range of SMBIOS table.
179 IN UINT16 QueryHandle
,
181 IN BOOLEAN RandomView
187 // bigger than SMBIOS_STRUCTURE_TABLE.MaxStructureSize
193 // address offset from structure table head.
197 // structure table head.
200 SMBIOS_STRUCTURE_POINTER pStruct
;
201 SMBIOS_STRUCTURE_TABLE
*SMBiosTable
;
204 LibSmbiosGetEPS (&SMBiosTable
);
205 if (SMBiosTable
== NULL
) {
206 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE
), gShellDebug1HiiHandle
);
207 return EFI_BAD_BUFFER_SIZE
;
210 if (CompareMem (SMBiosTable
->AnchorString
, "_SM_", 4) == 0) {
212 // Have get SMBIOS table
214 SmbiosPrintEPSInfo (SMBiosTable
, Option
);
216 SmbiosMajorVersion
= SMBiosTable
->MajorVersion
;
217 SmbiosMinorVersion
= SMBiosTable
->MinorVersion
;
219 ShellPrintEx(-1,-1,L
"=========================================================\n");
220 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND
), gShellDebug1HiiHandle
);
222 if (QueryType
== STRUCTURE_TYPE_RANDOM
) {
223 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM
), gShellDebug1HiiHandle
);
225 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE
), gShellDebug1HiiHandle
, QueryType
);
229 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM
), gShellDebug1HiiHandle
);
231 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE
), gShellDebug1HiiHandle
, QueryHandle
);
234 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SHOWTYPE
), gShellDebug1HiiHandle
);
235 ShellPrintEx(-1,-1,GetShowTypeString (gShowType
));
236 ShellPrintEx(-1,-1,L
"\n\n");
240 // Get internal commands, such as change options.
242 Status = WaitEnter ();
243 if (EFI_ERROR (Status)) {
244 if (Status == EFI_ABORTED) {
253 // Searching and display structure info
255 Handle
= QueryHandle
;
256 TableHead
= SMBiosTable
->TableAddress
;
258 for (Index
= 0; Index
< SMBiosTable
->NumberOfSmbiosStructures
; Index
++) {
260 // if reach the end of table, break..
262 if (Handle
== STRUCTURE_HANDLE_INVALID
) {
266 // handle then point to the next!
268 if (LibGetSmbiosStructure (&Handle
, Buffer
, &Length
) != DMI_SUCCESS
) {
271 Offset
= (UINT16
) (Offset
+ Length
);
272 pStruct
.Raw
= Buffer
;
275 // if QueryType==Random, print this structure.
276 // if QueryType!=Random, but Hdr->Type==QueryType, also print it.
277 // only if QueryType != Random and Hdr->Type != QueryType, skiped it.
279 if (QueryType
!= STRUCTURE_TYPE_RANDOM
&& pStruct
.Hdr
->Type
!= QueryType
) {
283 ShellPrintEx(-1,-1,L
"\n=========================================================\n");
284 ShellPrintHiiEx(-1,-1,NULL
,
285 STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE_HANDLE_DUMP_STRUCT
),
286 gShellDebug1HiiHandle
,
290 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH
), gShellDebug1HiiHandle
, Index
, Length
);
292 // Addr of structure in structure in table
294 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR
), gShellDebug1HiiHandle
, TableHead
+ Offset
);
295 DumpHex (0, 0, Length
, Buffer
);
299 // Get internal commands, such as change options.
301 Status = WaitEnter ();
302 if (EFI_ERROR (Status)) {
303 if (Status == EFI_ABORTED) {
311 if (gShowType
!= SHOW_NONE
) {
313 // check structure legality
315 SmbiosCheckStructure (&pStruct
);
318 // Print structure information
320 SmbiosPrintStructure (&pStruct
, gShowType
);
321 ShellPrintEx(-1,-1,L
"\n");
325 // Get internal commands, such as change options.
327 Status = WaitEnter ();
328 if (EFI_ERROR (Status)) {
329 if (Status == EFI_ABORTED) {
342 ShellPrintEx(-1,-1,L
"\n=========================================================\n");
346 return EFI_BAD_BUFFER_SIZE
;
350 Function to initialize the global mStatisticsTable object.
352 @retval EFI_SUCCESS print is successful.
356 InitSmbiosTableStatistics (
366 SMBIOS_STRUCTURE_POINTER pStruct
;
367 SMBIOS_STRUCTURE_TABLE
*SMBiosTable
;
368 STRUCTURE_STATISTICS
*pStatistics
;
371 LibSmbiosGetEPS (&SMBiosTable
);
372 if (SMBiosTable
== NULL
) {
373 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE
), gShellDebug1HiiHandle
);
374 return EFI_NOT_FOUND
;
377 if (CompareMem (SMBiosTable
->AnchorString
, "_SM_", 4) != 0) {
378 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SMBIOS_TABLE
), gShellDebug1HiiHandle
);
379 return EFI_INVALID_PARAMETER
;
382 // Allocate memory to mStatisticsTable
384 if (mStatisticsTable
!= NULL
) {
385 FreePool (mStatisticsTable
);
386 mStatisticsTable
= NULL
;
389 mStatisticsTable
= (STRUCTURE_STATISTICS
*) AllocateZeroPool (SMBiosTable
->NumberOfSmbiosStructures
* sizeof (STRUCTURE_STATISTICS
));
391 if (mStatisticsTable
== NULL
) {
392 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM
), gShellDebug1HiiHandle
);
393 return EFI_OUT_OF_RESOURCES
;
397 pStatistics
= mStatisticsTable
;
400 // search from the first one
402 Handle
= STRUCTURE_HANDLE_INVALID
;
403 LibGetSmbiosStructure (&Handle
, NULL
, NULL
);
404 for (Index
= 1; Index
<= SMBiosTable
->NumberOfSmbiosStructures
; Index
++) {
406 // If reach the end of table, break..
408 if (Handle
== STRUCTURE_HANDLE_INVALID
) {
412 // After LibGetSmbiosStructure(), handle then point to the next!
414 if (LibGetSmbiosStructure (&Handle
, Buffer
, &Length
) != DMI_SUCCESS
) {
418 pStruct
.Raw
= Buffer
;
419 Offset
= (UINT16
) (Offset
+ Length
);
422 // general statistics
424 pStatistics
->Index
= Index
;
425 pStatistics
->Type
= pStruct
.Hdr
->Type
;
426 pStatistics
->Handle
= pStruct
.Hdr
->Handle
;
427 pStatistics
->Length
= Length
;
428 pStatistics
->Addr
= Offset
;
430 pStatistics
= &mStatisticsTable
[Index
];
437 Function to display the global mStatisticsTable object.
439 @param[in] Option ECHO, NORMAL, or DETAIL control the amount of detail displayed.
441 @retval EFI_SUCCESS print is successful.
445 DisplayStatisticsTable (
451 STRUCTURE_STATISTICS
*pStatistics
;
452 SMBIOS_STRUCTURE_TABLE
*SMBiosTable
;
455 if (Option
< SHOW_OUTLINE
) {
459 // display EPS information firstly
461 LibSmbiosGetEPS (&SMBiosTable
);
462 if (SMBiosTable
== NULL
) {
463 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE
), gShellDebug1HiiHandle
);
464 return EFI_UNSUPPORTED
;
467 ShellPrintEx(-1,-1,L
"\n============================================================\n");
468 SmbiosPrintEPSInfo (SMBiosTable
, Option
);
470 if (Option
< SHOW_NORMAL
) {
474 if (mStatisticsTable
== NULL
) {
475 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS
), gShellDebug1HiiHandle
);
476 return EFI_NOT_FOUND
;
479 ShellPrintEx(-1,-1,L
"============================================================\n");
480 pStatistics
= &mStatisticsTable
[0];
481 Num
= SMBiosTable
->NumberOfSmbiosStructures
;
483 // display statistics table content
485 for (Index
= 1; Index
<= Num
; Index
++) {
486 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX
), gShellDebug1HiiHandle
, pStatistics
->Index
);
487 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE
), gShellDebug1HiiHandle
, pStatistics
->Type
);
488 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_HANDLE
), gShellDebug1HiiHandle
, pStatistics
->Handle
);
489 if (Option
>= SHOW_DETAIL
) {
490 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OFFSET
), gShellDebug1HiiHandle
, pStatistics
->Addr
);
491 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_LENGTH
), gShellDebug1HiiHandle
, pStatistics
->Length
);
494 ShellPrintEx(-1,-1,L
"\n");
495 pStatistics
= &mStatisticsTable
[Index
];
498 // Display 20 lines and wait for a page break
500 if (Index % 20 == 0) {
501 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ENTER_CONTINUE), gShellDebug1HiiHandle);
502 Status = WaitEnter ();
503 if (EFI_ERROR (Status)) {
504 if (Status == EFI_ABORTED) {
518 function to return a string of the detail level.
520 @param[in] ShowType The detail level whose name is desired in clear text.
522 @return A pointer to a string representing the ShowType (or 'undefined type' if not known).
539 return L
"SHOW_OUTLINE";
542 return L
"SHOW_NORMAL";
545 return L
"SHOW_DETAIL";
551 return L
"Undefined type";
557 InitializeSmbiosViewApplicationGetLineHelp (
561 return LibCmdGetStringByToken (STRING_ARRAY_NAME, &EfiSmbiosViewGuid, STRING_TOKEN (STR_SMBIOSVIEW_LINE_HELP), Str);