github.com/linuxboot/fiano@v1.2.0/pkg/uefi/rawregion.go (about) 1 // Copyright 2018 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 uefi 6 7 // RawRegion implements Region for a raw chunk of bytes in the firmware image. 8 type RawRegion struct { 9 // holds the raw data 10 buf []byte 11 // Metadata for extraction and recovery 12 ExtractPath string 13 // This is a pointer to the FlashRegion struct laid out in the ifd. 14 FRegion *FlashRegion 15 // Region Type as per the IFD 16 RegionType FlashRegionType 17 } 18 19 // SetFlashRegion sets the flash region. 20 func (rr *RawRegion) SetFlashRegion(fr *FlashRegion) { 21 rr.FRegion = fr 22 } 23 24 // FlashRegion gets the flash region. 25 func (rr *RawRegion) FlashRegion() (fr *FlashRegion) { 26 return rr.FRegion 27 } 28 29 // NewRawRegion creates a new region. 30 func NewRawRegion(buf []byte, r *FlashRegion, rt FlashRegionType) (Region, error) { 31 rr := &RawRegion{FRegion: r, RegionType: rt} 32 rr.buf = make([]byte, len(buf)) 33 copy(rr.buf, buf) 34 return rr, nil 35 } 36 37 // Type returns the flash region type. 38 func (rr *RawRegion) Type() FlashRegionType { 39 return rr.RegionType 40 } 41 42 // Buf returns the buffer. 43 // Used mostly for things interacting with the Firmware interface. 44 func (rr *RawRegion) Buf() []byte { 45 return rr.buf 46 } 47 48 // SetBuf sets the buffer. 49 // Used mostly for things interacting with the Firmware interface. 50 func (rr *RawRegion) SetBuf(buf []byte) { 51 rr.buf = buf 52 } 53 54 // Apply calls the visitor on the RawRegion. 55 func (rr *RawRegion) Apply(v Visitor) error { 56 return v.Visit(rr) 57 } 58 59 // ApplyChildren calls the visitor on each child node of RawRegion. 60 func (rr *RawRegion) ApplyChildren(v Visitor) error { 61 return nil 62 }