Skip to content

Commit 26a0815

Browse files
committed
intelmeta: pretty-print TXT policy manifest
Signed-off-by: Daniel Maslowski <[email protected]>
1 parent bdff266 commit 26a0815

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

cmds/intelmeta/main.go

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ package main
66

77
import (
88
"bytes"
9+
"encoding/binary"
910
"encoding/hex"
1011
"encoding/json"
1112
"flag"
1213
"fmt"
1314
"os"
15+
"strings"
1416

1517
"github.com/linuxboot/fiano/pkg/intel/metadata/bg/bgbootpolicy"
1618
"github.com/linuxboot/fiano/pkg/intel/metadata/bg/bgkey"
1719
"github.com/linuxboot/fiano/pkg/intel/metadata/cbnt/cbntbootpolicy"
1820
"github.com/linuxboot/fiano/pkg/intel/metadata/cbnt/cbntkey"
21+
"github.com/linuxboot/fiano/pkg/intel/metadata/common/pretty"
1922
"github.com/linuxboot/fiano/pkg/intel/metadata/fit"
2023
"github.com/linuxboot/fiano/pkg/log"
2124
)
@@ -68,6 +71,35 @@ Example FIT:
6871
6972
*/
7073

74+
// https://edc.intel.com/content/www/us/en/design/products-and-solutions/software-and-services/firmware-and-bios/firmware-interface-table/1.4/intel-txt-policy-data-record-type-0xa-rules/
75+
type IndexIOAddress struct {
76+
IndexRegisterAddress uint16
77+
DataRegisterAddress uint16
78+
AccessWidthInBytes uint8 // 1 -> 1-byte access, 2 -> 2-byte access
79+
BitPosition uint8 // e.g. 15 -> Bit15
80+
Index uint16
81+
}
82+
83+
// PrettyString returns the content of the structure in an easy-to-read format.
84+
func (s *IndexIOAddress) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
85+
var lines []string
86+
if withHeader {
87+
lines = append(lines, pretty.Header(depth, "Index IO Address", s))
88+
}
89+
if s == nil {
90+
return strings.Join(lines, "\n")
91+
}
92+
lines = append(lines, pretty.SubValue(depth+1, "Index Register Address", "", &s.IndexRegisterAddress, opts...)...)
93+
lines = append(lines, pretty.SubValue(depth+1, "Data Register Address", "", &s.DataRegisterAddress, opts...)...)
94+
lines = append(lines, pretty.SubValue(depth+1, "Access Width", "", &s.AccessWidthInBytes, opts...)...)
95+
lines = append(lines, pretty.SubValue(depth+1, "Bit Position", "", &s.BitPosition, opts...)...)
96+
lines = append(lines, pretty.SubValue(depth+1, "Index", "", &s.Index, opts...)...)
97+
if depth < 2 {
98+
lines = append(lines, "")
99+
}
100+
return strings.Join(lines, "\n")
101+
}
102+
71103
type FEntry struct {
72104
Type string
73105
Address uint64
@@ -221,8 +253,24 @@ func main() {
221253
fmt.Println(string(j))
222254
}
223255

256+
if txte != nil {
257+
var x IndexIOAddress
258+
b := make([]byte, 8)
259+
binary.LittleEndian.PutUint64(b, txte.GetEntryBase().Headers.Address.Pointer())
260+
r := bytes.NewReader(b)
261+
binary.Read(r, binary.LittleEndian, &x)
262+
if *flagJSON {
263+
j, err := json.MarshalIndent(x, "", " ")
264+
if err != nil {
265+
log.Fatalf("cannot marshal to JSON: %v", err)
266+
}
267+
fmt.Fprintf(os.Stderr, "TXT Policy\n%v\n", string(j))
268+
} else {
269+
fmt.Fprintf(os.Stderr, "TXT Policy\n%+v\n", x.PrettyString(0, true))
270+
}
271+
}
272+
224273
if meta.LeakedKey != "" {
225274
fmt.Fprintf(os.Stderr, "LEAKED BG KEY USED: %x\n", meta.LeakedKey)
226275
}
227-
fmt.Fprintf(os.Stderr, "TXT policy manifest @ %v\n", txte)
228276
}

0 commit comments

Comments
 (0)