From 345e4f743d8398dbd9c5d880f70ee9be15f08f41 Mon Sep 17 00:00:00 2001 From: Daniel Maslowski Date: Tue, 14 Dec 2021 02:53:20 +0100 Subject: [PATCH] pkg/amd/manifest: marshal PSP entry type names Signed-off-by: Daniel Maslowski --- go.mod | 1 + go.sum | 2 ++ pkg/amd/manifest/marshal_json.go | 53 ++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 pkg/amd/manifest/marshal_json.go diff --git a/go.mod b/go.mod index 9db8eaed..678adecd 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index c01406ec..8448ab71 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/amd/manifest/marshal_json.go b/pkg/amd/manifest/marshal_json.go new file mode 100644 index 00000000..bb83f3ab --- /dev/null +++ b/pkg/amd/manifest/marshal_json.go @@ -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)) +}