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
[] = {
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
= STRUCTURE_HANDLE_INVALID
;
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
193 // bigger than SMBIOS_STRUCTURE_TABLE.MaxStructureSize
199 // address offset from structure table head.
203 // structure table head.
206 SMBIOS_STRUCTURE_POINTER SmbiosStruct
;
207 SMBIOS_STRUCTURE_TABLE
*SMBiosTable
;
210 LibSmbiosGetEPS (&SMBiosTable
);
211 if (SMBiosTable
== NULL
) {
212 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE
), gShellDebug1HiiHandle
);
213 return EFI_BAD_BUFFER_SIZE
;
216 if (CompareMem (SMBiosTable
->AnchorString
, "_SM_", 4) == 0) {
218 // Have get SMBIOS table
220 SmbiosPrintEPSInfo (SMBiosTable
, Option
);
222 SmbiosMajorVersion
= SMBiosTable
->MajorVersion
;
223 SmbiosMinorVersion
= SMBiosTable
->MinorVersion
;
225 ShellPrintEx(-1,-1,L
"=========================================================\n");
226 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND
), gShellDebug1HiiHandle
);
228 if (QueryType
== STRUCTURE_TYPE_RANDOM
) {
229 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM
), gShellDebug1HiiHandle
);
231 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE
), gShellDebug1HiiHandle
, QueryType
);
235 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM
), gShellDebug1HiiHandle
);
237 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE
), gShellDebug1HiiHandle
, QueryHandle
);
240 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SHOWTYPE
), gShellDebug1HiiHandle
);
241 ShellPrintEx(-1,-1,GetShowTypeString (gShowType
));
242 ShellPrintEx(-1,-1,L
"\n\n");
246 // Get internal commands, such as change options.
248 Status = WaitEnter ();
249 if (EFI_ERROR (Status)) {
250 if (Status == EFI_ABORTED) {
259 // Searching and display structure info
261 Handle
= QueryHandle
;
262 TableHead
= SMBiosTable
->TableAddress
;
264 for (Index
= 0; Index
< SMBiosTable
->NumberOfSmbiosStructures
; Index
++) {
266 // if reach the end of table, break..
268 if (Handle
== STRUCTURE_HANDLE_INVALID
) {
272 // handle then point to the next!
274 if (LibGetSmbiosStructure (&Handle
, Buffer
, &Length
) != DMI_SUCCESS
) {
277 Offset
= (UINT16
) (Offset
+ Length
);
278 SmbiosStruct
.Raw
= Buffer
;
281 // if QueryType==Random, print this structure.
282 // if QueryType!=Random, but Hdr->Type==QueryType, also print it.
283 // only if QueryType != Random and Hdr->Type != QueryType, skiped it.
285 if (QueryType
!= STRUCTURE_TYPE_RANDOM
&& SmbiosStruct
.Hdr
->Type
!= QueryType
) {
289 ShellPrintEx(-1,-1,L
"\n=========================================================\n");
290 ShellPrintHiiEx(-1,-1,NULL
,
291 STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE_HANDLE_DUMP_STRUCT
),
292 gShellDebug1HiiHandle
,
293 SmbiosStruct
.Hdr
->Type
,
294 SmbiosStruct
.Hdr
->Handle
296 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH
), gShellDebug1HiiHandle
, Index
, Length
);
298 // Addr of structure in structure in table
300 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR
), gShellDebug1HiiHandle
, TableHead
+ Offset
);
301 DumpHex (0, 0, Length
, Buffer
);
305 // Get internal commands, such as change options.
307 Status = WaitEnter ();
308 if (EFI_ERROR (Status)) {
309 if (Status == EFI_ABORTED) {
317 if (gShowType
!= SHOW_NONE
) {
319 // check structure legality
321 SmbiosCheckStructure (&SmbiosStruct
);
324 // Print structure information
326 SmbiosPrintStructure (&SmbiosStruct
, gShowType
);
327 ShellPrintEx(-1,-1,L
"\n");
331 // Get internal commands, such as change options.
333 Status = WaitEnter ();
334 if (EFI_ERROR (Status)) {
335 if (Status == EFI_ABORTED) {
348 ShellPrintEx(-1,-1,L
"\n=========================================================\n");
352 return EFI_BAD_BUFFER_SIZE
;
356 Function to initialize the global mStatisticsTable object.
358 @retval EFI_SUCCESS print is successful.
362 InitSmbiosTableStatistics (
372 SMBIOS_STRUCTURE_POINTER SmbiosStruct
;
373 SMBIOS_STRUCTURE_TABLE
*SMBiosTable
;
374 STRUCTURE_STATISTICS
*StatisticsPointer
;
377 LibSmbiosGetEPS (&SMBiosTable
);
378 if (SMBiosTable
== NULL
) {
379 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE
), gShellDebug1HiiHandle
);
380 return EFI_NOT_FOUND
;
383 if (CompareMem (SMBiosTable
->AnchorString
, "_SM_", 4) != 0) {
384 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SMBIOS_TABLE
), gShellDebug1HiiHandle
);
385 return EFI_INVALID_PARAMETER
;
388 // Allocate memory to mStatisticsTable
390 if (mStatisticsTable
!= NULL
) {
391 FreePool (mStatisticsTable
);
392 mStatisticsTable
= NULL
;
395 mStatisticsTable
= (STRUCTURE_STATISTICS
*) AllocateZeroPool (SMBiosTable
->NumberOfSmbiosStructures
* sizeof (STRUCTURE_STATISTICS
));
397 if (mStatisticsTable
== NULL
) {
398 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM
), gShellDebug1HiiHandle
);
399 return EFI_OUT_OF_RESOURCES
;
403 StatisticsPointer
= mStatisticsTable
;
406 // search from the first one
408 Handle
= STRUCTURE_HANDLE_INVALID
;
409 LibGetSmbiosStructure (&Handle
, NULL
, NULL
);
410 for (Index
= 1; Index
<= SMBiosTable
->NumberOfSmbiosStructures
; Index
++) {
412 // If reach the end of table, break..
414 if (Handle
== STRUCTURE_HANDLE_INVALID
) {
418 // After LibGetSmbiosStructure(), handle then point to the next!
420 if (LibGetSmbiosStructure (&Handle
, Buffer
, &Length
) != DMI_SUCCESS
) {
424 SmbiosStruct
.Raw
= Buffer
;
425 Offset
= (UINT16
) (Offset
+ Length
);
428 // general statistics
430 StatisticsPointer
->Index
= Index
;
431 StatisticsPointer
->Type
= SmbiosStruct
.Hdr
->Type
;
432 StatisticsPointer
->Handle
= SmbiosStruct
.Hdr
->Handle
;
433 StatisticsPointer
->Length
= Length
;
434 StatisticsPointer
->Addr
= Offset
;
436 StatisticsPointer
= &mStatisticsTable
[Index
];
443 Function to display the global mStatisticsTable object.
445 @param[in] Option ECHO, NORMAL, or DETAIL control the amount of detail displayed.
447 @retval EFI_SUCCESS print is successful.
451 DisplayStatisticsTable (
457 STRUCTURE_STATISTICS
*StatisticsPointer
;
458 SMBIOS_STRUCTURE_TABLE
*SMBiosTable
;
461 if (Option
< SHOW_OUTLINE
) {
465 // display EPS information firstly
467 LibSmbiosGetEPS (&SMBiosTable
);
468 if (SMBiosTable
== NULL
) {
469 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE
), gShellDebug1HiiHandle
);
470 return EFI_UNSUPPORTED
;
473 ShellPrintEx(-1,-1,L
"\n============================================================\n");
474 SmbiosPrintEPSInfo (SMBiosTable
, Option
);
476 if (Option
< SHOW_NORMAL
) {
480 if (mStatisticsTable
== NULL
) {
481 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS
), gShellDebug1HiiHandle
);
482 return EFI_NOT_FOUND
;
485 ShellPrintEx(-1,-1,L
"============================================================\n");
486 StatisticsPointer
= &mStatisticsTable
[0];
487 Num
= SMBiosTable
->NumberOfSmbiosStructures
;
489 // display statistics table content
491 for (Index
= 1; Index
<= Num
; Index
++) {
492 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX
), gShellDebug1HiiHandle
, StatisticsPointer
->Index
);
493 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE
), gShellDebug1HiiHandle
, StatisticsPointer
->Type
);
494 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_HANDLE
), gShellDebug1HiiHandle
, StatisticsPointer
->Handle
);
495 if (Option
>= SHOW_DETAIL
) {
496 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OFFSET
), gShellDebug1HiiHandle
, StatisticsPointer
->Addr
);
497 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_LENGTH
), gShellDebug1HiiHandle
, StatisticsPointer
->Length
);
500 ShellPrintEx(-1,-1,L
"\n");
501 StatisticsPointer
= &mStatisticsTable
[Index
];
504 // Display 20 lines and wait for a page break
506 if (Index % 20 == 0) {
507 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ENTER_CONTINUE), gShellDebug1HiiHandle);
508 Status = WaitEnter ();
509 if (EFI_ERROR (Status)) {
510 if (Status == EFI_ABORTED) {
524 function to return a string of the detail level.
526 @param[in] ShowType The detail level whose name is desired in clear text.
528 @return A pointer to a string representing the ShowType (or 'undefined type' if not known).
545 return L
"SHOW_OUTLINE";
548 return L
"SHOW_NORMAL";
551 return L
"SHOW_DETAIL";
557 return L
"Undefined type";
563 InitializeSmbiosViewApplicationGetLineHelp (
567 return LibCmdGetStringByToken (STRING_ARRAY_NAME, &EfiSmbiosViewGuid, STRING_TOKEN (STR_SMBIOSVIEW_LINE_HELP), Str);