Skip to content

Commit

Permalink
intel/metadata/cbnt: do not marshal large data blobs to JSON
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Maslowski <[email protected]>
  • Loading branch information
orangecms committed May 13, 2023
1 parent 4eb86be commit 595edd5
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
56 changes: 56 additions & 0 deletions cmds/bginfo/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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: %x", err)
}

ACBPMagic := []byte("__ACBP__")
// __IBBS__ also seen in the next 16 bytes; not sure what that is
offset := bytes.Index(data, ACBPMagic)
if offset == -1 {
log.Fatalf("no %v (%x) magic found", string(ACBPMagic), ACBPMagic)
}

m := bgbootpolicy.Manifest{}
_, err = m.ReadFrom(bytes.NewReader(data[offset:]))
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))
}
}
55 changes: 55 additions & 0 deletions cmds/km/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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)
}

KEYMMagic := []byte("__KEYM__")
offset := bytes.Index(data, KEYMMagic)
if offset == -1 {
log.Fatalf("no %v magic (%x) found", string(KEYMMagic), KEYMMagic)
}

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))
}
}

0 comments on commit 595edd5

Please sign in to comment.