github.com/linuxboot/fiano@v1.2.0/pkg/intel/metadata/fit/entry_base.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 "fmt" 9 "io" 10 ) 11 12 // EntryBase is the common information for any FIT entry 13 type EntryBase struct { 14 // Headers is FIT entry headers. 15 // 16 // See "Table 1-1" in "1.2 Firmware Interface Table" in "Firmware Interface Table" specification: 17 // * https://www.intel.com/content/dam/www/public/us/en/documents/guides/fit-bios-specification.pdf 18 Headers EntryHeaders 19 20 // DataSegmentBytes is the raw bytes of the special data segment referenced by the headers. 21 // 22 // Is not nil only if FIT entry really references to a data segment. If FIT entry 23 // stores data directly in headers then DataSegmentBytes is nil. 24 DataSegmentBytes []byte `json:",omitempty"` 25 26 // HeadersErrors is the list of errors occurred while parsing and interpreting FIT entry headers. 27 HeadersErrors []error `json:",omitempty"` 28 } 29 30 // GetEntryBase returns EntryBase (which contains metadata of the Entry). 31 func (entry *EntryBase) GetEntryBase() *EntryBase { 32 return entry 33 } 34 35 // GoString implements fmt.GoStringer 36 func (entry *EntryBase) GoString() string { 37 return entry.Headers.GoString() 38 } 39 40 // injectDataSectionTo does the same as InjectData, but for io.WriteSeeker. 41 func (entry EntryBase) injectDataSectionTo(w io.WriteSeeker) error { 42 base := entry.GetEntryBase() 43 44 if len(base.DataSegmentBytes) == 0 { 45 return nil 46 } 47 48 firmwareSize, err := w.Seek(0, io.SeekEnd) 49 if err != nil { 50 return fmt.Errorf("unable to detect firmware size: %w", err) 51 } 52 53 dataSectionOffset := base.Headers.Address.Offset(uint64(firmwareSize)) 54 if _, err := w.Seek(int64(dataSectionOffset), io.SeekStart); err != nil { 55 return fmt.Errorf("unable to Seek(%d, %d) to write the data section: %w", int64(dataSectionOffset), io.SeekStart, err) 56 } 57 58 if _, err := w.Write(entry.DataSegmentBytes); err != nil { 59 return fmt.Errorf("unable to write the data section: %w", err) 60 } 61 62 return nil 63 }