TianoCore EDK2 master
Loading...
Searching...
No Matches
MiscSystemManufacturerFunction.c
Go to the documentation of this file.
1
16#include <Library/BaseLib.h>
18#include <Library/DebugLib.h>
19#include <Library/HiiLib.h>
21#include <Library/OemMiscLib.h>
22#include <Library/PrintLib.h>
24
25#include "SmbiosMisc.h"
26
39SMBIOS_MISC_TABLE_FUNCTION (MiscSystemManufacturer) {
40 CHAR8 *OptionalStrStart;
41 CHAR8 *StrStart;
42 UINTN ManuStrLen;
43 UINTN VerStrLen;
44 UINTN PdNameStrLen;
45 UINTN SerialNumStrLen;
46 UINTN SKUNumStrLen;
47 UINTN FamilyStrLen;
48 UINTN RecordLength;
49 EFI_STRING Manufacturer;
50 EFI_STRING ProductName;
51 EFI_STRING Version;
52 EFI_STRING SerialNumber;
53 EFI_STRING SKUNumber;
54 EFI_STRING Family;
55 EFI_STRING_ID TokenToGet;
56 SMBIOS_TABLE_TYPE1 *SmbiosRecord;
57 SMBIOS_TABLE_TYPE1 *InputData;
58 EFI_STATUS Status;
59 EFI_STRING_ID TokenToUpdate;
60 CHAR16 *Product;
61 CHAR16 *pVersion;
62
63 Status = EFI_SUCCESS;
64
65 //
66 // First check for invalid parameters.
67 //
68 if (RecordData == NULL) {
69 return EFI_INVALID_PARAMETER;
70 }
71
72 InputData = (SMBIOS_TABLE_TYPE1 *)RecordData;
73
74 Product = (CHAR16 *)PcdGetPtr (PcdSystemProductName);
75 if (StrLen (Product) > 0) {
76 TokenToUpdate = STRING_TOKEN (STR_MISC_SYSTEM_PRODUCT_NAME);
77 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Product, NULL);
78 } else {
80 mSmbiosMiscHiiHandle,
81 STRING_TOKEN (STR_MISC_SYSTEM_PRODUCT_NAME),
82 ProductNameType01
83 );
84 }
85
86 pVersion = (CHAR16 *)PcdGetPtr (PcdSystemVersion);
87 if (StrLen (pVersion) > 0) {
88 TokenToUpdate = STRING_TOKEN (STR_MISC_SYSTEM_VERSION);
89 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, pVersion, NULL);
90 } else {
92 mSmbiosMiscHiiHandle,
93 STRING_TOKEN (STR_MISC_SYSTEM_VERSION),
94 VersionType01
95 );
96 }
97
99 mSmbiosMiscHiiHandle,
100 STRING_TOKEN (STR_MISC_SYSTEM_SERIAL_NUMBER),
101 SerialNumType01
102 );
104 mSmbiosMiscHiiHandle,
105 STRING_TOKEN (STR_MISC_SYSTEM_MANUFACTURER),
106 SystemManufacturerType01
107 );
109 mSmbiosMiscHiiHandle,
110 STRING_TOKEN (STR_MISC_SYSTEM_SKU_NUMBER),
111 SkuNumberType01
112 );
114 mSmbiosMiscHiiHandle,
115 STRING_TOKEN (STR_MISC_SYSTEM_FAMILY),
116 FamilyType01
117 );
118
119 TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_MANUFACTURER);
120 Manufacturer = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
121 ManuStrLen = StrLen (Manufacturer);
122
123 TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_PRODUCT_NAME);
124 ProductName = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
125 PdNameStrLen = StrLen (ProductName);
126
127 TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_VERSION);
128 Version = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
129 VerStrLen = StrLen (Version);
130
131 TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SERIAL_NUMBER);
132 SerialNumber = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
133 SerialNumStrLen = StrLen (SerialNumber);
134
135 TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SKU_NUMBER);
136 SKUNumber = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
137 SKUNumStrLen = StrLen (SKUNumber);
138
139 TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_FAMILY);
140 Family = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
141 FamilyStrLen = StrLen (Family);
142
143 //
144 // Two zeros following the last string.
145 //
146 RecordLength = sizeof (SMBIOS_TABLE_TYPE1) +
147 ManuStrLen + 1 +
148 PdNameStrLen + 1 +
149 VerStrLen + 1 +
150 SerialNumStrLen + 1 +
151 SKUNumStrLen + 1 +
152 FamilyStrLen + 1 + 1;
153 SmbiosRecord = AllocateZeroPool (RecordLength);
154
155 if (SmbiosRecord == NULL) {
156 Status = EFI_OUT_OF_RESOURCES;
157 goto Exit;
158 }
159
160 (VOID)CopyMem (SmbiosRecord, InputData, sizeof (SMBIOS_TABLE_TYPE1));
161
162 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE1);
163
164 OemGetSystemUuid (&SmbiosRecord->Uuid);
165
166 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
167 UnicodeStrToAsciiStrS (Manufacturer, OptionalStrStart, ManuStrLen + 1);
168 StrStart = OptionalStrStart + ManuStrLen + 1;
169 UnicodeStrToAsciiStrS (ProductName, StrStart, PdNameStrLen + 1);
170 StrStart += PdNameStrLen + 1;
171 UnicodeStrToAsciiStrS (Version, StrStart, VerStrLen + 1);
172 StrStart += VerStrLen + 1;
173 UnicodeStrToAsciiStrS (SerialNumber, StrStart, SerialNumStrLen + 1);
174 StrStart += SerialNumStrLen + 1;
175 UnicodeStrToAsciiStrS (SKUNumber, StrStart, SKUNumStrLen + 1);
176 StrStart += SKUNumStrLen + 1;
177 UnicodeStrToAsciiStrS (Family, StrStart, FamilyStrLen + 1);
178
179 //
180 // Now we have got the full smbios record, call smbios protocol to add this record.
181 //
182 Status = SmbiosMiscAddRecord ((UINT8 *)SmbiosRecord, NULL);
183 if (EFI_ERROR (Status)) {
184 DEBUG ((
185 DEBUG_ERROR,
186 "[%a]:[%dL] Smbios Type01 Table Log Failed! %r \n",
187 __func__,
188 DEBUG_LINE_NUMBER,
189 Status
190 ));
191 }
192
193 FreePool (SmbiosRecord);
194
195Exit:
196 if (Manufacturer != NULL) {
197 FreePool (Manufacturer);
198 }
199
200 if (ProductName != NULL) {
201 FreePool (ProductName);
202 }
203
204 if (Version != NULL) {
205 FreePool (Version);
206 }
207
208 if (SerialNumber != NULL) {
209 FreePool (SerialNumber);
210 }
211
212 if (SKUNumber != NULL) {
213 FreePool (SKUNumber);
214 }
215
216 if (Family != NULL) {
217 FreePool (Family);
218 }
219
220 return Status;
221}
UINT64 UINTN
RETURN_STATUS EFIAPI UnicodeStrToAsciiStrS(IN CONST CHAR16 *Source, OUT CHAR8 *Destination, IN UINTN DestMax)
Definition: SafeString.c:2650
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 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 NULL
Definition: Base.h:319
#define DEBUG(Expression)
Definition: DebugLib.h:434
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
VOID EFIAPI OemGetSystemUuid(OUT GUID *SystemUuid)
Definition: OemMiscLib.c:251
#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 EFI_SUCCESS
Definition: UefiBaseType.h:112
#define STRING_TOKEN(t)