@@ -6,16 +6,19 @@ package main
6
6
7
7
import (
8
8
"bytes"
9
+ "encoding/binary"
9
10
"encoding/hex"
10
11
"encoding/json"
11
12
"flag"
12
13
"fmt"
13
14
"os"
15
+ "strings"
14
16
15
17
"github.com/linuxboot/fiano/pkg/intel/metadata/bg/bgbootpolicy"
16
18
"github.com/linuxboot/fiano/pkg/intel/metadata/bg/bgkey"
17
19
"github.com/linuxboot/fiano/pkg/intel/metadata/cbnt/cbntbootpolicy"
18
20
"github.com/linuxboot/fiano/pkg/intel/metadata/cbnt/cbntkey"
21
+ "github.com/linuxboot/fiano/pkg/intel/metadata/common/pretty"
19
22
"github.com/linuxboot/fiano/pkg/intel/metadata/fit"
20
23
"github.com/linuxboot/fiano/pkg/log"
21
24
)
@@ -68,6 +71,35 @@ Example FIT:
68
71
69
72
*/
70
73
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
+
71
103
type FEntry struct {
72
104
Type string
73
105
Address uint64
@@ -221,8 +253,24 @@ func main() {
221
253
fmt .Println (string (j ))
222
254
}
223
255
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
+
224
273
if meta .LeakedKey != "" {
225
274
fmt .Fprintf (os .Stderr , "LEAKED BG KEY USED: %x\n " , meta .LeakedKey )
226
275
}
227
- fmt .Fprintf (os .Stderr , "TXT policy manifest @ %v\n " , txte )
228
276
}
0 commit comments