+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved\r
- \r\r
- SPDX-License-Identifier: BSD-2-Clause-Patent\r
-\r
- \r\r
-\r
-Module Name:\r
-\r
- BiosIdLib.c\r
-\r
-Abstract:\r
-\r
- Boot service DXE BIOS ID library implementation.\r
-\r
- These functions in this file can be called during DXE and cannot be called during runtime\r
- or in SMM which should use a RT or SMM library.\r
-\r
---*/\r
-\r
-#include <PiDxe.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/HobLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/DebugLib.h>\r
-\r
-#include <Library/BiosIdLib.h>\r
-#include <Guid/BiosId.h>\r
-#include <Protocol/FirmwareVolume2.h>\r
-#include <Protocol/LoadedImage.h>\r
-\r
-\r
-EFI_STATUS\r
-GetImageFromFv (\r
- IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r
- IN EFI_GUID *NameGuid,\r
- IN EFI_SECTION_TYPE SectionType,\r
- OUT VOID **Buffer,\r
- OUT UINTN *Size\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_FV_FILETYPE FileType;\r
- EFI_FV_FILE_ATTRIBUTES Attributes;\r
- UINT32 AuthenticationStatus;\r
-\r
- //\r
- // Read desired section content in NameGuid file\r
- //\r
- *Buffer = NULL;\r
- *Size = 0;\r
- Status = Fv->ReadSection (\r
- Fv,\r
- NameGuid,\r
- SectionType,\r
- 0,\r
- Buffer,\r
- Size,\r
- &AuthenticationStatus\r
- );\r
-\r
- if (EFI_ERROR (Status) && (SectionType == EFI_SECTION_TE)) {\r
- //\r
- // Try reading PE32 section, since the TE section does not exist\r
- //\r
- *Buffer = NULL;\r
- *Size = 0;\r
- Status = Fv->ReadSection (\r
- Fv,\r
- NameGuid,\r
- EFI_SECTION_PE32,\r
- 0,\r
- Buffer,\r
- Size,\r
- &AuthenticationStatus\r
- );\r
- }\r
-\r
- if (EFI_ERROR (Status) &&\r
- ((SectionType == EFI_SECTION_TE) || (SectionType == EFI_SECTION_PE32))) {\r
- //\r
- // Try reading raw file, since the desired section does not exist\r
- //\r
- *Buffer = NULL;\r
- *Size = 0;\r
- Status = Fv->ReadFile (\r
- Fv,\r
- NameGuid,\r
- Buffer,\r
- Size,\r
- &FileType,\r
- &Attributes,\r
- &AuthenticationStatus\r
- );\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-GetImageEx (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_GUID *NameGuid,\r
- IN EFI_SECTION_TYPE SectionType,\r
- OUT VOID **Buffer,\r
- OUT UINTN *Size,\r
- BOOLEAN WithinImageFv\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_HANDLE *HandleBuffer;\r
- UINTN HandleCount;\r
- UINTN Index;\r
- EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
-\r
- EFI_FIRMWARE_VOLUME2_PROTOCOL *ImageFv;\r
- EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
-\r
-\r
- if (ImageHandle == NULL && WithinImageFv) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = EFI_NOT_FOUND;\r
- ImageFv = NULL;\r
- if (ImageHandle != NULL) {\r
- Status = gBS->HandleProtocol (\r
- ImageHandle,\r
- &gEfiLoadedImageProtocolGuid,\r
- (VOID **) &LoadedImage\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- Status = gBS->HandleProtocol (\r
- LoadedImage->DeviceHandle,\r
- &gEfiFirmwareVolume2ProtocolGuid,\r
- (VOID **) &ImageFv\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- Status = GetImageFromFv (ImageFv, NameGuid, SectionType, Buffer, Size);\r
- }\r
- }\r
-\r
- if (Status == EFI_SUCCESS || WithinImageFv) {\r
- return Status;\r
- }\r
-\r
- Status = gBS->LocateHandleBuffer (\r
- ByProtocol,\r
- &gEfiFirmwareVolume2ProtocolGuid,\r
- NULL,\r
- &HandleCount,\r
- &HandleBuffer\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- //\r
- // Find desired image in all Fvs\r
- //\r
- for (Index = 0; Index < HandleCount; ++Index) {\r
- Status = gBS->HandleProtocol (\r
- HandleBuffer[Index],\r
- &gEfiFirmwareVolume2ProtocolGuid,\r
- (VOID**)&Fv\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- gBS->FreePool(HandleBuffer);\r
- return Status;\r
- }\r
-\r
- if (ImageFv != NULL && Fv == ImageFv) {\r
- continue;\r
- }\r
-\r
- Status = GetImageFromFv (Fv, NameGuid, SectionType, Buffer, Size);\r
-\r
- if (!EFI_ERROR (Status)) {\r
- break;\r
- }\r
- }\r
- gBS->FreePool(HandleBuffer);\r
-\r
- //\r
- // Not found image\r
- //\r
- if (Index == HandleCount) {\r
- return EFI_NOT_FOUND;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- This function returns BIOS ID by searching HOB or FV.\r
-\r
- @param BiosIdImage The BIOS ID got from HOB or FV.\r
-\r
- @retval EFI_SUCCESS All parameters were valid and BIOS ID has been got.\r
- @retval EFI_NOT_FOUND BiosId image is not found, and no parameter will be modified.\r
- @retval EFI_INVALID_PARAMETER The parameter is NULL.\r
-\r
-**/\r
-EFI_STATUS\r
-GetBiosId (\r
- OUT BIOS_ID_IMAGE *BiosIdImage\r
- )\r
-\r
-{\r
- EFI_STATUS Status;\r
- VOID *Address = NULL;\r
- UINTN Size = 0;\r
-\r
- DEBUG ((EFI_D_INFO, "Get BIOS ID from FV\n"));\r
-\r
- Status = GetImageEx (\r
- NULL,\r
- &gEfiBiosIdGuid,\r
- EFI_SECTION_RAW,\r
- &Address,\r
- &Size,\r
- FALSE\r
- );\r
-\r
- if (Status == EFI_SUCCESS) {\r
- //\r
- // BiosId image is present in FV\r
- //\r
- if (Address != NULL) {\r
- Size = sizeof (BIOS_ID_IMAGE);\r
- gBS->CopyMem (\r
- (void *) BiosIdImage,\r
- Address,\r
- Size\r
- );\r
- //\r
- // GetImage () allocated buffer for Address, now clear it.\r
- //\r
- gBS->FreePool (Address);\r
-\r
- DEBUG ((EFI_D_INFO, "Get BIOS ID from FV successfully\n"));\r
- DEBUG ((EFI_D_INFO, "BIOS ID: %s\n", (CHAR16 *) (&(BiosIdImage->BiosIdString))));\r
-\r
- return EFI_SUCCESS;\r
- }\r
- }\r
- return EFI_NOT_FOUND;\r
-}\r
-\r
-/**\r
- This function returns the Version & Release Date and Time by getting and converting\r
- BIOS ID.\r
-\r
- @param BiosVersion The Bios Version out of the conversion.\r
- @param BiosReleaseDate The Bios Release Date out of the conversion.\r
- @param BiosReleaseTime - The Bios Release Time out of the conversion.\r
-\r
- @retval EFI_SUCCESS - BIOS Version & Release Date and Time have been got successfully.\r
- @retval EFI_NOT_FOUND - BiosId image is not found, and no parameter will be modified.\r
- @retval EFI_INVALID_PARAMETER - All the parameters are NULL.\r
-\r
-**/\r
-EFI_STATUS\r
-GetBiosVersionDateTime (\r
- OUT CHAR16 *BiosVersion, OPTIONAL\r
- OUT CHAR16 *BiosReleaseDate, OPTIONAL\r
- OUT CHAR16 *BiosReleaseTime OPTIONAL\r
- )\r
-{\r
- EFI_STATUS Status;\r
- BIOS_ID_IMAGE BiosIdImage;\r
-\r
- if ((BiosVersion == NULL) && (BiosReleaseDate == NULL) && (BiosReleaseTime == NULL)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = GetBiosId (&BiosIdImage);\r
- if (EFI_ERROR (Status)) {\r
- return EFI_NOT_FOUND;\r
- }\r
-\r
- if (BiosVersion != NULL) {\r
- //\r
- // Fill the BiosVersion data from the BIOS ID.\r
- //\r
- StrCpy (BiosVersion, (CHAR16 *) (&(BiosIdImage.BiosIdString)));\r
- }\r
-\r
- if (BiosReleaseDate != NULL) {\r
- //\r
- // Fill the build timestamp date from the BIOS ID in the "MM/DD/YY" format.\r
- //\r
- BiosReleaseDate[0] = BiosIdImage.BiosIdString.TimeStamp[2];\r
- BiosReleaseDate[1] = BiosIdImage.BiosIdString.TimeStamp[3];\r
- BiosReleaseDate[2] = (CHAR16) ((UINT8) ('/'));\r
-\r
- BiosReleaseDate[3] = BiosIdImage.BiosIdString.TimeStamp[4];\r
- BiosReleaseDate[4] = BiosIdImage.BiosIdString.TimeStamp[5];\r
- BiosReleaseDate[5] = (CHAR16) ((UINT8) ('/'));\r
-\r
- //\r
- // Add 20 for SMBIOS table\r
- // Current Linux kernel will misjudge 09 as year 0, so using 2009 for SMBIOS table\r
- //\r
- BiosReleaseDate[6] = '2';\r
- BiosReleaseDate[7] = '0';\r
- BiosReleaseDate[8] = BiosIdImage.BiosIdString.TimeStamp[0];\r
- BiosReleaseDate[9] = BiosIdImage.BiosIdString.TimeStamp[1];\r
-\r
- BiosReleaseDate[10] = (CHAR16) ((UINT8) ('\0'));\r
- }\r
-\r
- if (BiosReleaseTime != NULL) {\r
-\r
- //\r
- // Fill the build timestamp time from the BIOS ID in the "HH:MM" format.\r
- //\r
-\r
- BiosReleaseTime[0] = BiosIdImage.BiosIdString.TimeStamp[6];\r
- BiosReleaseTime[1] = BiosIdImage.BiosIdString.TimeStamp[7];\r
- BiosReleaseTime[2] = (CHAR16) ((UINT8) (':'));\r
-\r
- BiosReleaseTime[3] = BiosIdImage.BiosIdString.TimeStamp[8];\r
- BiosReleaseTime[4] = BiosIdImage.BiosIdString.TimeStamp[9];\r
-\r
- BiosReleaseTime[5] = (CHAR16) ((UINT8) ('\0'));\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r