]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c
Add "Debug1" profile (all but Edit and HexEdit commands)
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SmbiosView / SmbiosView.c
1 /** @file
2 Tools of clarify the content of the smbios table.
3
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
9
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.
12
13 **/
14
15 #include "../UefiShellDebug1CommandsLib.h"
16 #include "LibSmbiosView.h"
17 #include "smbiosview.h"
18 #include "PrintInfo.h"
19 #include "QueryTable.h"
20
21 UINT8 gShowType = SHOW_DETAIL;
22 STATIC STRUCTURE_STATISTICS *mStatisticsTable = NULL;
23
24 UINT8 SmbiosMajorVersion;
25 UINT8 SmbiosMinorVersion;
26
27 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
28 {L"-t", TypeValue},
29 {L"-h", TypeValue},
30 {L"-s", TypeFlag},
31 {L"-a", TypeFlag},
32 {NULL, TypeMax}
33 };
34
35 SHELL_STATUS
36 EFIAPI
37 ShellCommandRunSmbiosView (
38 IN EFI_HANDLE ImageHandle,
39 IN EFI_SYSTEM_TABLE *SystemTable
40 )
41 {
42 UINT8 StructType;
43 UINT16 StructHandle;
44 EFI_STATUS Status;
45 BOOLEAN RandomView;
46 LIST_ENTRY *Package;
47 CHAR16 *ProblemParam;
48 SHELL_STATUS ShellStatus;
49 CONST CHAR16 *Temp;
50
51 mStatisticsTable = NULL;
52 Package = NULL;
53 ShellStatus = SHELL_SUCCESS;
54
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;
61 } else {
62 ASSERT(FALSE);
63 }
64 } else {
65 if (ShellCommandLineGetCount(Package) > 1) {
66 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
67 ShellStatus = SHELL_INVALID_PARAMETER;
68 } else {
69
70 //
71 // Init Lib
72 //
73 Status = LibSmbiosInit ();
74 if (EFI_ERROR (Status)) {
75 ShellStatus = SHELL_NOT_FOUND;
76 goto Done;
77 }
78 //
79 // build statistics table
80 //
81 Status = InitSmbiosTableStatistics ();
82 if (EFI_ERROR (Status)) {
83 ShellStatus = SHELL_NOT_FOUND;
84 goto Done;
85 }
86
87 StructType = STRUCTURE_TYPE_RANDOM;
88 RandomView = TRUE;
89 //
90 // Initialize the StructHandle to be the first handle
91 //
92 StructHandle = STRUCTURE_HANDLE_INVALID;
93 LibGetSmbiosStructure (&StructHandle, NULL, NULL);
94
95 Temp = ShellCommandLineGetValue(Package, L"-t");
96 if (Temp != NULL) {
97 StructType = (UINT8) ShellStrToUintn (Temp);
98 }
99
100 Temp = ShellCommandLineGetValue(Package, L"-h");
101 if (Temp != NULL) {
102 RandomView = FALSE;
103 StructHandle = (UINT16) ShellStrToUintn(Temp);
104 }
105
106 if (ShellCommandLineGetFlag(Package, L"-s")) {
107 Status = DisplayStatisticsTable (SHOW_DETAIL);
108 if (EFI_ERROR(Status)) {
109 ShellStatus = SHELL_NOT_FOUND;
110 }
111 goto Done;
112 }
113
114 if (ShellCommandLineGetFlag(Package, L"-a")) {
115 gShowType = SHOW_ALL;
116 }
117 //
118 // Show SMBIOS structure information
119 //
120 Status = SMBiosView (StructType, StructHandle, gShowType, RandomView);
121 if (EFI_ERROR(Status)) {
122 ShellStatus = SHELL_NOT_FOUND;
123 }
124 }
125 }
126 Done:
127 //
128 // Release resources
129 //
130 if (mStatisticsTable != NULL) {
131 //
132 // Release statistics table
133 //
134 FreePool (mStatisticsTable);
135 mStatisticsTable = NULL;
136 }
137
138 if (Package != NULL) {
139 ShellCommandLineFreeVarList (Package);
140 }
141
142 LibSmbiosCleanup ();
143
144 return ShellStatus;
145 }
146
147 /**
148 Query all structures Data from SMBIOS table and Display
149 the information to users as required display option.
150
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.
155
156 @retval EFI_SUCCESS print is successful.
157 @retval EFI_BAD_BUFFER_SIZE structure is out of the range of SMBIOS table.
158 **/
159 EFI_STATUS
160 EFIAPI
161 SMBiosView (
162 IN UINT8 QueryType,
163 IN UINT16 QueryHandle,
164 IN UINT8 Option,
165 IN BOOLEAN RandomView
166 )
167 {
168 UINT16 Handle;
169 UINT8 Buffer[1024];
170 //
171 // bigger than SMBIOS_STRUCTURE_TABLE.MaxStructureSize
172 //
173 UINT16 Length;
174 UINTN Index;
175 UINT16 Offset;
176 //
177 // address offset from structure table head.
178 //
179 UINT32 TableHead;
180 //
181 // structure table head.
182 //
183
184 SMBIOS_STRUCTURE_POINTER pStruct;
185 SMBIOS_STRUCTURE_TABLE *SMBiosTable;
186
187 SMBiosTable = NULL;
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;
192 }
193
194 if (CompareMem (SMBiosTable->AnchorString, "_SM_", 4) == 0) {
195 //
196 // Have get SMBIOS table
197 //
198 SmbiosPrintEPSInfo (SMBiosTable, Option);
199
200 SmbiosMajorVersion = SMBiosTable->MajorVersion;
201 SmbiosMinorVersion = SMBiosTable->MinorVersion;
202
203 ShellPrintEx(-1,-1,L"=========================================================\n");
204 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND), gShellDebug1HiiHandle);
205
206 if (QueryType == STRUCTURE_TYPE_RANDOM) {
207 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM), gShellDebug1HiiHandle);
208 } else {
209 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE), gShellDebug1HiiHandle, QueryType);
210 }
211
212 if (RandomView) {
213 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM), gShellDebug1HiiHandle);
214 } else {
215 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE), gShellDebug1HiiHandle, QueryHandle);
216 }
217
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");
221
222 /*
223 //
224 // Get internal commands, such as change options.
225 //
226 Status = WaitEnter ();
227 if (EFI_ERROR (Status)) {
228 if (Status == EFI_ABORTED) {
229 return EFI_SUCCESS;
230 }
231
232 return Status;
233 }
234 */
235
236 //
237 // Searching and display structure info
238 //
239 Handle = QueryHandle;
240 TableHead = SMBiosTable->TableAddress;
241 Offset = 0;
242 for (Index = 0; Index < SMBiosTable->NumberOfSmbiosStructures; Index++) {
243 //
244 // if reach the end of table, break..
245 //
246 if (Handle == STRUCTURE_HANDLE_INVALID) {
247 break;
248 }
249 //
250 // handle then point to the next!
251 //
252 if (LibGetSmbiosStructure (&Handle, Buffer, &Length) != DMI_SUCCESS) {
253 break;
254 }
255 Offset = (UINT16) (Offset + Length);
256 pStruct.Raw = Buffer;
257
258 //
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.
262 //
263 if (QueryType != STRUCTURE_TYPE_RANDOM && pStruct.Hdr->Type != QueryType) {
264 continue;
265 }
266
267 ShellPrintEx(-1,-1,L"\n=========================================================\n");
268 ShellPrintHiiEx(-1,-1,NULL,
269 STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE_HANDLE_DUMP_STRUCT),
270 gShellDebug1HiiHandle,
271 pStruct.Hdr->Type,
272 pStruct.Hdr->Handle
273 );
274 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH), gShellDebug1HiiHandle, Index, Length);
275 //
276 // Addr of structure in structure in table
277 //
278 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR), gShellDebug1HiiHandle, TableHead + Offset);
279 DumpHex (0, 0, Length, Buffer);
280
281 /*
282 //
283 // Get internal commands, such as change options.
284 //
285 Status = WaitEnter ();
286 if (EFI_ERROR (Status)) {
287 if (Status == EFI_ABORTED) {
288 return EFI_SUCCESS;
289 }
290
291 return Status;
292 }
293 */
294
295 if (gShowType != SHOW_NONE) {
296 //
297 // check structure legality
298 //
299 SmbiosCheckStructure (&pStruct);
300
301 //
302 // Print structure information
303 //
304 SmbiosPrintStructure (&pStruct, gShowType);
305 ShellPrintEx(-1,-1,L"\n");
306
307 /*
308 //
309 // Get internal commands, such as change options.
310 //
311 Status = WaitEnter ();
312 if (EFI_ERROR (Status)) {
313 if (Status == EFI_ABORTED) {
314 return EFI_SUCCESS;
315 }
316
317 return Status;
318 }
319 */
320 }
321 if (!RandomView) {
322 break;
323 }
324 }
325
326 ShellPrintEx(-1,-1,L"\n=========================================================\n");
327 return EFI_SUCCESS;
328 }
329
330 return EFI_BAD_BUFFER_SIZE;
331 }
332
333 /**
334 Function to initialize the global mStatisticsTable object.
335
336 @retval EFI_SUCCESS print is successful.
337 **/
338 EFI_STATUS
339 EFIAPI
340 InitSmbiosTableStatistics (
341 VOID
342 )
343 {
344 UINT16 Handle;
345 UINT8 Buffer[1024];
346 UINT16 Length;
347 UINT16 Offset;
348 UINT16 Index;
349
350 SMBIOS_STRUCTURE_POINTER pStruct;
351 SMBIOS_STRUCTURE_TABLE *SMBiosTable;
352 STRUCTURE_STATISTICS *pStatistics;
353
354 SMBiosTable = NULL;
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;
359 }
360
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;
364 }
365 //
366 // Allocate memory to mStatisticsTable
367 //
368 if (mStatisticsTable != NULL) {
369 FreePool (mStatisticsTable);
370 mStatisticsTable = NULL;
371 }
372
373 mStatisticsTable = (STRUCTURE_STATISTICS *) AllocatePool (SMBiosTable->NumberOfSmbiosStructures * sizeof (STRUCTURE_STATISTICS));
374
375 if (mStatisticsTable == NULL) {
376 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM), gShellDebug1HiiHandle);
377 return EFI_OUT_OF_RESOURCES;
378 }
379
380 Offset = 0;
381 pStatistics = mStatisticsTable;
382
383 //
384 // search from the first one
385 //
386 Handle = STRUCTURE_HANDLE_INVALID;
387 LibGetSmbiosStructure (&Handle, NULL, NULL);
388 for (Index = 1; Index <= SMBiosTable->NumberOfSmbiosStructures; Index++) {
389 //
390 // If reach the end of table, break..
391 //
392 if (Handle == STRUCTURE_HANDLE_INVALID) {
393 break;
394 }
395 //
396 // After LibGetSmbiosStructure(), handle then point to the next!
397 //
398 if (LibGetSmbiosStructure (&Handle, Buffer, &Length) != DMI_SUCCESS) {
399 break;
400 }
401
402 pStruct.Raw = Buffer;
403 Offset = (UINT16) (Offset + Length);
404
405 //
406 // general statistics
407 //
408 pStatistics->Index = Index;
409 pStatistics->Type = pStruct.Hdr->Type;
410 pStatistics->Handle = pStruct.Hdr->Handle;
411 pStatistics->Length = Length;
412 pStatistics->Addr = Offset;
413
414 pStatistics = &mStatisticsTable[Index];
415 }
416
417 return EFI_SUCCESS;
418 }
419
420 /**
421 Function to display the global mStatisticsTable object.
422
423 @param[in] Option ECHO, NORMAL, or DETAIL control the amount of detail displayed.
424
425 @retval EFI_SUCCESS print is successful.
426 **/
427 EFI_STATUS
428 EFIAPI
429 DisplayStatisticsTable (
430 IN UINT8 Option
431 )
432 {
433 UINTN Index;
434 UINTN Num;
435 STRUCTURE_STATISTICS *pStatistics;
436 SMBIOS_STRUCTURE_TABLE *SMBiosTable;
437
438 SMBiosTable = NULL;
439 if (Option < SHOW_OUTLINE) {
440 return EFI_SUCCESS;
441 }
442 //
443 // display EPS information firstly
444 //
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;
449 }
450
451 ShellPrintEx(-1,-1,L"\n============================================================\n");
452 SmbiosPrintEPSInfo (SMBiosTable, Option);
453
454 if (Option < SHOW_NORMAL) {
455 return EFI_SUCCESS;
456 }
457
458 if (mStatisticsTable == NULL) {
459 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS), gShellDebug1HiiHandle);
460 return EFI_NOT_FOUND;
461 }
462
463 ShellPrintEx(-1,-1,L"============================================================\n");
464 pStatistics = &mStatisticsTable[0];
465 Num = SMBiosTable->NumberOfSmbiosStructures;
466 //
467 // display statistics table content
468 //
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);
476 }
477
478 ShellPrintEx(-1,-1,L"\n");
479 pStatistics = &mStatisticsTable[Index];
480 /*
481 //
482 // Display 20 lines and wait for a page break
483 //
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) {
489 return EFI_SUCCESS;
490 }
491
492 return Status;
493 }
494 }
495 */
496 }
497
498 return EFI_SUCCESS;
499 }
500
501 /**
502 function to return a string of the detail level.
503
504 @param[in] ShowType The detail level whose name is desired in clear text.
505
506 @return A pointer to a string representing the ShowType (or 'undefined type' if not known).
507 **/
508 CHAR16 *
509 EFIAPI
510 GetShowTypeString (
511 UINT8 ShowType
512 )
513 {
514 //
515 // show type
516 //
517 switch (ShowType) {
518
519 case SHOW_NONE:
520 return L"SHOW_NONE";
521
522 case SHOW_OUTLINE:
523 return L"SHOW_OUTLINE";
524
525 case SHOW_NORMAL:
526 return L"SHOW_NORMAL";
527
528 case SHOW_DETAIL:
529 return L"SHOW_DETAIL";
530
531 case SHOW_ALL:
532 return L"SHOW_ALL";
533
534 default:
535 return L"Undefined type";
536 }
537 }
538
539 /*
540 EFI_STATUS
541 InitializeSmbiosViewApplicationGetLineHelp (
542 OUT CHAR16 **Str
543 )
544 {
545 return LibCmdGetStringByToken (STRING_ARRAY_NAME, &EfiSmbiosViewGuid, STRING_TOKEN (STR_SMBIOSVIEW_LINE_HELP), Str);
546 }
547 */