2 Tools of clarify the content of the smbios table.
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
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
[] = {
36 Function for 'smbiosview' command.
38 @param[in] ImageHandle Handle to the Image (NULL if Internal).
39 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
43 ShellCommandRunSmbiosView (
44 IN EFI_HANDLE ImageHandle
,
45 IN EFI_SYSTEM_TABLE
*SystemTable
54 SHELL_STATUS ShellStatus
;
57 mStatisticsTable
= NULL
;
59 ShellStatus
= SHELL_SUCCESS
;
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
;
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
;
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"))
88 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
);
89 ShellStatus
= SHELL_INVALID_PARAMETER
;
95 Status
= LibSmbiosInit ();
96 if (EFI_ERROR (Status
)) {
97 ShellStatus
= SHELL_NOT_FOUND
;
101 // build statistics table
103 Status
= InitSmbiosTableStatistics ();
104 if (EFI_ERROR (Status
)) {
105 ShellStatus
= SHELL_NOT_FOUND
;
109 StructType
= STRUCTURE_TYPE_RANDOM
;
112 // Initialize the StructHandle to be the first handle
114 StructHandle
= INVALID_HANDLE
;
115 LibGetSmbiosStructure (&StructHandle
, NULL
, NULL
);
117 Temp
= ShellCommandLineGetValue(Package
, L
"-t");
119 StructType
= (UINT8
) ShellStrToUintn (Temp
);
122 Temp
= ShellCommandLineGetValue(Package
, L
"-h");
125 StructHandle
= (UINT16
) ShellStrToUintn(Temp
);
128 if (ShellCommandLineGetFlag(Package
, L
"-s")) {
129 Status
= DisplayStatisticsTable (SHOW_DETAIL
);
130 if (EFI_ERROR(Status
)) {
131 ShellStatus
= SHELL_NOT_FOUND
;
136 if (ShellCommandLineGetFlag(Package
, L
"-a")) {
137 gShowType
= SHOW_ALL
;
140 // Show SMBIOS structure information
142 Status
= SMBiosView (StructType
, StructHandle
, gShowType
, RandomView
);
143 if (EFI_ERROR(Status
)) {
144 ShellStatus
= SHELL_NOT_FOUND
;
152 if (mStatisticsTable
!= NULL
) {
154 // Release statistics table
156 FreePool (mStatisticsTable
);
157 mStatisticsTable
= NULL
;
160 if (Package
!= NULL
) {
161 ShellCommandLineFreeVarList (Package
);
170 Query all structures Data from SMBIOS table and Display
171 the information to users as required display option.
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.
178 @retval EFI_SUCCESS print is successful.
179 @retval EFI_BAD_BUFFER_SIZE structure is out of the range of SMBIOS table.
185 IN UINT16 QueryHandle
,
187 IN BOOLEAN RandomView
195 SMBIOS_STRUCTURE_POINTER SmbiosStruct
;
196 SMBIOS_TABLE_ENTRY_POINT
*SMBiosTable
;
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
;
205 if (CompareMem (SMBiosTable
->AnchorString
, "_SM_", 4) == 0) {
207 // Have got SMBIOS table
209 SmbiosPrintEPSInfo (SMBiosTable
, Option
);
211 SmbiosMajorVersion
= SMBiosTable
->MajorVersion
;
212 SmbiosMinorVersion
= SMBiosTable
->MinorVersion
;
214 ShellPrintEx(-1,-1,L
"=========================================================\n");
215 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND
), gShellDebug1HiiHandle
);
217 if (QueryType
== STRUCTURE_TYPE_RANDOM
) {
218 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM
), gShellDebug1HiiHandle
);
220 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE
), gShellDebug1HiiHandle
, QueryType
);
224 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM
), gShellDebug1HiiHandle
);
226 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE
), gShellDebug1HiiHandle
, QueryHandle
);
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");
235 // Get internal commands, such as change options.
237 Status = WaitEnter ();
238 if (EFI_ERROR (Status)) {
239 if (Status == EFI_ABORTED) {
248 // Searching and display structure info
250 Handle
= QueryHandle
;
251 for (Index
= 0; Index
< SMBiosTable
->NumberOfSmbiosStructures
; Index
++) {
253 // if reach the end of table, break..
255 if (Handle
== INVALID_HANDLE
) {
259 // handle then point to the next!
261 if (LibGetSmbiosStructure (&Handle
, &Buffer
, &Length
) != DMI_SUCCESS
) {
265 SmbiosStruct
.Raw
= Buffer
;
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.
272 if (QueryType
!= STRUCTURE_TYPE_RANDOM
&& SmbiosStruct
.Hdr
->Type
!= QueryType
) {
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
283 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH
), gShellDebug1HiiHandle
, Index
, Length
);
285 // Addr of structure in structure in table
287 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR
), gShellDebug1HiiHandle
, (UINTN
) Buffer
);
288 DumpHex (0, 0, Length
, Buffer
);
292 // Get internal commands, such as change options.
294 Status = WaitEnter ();
295 if (EFI_ERROR (Status)) {
296 if (Status == EFI_ABORTED) {
304 if (gShowType
!= SHOW_NONE
) {
306 // Print structure information
308 SmbiosPrintStructure (&SmbiosStruct
, gShowType
);
309 ShellPrintEx(-1,-1,L
"\n");
313 // Get internal commands, such as change options.
315 Status = WaitEnter ();
316 if (EFI_ERROR (Status)) {
317 if (Status == EFI_ABORTED) {
329 // Support Execution Interrupt.
331 if (ShellGetExecutionBreakFlag ()) {
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 SmbiosStruct
;
361 SMBIOS_TABLE_ENTRY_POINT
*SMBiosTable
;
362 STRUCTURE_STATISTICS
*StatisticsPointer
;
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 StatisticsPointer
= mStatisticsTable
;
394 // search from the first one
396 Handle
= INVALID_HANDLE
;
397 LibGetSmbiosStructure (&Handle
, NULL
, NULL
);
398 for (Index
= 1; Index
<= SMBiosTable
->NumberOfSmbiosStructures
; Index
++) {
400 // If reach the end of table, break..
402 if (Handle
== INVALID_HANDLE
) {
406 // After LibGetSmbiosStructure(), handle then point to the next!
408 if (LibGetSmbiosStructure (&Handle
, &Buffer
, &Length
) != DMI_SUCCESS
) {
412 SmbiosStruct
.Raw
= Buffer
;
415 // general statistics
417 StatisticsPointer
->Index
= Index
;
418 StatisticsPointer
->Type
= SmbiosStruct
.Hdr
->Type
;
419 StatisticsPointer
->Handle
= SmbiosStruct
.Hdr
->Handle
;
420 StatisticsPointer
->Length
= Length
;
421 StatisticsPointer
->Addr
= Offset
;
423 Offset
= (UINT16
) (Offset
+ Length
);
425 StatisticsPointer
= &mStatisticsTable
[Index
];
432 Function to display the global mStatisticsTable object.
434 @param[in] Option ECHO, NORMAL, or DETAIL control the amount of detail displayed.
436 @retval EFI_SUCCESS print is successful.
440 DisplayStatisticsTable (
446 STRUCTURE_STATISTICS
*StatisticsPointer
;
447 SMBIOS_TABLE_ENTRY_POINT
*SMBiosTable
;
450 if (Option
< SHOW_OUTLINE
) {
454 // display EPS information firstly
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
;
462 ShellPrintEx(-1,-1,L
"\n============================================================\n");
463 SmbiosPrintEPSInfo (SMBiosTable
, Option
);
465 if (Option
< SHOW_NORMAL
) {
469 if (mStatisticsTable
== NULL
) {
470 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS
), gShellDebug1HiiHandle
);
471 return EFI_NOT_FOUND
;
474 ShellPrintEx(-1,-1,L
"============================================================\n");
475 StatisticsPointer
= &mStatisticsTable
[0];
476 Num
= SMBiosTable
->NumberOfSmbiosStructures
;
478 // display statistics table content
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
);
489 ShellPrintEx(-1,-1,L
"\n");
490 StatisticsPointer
= &mStatisticsTable
[Index
];
493 // Display 20 lines and wait for a page break
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) {
513 function to return a string of the detail level.
515 @param[in] ShowType The detail level whose name is desired in clear text.
517 @return A pointer to a string representing the ShowType (or 'undefined type' if not known).
534 return L
"SHOW_OUTLINE";
537 return L
"SHOW_NORMAL";
540 return L
"SHOW_DETAIL";
546 return L
"Undefined type";