3 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 MiscBaseBoardManufacturerFunction.c
15 BaseBoard manufacturer information boot time changes.
21 #include "CommonHeader.h"
22 #include "MiscSubclassDriver.h"
23 #include <Library/NetLib.h>
24 #include "Library/DebugLib.h"
25 #include <Uefi/UefiBaseType.h>
26 #include <Guid/PlatformInfo.h>
29 extern EFI_PLATFORM_INFO_HOB
*mPlatformInfo
;
32 This function makes boot time changes to the contents of the
33 MiscBaseBoardManufacturer (Type 2).
35 @param RecordData Pointer to copy of RecordData from the Data Table.
37 @retval EFI_SUCCESS All parameters were valid.
38 @retval EFI_UNSUPPORTED Unexpected RecordType value.
39 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
42 MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer
)
44 CHAR8
*OptionalStrStart
;
48 UINTN AssertTagStrLen
;
49 UINTN SerialNumStrLen
;
52 EFI_STRING Manufacturer
;
55 EFI_STRING SerialNumber
;
58 STRING_REF TokenToGet
;
59 EFI_SMBIOS_HANDLE SmbiosHandle
;
60 SMBIOS_TABLE_TYPE2
*SmbiosRecord
;
61 EFI_MISC_BASE_BOARD_MANUFACTURER
*ForType2InputData
;
68 ForType2InputData
= (EFI_MISC_BASE_BOARD_MANUFACTURER
*)RecordData
;
71 // First check for invalid parameters.
73 if (RecordData
== NULL
|| mPlatformInfo
== NULL
) {
74 return EFI_INVALID_PARAMETER
;
77 if (BOARD_ID_MINNOW2_TURBOT
== mPlatformInfo
->BoardId
) {
78 UnicodeSPrint (Buffer
, sizeof (Buffer
),L
"ADI");
79 HiiSetString(mHiiHandle
,STRING_TOKEN(STR_MISC_BASE_BOARD_MANUFACTURER
), Buffer
, NULL
);
81 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_MANUFACTURER
);
82 Manufacturer
= SmbiosMiscGetString (TokenToGet
);
83 ManuStrLen
= StrLen(Manufacturer
);
84 if (ManuStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
85 return EFI_UNSUPPORTED
;
88 if (BOARD_ID_MINNOW2_TURBOT
== mPlatformInfo
->BoardId
) {
89 UnicodeSPrint (Buffer
, sizeof (Buffer
),L
"MinnowBoard Turbot");
90 HiiSetString(mHiiHandle
,STRING_TOKEN(STR_MISC_BASE_BOARD_PRODUCT_NAME1
), Buffer
, NULL
);
92 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_PRODUCT_NAME1
);
93 Product
= SmbiosMiscGetString (TokenToGet
);
94 ProductStrLen
= StrLen(Product
);
95 if (ProductStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
96 return EFI_UNSUPPORTED
;
98 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_VERSION
);
99 Version
= SmbiosMiscGetString (TokenToGet
);
100 VerStrLen
= StrLen(Version
);
101 if (VerStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
102 return EFI_UNSUPPORTED
;
106 //Get handle infomation
110 Status
= gBS
->LocateHandle (
112 &gEfiSimpleNetworkProtocolGuid
,
118 if (Status
== EFI_BUFFER_TOO_SMALL
) {
119 Handles
= AllocateZeroPool(BufferSize
);
120 if (Handles
== NULL
) {
121 return (EFI_OUT_OF_RESOURCES
);
123 Status
= gBS
->LocateHandle(
125 &gEfiSimpleNetworkProtocolGuid
,
135 Status
= NetLibGetMacString (
140 if (EFI_ERROR (Status
)) {
143 SerialNumber
= MacStr
;
144 SerialNumStrLen
= StrLen(SerialNumber
);
145 if (SerialNumStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
146 return EFI_UNSUPPORTED
;
148 DEBUG ((EFI_D_ERROR
, "MAC Address: %S\n", MacStr
));
150 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_ASSET_TAG
);
151 AssertTag
= SmbiosMiscGetString (TokenToGet
);
152 AssertTagStrLen
= StrLen(AssertTag
);
153 if (AssertTagStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
154 return EFI_UNSUPPORTED
;
157 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_CHASSIS_LOCATION
);
158 Chassis
= SmbiosMiscGetString (TokenToGet
);
159 ChassisStrLen
= StrLen(Chassis
);
160 if (ChassisStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
161 return EFI_UNSUPPORTED
;
166 // Two zeros following the last string.
168 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE2
) + ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1 + SerialNumStrLen
+ 1 + AssertTagStrLen
+ 1 + ChassisStrLen
+1 + 1);
169 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE2
) + ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1 + SerialNumStrLen
+ 1 + AssertTagStrLen
+ 1 + ChassisStrLen
+1 + 1);
171 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION
;
172 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE2
);
175 // Make handle chosen by smbios protocol.add automatically.
177 SmbiosRecord
->Hdr
.Handle
= 0;
180 // Manu will be the 1st optional string following the formatted structure.
182 SmbiosRecord
->Manufacturer
= 1;
185 // ProductName will be the 2st optional string following the formatted structure.
187 SmbiosRecord
->ProductName
= 2;
190 // Version will be the 3rd optional string following the formatted structure.
192 SmbiosRecord
->Version
= 3;
195 // SerialNumber will be the 4th optional string following the formatted structure.
197 SmbiosRecord
->SerialNumber
= 4;
200 // AssertTag will be the 5th optional string following the formatted structure.
202 SmbiosRecord
->AssetTag
= 5;
205 // LocationInChassis will be the 6th optional string following the formatted structure.
207 SmbiosRecord
->LocationInChassis
= 6;
208 SmbiosRecord
->FeatureFlag
= (*(BASE_BOARD_FEATURE_FLAGS
*)&(ForType2InputData
->BaseBoardFeatureFlags
));
209 SmbiosRecord
->ChassisHandle
= 0;
210 SmbiosRecord
->BoardType
= (UINT8
)ForType2InputData
->BaseBoardType
;
211 SmbiosRecord
->NumberOfContainedObjectHandles
= 0;
213 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
216 // Since we fill NumberOfContainedObjectHandles = 0 for simple, just after this filed to fill string
218 UnicodeStrToAsciiStr(Manufacturer
, OptionalStrStart
);
219 UnicodeStrToAsciiStr(Product
, OptionalStrStart
+ ManuStrLen
+ 1);
220 UnicodeStrToAsciiStr(Version
, OptionalStrStart
+ ManuStrLen
+ 1 + ProductStrLen
+ 1);
221 UnicodeStrToAsciiStr(SerialNumber
, OptionalStrStart
+ ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1);
222 UnicodeStrToAsciiStr(AssertTag
, OptionalStrStart
+ ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1 + SerialNumStrLen
+ 1);
223 UnicodeStrToAsciiStr(Chassis
, OptionalStrStart
+ ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1 + SerialNumStrLen
+ 1 + AssertTagStrLen
+ 1);
226 // Now we have got the full smbios record, call smbios protocol to add this record.
228 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
229 Status
= Smbios
-> Add(
233 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
236 FreePool(SmbiosRecord
);