Skip to content

Commit

Permalink
Nt32Pkg: Fixes to correctly set SMBIOS Type 3
Browse files Browse the repository at this point in the history
When running Nt32Pkg, SMBIOS Type 3 was missing Height, NumberofPowerCords, and SKU Number.
Also, ContainedElements was not being handled correctly.
Fixed code to add example data, correct some variable names (Assert -> Asset), and properly handle setting the Type 3 values.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chris Phillips <[email protected]>
Reviewed-by: Star Zeng <[email protected]>
  • Loading branch information
chrisp00 authored and lzeng14 committed Jan 12, 2017
1 parent fed77c5 commit a679e8b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**@file
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2017 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
Expand Down Expand Up @@ -39,7 +40,9 @@ MISC_SMBIOS_TABLE_DATA(EFI_MISC_CHASSIS_MANUFACTURER_DATA, MiscChassisManufactur
EfiChassisStateOther, // ChassisPowerSupplyState
EfiChassisStateOther, // ChassisThermalState
EfiChassisSecurityStatusOther, // ChassisSecurityState
0 // ChassisOemDefined
0, // ChassisOemDefined
1, // Height
1 // NumberofPowerCords
};

/* eof - MiscChassisManufacaturerData.c */
74 changes: 60 additions & 14 deletions Nt32Pkg/MiscSubClassPlatformDxe/MiscChassisManufacturerFunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
SMBIOS type 3.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2017 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
Expand Down Expand Up @@ -31,17 +32,20 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscChassisManufacturer)
CHAR8 *OptionalStrStart;
UINTN ManuStrLen;
UINTN VerStrLen;
UINTN AssertTagStrLen;
UINTN AssetTagStrLen;
UINTN SerialNumStrLen;
UINTN SkuNumberStrLen;
EFI_STATUS Status;
EFI_STRING Manufacturer;
EFI_STRING Version;
EFI_STRING SerialNumber;
EFI_STRING AssertTag;
EFI_STRING AssetTag;
EFI_STRING SkuNumber;
STRING_REF TokenToGet;
EFI_SMBIOS_HANDLE SmbiosHandle;
SMBIOS_TABLE_TYPE3 *SmbiosRecord;
EFI_MISC_CHASSIS_MANUFACTURER *ForType3InputData;
UINT8 *Buffer;

ForType3InputData = (EFI_MISC_CHASSIS_MANUFACTURER *)RecordData;

Expand Down Expand Up @@ -74,20 +78,40 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscChassisManufacturer)
}

TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_ASSET_TAG);
AssertTag = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
AssertTagStrLen = StrLen(AssertTag);
if (AssertTagStrLen > SMBIOS_STRING_MAX_LENGTH) {
AssetTag = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
AssetTagStrLen = StrLen(AssetTag);
if (AssetTagStrLen > SMBIOS_STRING_MAX_LENGTH) {
return EFI_UNSUPPORTED;
}

TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_SKU_NUMBER);
SkuNumber = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
SkuNumberStrLen = StrLen(SkuNumber);
if (SkuNumberStrLen > SMBIOS_STRING_MAX_LENGTH) {
return EFI_UNSUPPORTED;
}

//
// Two zeros following the last string.
//
SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + 1);
ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + 1);
// Since we set ContainedElementCount = 0 and ContainedElementRecordLength = 0,
// remove sizeof (CONTAINED_ELEMENT) for ContainedElements[1].
//
// Add sizeof (SMBIOS_TABLE_STRING) for SKU Number, since not contained in SMBIOS_TABLE_TYPE3.
//
SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE3) - sizeof (CONTAINED_ELEMENT) + sizeof (SMBIOS_TABLE_STRING) + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssetTagStrLen + 1 + SkuNumberStrLen + 1 + 1);
ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE3) - sizeof (CONTAINED_ELEMENT) + sizeof (SMBIOS_TABLE_STRING) + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssetTagStrLen + 1 + SkuNumberStrLen + 1 + 1);

Buffer = (UINT8 *) SmbiosRecord;

SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE;
SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE3);
//
// Since we set ContainedElementCount = 0 and ContainedElementRecordLength = 0,
// remove sizeof (CONTAINED_ELEMENT) for ContainedElements[1].
//
// Add sizeof (SMBIOS_TABLE_STRING) for SKU Number, since not contained in SMBIOS_TABLE_TYPE3.
//
SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE3) - sizeof (CONTAINED_ELEMENT) + sizeof (SMBIOS_TABLE_STRING);
//
// Make handle chosen by smbios protocol.add automatically.
//
Expand All @@ -106,20 +130,42 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscChassisManufacturer)
//
SmbiosRecord->SerialNumber = 3;
//
// AssertTag will be the 4th optional string following the formatted structure.
// AssetTag will be the 4th optional string following the formatted structure.
//
SmbiosRecord->AssetTag = 4;
SmbiosRecord->AssetTag = 4;

SmbiosRecord->BootupState = (UINT8)ForType3InputData->ChassisBootupState;
SmbiosRecord->PowerSupplyState = (UINT8)ForType3InputData->ChassisPowerSupplyState;
SmbiosRecord->ThermalState = (UINT8)ForType3InputData->ChassisThermalState;
SmbiosRecord->SecurityStatus = (UINT8)ForType3InputData->ChassisSecurityState;
CopyMem (SmbiosRecord->OemDefined,(UINT8*)&ForType3InputData->ChassisOemDefined, 4);
SmbiosRecord->Height = (UINT8)ForType3InputData->ChassisHeight;
SmbiosRecord->NumberofPowerCords = (UINT8)ForType3InputData->ChassisNumberPowerCords;
SmbiosRecord->ContainedElementCount = 0;
SmbiosRecord->ContainedElementRecordLength = 0;

//
// SKU Number will be the 5th optional string following the formatted structure.
//
// Since SKU Number is not in SMBIOS_TABLE_TYPE3 structure, must locate it after ContainedElementRecordLength.
//
Buffer[sizeof (SMBIOS_TABLE_TYPE3) - sizeof (CONTAINED_ELEMENT)] = 5;

OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);
UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1);
UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1);
UnicodeStrToAsciiStr(AssertTag, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);
//
// Since we set ContainedElementCount = 0 and ContainedElementRecordLength = 0,
// remove sizeof (CONTAINED_ELEMENT) for ContainedElements[1].
//
OptionalStrStart -= sizeof (CONTAINED_ELEMENT);
//
// Add sizeof (SMBIOS_TABLE_STRING) for SKU Number, since not contained in SMBIOS_TABLE_TYPE3.
//
OptionalStrStart += sizeof (SMBIOS_TABLE_STRING);
UnicodeStrToAsciiStr (Manufacturer, OptionalStrStart);
UnicodeStrToAsciiStr (Version, OptionalStrStart + ManuStrLen + 1);
UnicodeStrToAsciiStr (SerialNumber, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1);
UnicodeStrToAsciiStr (AssetTag, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);
UnicodeStrToAsciiStr (SkuNumber, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssetTagStrLen + 1);

//
// Now we have got the full smbios record, call smbios protocol to add this record.
Expand Down
2 changes: 2 additions & 0 deletions Nt32Pkg/MiscSubClassPlatformDxe/MiscSubclassDriver.uni
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// *++
//
// Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
// (C) Copyright 2017 Hewlett Packard Enterprise Development LP<BR>
// This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
Expand Down Expand Up @@ -45,6 +46,7 @@
#string STR_MISC_CHASSIS_VERSION #language en-US "Chassis Version"
#string STR_MISC_CHASSIS_SERIAL_NUMBER #language en-US "Chassis Serial Number"
#string STR_MISC_CHASSIS_ASSET_TAG #language en-US "Chassis Asset Tag"
#string STR_MISC_CHASSIS_SKU_NUMBER #language en-US "Chassis SKU Number"

#string STR_MISC_OEM_STRING #language en-US "System Language String"

Expand Down

0 comments on commit a679e8b

Please sign in to comment.