3 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 MiscBaseBoardManufacturerFunction.c
21 BaseBoard manufacturer information boot time changes.
27 #include "CommonHeader.h"
28 #include "MiscSubclassDriver.h"
29 #include <Library/NetLib.h>
30 #include "Library/DebugLib.h"
31 #include <Uefi/UefiBaseType.h>
32 #include <Guid/PlatformInfo.h>
35 extern EFI_PLATFORM_INFO_HOB
*mPlatformInfo
;
38 This function makes boot time changes to the contents of the
39 MiscBaseBoardManufacturer (Type 2).
41 @param RecordData Pointer to copy of RecordData from the Data Table.
43 @retval EFI_SUCCESS All parameters were valid.
44 @retval EFI_UNSUPPORTED Unexpected RecordType value.
45 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
48 MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer
)
50 CHAR8
*OptionalStrStart
;
54 UINTN AssertTagStrLen
;
55 UINTN SerialNumStrLen
;
58 EFI_STRING Manufacturer
;
61 EFI_STRING SerialNumber
;
64 STRING_REF TokenToGet
;
65 EFI_SMBIOS_HANDLE SmbiosHandle
;
66 SMBIOS_TABLE_TYPE2
*SmbiosRecord
;
67 EFI_MISC_BASE_BOARD_MANUFACTURER
*ForType2InputData
;
74 ForType2InputData
= (EFI_MISC_BASE_BOARD_MANUFACTURER
*)RecordData
;
77 // First check for invalid parameters.
79 if (RecordData
== NULL
|| mPlatformInfo
== NULL
) {
80 return EFI_INVALID_PARAMETER
;
83 if (BOARD_ID_MINNOW2_TURBOT
== mPlatformInfo
->BoardId
) {
84 UnicodeSPrint (Buffer
, sizeof (Buffer
),L
"ADI");
85 HiiSetString(mHiiHandle
,STRING_TOKEN(STR_MISC_BASE_BOARD_MANUFACTURER
), Buffer
, NULL
);
87 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_MANUFACTURER
);
88 Manufacturer
= SmbiosMiscGetString (TokenToGet
);
89 ManuStrLen
= StrLen(Manufacturer
);
90 if (ManuStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
91 return EFI_UNSUPPORTED
;
94 if (BOARD_ID_MINNOW2_TURBOT
== mPlatformInfo
->BoardId
) {
95 UnicodeSPrint (Buffer
, sizeof (Buffer
),L
"MinnowBoard Turbot");
96 HiiSetString(mHiiHandle
,STRING_TOKEN(STR_MISC_BASE_BOARD_PRODUCT_NAME1
), Buffer
, NULL
);
98 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_PRODUCT_NAME1
);
99 Product
= SmbiosMiscGetString (TokenToGet
);
100 ProductStrLen
= StrLen(Product
);
101 if (ProductStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
102 return EFI_UNSUPPORTED
;
104 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_VERSION
);
105 Version
= SmbiosMiscGetString (TokenToGet
);
106 VerStrLen
= StrLen(Version
);
107 if (VerStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
108 return EFI_UNSUPPORTED
;
112 //Get handle infomation
116 Status
= gBS
->LocateHandle (
118 &gEfiSimpleNetworkProtocolGuid
,
124 if (Status
== EFI_BUFFER_TOO_SMALL
) {
125 Handles
= AllocateZeroPool(BufferSize
);
126 if (Handles
== NULL
) {
127 return (EFI_OUT_OF_RESOURCES
);
129 Status
= gBS
->LocateHandle(
131 &gEfiSimpleNetworkProtocolGuid
,
141 Status
= NetLibGetMacString (
146 if (EFI_ERROR (Status
)) {
149 SerialNumber
= MacStr
;
150 SerialNumStrLen
= StrLen(SerialNumber
);
151 if (SerialNumStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
152 return EFI_UNSUPPORTED
;
154 DEBUG ((EFI_D_ERROR
, "MAC Address: %S\n", MacStr
));
156 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_ASSET_TAG
);
157 AssertTag
= SmbiosMiscGetString (TokenToGet
);
158 AssertTagStrLen
= StrLen(AssertTag
);
159 if (AssertTagStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
160 return EFI_UNSUPPORTED
;
163 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_CHASSIS_LOCATION
);
164 Chassis
= SmbiosMiscGetString (TokenToGet
);
165 ChassisStrLen
= StrLen(Chassis
);
166 if (ChassisStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
167 return EFI_UNSUPPORTED
;
172 // Two zeros following the last string.
174 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE2
) + ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1 + SerialNumStrLen
+ 1 + AssertTagStrLen
+ 1 + ChassisStrLen
+1 + 1);
175 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE2
) + ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1 + SerialNumStrLen
+ 1 + AssertTagStrLen
+ 1 + ChassisStrLen
+1 + 1);
177 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION
;
178 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE2
);
181 // Make handle chosen by smbios protocol.add automatically.
183 SmbiosRecord
->Hdr
.Handle
= 0;
186 // Manu will be the 1st optional string following the formatted structure.
188 SmbiosRecord
->Manufacturer
= 1;
191 // ProductName will be the 2st optional string following the formatted structure.
193 SmbiosRecord
->ProductName
= 2;
196 // Version will be the 3rd optional string following the formatted structure.
198 SmbiosRecord
->Version
= 3;
201 // SerialNumber will be the 4th optional string following the formatted structure.
203 SmbiosRecord
->SerialNumber
= 4;
206 // AssertTag will be the 5th optional string following the formatted structure.
208 SmbiosRecord
->AssetTag
= 5;
211 // LocationInChassis will be the 6th optional string following the formatted structure.
213 SmbiosRecord
->LocationInChassis
= 6;
214 SmbiosRecord
->FeatureFlag
= (*(BASE_BOARD_FEATURE_FLAGS
*)&(ForType2InputData
->BaseBoardFeatureFlags
));
215 SmbiosRecord
->ChassisHandle
= 0;
216 SmbiosRecord
->BoardType
= (UINT8
)ForType2InputData
->BaseBoardType
;
217 SmbiosRecord
->NumberOfContainedObjectHandles
= 0;
219 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
222 // Since we fill NumberOfContainedObjectHandles = 0 for simple, just after this filed to fill string
224 UnicodeStrToAsciiStr(Manufacturer
, OptionalStrStart
);
225 UnicodeStrToAsciiStr(Product
, OptionalStrStart
+ ManuStrLen
+ 1);
226 UnicodeStrToAsciiStr(Version
, OptionalStrStart
+ ManuStrLen
+ 1 + ProductStrLen
+ 1);
227 UnicodeStrToAsciiStr(SerialNumber
, OptionalStrStart
+ ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1);
228 UnicodeStrToAsciiStr(AssertTag
, OptionalStrStart
+ ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1 + SerialNumStrLen
+ 1);
229 UnicodeStrToAsciiStr(Chassis
, OptionalStrStart
+ ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1 + SerialNumStrLen
+ 1 + AssertTagStrLen
+ 1);
232 // Now we have got the full smbios record, call smbios protocol to add this record.
234 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
235 Status
= Smbios
-> Add(
239 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
242 FreePool(SmbiosRecord
);