3 Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
4 Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
6 Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/BaseLib.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/DebugLib.h>
14 #include <Library/HiiLib.h>
15 #include <Library/MemoryAllocationLib.h>
16 #include <Library/PrintLib.h>
17 #include <Library/UefiBootServicesTableLib.h>
19 #include "SmbiosMisc.h"
22 CONST CHAR8
*MonthStr
;
27 MONTH_DESCRIPTION mMonthDescription
[] = {
40 { "???", 1 }, // Use 1 as default month
44 Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'
47 @param Value Pointer to Base2_Data
53 Base2ToByteWith64KUnit (
59 Size
= ((Value
+ (SIZE_64KB
- 1)) >> 16);
65 Returns the date and time this file (and firmware) was built.
67 @param[out] *Time Pointer to the EFI_TIME structure to fill in.
74 CONST CHAR8
*ReleaseDate
= __DATE__
;
75 CONST CHAR8
*ReleaseTime
= __TIME__
;
78 for (i
= 0; i
< 12; i
++) {
79 if (AsciiStrnCmp (ReleaseDate
, mMonthDescription
[i
].MonthStr
, 3) == 0) {
84 Time
->Month
= mMonthDescription
[i
].MonthInt
;
85 Time
->Day
= AsciiStrDecimalToUintn (ReleaseDate
+ 4);
86 Time
->Year
= AsciiStrDecimalToUintn (ReleaseDate
+ 7);
87 Time
->Hour
= AsciiStrDecimalToUintn (ReleaseTime
);
88 Time
->Minute
= AsciiStrDecimalToUintn (ReleaseTime
+ 3);
89 Time
->Second
= AsciiStrDecimalToUintn (ReleaseTime
+ 6);
93 Fetches the firmware ('BIOS') release date from the
94 FirmwareVersionInfo HOB.
96 @return The release date as a UTF-16 string
106 ReleaseDate
= AllocateZeroPool ((sizeof (CHAR16
)) * SMBIOS_STRING_MAX_LENGTH
);
107 if (ReleaseDate
== NULL
) {
111 GetReleaseTime (&BuildTime
);
113 (VOID
)UnicodeSPrintAsciiFormat (
115 (sizeof (CHAR16
)) * SMBIOS_STRING_MAX_LENGTH
,
126 Fetches the firmware ('BIOS') version from the
127 FirmwareVersionInfo HOB.
129 @return The version as a UTF-16 string
136 CHAR16
*ReleaseString
;
138 ReleaseString
= (CHAR16
*)FixedPcdGetPtr (PcdFirmwareVersionString
);
140 return ReleaseString
;
144 This function makes boot time changes to the contents of the
145 MiscBiosVendor (Type 0) record.
147 @param RecordData Pointer to SMBIOS table with default values.
148 @param Smbios SMBIOS protocol.
150 @retval EFI_SUCCESS The SMBIOS table was successfully added.
151 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
152 @retval EFI_OUT_OF_RESOURCES Failed to allocate required memory.
155 SMBIOS_MISC_TABLE_FUNCTION (MiscBiosVendor
) {
156 CHAR8
*OptionalStrStart
;
161 UINTN BiosPhysicalSize
;
165 CHAR16
*Char16String
;
167 EFI_STRING_ID TokenToUpdate
;
168 EFI_STRING_ID TokenToGet
;
169 SMBIOS_TABLE_TYPE0
*SmbiosRecord
;
170 SMBIOS_TABLE_TYPE0
*InputData
;
173 // First check for invalid parameters.
175 if (RecordData
== NULL
) {
176 return EFI_INVALID_PARAMETER
;
179 InputData
= (SMBIOS_TABLE_TYPE0
*)RecordData
;
181 Vendor
= (CHAR16
*)PcdGetPtr (PcdFirmwareVendor
);
183 if (StrLen (Vendor
) > 0) {
184 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_VENDOR
);
185 HiiSetString (mSmbiosMiscHiiHandle
, TokenToUpdate
, Vendor
, NULL
);
188 Version
= GetBiosVersion ();
190 if (StrLen (Version
) > 0) {
191 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_VERSION
);
192 HiiSetString (mSmbiosMiscHiiHandle
, TokenToUpdate
, Version
, NULL
);
194 Version
= (CHAR16
*)PcdGetPtr (PcdFirmwareVersionString
);
195 if (StrLen (Version
) > 0) {
196 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_VERSION
);
197 HiiSetString (mSmbiosMiscHiiHandle
, TokenToUpdate
, Version
, NULL
);
201 Char16String
= GetBiosReleaseDate ();
202 if (StrLen (Char16String
) > 0) {
203 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE
);
204 HiiSetString (mSmbiosMiscHiiHandle
, TokenToUpdate
, Char16String
, NULL
);
207 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_VENDOR
);
208 Vendor
= HiiGetPackageString (&gEfiCallerIdGuid
, TokenToGet
, NULL
);
209 VendorStrLen
= StrLen (Vendor
);
211 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_VERSION
);
212 Version
= HiiGetPackageString (&gEfiCallerIdGuid
, TokenToGet
, NULL
);
213 VerStrLen
= StrLen (Version
);
215 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE
);
216 ReleaseDate
= HiiGetPackageString (&gEfiCallerIdGuid
, TokenToGet
, NULL
);
217 DateStrLen
= StrLen (ReleaseDate
);
220 // Now update the BiosPhysicalSize
222 BiosPhysicalSize
= FixedPcdGet32 (PcdFdSize
);
225 // Two zeros following the last string.
227 SmbiosRecord
= AllocateZeroPool (
228 sizeof (SMBIOS_TABLE_TYPE0
) + VendorStrLen
+ 1 +
232 if (SmbiosRecord
== NULL
) {
233 Status
= EFI_OUT_OF_RESOURCES
;
237 (VOID
)CopyMem (SmbiosRecord
, InputData
, sizeof (SMBIOS_TABLE_TYPE0
));
239 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE0
);
240 SmbiosRecord
->BiosSegment
= (UINT16
)(FixedPcdGet32 (PcdFdBaseAddress
) / SIZE_64KB
);
241 if (BiosPhysicalSize
< SIZE_16MB
) {
242 SmbiosRecord
->BiosSize
= Base2ToByteWith64KUnit (BiosPhysicalSize
) - 1;
244 SmbiosRecord
->BiosSize
= 0xFF;
245 if (BiosPhysicalSize
< SIZE_16GB
) {
246 SmbiosRecord
->ExtendedBiosSize
.Size
= BiosPhysicalSize
/ SIZE_1MB
;
247 SmbiosRecord
->ExtendedBiosSize
.Unit
= 0; // Size is in MB
249 SmbiosRecord
->ExtendedBiosSize
.Size
= BiosPhysicalSize
/ SIZE_1GB
;
250 SmbiosRecord
->ExtendedBiosSize
.Unit
= 1; // Size is in GB
254 SmbiosRecord
->SystemBiosMajorRelease
= (UINT8
)(PcdGet16 (PcdSystemBiosRelease
) >> 8);
255 SmbiosRecord
->SystemBiosMinorRelease
= (UINT8
)(PcdGet16 (PcdSystemBiosRelease
) & 0xFF);
257 SmbiosRecord
->EmbeddedControllerFirmwareMajorRelease
= (UINT16
)
258 (PcdGet16 (PcdEmbeddedControllerFirmwareRelease
) >> 8);
259 SmbiosRecord
->EmbeddedControllerFirmwareMinorRelease
= (UINT16
)
260 (PcdGet16 (PcdEmbeddedControllerFirmwareRelease
) & 0xFF);
262 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
263 UnicodeStrToAsciiStrS (Vendor
, OptionalStrStart
, VendorStrLen
+ 1);
264 StrStart
= OptionalStrStart
+ VendorStrLen
+ 1;
265 UnicodeStrToAsciiStrS (Version
, StrStart
, VerStrLen
+ 1);
266 StrStart
+= VerStrLen
+ 1;
267 UnicodeStrToAsciiStrS (ReleaseDate
, StrStart
, DateStrLen
+ 1);
269 // Now we have got the full smbios record, call smbios protocol to add this record.
271 Status
= SmbiosMiscAddRecord ((UINT8
*)SmbiosRecord
, NULL
);
272 if (EFI_ERROR (Status
)) {
275 "[%a]:[%dL] Smbios Type00 Table Log Failed! %r \n",
282 FreePool (SmbiosRecord
);
285 if (Vendor
!= NULL
) {
289 if (Version
!= NULL
) {
293 if (ReleaseDate
!= NULL
) {
294 FreePool (ReleaseDate
);
297 if (Char16String
!= NULL
) {
298 FreePool (Char16String
);