github.com/linuxboot/fiano@v1.2.0/pkg/intel/metadata/fit/ent_txt_policy_record.go (about) 1 // Copyright 2017-2021 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 package fit 6 7 import ( 8 "bytes" 9 "encoding/binary" 10 "fmt" 11 "io" 12 ) 13 14 // EntryTXTPolicyRecord represents a FIT entry of type "TXT Policy Record" (0x0A) 15 type EntryTXTPolicyRecord struct{ EntryBase } 16 17 var _ EntryCustomGetDataSegmentSizer = (*EntryTXTPolicyRecord)(nil) 18 19 // Init initializes the entry using EntryHeaders and firmware image. 20 func (entry *EntryTXTPolicyRecord) CustomGetDataSegmentSize(firmware io.ReadSeeker) (uint64, error) { 21 // TXT policy record has no data section and the Address field is used to store the data. 22 return 0, nil 23 } 24 25 var _ EntryCustomRecalculateHeaderser = (*EntryTXTPolicyRecord)(nil) 26 27 // CustomRecalculateHeaders recalculates metadata to be consistent with data. 28 // For example, it fixes checksum, data size, entry type and so on. 29 func (entry *EntryTXTPolicyRecord) CustomRecalculateHeaders() error { 30 entryBase := entry.GetEntryBase() 31 entryBase.DataSegmentBytes = nil 32 hdr := &entryBase.Headers 33 hdr.TypeAndIsChecksumValid.SetType(EntryTypeTXTPolicyRecord) 34 35 // See 4.9.10 of the FIT specification. 36 hdr.TypeAndIsChecksumValid.SetIsChecksumValid(false) 37 // See 4.9.11 of the FIT specification. 38 hdr.Size.SetUint32(0) 39 return nil 40 } 41 42 // EntryTXTPolicyRecordDataInterface is a parsed TXT Policy Record entry 43 type EntryTXTPolicyRecordDataInterface interface { 44 IsTXTEnabled() bool 45 } 46 47 // EntryTXTPolicyRecordDataIndexedIO is a parsed TXT Policy Record entry of 48 // version 1. 49 type EntryTXTPolicyRecordDataIndexedIO struct { 50 IndexRegisterIOAddress uint16 51 DataRegisterIOAddress uint16 52 AccessWidth uint8 53 BitPosition uint8 54 Index uint16 55 } 56 57 // IsTXTEnabled returns true if TXT is enabled. 58 func (entryData *EntryTXTPolicyRecordDataIndexedIO) IsTXTEnabled() bool { 59 panic("not implemented") 60 } 61 62 // EntryTXTPolicyRecordDataFlatPointer is a parsed TXT Policy Record entry 63 // of version 0 64 type EntryTXTPolicyRecordDataFlatPointer uint64 65 66 // TPMPolicyPointer returns the TPM Policy pointer. 67 func (entryData EntryTXTPolicyRecordDataFlatPointer) TPMPolicyPointer() uint64 { 68 return uint64(entryData & 0x7fffffffffffffff) 69 } 70 71 // IsTXTEnabled returns true if TXT is enabled. 72 func (entryData EntryTXTPolicyRecordDataFlatPointer) IsTXTEnabled() bool { 73 return entryData&0x8000000000000000 != 0 74 } 75 76 // Parse parses TXT Policy Record entry 77 func (entry *EntryTXTPolicyRecord) Parse() (EntryTXTPolicyRecordDataInterface, error) { 78 switch entry.Headers.Version { 79 case 0: 80 result := EntryTXTPolicyRecordDataFlatPointer(entry.Headers.Address.Pointer()) 81 return result, nil 82 case 1: 83 var b [8]byte 84 binary.LittleEndian.PutUint64(b[:], entry.Headers.Address.Pointer()) 85 var dataParsed EntryTXTPolicyRecordDataIndexedIO 86 err := binary.Read(bytes.NewReader(b[:]), binary.LittleEndian, &dataParsed) 87 if err != nil { 88 return nil, fmt.Errorf("unable to parse EntryTXTPolicyRecordDataIndexedIO: %w", err) 89 } 90 return &dataParsed, nil 91 } 92 93 return nil, &ErrInvalidTXTPolicyRecordVersion{entry.Headers.Version} 94 }