2 Tools of clarify the content of the smbios table.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "../UefiShellDebug1CommandsLib.h"
17 #include "LibSmbiosView.h"
18 #include "SmbiosView.h"
19 #include "PrintInfo.h"
20 #include "QueryTable.h"
22 UINT8 gShowType
= SHOW_DETAIL
;
23 STATIC STRUCTURE_STATISTICS
*mStatisticsTable
= NULL
;
25 UINT8 SmbiosMajorVersion
;
26 UINT8 SmbiosMinorVersion
;
28 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
37 Function for 'smbiosview' command.
39 @param[in] ImageHandle Handle to the Image (NULL if Internal).
40 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
44 ShellCommandRunSmbiosView (
45 IN EFI_HANDLE ImageHandle
,
46 IN EFI_SYSTEM_TABLE
*SystemTable
55 SHELL_STATUS ShellStatus
;
58 mStatisticsTable
= NULL
;
60 ShellStatus
= SHELL_SUCCESS
;
62 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
63 if (EFI_ERROR(Status
)) {
64 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
65 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"smbiosview", ProblemParam
);
66 FreePool(ProblemParam
);
67 ShellStatus
= SHELL_INVALID_PARAMETER
;
72 if (ShellCommandLineGetCount(Package
) > 1) {
73 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
, L
"smbiosview");
74 ShellStatus
= SHELL_INVALID_PARAMETER
;
75 } else if (ShellCommandLineGetFlag(Package
, L
"-t") && ShellCommandLineGetValue(Package
, L
"-t") == NULL
) {
76 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDebug1HiiHandle
, L
"smbiosview", L
"-t");
77 ShellStatus
= SHELL_INVALID_PARAMETER
;
78 } else if (ShellCommandLineGetFlag(Package
, L
"-h") && ShellCommandLineGetValue(Package
, L
"-h") == NULL
) {
79 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDebug1HiiHandle
, L
"smbiosview", L
"-h");
80 ShellStatus
= SHELL_INVALID_PARAMETER
;
82 (ShellCommandLineGetFlag(Package
, L
"-t") && ShellCommandLineGetFlag(Package
, L
"-h")) ||
83 (ShellCommandLineGetFlag(Package
, L
"-t") && ShellCommandLineGetFlag(Package
, L
"-s")) ||
84 (ShellCommandLineGetFlag(Package
, L
"-t") && ShellCommandLineGetFlag(Package
, L
"-a")) ||
85 (ShellCommandLineGetFlag(Package
, L
"-h") && ShellCommandLineGetFlag(Package
, L
"-s")) ||
86 (ShellCommandLineGetFlag(Package
, L
"-h") && ShellCommandLineGetFlag(Package
, L
"-a")) ||
87 (ShellCommandLineGetFlag(Package
, L
"-s") && ShellCommandLineGetFlag(Package
, L
"-a"))
89 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
, L
"smbiosview");
90 ShellStatus
= SHELL_INVALID_PARAMETER
;
96 Status
= LibSmbiosInit ();
97 if (EFI_ERROR (Status
)) {
98 ShellStatus
= SHELL_NOT_FOUND
;
102 // build statistics table
104 Status
= InitSmbiosTableStatistics ();
105 if (EFI_ERROR (Status
)) {
106 ShellStatus
= SHELL_NOT_FOUND
;
110 StructType
= STRUCTURE_TYPE_RANDOM
;
113 // Initialize the StructHandle to be the first handle
115 StructHandle
= INVALID_HANDLE
;
116 LibGetSmbiosStructure (&StructHandle
, NULL
, NULL
);
118 Temp
= ShellCommandLineGetValue(Package
, L
"-t");
120 StructType
= (UINT8
) ShellStrToUintn (Temp
);
123 Temp
= ShellCommandLineGetValue(Package
, L
"-h");
126 StructHandle
= (UINT16
) ShellStrToUintn(Temp
);
129 if (ShellCommandLineGetFlag(Package
, L
"-s")) {
130 Status
= DisplayStatisticsTable (SHOW_DETAIL
);
131 if (EFI_ERROR(Status
)) {
132 ShellStatus
= SHELL_NOT_FOUND
;
137 if (ShellCommandLineGetFlag(Package
, L
"-a")) {
138 gShowType
= SHOW_ALL
;
141 // Show SMBIOS structure information
143 Status
= SMBiosView (StructType
, StructHandle
, gShowType
, RandomView
);
144 if (EFI_ERROR(Status
)) {
145 ShellStatus
= SHELL_NOT_FOUND
;
153 if (mStatisticsTable
!= NULL
) {
155 // Release statistics table
157 FreePool (mStatisticsTable
);
158 mStatisticsTable
= NULL
;
161 if (Package
!= NULL
) {
162 ShellCommandLineFreeVarList (Package
);
171 Query all structures Data from SMBIOS table and Display
172 the information to users as required display option.
174 @param[in] QueryType Structure type to view.
175 @param[in] QueryHandle Structure handle to view.
176 @param[in] Option Display option: none,outline,normal,detail.
177 @param[in] RandomView Support for -h parameter.
179 @retval EFI_SUCCESS print is successful.
180 @retval EFI_BAD_BUFFER_SIZE structure is out of the range of SMBIOS table.
186 IN UINT16 QueryHandle
,
188 IN BOOLEAN RandomView
196 SMBIOS_STRUCTURE_POINTER SmbiosStruct
;
197 SMBIOS_TABLE_ENTRY_POINT
*SMBiosTable
;
200 LibSmbiosGetEPS (&SMBiosTable
);
201 if (SMBiosTable
== NULL
) {
202 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE
), gShellDebug1HiiHandle
);
203 return EFI_BAD_BUFFER_SIZE
;
206 if (CompareMem (SMBiosTable
->AnchorString
, "_SM_", 4) == 0) {
208 // Have got SMBIOS table
210 SmbiosPrintEPSInfo (SMBiosTable
, Option
);
212 SmbiosMajorVersion
= SMBiosTable
->MajorVersion
;
213 SmbiosMinorVersion
= SMBiosTable
->MinorVersion
;
215 ShellPrintEx(-1,-1,L
"=========================================================\n");
216 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND
), gShellDebug1HiiHandle
);
218 if (QueryType
== STRUCTURE_TYPE_RANDOM
) {
219 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM
), gShellDebug1HiiHandle
);
221 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE
), gShellDebug1HiiHandle
, QueryType
);
225 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM
), gShellDebug1HiiHandle
);
227 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE
), gShellDebug1HiiHandle
, QueryHandle
);
230 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SHOWTYPE
), gShellDebug1HiiHandle
);
231 ShellPrintEx(-1,-1,GetShowTypeString (gShowType
));
232 ShellPrintEx(-1,-1,L
"\n\n");
236 // Get internal commands, such as change options.
238 Status = WaitEnter ();
239 if (EFI_ERROR (Status)) {
240 if (Status == EFI_ABORTED) {
249 // Searching and display structure info
251 Handle
= QueryHandle
;
252 for (Index
= 0; Index
< SMBiosTable
->NumberOfSmbiosStructures
; Index
++) {
254 // if reach the end of table, break..
256 if (Handle
== INVALID_HANDLE
) {
260 // handle then point to the next!
262 if (LibGetSmbiosStructure (&Handle
, &Buffer
, &Length
) != DMI_SUCCESS
) {
266 SmbiosStruct
.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
&& SmbiosStruct
.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
,
281 SmbiosStruct
.Hdr
->Type
,
282 SmbiosStruct
.Hdr
->Handle
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
, (UINTN
) Buffer
);
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 // Print structure information
309 SmbiosPrintStructure (&SmbiosStruct
, gShowType
);
310 ShellPrintEx(-1,-1,L
"\n");
314 // Get internal commands, such as change options.
316 Status = WaitEnter ();
317 if (EFI_ERROR (Status)) {
318 if (Status == EFI_ABORTED) {
330 // Support Execution Interrupt.
332 if (ShellGetExecutionBreakFlag ()) {
337 ShellPrintEx(-1,-1,L
"\n=========================================================\n");
341 return EFI_BAD_BUFFER_SIZE
;
345 Function to initialize the global mStatisticsTable object.
347 @retval EFI_SUCCESS print is successful.
351 InitSmbiosTableStatistics (
361 SMBIOS_STRUCTURE_POINTER SmbiosStruct
;
362 SMBIOS_TABLE_ENTRY_POINT
*SMBiosTable
;
363 STRUCTURE_STATISTICS
*StatisticsPointer
;
366 LibSmbiosGetEPS (&SMBiosTable
);
367 if (SMBiosTable
== NULL
) {
368 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE
), gShellDebug1HiiHandle
);
369 return EFI_NOT_FOUND
;
372 if (CompareMem (SMBiosTable
->AnchorString
, "_SM_", 4) != 0) {
373 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SMBIOS_TABLE
), gShellDebug1HiiHandle
);
374 return EFI_INVALID_PARAMETER
;
377 // Allocate memory to mStatisticsTable
379 if (mStatisticsTable
!= NULL
) {
380 FreePool (mStatisticsTable
);
381 mStatisticsTable
= NULL
;
384 mStatisticsTable
= (STRUCTURE_STATISTICS
*) AllocateZeroPool (SMBiosTable
->NumberOfSmbiosStructures
* sizeof (STRUCTURE_STATISTICS
));
386 if (mStatisticsTable
== NULL
) {
387 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM
), gShellDebug1HiiHandle
);
388 return EFI_OUT_OF_RESOURCES
;
392 StatisticsPointer
= mStatisticsTable
;
395 // search from the first one
397 Handle
= INVALID_HANDLE
;
398 LibGetSmbiosStructure (&Handle
, NULL
, NULL
);
399 for (Index
= 1; Index
<= SMBiosTable
->NumberOfSmbiosStructures
; Index
++) {
401 // If reach the end of table, break..
403 if (Handle
== INVALID_HANDLE
) {
407 // After LibGetSmbiosStructure(), handle then point to the next!
409 if (LibGetSmbiosStructure (&Handle
, &Buffer
, &Length
) != DMI_SUCCESS
) {
413 SmbiosStruct
.Raw
= Buffer
;
416 // general statistics
418 StatisticsPointer
->Index
= Index
;
419 StatisticsPointer
->Type
= SmbiosStruct
.Hdr
->Type
;
420 StatisticsPointer
->Handle
= SmbiosStruct
.Hdr
->Handle
;
421 StatisticsPointer
->Length
= Length
;
422 StatisticsPointer
->Addr
= Offset
;
424 Offset
= (UINT16
) (Offset
+ Length
);
426 StatisticsPointer
= &mStatisticsTable
[Index
];
433 Function to display the global mStatisticsTable object.
435 @param[in] Option ECHO, NORMAL, or DETAIL control the amount of detail displayed.
437 @retval EFI_SUCCESS print is successful.
441 DisplayStatisticsTable (
447 STRUCTURE_STATISTICS
*StatisticsPointer
;
448 SMBIOS_TABLE_ENTRY_POINT
*SMBiosTable
;
451 if (Option
< SHOW_OUTLINE
) {
455 // display EPS information firstly
457 LibSmbiosGetEPS (&SMBiosTable
);
458 if (SMBiosTable
== NULL
) {
459 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE
), gShellDebug1HiiHandle
);
460 return EFI_UNSUPPORTED
;
463 ShellPrintEx(-1,-1,L
"\n============================================================\n");
464 SmbiosPrintEPSInfo (SMBiosTable
, Option
);
466 if (Option
< SHOW_NORMAL
) {
470 if (mStatisticsTable
== NULL
) {
471 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS
), gShellDebug1HiiHandle
);
472 return EFI_NOT_FOUND
;
475 ShellPrintEx(-1,-1,L
"============================================================\n");
476 StatisticsPointer
= &mStatisticsTable
[0];
477 Num
= SMBiosTable
->NumberOfSmbiosStructures
;
479 // display statistics table content
481 for (Index
= 1; Index
<= Num
; Index
++) {
482 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX
), gShellDebug1HiiHandle
, StatisticsPointer
->Index
);
483 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE
), gShellDebug1HiiHandle
, StatisticsPointer
->Type
);
484 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_HANDLE
), gShellDebug1HiiHandle
, StatisticsPointer
->Handle
);
485 if (Option
>= SHOW_DETAIL
) {
486 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OFFSET
), gShellDebug1HiiHandle
, StatisticsPointer
->Addr
);
487 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_LENGTH
), gShellDebug1HiiHandle
, StatisticsPointer
->Length
);
490 ShellPrintEx(-1,-1,L
"\n");
491 StatisticsPointer
= &mStatisticsTable
[Index
];
494 // Display 20 lines and wait for a page break
496 if (Index % 20 == 0) {
497 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ENTER_CONTINUE), gShellDebug1HiiHandle);
498 Status = WaitEnter ();
499 if (EFI_ERROR (Status)) {
500 if (Status == EFI_ABORTED) {
514 function to return a string of the detail level.
516 @param[in] ShowType The detail level whose name is desired in clear text.
518 @return A pointer to a string representing the ShowType (or 'undefined type' if not known).
535 return L
"SHOW_OUTLINE";
538 return L
"SHOW_NORMAL";
541 return L
"SHOW_DETAIL";
547 return L
"Undefined type";