2 Lib fucntions for SMBIOS. Used to get system serial number and GUID
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 <Guid/Smbios.h>
17 #include "LibSmbios.h"
20 LibGetSmbiosSystemGuidAndSerialNumber (
21 IN EFI_GUID
*SystemGuid
,
22 OUT CHAR8
**SystemSerialNumber
26 SMBIOS_STRUCTURE_TABLE
*SmbiosTable
;
27 SMBIOS_STRUCTURE_POINTER Smbios
;
28 SMBIOS_STRUCTURE_POINTER SmbiosEnd
;
31 Status
= GetSystemConfigurationTable (&gEfiSmbiosTableGuid
, (VOID
**) &SmbiosTable
);
32 if (EFI_ERROR (Status
)) {
36 Smbios
.Hdr
= (SMBIOS_HEADER
*) ((UINTN
) (SmbiosTable
->TableAddress
));
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) {
43 // Older version did not support Guid and Serial number
48 // SMBIOS tables are byte packed so we need to do a byte copy to
49 // prevend alignment faults on Itanium-based platform.
51 CopyMem (SystemGuid
, &Smbios
.Type1
->Uuid
, sizeof (EFI_GUID
));
52 *SystemSerialNumber
= LibGetSmbiosString (&Smbios
, Smbios
.Type1
->SerialNumber
);
56 // Make Smbios point to the next record
58 LibGetSmbiosString (&Smbios
, (UINT16
) (-1));
60 if (Smbios
.Raw
>= SmbiosEnd
.Raw
) {
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
75 IN SMBIOS_STRUCTURE_POINTER
*Smbios
,
76 IN UINT16 StringNumber
80 Return SMBIOS string given the string number.
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.
88 Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1
94 ASSERT (Smbios
!= NULL
);
97 // Skip over formatted section
99 String
= (CHAR8
*) (Smbios
->Raw
+ Smbios
->Hdr
->Length
);
102 // Look through unformated section
104 for (Index
= 1; Index
<= StringNumber
; Index
++) {
105 if (StringNumber
== Index
) {
111 for (; *String
!= 0; String
++);
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
120 Smbios
->Raw
= (UINT8
*)++String
;