diff --git a/cmds/bginfo/main.go b/cmds/bginfo/main.go new file mode 100644 index 00000000..e08e8201 --- /dev/null +++ b/cmds/bginfo/main.go @@ -0,0 +1,48 @@ +// Copyright 2017-2018 the LinuxBoot Authors. All rights reserved +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// fspinfo prints FSP header information. + +package main + +import ( + "bytes" + "encoding/json" + "flag" + "fmt" + "os" + + "github.com/linuxboot/fiano/pkg/intel/metadata/bg/bgbootpolicy" + "github.com/linuxboot/fiano/pkg/log" +) + +var ( + flagJSON = flag.Bool("j", false, "Output as JSON") +) + +func main() { + flag.Parse() + if flag.Arg(0) == "" { + log.Fatalf("missing file name") + } + data, err := os.ReadFile(flag.Arg(0)) + if err != nil { + log.Fatalf("cannot read input file: %v", err) + } + m := bgbootpolicy.Manifest{} + _, err = m.ReadFrom(bytes.NewReader(data)) + if err != nil { + log.Fatalf("%v", err) + } + + j, err := json.MarshalIndent(m, "", " ") + if err != nil { + log.Fatalf("cannot marshal JSON: %v", err) + } + if *flagJSON { + fmt.Println(string(j)) + } else { + fmt.Print(m.PrettyString(0, true)) + } +} diff --git a/cmds/km/main.go b/cmds/km/main.go new file mode 100644 index 00000000..442068f5 --- /dev/null +++ b/cmds/km/main.go @@ -0,0 +1,48 @@ +// Copyright 2017-2018 the LinuxBoot Authors. All rights reserved +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// fspinfo prints FSP header information. + +package main + +import ( + "bytes" + "encoding/json" + "flag" + "fmt" + "os" + + "github.com/linuxboot/fiano/pkg/intel/metadata/cbnt/cbntkey" + "github.com/linuxboot/fiano/pkg/log" +) + +var ( + flagJSON = flag.Bool("j", false, "Output as JSON") +) + +func main() { + flag.Parse() + if flag.Arg(0) == "" { + log.Fatalf("missing file name") + } + data, err := os.ReadFile(flag.Arg(0)) + if err != nil { + log.Fatalf("cannot read input file: %v", err) + } + m := cbntkey.Manifest{} + _, err = m.ReadFrom(bytes.NewReader(data)) + if err != nil { + log.Fatalf("%v", err) + } + + j, err := json.MarshalIndent(m, "", " ") + if err != nil { + log.Fatalf("cannot marshal JSON: %v", err) + } + if *flagJSON { + fmt.Println(string(j)) + } else { + fmt.Print(m.PrettyString(0, true)) + } +}