Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/amd/manifest: marshal PSP entry type names #343

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/linuxboot/fiano
go 1.16

require (
github.com/orangecms/PSP-Entry-Types v1.0.1 // indirect
github.com/spf13/pflag v1.0.5
github.com/u-root/u-root v0.0.0-20210724144310-637617c480d4
github.com/ulikunitz/xz v0.5.10
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/orangecms/PSP-Entry-Types v1.0.1 h1:CTJ/+esmVshvkpNbOAcdZGf/I/hUh3fo6PUwtBwxmpA=
github.com/orangecms/PSP-Entry-Types v1.0.1/go.mod h1:gveQh8FM6402D5v+xtvRHYwecihTLmxPQDZJTFjpqSo=
github.com/orangecms/go-framebuffer v0.0.0-20200613202404-a0700d90c330/go.mod h1:3Myb/UszJY32F2G7yGkUtcW/ejHpjlGfYLim7cv2uKA=
github.com/pborman/getopt/v2 v2.1.0/go.mod h1:4NtW75ny4eBw9fO1bhtNdYTlZKYX5/tBLtsOpwKIKd0=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down
53 changes: 53 additions & 0 deletions pkg/amd/manifest/marshal_json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package manifest

import (
"encoding/json"
"fmt"

pspentries "github.com/orangecms/PSP-Entry-Types"
)

var knownTypes = pspentries.Types()

func (t BIOSDirectoryTableEntryType) MarshalJSON() ([]byte, error) {
for _, knownType := range knownTypes {
if knownType.Type == uint32(t) {
name := knownType.Name
if name == "" {
name = knownType.ProposedName
}
if name == "" {
return json.Marshal(fmt.Sprintf("0x%x", t))
}
return json.Marshal(name)
}
}
return json.Marshal(fmt.Sprintf("0x%x", t))
}

/*
TODO: extend information, also for PSPDirectoryTableEntry
func (e BIOSDirectoryTableEntry) MarshalJSON() json.RawMessage {
info := TypeInfo{
Name: name,
Comment: knownType.Comment,
}
entry.TypeInfo = &info
}
*/

func (t PSPDirectoryTableEntryType) MarshalJSON() ([]byte, error) {
for _, knownType := range knownTypes {
if knownType.Type == uint32(t) {
name := knownType.Name
if name == "" {
name = knownType.ProposedName
}
if name == "" {
return json.Marshal(fmt.Sprintf("0x%x", t))
}
return json.Marshal(name)
}
}
return json.Marshal(fmt.Sprintf("0x%x", t))
}