TianoCore EDK2 master
Loading...
Searching...
No Matches
MiscBaseBoardManufacturerFunction.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 (MiscBaseBoardManufacturer) {
40 CHAR8 *OptionalStrStart;
41 CHAR8 *StrStart;
42 UINTN RecordLength;
43 UINTN ManuStrLen;
44 UINTN ProductNameStrLen;
45 UINTN VerStrLen;
46 UINTN SerialNumStrLen;
47 UINTN AssetTagStrLen;
48 UINTN ChassisLocaStrLen;
49 UINTN HandleCount;
50 UINT16 *HandleArray;
51 CHAR16 *BaseBoardManufacturer;
52 CHAR16 *BaseBoardProductName;
53 CHAR16 *Version;
54 EFI_STRING SerialNumber;
55 EFI_STRING AssetTag;
56 EFI_STRING ChassisLocation;
57 EFI_STRING_ID TokenToGet;
58 SMBIOS_TABLE_TYPE2 *SmbiosRecord;
59 SMBIOS_TABLE_TYPE2 *InputData;
60 EFI_STATUS Status;
61
62 EFI_STRING_ID TokenToUpdate;
63
64 HandleCount = 0;
65 HandleArray = NULL;
66 InputData = NULL;
67
68 //
69 // First check for invalid parameters.
70 //
71 if (RecordData == NULL) {
72 return EFI_INVALID_PARAMETER;
73 }
74
75 InputData = (SMBIOS_TABLE_TYPE2 *)RecordData;
76
77 BaseBoardManufacturer = (CHAR16 *)PcdGetPtr (PcdBaseBoardManufacturer);
78 if (StrLen (BaseBoardManufacturer) > 0) {
79 TokenToUpdate = STRING_TOKEN (STR_MISC_BASE_BOARD_MANUFACTURER);
80 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, BaseBoardManufacturer, NULL);
81 } else {
83 mSmbiosMiscHiiHandle,
84 STRING_TOKEN (STR_MISC_BASE_BOARD_MANUFACTURER),
85 BoardManufacturerType02
86 );
87 }
88
89 BaseBoardProductName = (CHAR16 *)PcdGetPtr (PcdBaseBoardProductName);
90 if (StrLen (BaseBoardProductName) > 0) {
91 TokenToUpdate = STRING_TOKEN (STR_MISC_BASE_BOARD_PRODUCT_NAME);
92 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, BaseBoardProductName, NULL);
93 } else {
95 mSmbiosMiscHiiHandle,
96 STRING_TOKEN (STR_MISC_BASE_BOARD_PRODUCT_NAME),
97 ProductNameType02
98 );
99 }
100
101 Version = (CHAR16 *)PcdGetPtr (PcdBaseBoardVersion);
102 if (StrLen (Version) > 0) {
103 TokenToUpdate = STRING_TOKEN (STR_MISC_BASE_BOARD_VERSION);
104 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Version, NULL);
105 } else {
107 mSmbiosMiscHiiHandle,
108 STRING_TOKEN (STR_MISC_BASE_BOARD_VERSION),
109 VersionType02
110 );
111 }
112
114 mSmbiosMiscHiiHandle,
115 STRING_TOKEN (STR_MISC_BASE_BOARD_ASSET_TAG),
116 AssetTagType02
117 );
119 mSmbiosMiscHiiHandle,
120 STRING_TOKEN (STR_MISC_BASE_BOARD_SERIAL_NUMBER),
121 SerialNumberType02
122 );
124 mSmbiosMiscHiiHandle,
125 STRING_TOKEN (STR_MISC_BASE_BOARD_SKU_NUMBER),
126 SerialNumberType02
127 );
129 mSmbiosMiscHiiHandle,
130 STRING_TOKEN (STR_MISC_BASE_BOARD_CHASSIS_LOCATION),
131 ChassisLocationType02
132 );
133
134 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_MANUFACTURER);
135 BaseBoardManufacturer = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
136 ManuStrLen = StrLen (BaseBoardManufacturer);
137
138 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_PRODUCT_NAME);
139 BaseBoardProductName = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
140 ProductNameStrLen = StrLen (BaseBoardProductName);
141
142 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_VERSION);
143 Version = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
144 VerStrLen = StrLen (Version);
145
146 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_SERIAL_NUMBER);
147 SerialNumber = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
148 SerialNumStrLen = StrLen (SerialNumber);
149
150 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_ASSET_TAG);
151 AssetTag = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
152 AssetTagStrLen = StrLen (AssetTag);
153
154 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_CHASSIS_LOCATION);
155 ChassisLocation = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
156 ChassisLocaStrLen = StrLen (ChassisLocation);
157
158 //
159 // Two zeros following the last string.
160 //
161 RecordLength = sizeof (SMBIOS_TABLE_TYPE2) +
162 ManuStrLen + 1 +
163 ProductNameStrLen + 1 +
164 VerStrLen + 1 +
165 SerialNumStrLen + 1 +
166 AssetTagStrLen + 1 +
167 ChassisLocaStrLen + 1 + 1;
168 SmbiosRecord = AllocateZeroPool (RecordLength);
169 if (SmbiosRecord == NULL) {
170 Status = EFI_OUT_OF_RESOURCES;
171 goto Exit;
172 }
173
174 (VOID)CopyMem (SmbiosRecord, InputData, sizeof (SMBIOS_TABLE_TYPE2));
175 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE2);
176
177 //
178 // Update Contained objects Handle
179 //
180 SmbiosRecord->NumberOfContainedObjectHandles = 0;
182 EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE,
183 &HandleArray,
184 &HandleCount
185 );
186 // It's assumed there's at most a single chassis
187 ASSERT (HandleCount < 2);
188 if (HandleCount > 0) {
189 SmbiosRecord->ChassisHandle = HandleArray[0];
190 }
191
192 FreePool (HandleArray);
193
194 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
195 UnicodeStrToAsciiStrS (BaseBoardManufacturer, OptionalStrStart, ManuStrLen + 1);
196
197 StrStart = OptionalStrStart + ManuStrLen + 1;
198 UnicodeStrToAsciiStrS (BaseBoardProductName, StrStart, ProductNameStrLen + 1);
199
200 StrStart += ProductNameStrLen + 1;
201 UnicodeStrToAsciiStrS (Version, StrStart, VerStrLen + 1);
202
203 StrStart += VerStrLen + 1;
204 UnicodeStrToAsciiStrS (SerialNumber, StrStart, SerialNumStrLen + 1);
205
206 StrStart += SerialNumStrLen + 1;
207 UnicodeStrToAsciiStrS (AssetTag, StrStart, AssetTagStrLen + 1);
208
209 StrStart += AssetTagStrLen + 1;
210 UnicodeStrToAsciiStrS (ChassisLocation, StrStart, ChassisLocaStrLen + 1);
211
212 Status = SmbiosMiscAddRecord ((UINT8 *)SmbiosRecord, NULL);
213 if (EFI_ERROR (Status)) {
214 DEBUG ((
215 DEBUG_ERROR,
216 "[%a]:[%dL] Smbios Type02 Table Log Failed! %r \n",
217 __func__,
218 DEBUG_LINE_NUMBER,
219 Status
220 ));
221 }
222
223 FreePool (SmbiosRecord);
224
225Exit:
226 if (BaseBoardManufacturer != NULL) {
227 FreePool (BaseBoardManufacturer);
228 }
229
230 if (BaseBoardProductName != NULL) {
231 FreePool (BaseBoardProductName);
232 }
233
234 if (Version != NULL) {
235 FreePool (Version);
236 }
237
238 if (SerialNumber != NULL) {
239 FreePool (SerialNumber);
240 }
241
242 if (AssetTag != NULL) {
243 FreePool (AssetTag);
244 }
245
246 if (ChassisLocation != NULL) {
247 FreePool (ChassisLocation);
248 }
249
250 return 0;
251}
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
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
VOID SmbiosMiscGetLinkTypeHandle(IN UINT8 SmbiosType, OUT UINT16 **HandleArray, OUT UINTN *HandleCount)
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)