]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/Smbios.c
Add "Debug1" profile (all but Edit and HexEdit commands)
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SmbiosView / Smbios.c
1 /** @file
2 Lib fucntions for SMBIOS. Used to get system serial number and GUID
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 <Guid/Smbios.h>
17 #include "LibSmbios.h"
18
19 EFI_STATUS
20 LibGetSmbiosSystemGuidAndSerialNumber (
21 IN EFI_GUID *SystemGuid,
22 OUT CHAR8 **SystemSerialNumber
23 )
24 {
25 EFI_STATUS Status;
26 SMBIOS_STRUCTURE_TABLE *SmbiosTable;
27 SMBIOS_STRUCTURE_POINTER Smbios;
28 SMBIOS_STRUCTURE_POINTER SmbiosEnd;
29 UINT16 Index;
30
31 Status = GetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **) &SmbiosTable);
32 if (EFI_ERROR (Status)) {
33 return EFI_NOT_FOUND;
34 }
35
36 Smbios.Hdr = (SMBIOS_HEADER *) ((UINTN) (SmbiosTable->TableAddress));
37
38 SmbiosEnd.Raw = (UINT8 *) ((UINTN) (SmbiosTable->TableAddress + SmbiosTable->TableLength));
39 for (Index = 0; Index < SmbiosTable->TableLength; Index++) {
40 if (Smbios.Hdr->Type == 1) {
41 if (Smbios.Hdr->Length < 0x19) {
42 //
43 // Older version did not support Guid and Serial number
44 //
45 continue;
46 }
47 //
48 // SMBIOS tables are byte packed so we need to do a byte copy to
49 // prevend alignment faults on Itanium-based platform.
50 //
51 CopyMem (SystemGuid, &Smbios.Type1->Uuid, sizeof (EFI_GUID));
52 *SystemSerialNumber = LibGetSmbiosString (&Smbios, Smbios.Type1->SerialNumber);
53 return EFI_SUCCESS;
54 }
55 //
56 // Make Smbios point to the next record
57 //
58 LibGetSmbiosString (&Smbios, (UINT16) (-1));
59
60 if (Smbios.Raw >= SmbiosEnd.Raw) {
61 //
62 // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e.
63 // given this we must double check against the lenght of
64 // the structure. My home PC has this bug.ruthard
65 //
66 return EFI_SUCCESS;
67 }
68 }
69
70 return EFI_SUCCESS;
71 }
72
73 CHAR8 *
74 LibGetSmbiosString (
75 IN SMBIOS_STRUCTURE_POINTER *Smbios,
76 IN UINT16 StringNumber
77 )
78 /*++
79 Routine Description:
80 Return SMBIOS string given the string number.
81
82 Arguments:
83 Smbios - Pointer to SMBIOS structure
84 StringNumber - String number to return. -1 is used to skip all strings and
85 point to the next SMBIOS structure.
86
87 Returns:
88 Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1
89 **/
90 {
91 UINT16 Index;
92 CHAR8 *String;
93
94 ASSERT (Smbios != NULL);
95
96 //
97 // Skip over formatted section
98 //
99 String = (CHAR8 *) (Smbios->Raw + Smbios->Hdr->Length);
100
101 //
102 // Look through unformated section
103 //
104 for (Index = 1; Index <= StringNumber; Index++) {
105 if (StringNumber == Index) {
106 return String;
107 }
108 //
109 // Skip string
110 //
111 for (; *String != 0; String++);
112 String++;
113
114 if (*String == 0) {
115 //
116 // If double NULL then we are done.
117 // Retrun pointer to next structure in Smbios.
118 // if you pass in a -1 you will always get here
119 //
120 Smbios->Raw = (UINT8 *)++String;
121 return NULL;
122 }
123 }
124
125 return NULL;
126 }