TianoCore EDK2 master
Loading...
Searching...
No Matches
MiscBiosVendorFunction.c
Go to the documentation of this file.
1
12#include <Library/BaseLib.h>
14#include <Library/DebugLib.h>
15#include <Library/HiiLib.h>
17#include <Library/OemMiscLib.h>
18#include <Library/PrintLib.h>
20
21#include "SmbiosMisc.h"
22
23typedef struct {
24 CONST CHAR8 *MonthStr;
25 UINT32 MonthInt;
27
29MONTH_DESCRIPTION mMonthDescription[] = {
30 { "Jan", 1 },
31 { "Feb", 2 },
32 { "Mar", 3 },
33 { "Apr", 4 },
34 { "May", 5 },
35 { "Jun", 6 },
36 { "Jul", 7 },
37 { "Aug", 8 },
38 { "Sep", 9 },
39 { "Oct", 10 },
40 { "Nov", 11 },
41 { "Dec", 12 },
42 { "???", 1 }, // Use 1 as default month
43};
44
54UINT8
56 IN UINTN Value
57 )
58{
59 UINT8 Size;
60
61 Size = ((Value + (SIZE_64KB - 1)) >> 16);
62
63 return Size;
64}
65
71VOID
73 OUT EFI_TIME *Time
74 )
75{
76 CONST CHAR8 *ReleaseDate = __DATE__;
77 CONST CHAR8 *ReleaseTime = __TIME__;
78 UINTN i;
79
80 for (i = 0; i < 12; i++) {
81 if (AsciiStrnCmp (ReleaseDate, mMonthDescription[i].MonthStr, 3) == 0) {
82 break;
83 }
84 }
85
86 Time->Month = mMonthDescription[i].MonthInt;
87 Time->Day = AsciiStrDecimalToUintn (ReleaseDate + 4);
88 Time->Year = AsciiStrDecimalToUintn (ReleaseDate + 7);
89 Time->Hour = AsciiStrDecimalToUintn (ReleaseTime);
90 Time->Minute = AsciiStrDecimalToUintn (ReleaseTime + 3);
91 Time->Second = AsciiStrDecimalToUintn (ReleaseTime + 6);
92}
93
100CHAR16 *
102 VOID
103 )
104{
105 CHAR16 *ReleaseDate;
106 EFI_TIME BuildTime;
107
108 ReleaseDate = AllocateZeroPool ((sizeof (CHAR16)) * SMBIOS_STRING_MAX_LENGTH);
109 if (ReleaseDate == NULL) {
110 return NULL;
111 }
112
113 GetReleaseTime (&BuildTime);
114
116 ReleaseDate,
117 (sizeof (CHAR16)) * SMBIOS_STRING_MAX_LENGTH,
118 "%02d/%02d/%4d",
119 BuildTime.Month,
120 BuildTime.Day,
121 BuildTime.Year
122 );
123
124 return ReleaseDate;
125}
126
134VOID
136 VOID
137 )
138{
139 CHAR16 *DefaultVersionString;
140 CHAR16 *Version;
141 EFI_STRING_ID TokenToUpdate;
142
143 DefaultVersionString = HiiGetString (
144 mSmbiosMiscHiiHandle,
145 STRING_TOKEN (STR_MISC_BIOS_VERSION),
146 NULL
147 );
148
150 mSmbiosMiscHiiHandle,
151 STRING_TOKEN (STR_MISC_BIOS_VERSION),
152 BiosVersionType00
153 );
154
155 Version = HiiGetString (
156 mSmbiosMiscHiiHandle,
157 STRING_TOKEN (STR_MISC_BIOS_VERSION),
158 NULL
159 );
160
161 if (((StrCmp (Version, DefaultVersionString) == 0) || (StrLen (Version) == 0))) {
162 Version = (CHAR16 *)FixedPcdGetPtr (PcdFirmwareVersionString);
163 if (StrLen (Version) > 0) {
164 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VERSION);
165 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Version, NULL);
166 }
167 }
168}
169
182SMBIOS_MISC_TABLE_FUNCTION (MiscBiosVendor) {
183 CHAR8 *OptionalStrStart;
184 CHAR8 *StrStart;
185 UINTN VendorStrLen;
186 UINTN VerStrLen;
187 UINTN DateStrLen;
188 UINT64 BiosPhysicalSize;
189 CHAR16 *Vendor;
190 CHAR16 *Version;
191 CHAR16 *ReleaseDate;
192 CHAR16 *Char16String;
193 EFI_STATUS Status;
194 EFI_STRING_ID TokenToUpdate;
195 EFI_STRING_ID TokenToGet;
196 SMBIOS_TABLE_TYPE0 *SmbiosRecord;
197 SMBIOS_TABLE_TYPE0 *InputData;
198
199 //
200 // First check for invalid parameters.
201 //
202 if (RecordData == NULL) {
203 return EFI_INVALID_PARAMETER;
204 }
205
206 InputData = (SMBIOS_TABLE_TYPE0 *)RecordData;
207
208 Vendor = (CHAR16 *)PcdGetPtr (PcdFirmwareVendor);
209
210 if (StrLen (Vendor) > 0) {
211 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VENDOR);
212 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Vendor, NULL);
213 }
214
216
217 Char16String = GetBiosReleaseDate ();
218 if (StrLen (Char16String) > 0) {
219 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);
220 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Char16String, NULL);
221 }
222
223 TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VENDOR);
224 Vendor = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
225 VendorStrLen = StrLen (Vendor);
226
227 TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VERSION);
228 Version = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
229 VerStrLen = StrLen (Version);
230
231 TokenToGet = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);
232 ReleaseDate = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
233 DateStrLen = StrLen (ReleaseDate);
234
235 //
236 // Now update the BiosPhysicalSize
237 //
238 BiosPhysicalSize = FixedPcdGet32 (PcdFdSize);
239
240 //
241 // Two zeros following the last string.
242 //
243 SmbiosRecord = AllocateZeroPool (
244 sizeof (SMBIOS_TABLE_TYPE0) + VendorStrLen + 1 +
245 VerStrLen + 1 +
246 DateStrLen + 1 + 1
247 );
248 if (SmbiosRecord == NULL) {
249 Status = EFI_OUT_OF_RESOURCES;
250 goto Exit;
251 }
252
253 (VOID)CopyMem (SmbiosRecord, InputData, sizeof (SMBIOS_TABLE_TYPE0));
254
255 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0);
256 SmbiosRecord->BiosSegment = 0;
257 if (BiosPhysicalSize < SIZE_16MB) {
258 SmbiosRecord->BiosSize = Base2ToByteWith64KUnit (BiosPhysicalSize) - 1;
259 } else {
260 SmbiosRecord->BiosSize = 0xFF;
261 if (BiosPhysicalSize < SIZE_16GB) {
262 SmbiosRecord->ExtendedBiosSize.Size = BiosPhysicalSize / SIZE_1MB;
263 SmbiosRecord->ExtendedBiosSize.Unit = 0; // Size is in MB
264 } else {
265 SmbiosRecord->ExtendedBiosSize.Size = BiosPhysicalSize / SIZE_1GB;
266 SmbiosRecord->ExtendedBiosSize.Unit = 1; // Size is in GB
267 }
268 }
269
270 SmbiosRecord->SystemBiosMajorRelease = (UINT8)(OemGetBiosRelease () >> 8);
271 SmbiosRecord->SystemBiosMinorRelease = (UINT8)(OemGetBiosRelease () & 0xFF);
272
273 SmbiosRecord->EmbeddedControllerFirmwareMajorRelease = (UINT16)(OemGetEmbeddedControllerFirmwareRelease () >> 8);
274 SmbiosRecord->EmbeddedControllerFirmwareMinorRelease = (UINT16)(OemGetEmbeddedControllerFirmwareRelease () & 0xFF);
275
276 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
277 UnicodeStrToAsciiStrS (Vendor, OptionalStrStart, VendorStrLen + 1);
278 StrStart = OptionalStrStart + VendorStrLen + 1;
279 UnicodeStrToAsciiStrS (Version, StrStart, VerStrLen + 1);
280 StrStart += VerStrLen + 1;
281 UnicodeStrToAsciiStrS (ReleaseDate, StrStart, DateStrLen + 1);
282 //
283 // Now we have got the full smbios record, call smbios protocol to add this record.
284 //
285 Status = SmbiosMiscAddRecord ((UINT8 *)SmbiosRecord, NULL);
286 if (EFI_ERROR (Status)) {
287 DEBUG ((
288 DEBUG_ERROR,
289 "[%a]:[%dL] Smbios Type00 Table Log Failed! %r \n",
290 __func__,
291 DEBUG_LINE_NUMBER,
292 Status
293 ));
294 }
295
296 FreePool (SmbiosRecord);
297
298Exit:
299 if (Vendor != NULL) {
300 FreePool (Vendor);
301 }
302
303 if (Version != NULL) {
304 FreePool (Version);
305 }
306
307 if (ReleaseDate != NULL) {
308 FreePool (ReleaseDate);
309 }
310
311 if (Char16String != NULL) {
312 FreePool (Char16String);
313 }
314
315 return Status;
316}
UINT64 UINTN
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
INTN EFIAPI AsciiStrnCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString, IN UINTN Length)
Definition: String.c:872
RETURN_STATUS EFIAPI UnicodeStrToAsciiStrS(IN CONST CHAR16 *Source, OUT CHAR8 *Destination, IN UINTN DestMax)
Definition: SafeString.c:2650
UINTN EFIAPI AsciiStrDecimalToUintn(IN CONST CHAR8 *String)
Definition: String.c:1006
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STRING EFIAPI HiiGetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL)
Definition: HiiString.c:211
EFI_STRING EFIAPI HiiGetPackageString(IN CONST EFI_GUID *PackageListGuid, IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL)
Definition: HiiString.c:171
EFI_STRING_ID EFIAPI HiiSetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId OPTIONAL, IN CONST EFI_STRING String, IN CONST CHAR8 *SupportedLanguages OPTIONAL)
Definition: HiiString.c:52
#define SMBIOS_STRING_MAX_LENGTH
Definition: SmBios.h:37
UINTN EFIAPI UnicodeSPrintAsciiFormat(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:583
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
CHAR16 * GetBiosReleaseDate(VOID)
VOID SetBiosVersion(VOID)
UINT8 Base2ToByteWith64KUnit(IN UINTN Value)
VOID GetReleaseTime(OUT EFI_TIME *Time)
VOID EFIAPI OemUpdateSmbiosInfo(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID TokenToUpdate, IN OEM_MISC_SMBIOS_HII_STRING_FIELD Field)
Definition: OemMiscLib.c:136
UINT16 EFIAPI OemGetEmbeddedControllerFirmwareRelease(VOID)
Definition: OemMiscLib.c:279
UINT16 EFIAPI OemGetBiosRelease(VOID)
Definition: OemMiscLib.c:265
#define FixedPcdGet32(TokenName)
Definition: PcdLib.h:92
#define FixedPcdGetPtr(TokenName)
Definition: PcdLib.h:134
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
EFI_STATUS SmbiosMiscAddRecord(IN UINT8 *Buffer, IN OUT EFI_SMBIOS_HANDLE *SmbiosHandle OPTIONAL)
VOID EFIAPI Exit(IN EFI_STATUS Status)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define STRING_TOKEN(t)