3 Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 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.
20 Boot service DXE BIOS ID library implementation.
22 These functions in this file can be called during DXE and cannot be called during runtime
23 or in SMM which should use a RT or SMM library.
28 #include <Library/BaseLib.h>
29 #include <Library/HobLib.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/DebugLib.h>
34 #include <Library/BiosIdLib.h>
35 #include <Guid/BiosId.h>
36 #include <Protocol/FirmwareVolume2.h>
37 #include <Protocol/LoadedImage.h>
42 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
43 IN EFI_GUID
*NameGuid
,
44 IN EFI_SECTION_TYPE SectionType
,
50 EFI_FV_FILETYPE FileType
;
51 EFI_FV_FILE_ATTRIBUTES Attributes
;
52 UINT32 AuthenticationStatus
;
55 // Read desired section content in NameGuid file
59 Status
= Fv
->ReadSection (
69 if (EFI_ERROR (Status
) && (SectionType
== EFI_SECTION_TE
)) {
71 // Try reading PE32 section, since the TE section does not exist
75 Status
= Fv
->ReadSection (
86 if (EFI_ERROR (Status
) &&
87 ((SectionType
== EFI_SECTION_TE
) || (SectionType
== EFI_SECTION_PE32
))) {
89 // Try reading raw file, since the desired section does not exist
93 Status
= Fv
->ReadFile (
100 &AuthenticationStatus
110 IN EFI_HANDLE ImageHandle
,
111 IN EFI_GUID
*NameGuid
,
112 IN EFI_SECTION_TYPE SectionType
,
115 BOOLEAN WithinImageFv
119 EFI_HANDLE
*HandleBuffer
;
122 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
124 EFI_FIRMWARE_VOLUME2_PROTOCOL
*ImageFv
;
125 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
128 if (ImageHandle
== NULL
&& WithinImageFv
) {
129 return EFI_INVALID_PARAMETER
;
132 Status
= EFI_NOT_FOUND
;
134 if (ImageHandle
!= NULL
) {
135 Status
= gBS
->HandleProtocol (
137 &gEfiLoadedImageProtocolGuid
,
138 (VOID
**) &LoadedImage
140 if (EFI_ERROR (Status
)) {
143 Status
= gBS
->HandleProtocol (
144 LoadedImage
->DeviceHandle
,
145 &gEfiFirmwareVolume2ProtocolGuid
,
148 if (!EFI_ERROR (Status
)) {
149 Status
= GetImageFromFv (ImageFv
, NameGuid
, SectionType
, Buffer
, Size
);
153 if (Status
== EFI_SUCCESS
|| WithinImageFv
) {
157 Status
= gBS
->LocateHandleBuffer (
159 &gEfiFirmwareVolume2ProtocolGuid
,
164 if (EFI_ERROR (Status
)) {
169 // Find desired image in all Fvs
171 for (Index
= 0; Index
< HandleCount
; ++Index
) {
172 Status
= gBS
->HandleProtocol (
174 &gEfiFirmwareVolume2ProtocolGuid
,
178 if (EFI_ERROR (Status
)) {
179 gBS
->FreePool(HandleBuffer
);
183 if (ImageFv
!= NULL
&& Fv
== ImageFv
) {
187 Status
= GetImageFromFv (Fv
, NameGuid
, SectionType
, Buffer
, Size
);
189 if (!EFI_ERROR (Status
)) {
193 gBS
->FreePool(HandleBuffer
);
198 if (Index
== HandleCount
) {
199 return EFI_NOT_FOUND
;
206 This function returns BIOS ID by searching HOB or FV.
208 @param BiosIdImage The BIOS ID got from HOB or FV.
210 @retval EFI_SUCCESS All parameters were valid and BIOS ID has been got.
211 @retval EFI_NOT_FOUND BiosId image is not found, and no parameter will be modified.
212 @retval EFI_INVALID_PARAMETER The parameter is NULL.
217 OUT BIOS_ID_IMAGE
*BiosIdImage
222 VOID
*Address
= NULL
;
225 DEBUG ((EFI_D_INFO
, "Get BIOS ID from FV\n"));
227 Status
= GetImageEx (
236 if (Status
== EFI_SUCCESS
) {
238 // BiosId image is present in FV
240 if (Address
!= NULL
) {
241 Size
= sizeof (BIOS_ID_IMAGE
);
243 (void *) BiosIdImage
,
248 // GetImage () allocated buffer for Address, now clear it.
250 gBS
->FreePool (Address
);
252 DEBUG ((EFI_D_INFO
, "Get BIOS ID from FV successfully\n"));
253 DEBUG ((EFI_D_INFO
, "BIOS ID: %s\n", (CHAR16
*) (&(BiosIdImage
->BiosIdString
))));
258 return EFI_NOT_FOUND
;
262 This function returns the Version & Release Date and Time by getting and converting
265 @param BiosVersion The Bios Version out of the conversion.
266 @param BiosReleaseDate The Bios Release Date out of the conversion.
267 @param BiosReleaseTime - The Bios Release Time out of the conversion.
269 @retval EFI_SUCCESS - BIOS Version & Release Date and Time have been got successfully.
270 @retval EFI_NOT_FOUND - BiosId image is not found, and no parameter will be modified.
271 @retval EFI_INVALID_PARAMETER - All the parameters are NULL.
275 GetBiosVersionDateTime (
276 OUT CHAR16
*BiosVersion
, OPTIONAL
277 OUT CHAR16
*BiosReleaseDate
, OPTIONAL
278 OUT CHAR16
*BiosReleaseTime OPTIONAL
282 BIOS_ID_IMAGE BiosIdImage
;
284 if ((BiosVersion
== NULL
) && (BiosReleaseDate
== NULL
) && (BiosReleaseTime
== NULL
)) {
285 return EFI_INVALID_PARAMETER
;
288 Status
= GetBiosId (&BiosIdImage
);
289 if (EFI_ERROR (Status
)) {
290 return EFI_NOT_FOUND
;
293 if (BiosVersion
!= NULL
) {
295 // Fill the BiosVersion data from the BIOS ID.
297 StrCpy (BiosVersion
, (CHAR16
*) (&(BiosIdImage
.BiosIdString
)));
300 if (BiosReleaseDate
!= NULL
) {
302 // Fill the build timestamp date from the BIOS ID in the "MM/DD/YY" format.
304 BiosReleaseDate
[0] = BiosIdImage
.BiosIdString
.TimeStamp
[2];
305 BiosReleaseDate
[1] = BiosIdImage
.BiosIdString
.TimeStamp
[3];
306 BiosReleaseDate
[2] = (CHAR16
) ((UINT8
) ('/'));
308 BiosReleaseDate
[3] = BiosIdImage
.BiosIdString
.TimeStamp
[4];
309 BiosReleaseDate
[4] = BiosIdImage
.BiosIdString
.TimeStamp
[5];
310 BiosReleaseDate
[5] = (CHAR16
) ((UINT8
) ('/'));
313 // Add 20 for SMBIOS table
314 // Current Linux kernel will misjudge 09 as year 0, so using 2009 for SMBIOS table
316 BiosReleaseDate
[6] = '2';
317 BiosReleaseDate
[7] = '0';
318 BiosReleaseDate
[8] = BiosIdImage
.BiosIdString
.TimeStamp
[0];
319 BiosReleaseDate
[9] = BiosIdImage
.BiosIdString
.TimeStamp
[1];
321 BiosReleaseDate
[10] = (CHAR16
) ((UINT8
) ('\0'));
324 if (BiosReleaseTime
!= NULL
) {
327 // Fill the build timestamp time from the BIOS ID in the "HH:MM" format.
330 BiosReleaseTime
[0] = BiosIdImage
.BiosIdString
.TimeStamp
[6];
331 BiosReleaseTime
[1] = BiosIdImage
.BiosIdString
.TimeStamp
[7];
332 BiosReleaseTime
[2] = (CHAR16
) ((UINT8
) (':'));
334 BiosReleaseTime
[3] = BiosIdImage
.BiosIdString
.TimeStamp
[8];
335 BiosReleaseTime
[4] = BiosIdImage
.BiosIdString
.TimeStamp
[9];
337 BiosReleaseTime
[5] = (CHAR16
) ((UINT8
) ('\0'));