Skip to content

Commit

Permalink
Added TPM BIOS support for cray servers (#53)
Browse files Browse the repository at this point in the history
Jira: CASMHMS-5596
  • Loading branch information
shunr-hpe authored Nov 17, 2022
1 parent e992565 commit 62fdcd3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.16.0
1.17.0
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\

## [1.17.0] - 2022-11-14

### Changed

- Added TPM State BIOS support for cray servers

## [1.16.0] - 2022-07-19

### Changed
Expand Down
77 changes: 50 additions & 27 deletions cmd/scsd/bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const (
type BiosAttributeName string

const (
TpmStateAttributeCray BiosAttributeName = "TPM State" // todo change to real name once it is known
TpmStateAttributeCray BiosAttributeName = "TPM Control"
TpmStateAttributeGigabyte BiosAttributeName = "TPM State"
TpmStateAttributeHpe BiosAttributeName = "TpmState"
TpmStateAttributeIntel BiosAttributeName = "TpmOperation"
Expand All @@ -130,10 +130,6 @@ const (
DisabledIntel int = 0
)

type rfManagers struct {
Members []rfManagersMembers
}

type rfManagersMembers struct {
ID string `json:"@odata.id"`
}
Expand Down Expand Up @@ -222,17 +218,53 @@ type rfBiosSDGigabyte struct {
Attributes map[string]interface{} `json:"Attributes"` // this can be nil. the values can be either string or int
}

/*
Example for rfBiosCray
{
"@odata.etag": "W/\"1665087620\"",
"@odata.id": "/redfish/v1/Systems/Node0/Bios",
"Attributes": {
"TPM Control": {
"AllowableValues": [
"Disabled",
"Enabled"
],
"DataType": "string",
"current_value": "Enabled",
"default_value": "Enabled",
"menu_type": "Debug",
"reset_type": "Cold"
}
},
"Id": "Bios",
"Name": "Current BIOS Settings"
}
*/
type rfBiosCray struct {
ETag string `json:"@odata.etag"`
Attributes map[string]rfBiosAttributeCray `json:"Attributes"`
}

type rfBiosAttributeCray struct {
AllowedValues []interface{} `json:"AllowedValues"`
DataType string `json:"DataType"`
CurrentValue interface{} `json:"current_value"`
AllowableValues []interface{} `json:"AllowableValues"`
DataType string `json:"DataType"`
CurrentValue interface{} `json:"current_value"`
}

/*
Example for rfBiosSDCray
{
"@odata.etag": "W/\"1668554829\"",
"@odata.id": "/redfish/v1/Systems/Node0/Bios/SD",
"@odata.type": "#Bios.v1_0_2.Bios",
"Attributes": {
"TPM Control": "Enabled"
},
"Description": "Future BIOS Settings",
"Id": "SD",
"Name": "Future BIOS Settings"
}
*/
type rfBiosSDCray struct {
ETag string `json:"@odata.etag"`
Attributes map[string]interface{} `json:"Attributes"`
Expand All @@ -251,10 +283,6 @@ type rfRegistries struct {
Members []rfManagersMembers
}

type rfRegistriesMembers struct {
ID string `json:"@odata.id"`
}

type rfBiosAttributesRegistries struct {
Location []rfRegistriesLocations
}
Expand Down Expand Up @@ -341,7 +369,7 @@ func getManufacturerType(chassis *rfChassis) manufacturerType {
}

func getRedfish(targets []targInfo, uri string) (tasks []trsapi.HttpTask, err error, httpCode int) {
tasks, _, err, httpCode = getRedfishNoCheck(targets, uri)
tasks, _, _, _ = getRedfishNoCheck(targets, uri)

err = checkStatusCodes(tasks)
if err != nil {
Expand Down Expand Up @@ -992,6 +1020,9 @@ func getBiosCray(biosCommon *BiosCommon) (biosCray *BiosCray, err error, httpCod

func patchBiosCray(biosCommon *BiosCommon, attributeName PatchAttributeName, attrbiuteValue PatchAttributeValue) (err error, httpCode int) {
biosCray, err, httpCode := getBiosCray(biosCommon)
if err != nil {
return
}

name := string(attributeName.cray)
futureValue := fmt.Sprintf("%v", attrbiuteValue.cray)
Expand All @@ -1004,7 +1035,7 @@ func patchBiosCray(biosCommon *BiosCommon, attributeName PatchAttributeName, att
}

foundValueDefined := false
for _, value := range attribute.AllowedValues {
for _, value := range attribute.AllowableValues {
if value == futureValue {
foundValueDefined = true
break
Expand All @@ -1013,7 +1044,7 @@ func patchBiosCray(biosCommon *BiosCommon, attributeName PatchAttributeName, att
if !foundValueDefined {
logger.Errorf(
"Tried to set %s with redfish value %s, but redfish only supports %v",
name, futureValue, attribute.AllowedValues)
name, futureValue, attribute.AllowableValues)
err = fmt.Errorf("BIOS %s value %s is not supported", name, futureValue)
httpCode = http.StatusMethodNotAllowed
return
Expand All @@ -1024,7 +1055,7 @@ func patchBiosCray(biosCommon *BiosCommon, attributeName PatchAttributeName, att
etag := biosCray.future.ETag
if etag == "" {
// when SD (i.e. the future settings) is not avialble the If-Match header should match anything
// gigabyte will reject any patch request that does not have a If-Match header
// This is not strictly required because cray hardware does not currently require the etag
etag = "*"
}
tasks, err, httpCode := patchRedfishEtag(biosCommon.targets, biosCray.futureUri, []byte(rfRequestBody), []string{etag})
Expand Down Expand Up @@ -1122,15 +1153,7 @@ func patchBios(r *http.Request, attributeName PatchAttributeName, attributeValue

switch biosCommon.manufacturerType {
case cray:
// todo implement once castle supports showing tpm via the redfish bios interface
logger.Errorf(
"Modifications for %s has not been implmented for cray hardware. xname: %s",
attributeName.cray, xname)
err = fmt.Errorf("Modifications not supported by BMC at %s", xname)
httpCode = http.StatusBadRequest

// todo here is the code that likely implements this
// err, httpCode = patchBiosCray(biosCommon, attributeName, attributeValue)
err, httpCode = patchBiosCray(biosCommon, attributeName, attributeValue)
case gigabyte:
err, httpCode = patchBiosGigabyte(biosCommon, attributeName, attributeValue)
case hpe:
Expand Down Expand Up @@ -1240,11 +1263,11 @@ func toTpmStateCray(bios *BiosCray) BiosTpmState {
tpmStateKey := string(TpmStateAttributeCray)
attribute, ok := bios.current.Attributes[tpmStateKey]
if ok {
state.Current = toTpmStateValueGigabyte(attribute.CurrentValue)
state.Current = toTpmStateValueCray(attribute.CurrentValue)

attributeFuture, okFuture := bios.future.Attributes[tpmStateKey]
if okFuture {
state.Future = toTpmStateValueGigabyte(attributeFuture)
state.Future = toTpmStateValueCray(attributeFuture)
} else {
state.Future = state.Current
}
Expand Down

0 comments on commit 62fdcd3

Please sign in to comment.