Skip to content

Commit da19e31

Browse files
committed
Draft km and bginfo commands (to be discarded)
Signed-off-by: Daniel Maslowski <[email protected]>
1 parent 01213bb commit da19e31

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

cmds/bginfo/main.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2017-2018 the LinuxBoot Authors. All rights reserved
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// fspinfo prints FSP header information.
6+
7+
package main
8+
9+
import (
10+
"bytes"
11+
"encoding/json"
12+
"flag"
13+
"fmt"
14+
"os"
15+
16+
"github.com/linuxboot/fiano/pkg/intel/metadata/bg/bgbootpolicy"
17+
"github.com/linuxboot/fiano/pkg/log"
18+
)
19+
20+
var (
21+
flagJSON = flag.Bool("j", false, "Output as JSON")
22+
)
23+
24+
func main() {
25+
flag.Parse()
26+
if flag.Arg(0) == "" {
27+
log.Fatalf("missing file name")
28+
}
29+
data, err := os.ReadFile(flag.Arg(0))
30+
if err != nil {
31+
log.Fatalf("cannot read input file: %x", err)
32+
}
33+
34+
ACBPMagic := []byte("__ACBP__")
35+
// __IBBS__ also seen in the next 16 bytes; not sure what that is
36+
offset := bytes.Index(data, ACBPMagic)
37+
if offset == -1 {
38+
log.Fatalf("no %v (%x) magic found", string(ACBPMagic), ACBPMagic)
39+
}
40+
41+
m := bgbootpolicy.Manifest{}
42+
_, err = m.ReadFrom(bytes.NewReader(data[offset:]))
43+
if err != nil {
44+
log.Fatalf("%v", err)
45+
}
46+
47+
j, err := json.MarshalIndent(m, "", " ")
48+
if err != nil {
49+
log.Fatalf("cannot marshal JSON: %v", err)
50+
}
51+
if *flagJSON {
52+
fmt.Println(string(j))
53+
} else {
54+
fmt.Print(m.PrettyString(0, true))
55+
}
56+
}

cmds/km/main.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2017-2018 the LinuxBoot Authors. All rights reserved
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// fspinfo prints FSP header information.
6+
7+
package main
8+
9+
import (
10+
"bytes"
11+
"encoding/json"
12+
"flag"
13+
"fmt"
14+
"os"
15+
16+
"github.com/linuxboot/fiano/pkg/intel/metadata/cbnt/cbntkey"
17+
"github.com/linuxboot/fiano/pkg/log"
18+
)
19+
20+
var (
21+
flagJSON = flag.Bool("j", false, "Output as JSON")
22+
)
23+
24+
func main() {
25+
flag.Parse()
26+
if flag.Arg(0) == "" {
27+
log.Fatalf("missing file name")
28+
}
29+
data, err := os.ReadFile(flag.Arg(0))
30+
if err != nil {
31+
log.Fatalf("cannot read input file: %v", err)
32+
}
33+
34+
KEYMMagic := []byte("__KEYM__")
35+
offset := bytes.Index(data, KEYMMagic)
36+
if offset == -1 {
37+
log.Fatalf("no %v magic (%x) found", string(KEYMMagic), KEYMMagic)
38+
}
39+
40+
m := cbntkey.Manifest{}
41+
_, err = m.ReadFrom(bytes.NewReader(data))
42+
if err != nil {
43+
log.Fatalf("%v", err)
44+
}
45+
46+
j, err := json.MarshalIndent(m, "", " ")
47+
if err != nil {
48+
log.Fatalf("cannot marshal JSON: %v", err)
49+
}
50+
if *flagJSON {
51+
fmt.Println(string(j))
52+
} else {
53+
fmt.Print(m.PrettyString(0, true))
54+
}
55+
}

0 commit comments

Comments
 (0)