2 Tools of clarify the content of the smbios table.
4 Copyright (c) 2005 - 2010, 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 (EmptyParamList
, &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
;
73 Status
= LibSmbiosInit ();
74 if (EFI_ERROR (Status
)) {
75 ShellStatus
= SHELL_NOT_FOUND
;
79 // build statistics table
81 Status
= InitSmbiosTableStatistics ();
82 if (EFI_ERROR (Status
)) {
83 ShellStatus
= SHELL_NOT_FOUND
;
87 StructType
= STRUCTURE_TYPE_RANDOM
;
90 // Initialize the StructHandle to be the first handle
92 StructHandle
= STRUCTURE_HANDLE_INVALID
;
93 LibGetSmbiosStructure (&StructHandle
, NULL
, NULL
);
95 Temp
= ShellCommandLineGetValue(Package
, L
"-t");
97 StructType
= (UINT8
) ShellStrToUintn (Temp
);
100 Temp
= ShellCommandLineGetValue(Package
, L
"-h");
103 StructHandle
= (UINT16
) ShellStrToUintn(Temp
);
106 if (ShellCommandLineGetFlag(Package
, L
"-s")) {
107 Status
= DisplayStatisticsTable (SHOW_DETAIL
);
108 if (EFI_ERROR(Status
)) {
109 ShellStatus
= SHELL_NOT_FOUND
;
114 if (ShellCommandLineGetFlag(Package
, L
"-a")) {
115 gShowType
= SHOW_ALL
;
118 // Show SMBIOS structure information
120 Status
= SMBiosView (StructType
, StructHandle
, gShowType
, RandomView
);
121 if (EFI_ERROR(Status
)) {
122 ShellStatus
= SHELL_NOT_FOUND
;
130 if (mStatisticsTable
!= NULL
) {
132 // Release statistics table
134 FreePool (mStatisticsTable
);
135 mStatisticsTable
= NULL
;
138 if (Package
!= NULL
) {
139 ShellCommandLineFreeVarList (Package
);
148 Query all structures Data from SMBIOS table and Display
149 the information to users as required display option.
151 @param[in] QueryType Structure type to view.
152 @param[in] QueryHandle Structure handle to view.
153 @param[in] Option Display option: none,outline,normal,detail.
154 @param[in] RandomView Support for -h parameter.
156 @retval EFI_SUCCESS print is successful.
157 @retval EFI_BAD_BUFFER_SIZE structure is out of the range of SMBIOS table.
163 IN UINT16 QueryHandle
,
165 IN BOOLEAN RandomView
171 // bigger than SMBIOS_STRUCTURE_TABLE.MaxStructureSize
177 // address offset from structure table head.
181 // structure table head.
184 SMBIOS_STRUCTURE_POINTER pStruct
;
185 SMBIOS_STRUCTURE_TABLE
*SMBiosTable
;
188 LibSmbiosGetEPS (&SMBiosTable
);
189 if (SMBiosTable
== NULL
) {
190 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE
), gShellDebug1HiiHandle
);
191 return EFI_BAD_BUFFER_SIZE
;
194 if (CompareMem (SMBiosTable
->AnchorString
, "_SM_", 4) == 0) {
196 // Have get SMBIOS table
198 SmbiosPrintEPSInfo (SMBiosTable
, Option
);
200 SmbiosMajorVersion
= SMBiosTable
->MajorVersion
;
201 SmbiosMinorVersion
= SMBiosTable
->MinorVersion
;
203 ShellPrintEx(-1,-1,L
"=========================================================\n");
204 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND
), gShellDebug1HiiHandle
);
206 if (QueryType
== STRUCTURE_TYPE_RANDOM
) {
207 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM
), gShellDebug1HiiHandle
);
209 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE
), gShellDebug1HiiHandle
, QueryType
);
213 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM
), gShellDebug1HiiHandle
);
215 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE
), gShellDebug1HiiHandle
, QueryHandle
);
218 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SHOWTYPE
), gShellDebug1HiiHandle
);
219 ShellPrintEx(-1,-1,GetShowTypeString (gShowType
));
220 ShellPrintEx(-1,-1,L
"\n\n");
224 // Get internal commands, such as change options.
226 Status = WaitEnter ();
227 if (EFI_ERROR (Status)) {
228 if (Status == EFI_ABORTED) {
237 // Searching and display structure info
239 Handle
= QueryHandle
;
240 TableHead
= SMBiosTable
->TableAddress
;
242 for (Index
= 0; Index
< SMBiosTable
->NumberOfSmbiosStructures
; Index
++) {
244 // if reach the end of table, break..
246 if (Handle
== STRUCTURE_HANDLE_INVALID
) {
250 // handle then point to the next!
252 if (LibGetSmbiosStructure (&Handle
, Buffer
, &Length
) != DMI_SUCCESS
) {
255 Offset
= (UINT16
) (Offset
+ Length
);
256 pStruct
.Raw
= Buffer
;
259 // if QueryType==Random, print this structure.
260 // if QueryType!=Random, but Hdr->Type==QueryType, also print it.
261 // only if QueryType != Random and Hdr->Type != QueryType, skiped it.
263 if (QueryType
!= STRUCTURE_TYPE_RANDOM
&& pStruct
.Hdr
->Type
!= QueryType
) {
267 ShellPrintEx(-1,-1,L
"\n=========================================================\n");
268 ShellPrintHiiEx(-1,-1,NULL
,
269 STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE_HANDLE_DUMP_STRUCT
),
270 gShellDebug1HiiHandle
,
274 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH
), gShellDebug1HiiHandle
, Index
, Length
);
276 // Addr of structure in structure in table
278 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR
), gShellDebug1HiiHandle
, TableHead
+ Offset
);
279 DumpHex (0, 0, Length
, Buffer
);
283 // Get internal commands, such as change options.
285 Status = WaitEnter ();
286 if (EFI_ERROR (Status)) {
287 if (Status == EFI_ABORTED) {
295 if (gShowType
!= SHOW_NONE
) {
297 // check structure legality
299 SmbiosCheckStructure (&pStruct
);
302 // Print structure information
304 SmbiosPrintStructure (&pStruct
, gShowType
);
305 ShellPrintEx(-1,-1,L
"\n");
309 // Get internal commands, such as change options.
311 Status = WaitEnter ();
312 if (EFI_ERROR (Status)) {
313 if (Status == EFI_ABORTED) {
326 ShellPrintEx(-1,-1,L
"\n=========================================================\n");
330 return EFI_BAD_BUFFER_SIZE
;
334 Function to initialize the global mStatisticsTable object.
336 @retval EFI_SUCCESS print is successful.
340 InitSmbiosTableStatistics (
350 SMBIOS_STRUCTURE_POINTER pStruct
;
351 SMBIOS_STRUCTURE_TABLE
*SMBiosTable
;
352 STRUCTURE_STATISTICS
*pStatistics
;
355 LibSmbiosGetEPS (&SMBiosTable
);
356 if (SMBiosTable
== NULL
) {
357 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE
), gShellDebug1HiiHandle
);
358 return EFI_NOT_FOUND
;
361 if (CompareMem (SMBiosTable
->AnchorString
, "_SM_", 4) != 0) {
362 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SMBIOS_TABLE
), gShellDebug1HiiHandle
);
363 return EFI_INVALID_PARAMETER
;
366 // Allocate memory to mStatisticsTable
368 if (mStatisticsTable
!= NULL
) {
369 FreePool (mStatisticsTable
);
370 mStatisticsTable
= NULL
;
373 mStatisticsTable
= (STRUCTURE_STATISTICS
*) AllocatePool (SMBiosTable
->NumberOfSmbiosStructures
* sizeof (STRUCTURE_STATISTICS
));
375 if (mStatisticsTable
== NULL
) {
376 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM
), gShellDebug1HiiHandle
);
377 return EFI_OUT_OF_RESOURCES
;
381 pStatistics
= mStatisticsTable
;
384 // search from the first one
386 Handle
= STRUCTURE_HANDLE_INVALID
;
387 LibGetSmbiosStructure (&Handle
, NULL
, NULL
);
388 for (Index
= 1; Index
<= SMBiosTable
->NumberOfSmbiosStructures
; Index
++) {
390 // If reach the end of table, break..
392 if (Handle
== STRUCTURE_HANDLE_INVALID
) {
396 // After LibGetSmbiosStructure(), handle then point to the next!
398 if (LibGetSmbiosStructure (&Handle
, Buffer
, &Length
) != DMI_SUCCESS
) {
402 pStruct
.Raw
= Buffer
;
403 Offset
= (UINT16
) (Offset
+ Length
);
406 // general statistics
408 pStatistics
->Index
= Index
;
409 pStatistics
->Type
= pStruct
.Hdr
->Type
;
410 pStatistics
->Handle
= pStruct
.Hdr
->Handle
;
411 pStatistics
->Length
= Length
;
412 pStatistics
->Addr
= Offset
;
414 pStatistics
= &mStatisticsTable
[Index
];
421 Function to display the global mStatisticsTable object.
423 @param[in] Option ECHO, NORMAL, or DETAIL control the amount of detail displayed.
425 @retval EFI_SUCCESS print is successful.
429 DisplayStatisticsTable (
435 STRUCTURE_STATISTICS
*pStatistics
;
436 SMBIOS_STRUCTURE_TABLE
*SMBiosTable
;
439 if (Option
< SHOW_OUTLINE
) {
443 // display EPS information firstly
445 LibSmbiosGetEPS (&SMBiosTable
);
446 if (SMBiosTable
== NULL
) {
447 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE
), gShellDebug1HiiHandle
);
448 return EFI_UNSUPPORTED
;
451 ShellPrintEx(-1,-1,L
"\n============================================================\n");
452 SmbiosPrintEPSInfo (SMBiosTable
, Option
);
454 if (Option
< SHOW_NORMAL
) {
458 if (mStatisticsTable
== NULL
) {
459 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS
), gShellDebug1HiiHandle
);
460 return EFI_NOT_FOUND
;
463 ShellPrintEx(-1,-1,L
"============================================================\n");
464 pStatistics
= &mStatisticsTable
[0];
465 Num
= SMBiosTable
->NumberOfSmbiosStructures
;
467 // display statistics table content
469 for (Index
= 1; Index
<= Num
; Index
++) {
470 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX
), gShellDebug1HiiHandle
, pStatistics
->Index
);
471 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE
), gShellDebug1HiiHandle
, pStatistics
->Type
);
472 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_HANDLE
), gShellDebug1HiiHandle
, pStatistics
->Handle
);
473 if (Option
>= SHOW_DETAIL
) {
474 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OFFSET
), gShellDebug1HiiHandle
, pStatistics
->Addr
);
475 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_LENGTH
), gShellDebug1HiiHandle
, pStatistics
->Length
);
478 ShellPrintEx(-1,-1,L
"\n");
479 pStatistics
= &mStatisticsTable
[Index
];
482 // Display 20 lines and wait for a page break
484 if (Index % 20 == 0) {
485 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ENTER_CONTINUE), gShellDebug1HiiHandle);
486 Status = WaitEnter ();
487 if (EFI_ERROR (Status)) {
488 if (Status == EFI_ABORTED) {
502 function to return a string of the detail level.
504 @param[in] ShowType The detail level whose name is desired in clear text.
506 @return A pointer to a string representing the ShowType (or 'undefined type' if not known).
523 return L
"SHOW_OUTLINE";
526 return L
"SHOW_NORMAL";
529 return L
"SHOW_DETAIL";
535 return L
"Undefined type";
541 InitializeSmbiosViewApplicationGetLineHelp (
545 return LibCmdGetStringByToken (STRING_ARRAY_NAME, &EfiSmbiosViewGuid, STRING_TOKEN (STR_SMBIOSVIEW_LINE_HELP), Str);