3 Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved
5 SPDX-License-Identifier: BSD-2-Clause-Patent
15 Boot service DXE BIOS ID library implementation.
17 These functions in this file can be called during DXE and cannot be called during runtime
18 or in SMM which should use a RT or SMM library.
23 #include <Library/BaseLib.h>
24 #include <Library/HobLib.h>
25 #include <Library/UefiBootServicesTableLib.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/DebugLib.h>
29 #include <Library/BiosIdLib.h>
30 #include <Guid/BiosId.h>
31 #include <Protocol/FirmwareVolume2.h>
32 #include <Protocol/LoadedImage.h>
37 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
38 IN EFI_GUID
*NameGuid
,
39 IN EFI_SECTION_TYPE SectionType
,
45 EFI_FV_FILETYPE FileType
;
46 EFI_FV_FILE_ATTRIBUTES Attributes
;
47 UINT32 AuthenticationStatus
;
50 // Read desired section content in NameGuid file
54 Status
= Fv
->ReadSection (
64 if (EFI_ERROR (Status
) && (SectionType
== EFI_SECTION_TE
)) {
66 // Try reading PE32 section, since the TE section does not exist
70 Status
= Fv
->ReadSection (
81 if (EFI_ERROR (Status
) &&
82 ((SectionType
== EFI_SECTION_TE
) || (SectionType
== EFI_SECTION_PE32
))) {
84 // Try reading raw file, since the desired section does not exist
88 Status
= Fv
->ReadFile (
105 IN EFI_HANDLE ImageHandle
,
106 IN EFI_GUID
*NameGuid
,
107 IN EFI_SECTION_TYPE SectionType
,
110 BOOLEAN WithinImageFv
114 EFI_HANDLE
*HandleBuffer
;
117 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
119 EFI_FIRMWARE_VOLUME2_PROTOCOL
*ImageFv
;
120 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
123 if (ImageHandle
== NULL
&& WithinImageFv
) {
124 return EFI_INVALID_PARAMETER
;
127 Status
= EFI_NOT_FOUND
;
129 if (ImageHandle
!= NULL
) {
130 Status
= gBS
->HandleProtocol (
132 &gEfiLoadedImageProtocolGuid
,
133 (VOID
**) &LoadedImage
135 if (EFI_ERROR (Status
)) {
138 Status
= gBS
->HandleProtocol (
139 LoadedImage
->DeviceHandle
,
140 &gEfiFirmwareVolume2ProtocolGuid
,
143 if (!EFI_ERROR (Status
)) {
144 Status
= GetImageFromFv (ImageFv
, NameGuid
, SectionType
, Buffer
, Size
);
148 if (Status
== EFI_SUCCESS
|| WithinImageFv
) {
152 Status
= gBS
->LocateHandleBuffer (
154 &gEfiFirmwareVolume2ProtocolGuid
,
159 if (EFI_ERROR (Status
)) {
164 // Find desired image in all Fvs
166 for (Index
= 0; Index
< HandleCount
; ++Index
) {
167 Status
= gBS
->HandleProtocol (
169 &gEfiFirmwareVolume2ProtocolGuid
,
173 if (EFI_ERROR (Status
)) {
174 gBS
->FreePool(HandleBuffer
);
178 if (ImageFv
!= NULL
&& Fv
== ImageFv
) {
182 Status
= GetImageFromFv (Fv
, NameGuid
, SectionType
, Buffer
, Size
);
184 if (!EFI_ERROR (Status
)) {
188 gBS
->FreePool(HandleBuffer
);
193 if (Index
== HandleCount
) {
194 return EFI_NOT_FOUND
;
201 This function returns BIOS ID by searching HOB or FV.
203 @param BiosIdImage The BIOS ID got from HOB or FV.
205 @retval EFI_SUCCESS All parameters were valid and BIOS ID has been got.
206 @retval EFI_NOT_FOUND BiosId image is not found, and no parameter will be modified.
207 @retval EFI_INVALID_PARAMETER The parameter is NULL.
212 OUT BIOS_ID_IMAGE
*BiosIdImage
217 VOID
*Address
= NULL
;
220 DEBUG ((EFI_D_INFO
, "Get BIOS ID from FV\n"));
222 Status
= GetImageEx (
231 if (Status
== EFI_SUCCESS
) {
233 // BiosId image is present in FV
235 if (Address
!= NULL
) {
236 Size
= sizeof (BIOS_ID_IMAGE
);
238 (void *) BiosIdImage
,
243 // GetImage () allocated buffer for Address, now clear it.
245 gBS
->FreePool (Address
);
247 DEBUG ((EFI_D_INFO
, "Get BIOS ID from FV successfully\n"));
248 DEBUG ((EFI_D_INFO
, "BIOS ID: %s\n", (CHAR16
*) (&(BiosIdImage
->BiosIdString
))));
253 return EFI_NOT_FOUND
;
257 This function returns the Version & Release Date and Time by getting and converting
260 @param BiosVersion The Bios Version out of the conversion.
261 @param BiosReleaseDate The Bios Release Date out of the conversion.
262 @param BiosReleaseTime - The Bios Release Time out of the conversion.
264 @retval EFI_SUCCESS - BIOS Version & Release Date and Time have been got successfully.
265 @retval EFI_NOT_FOUND - BiosId image is not found, and no parameter will be modified.
266 @retval EFI_INVALID_PARAMETER - All the parameters are NULL.
270 GetBiosVersionDateTime (
271 OUT CHAR16
*BiosVersion
, OPTIONAL
272 OUT CHAR16
*BiosReleaseDate
, OPTIONAL
273 OUT CHAR16
*BiosReleaseTime OPTIONAL
277 BIOS_ID_IMAGE BiosIdImage
;
279 if ((BiosVersion
== NULL
) && (BiosReleaseDate
== NULL
) && (BiosReleaseTime
== NULL
)) {
280 return EFI_INVALID_PARAMETER
;
283 Status
= GetBiosId (&BiosIdImage
);
284 if (EFI_ERROR (Status
)) {
285 return EFI_NOT_FOUND
;
288 if (BiosVersion
!= NULL
) {
290 // Fill the BiosVersion data from the BIOS ID.
292 StrCpy (BiosVersion
, (CHAR16
*) (&(BiosIdImage
.BiosIdString
)));
295 if (BiosReleaseDate
!= NULL
) {
297 // Fill the build timestamp date from the BIOS ID in the "MM/DD/YY" format.
299 BiosReleaseDate
[0] = BiosIdImage
.BiosIdString
.TimeStamp
[2];
300 BiosReleaseDate
[1] = BiosIdImage
.BiosIdString
.TimeStamp
[3];
301 BiosReleaseDate
[2] = (CHAR16
) ((UINT8
) ('/'));
303 BiosReleaseDate
[3] = BiosIdImage
.BiosIdString
.TimeStamp
[4];
304 BiosReleaseDate
[4] = BiosIdImage
.BiosIdString
.TimeStamp
[5];
305 BiosReleaseDate
[5] = (CHAR16
) ((UINT8
) ('/'));
308 // Add 20 for SMBIOS table
309 // Current Linux kernel will misjudge 09 as year 0, so using 2009 for SMBIOS table
311 BiosReleaseDate
[6] = '2';
312 BiosReleaseDate
[7] = '0';
313 BiosReleaseDate
[8] = BiosIdImage
.BiosIdString
.TimeStamp
[0];
314 BiosReleaseDate
[9] = BiosIdImage
.BiosIdString
.TimeStamp
[1];
316 BiosReleaseDate
[10] = (CHAR16
) ((UINT8
) ('\0'));
319 if (BiosReleaseTime
!= NULL
) {
322 // Fill the build timestamp time from the BIOS ID in the "HH:MM" format.
325 BiosReleaseTime
[0] = BiosIdImage
.BiosIdString
.TimeStamp
[6];
326 BiosReleaseTime
[1] = BiosIdImage
.BiosIdString
.TimeStamp
[7];
327 BiosReleaseTime
[2] = (CHAR16
) ((UINT8
) (':'));
329 BiosReleaseTime
[3] = BiosIdImage
.BiosIdString
.TimeStamp
[8];
330 BiosReleaseTime
[4] = BiosIdImage
.BiosIdString
.TimeStamp
[9];
332 BiosReleaseTime
[5] = (CHAR16
) ((UINT8
) ('\0'));