From bdc82a83df1d848a6b63c6d53a9c6ddf8856fb1e Mon Sep 17 00:00:00 2001 From: Daniel Maslowski Date: Tue, 14 Dec 2021 03:06:46 +0100 Subject: [PATCH] WIP amdana Signed-off-by: Daniel Maslowski --- cmds/amdana/main.go | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 cmds/amdana/main.go diff --git a/cmds/amdana/main.go b/cmds/amdana/main.go new file mode 100644 index 00000000..4562c313 --- /dev/null +++ b/cmds/amdana/main.go @@ -0,0 +1,60 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "io/ioutil" + "log" + + amd "github.com/linuxboot/fiano/pkg/amd/manifest" +) + +const ( + // This needed a look at the image; how can we fully automate it? + mapping = 0xff000000 +) + +// this is only for Go - would be 5 lines inline in JS, thanks... +type image []byte + +func (f image) ImageBytes() []byte { + return []byte(f) +} + +func (f image) PhysAddrToOffset(physAddr uint64) uint64 { + return physAddr - mapping +} + +func (f image) OffsetToPhysAddr(offset uint64) uint64 { + return offset + mapping +} + +func main() { + flag.Parse() + args := flag.Args() + + var path string + + if len(args) > 0 { + path = args[0] + data, err := ioutil.ReadFile(path) + if err != nil { + log.Fatal(err) + } + // We could also use this, but its mapping wouldn't work with some images + // FIXME: figure out those mappings + // var amdfw amd.FirmwareImage = data + var amdfw image = data + fw, err := amd.NewAMDFirmware(amdfw) + if err != nil { + log.Fatal(err) + } + a := fw.PSPFirmware() + j, err := json.MarshalIndent(a, "", " ") + if err != nil { + log.Fatal(err) + } + fmt.Printf(string(j)) + } +}