Skip to content

Commit 74d2c53

Browse files
committed
pkg/amd/manifest: marshal PSP entry type names
Signed-off-by: Daniel Maslowski <[email protected]>
1 parent 9a1898c commit 74d2c53

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/linuxboot/fiano
33
go 1.16
44

55
require (
6+
github.com/orangecms/PSP-Entry-Types v1.0.1 // indirect
67
github.com/u-root/u-root v0.0.0-20210724144310-637617c480d4
78
github.com/ulikunitz/xz v0.5.10
89
golang.org/x/text v0.3.6

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
8686
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
8787
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
8888
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
89+
github.com/orangecms/PSP-Entry-Types v1.0.1 h1:CTJ/+esmVshvkpNbOAcdZGf/I/hUh3fo6PUwtBwxmpA=
90+
github.com/orangecms/PSP-Entry-Types v1.0.1/go.mod h1:gveQh8FM6402D5v+xtvRHYwecihTLmxPQDZJTFjpqSo=
8991
github.com/orangecms/go-framebuffer v0.0.0-20200613202404-a0700d90c330/go.mod h1:3Myb/UszJY32F2G7yGkUtcW/ejHpjlGfYLim7cv2uKA=
9092
github.com/pborman/getopt/v2 v2.1.0/go.mod h1:4NtW75ny4eBw9fO1bhtNdYTlZKYX5/tBLtsOpwKIKd0=
9193
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=

pkg/amd/manifest/marshal_json.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package manifest
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
pspentries "github.com/orangecms/PSP-Entry-Types"
8+
)
9+
10+
var knownTypes = pspentries.Types()
11+
12+
func (t BIOSDirectoryTableEntryType) MarshalJSON() ([]byte, error) {
13+
for _, knownType := range knownTypes {
14+
if knownType.Type == uint32(t) {
15+
name := knownType.Name
16+
if name == "" {
17+
name = knownType.ProposedName
18+
}
19+
if name == "" {
20+
return json.Marshal(fmt.Sprintf("0x%x", t))
21+
}
22+
return json.Marshal(name)
23+
}
24+
}
25+
return json.Marshal(fmt.Sprintf("0x%x", t))
26+
}
27+
28+
/*
29+
TODO: extend information, also for PSPDirectoryTableEntry
30+
func (e BIOSDirectoryTableEntry) MarshalJSON() json.RawMessage {
31+
info := TypeInfo{
32+
Name: name,
33+
Comment: knownType.Comment,
34+
}
35+
entry.TypeInfo = &info
36+
}
37+
*/
38+
39+
func (t PSPDirectoryTableEntryType) MarshalJSON() ([]byte, error) {
40+
for _, knownType := range knownTypes {
41+
if knownType.Type == uint32(t) {
42+
name := knownType.Name
43+
if name == "" {
44+
name = knownType.ProposedName
45+
}
46+
if name == "" {
47+
return json.Marshal(fmt.Sprintf("0x%x", t))
48+
}
49+
return json.Marshal(name)
50+
}
51+
}
52+
return json.Marshal(fmt.Sprintf("0x%x", t))
53+
}

0 commit comments

Comments
 (0)