Documentation
¶
Overview ¶
Package uefi contents data types for the components found in UEFI and an Parse function for reading an image.
Index ¶
- Constants
- Variables
- func Align(val uint64, base uint64) uint64
- func Align4(val uint64) uint64
- func Align8(val uint64) uint64
- func Checksum16(buf []byte) (uint16, error)
- func Checksum8(buf []byte) uint8
- func Erase(buf []byte, polarity byte)
- func FindFirmwareVolumeOffset(data []byte) int64
- func FindSignature(buf []byte) (int, error)
- func MarshalFirmware(f Firmware) ([]byte, error)
- func Read3Size(size [3]uint8) uint64
- func SetErasePolarity(ep byte) error
- func Write3Size(size uint64) [3]uint8
- type BIOSPadding
- type BIOSRegion
- func (br *BIOSRegion) Apply(v Visitor) error
- func (br *BIOSRegion) ApplyChildren(v Visitor) error
- func (br *BIOSRegion) Buf() []byte
- func (br *BIOSRegion) FirstFV() (*FirmwareVolume, error)
- func (br *BIOSRegion) FlashRegion() (fr *FlashRegion)
- func (br *BIOSRegion) SetBuf(buf []byte)
- func (br *BIOSRegion) SetFlashRegion(fr *FlashRegion)
- func (br *BIOSRegion) Type() FlashRegionType
- type Block
- type DepExOp
- type DepExOpCode
- type FVFileType
- type File
- func (f *File) Apply(v Visitor) error
- func (f *File) ApplyChildren(v Visitor) error
- func (f *File) Buf() []byte
- func (f *File) ChecksumAndAssemble(fileData []byte) error
- func (f *File) ChecksumHeader() uint8
- func (f *File) HeaderLen() uint64
- func (f *File) SetBuf(buf []byte)
- func (f *File) SetSize(size uint64, resizeFile bool)
- type FileHeader
- type FileHeaderExtended
- type Firmware
- type FirmwareVolume
- func (fv *FirmwareVolume) Apply(v Visitor) error
- func (fv *FirmwareVolume) ApplyChildren(v Visitor) error
- func (fv *FirmwareVolume) Buf() []byte
- func (fv *FirmwareVolume) GetErasePolarity() uint8
- func (fv *FirmwareVolume) InsertFile(alignedOffset uint64, fBuf []byte) error
- func (fv *FirmwareVolume) SetBuf(buf []byte)
- type FirmwareVolumeExtHeader
- type FirmwareVolumeFixedHeader
- type FlashDescriptor
- type FlashDescriptorMap
- type FlashFrequency
- type FlashImage
- type FlashMasterSection
- type FlashParams
- func (p *FlashParams) DualOutputFastReadSupported() uint
- func (p *FlashParams) FastReadEnabled() uint
- func (p *FlashParams) FastReadFrequency() FlashFrequency
- func (p *FlashParams) FirstChipDensity() uint
- func (p *FlashParams) FlashReadStatusFrequency() FlashFrequency
- func (p *FlashParams) FlashWriteFrequency() FlashFrequency
- func (p *FlashParams) ReadClockFrequency() FlashFrequency
- func (p *FlashParams) SecondChipDensity() uint
- func (p *FlashParams) String() string
- type FlashRegion
- type FlashRegionSection
- type FlashRegionType
- type GUIDEDSectionAttribute
- type IntegrityCheck
- type ROMAttributes
- type RawRegion
- func (rr *RawRegion) Apply(v Visitor) error
- func (rr *RawRegion) ApplyChildren(v Visitor) error
- func (rr *RawRegion) Buf() []byte
- func (rr *RawRegion) FlashRegion() (fr *FlashRegion)
- func (rr *RawRegion) SetBuf(buf []byte)
- func (rr *RawRegion) SetFlashRegion(fr *FlashRegion)
- func (rr *RawRegion) Type() FlashRegionType
- type Region
- type RegionPermissions
- type Section
- type SectionExtHeader
- type SectionGUIDDefined
- type SectionGUIDDefinedHeader
- type SectionHeader
- type SectionType
- type TypeHeader
- type TypeSpecificHeader
- type TypedFirmware
- type Visitor
Constants ¶
const ( // FileHeaderMinLength is the minimum length of a firmware file header. FileHeaderMinLength = 0x18 // FileHeaderExtMinLength is the minimum length of an extended firmware file header. FileHeaderExtMinLength = 0x20 // EmptyBodyChecksum is the value placed in the File IntegrityCheck field if the body checksum bit isn't set. EmptyBodyChecksum uint8 = 0xAA )
const ( FirmwareVolumeFixedHeaderSize = 56 FirmwareVolumeMinSize = FirmwareVolumeFixedHeaderSize + 8 // +8 for the null block that terminates the block list FirmwareVolumeExtHeaderMinSize = 20 )
FirmwareVolume constants
const ( // FlashDescriptorLength represents the size of the descriptor region. FlashDescriptorLength = 0x1000 // FlashSignatureLength represents the size of the flash signature FlashSignatureLength = 4 )
const ( // SectionMinLength is the minimum length of a file section header. SectionMinLength = 0x04 // SectionExtMinLength is the minimum length of an extended file section header. SectionExtMinLength = 0x08 )
const ( // FlashDescriptorMapMaxBase is the maximum base address for a flash descriptor // region FlashDescriptorMapMaxBase = 0xe0 )
const FlashMasterSectionSize = 12
FlashMasterSectionSize is the size in bytes of the FlashMaster section
const (
// FlashParamsSize is the size of a FlashParams struct
FlashParamsSize = 4
)
const FlashRegionSectionSize = 64
FlashRegionSectionSize is the size of the Region descriptor. It is made up by 16 fields, each 2x16-bits large.
const (
// RegionBlockSize assumes the region struct values correspond to blocks of 0x1000 in size
RegionBlockSize = 0x1000
)
Variables ¶
var ( ZeroGUID = guid.MustParse("00000000-0000-0000-0000-000000000000") FFGUID = guid.MustParse("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF") )
Stock GUIDS
var ( FFS1 = guid.MustParse("7a9354d9-0468-444a-81ce-0bf617d890df") FFS2 = guid.MustParse("8c8ce578-8a3d-4f1c-9935-896185c32dd3") FFS3 = guid.MustParse("5473c07a-3dcb-4dca-bd6f-1e9689e7349a") EVSA = guid.MustParse("fff12b8d-7696-4c8b-a985-2747075b4f50") NVAR = guid.MustParse("cef5b9a3-476d-497f-9fdc-e98143e0422c") EVSA2 = guid.MustParse("00504624-8a59-4eeb-bd0f-6b36e96128e0") AppleBoot = guid.MustParse("04adeead-61ff-4d31-b6ba-64f8bf901f5a") PFH1 = guid.MustParse("16b45da2-7d70-4aea-a58d-760e9ecb841d") PFH2 = guid.MustParse("e360bdba-c3ce-46be-8f37-b231e5cb9f35") )
Valid FV GUIDs
var Attributes = ROMAttributes{ErasePolarity: poisonedPolarity}
Attributes holds the global attributes
var DepExNamesToOpCodes = map[DepExOpCode]byte{}
DepExNamesToOpCodes maps the operation back to the code.
var DepExOpCodes = map[byte]DepExOpCode{
0x0: "BEFORE",
0x1: "AFTER",
0x2: "PUSH",
0x3: "AND",
0x4: "OR",
0x5: "NOT",
0x6: "TRUE",
0x7: "FALSE",
0x8: "END",
0x9: "SOR",
}
DepExOpCodes maps the numeric code to the string.
var FVGUIDs = map[guid.GUID]string{ *FFS1: "FFS1", *FFS2: "FFS2", *FFS3: "FFS3", *EVSA: "NVRAM_EVSA", *NVAR: "NVRAM_NVAR", *EVSA2: "NVRAM_EVSA2", *AppleBoot: "APPLE_BOOT", *PFH1: "PFH1", *PFH2: "PFH2", }
FVGUIDs holds common FV type names
var FlashFrequencyStringMap = map[FlashFrequency]string{ Freq20MHz: "20MHz", Freq33MHz: "33MHz", Freq48MHz: "48MHz", Freq50MHz30MHz: "50Mhz30MHz", Freq17MHz: "17MHz", }
FlashFrequencyStringMap maps frequency constants to strings
var (
FlashSignature = []byte{0x5a, 0xa5, 0xf0, 0x0f}
)
FlashSignature is the sequence of bytes that a Flash image is expected to start with.
var SupportedFiles = map[FVFileType]bool{ FVFileTypeFreeForm: true, FVFileTypeSECCore: true, FVFileTypePEICore: true, FVFileTypeDXECore: true, FVFileTypeDriver: true, FVFileTypeCombinedPEIMDriver: true, FVFileTypeApplication: true, FVFileTypeSMM: true, FVFileTypeVolumeImage: true, FVFileTypeCombinedSMMDXE: true, FVFileTypeSMMCore: true, FVFileTypeSMMStandalone: true, FVFileTypeSMMCoreStandalone: true, }
SupportedFiles is a list of files types which will be parsed. File types not on this list are treated as opaque binary blobs.
Functions ¶
func Checksum16 ¶
Checksum16 does a 16 bit checksum of the byte slice passed in.
func FindFirmwareVolumeOffset ¶
FindFirmwareVolumeOffset searches for a firmware volume signature, "_FVH" using 8-byte alignment. If found, returns the offset from the start of the bios region, otherwise returns -1.
func FindSignature ¶
FindSignature searches for an Intel flash signature.
func MarshalFirmware ¶
MarshalFirmware marshals the firmware element to JSON, including the type information at the top.
func SetErasePolarity ¶
SetErasePolarity sets the Erase Polarity for the flash image. It checks to see if there are conflicting Erase Polarities.
func Write3Size ¶
Write3Size writes a size into a 3-byte array
Types ¶
type BIOSPadding ¶
type BIOSPadding struct { Offset uint64 // Metadata ExtractPath string // contains filtered or unexported fields }
BIOSPadding holds the padding in between firmware volumes This may sometimes hold data, even though it shouldn't. We need to preserve it though.
func NewBIOSPadding ¶
func NewBIOSPadding(buf []byte, offset uint64) (*BIOSPadding, error)
NewBIOSPadding parses a sequence of bytes and returns a BIOSPadding object.
func (*BIOSPadding) Apply ¶
func (bp *BIOSPadding) Apply(v Visitor) error
Apply a visitor to the BIOSPadding.
func (*BIOSPadding) ApplyChildren ¶
func (bp *BIOSPadding) ApplyChildren(v Visitor) error
ApplyChildren applies a visitor to all the direct children of the BIOSPadding
type BIOSRegion ¶
type BIOSRegion struct { Elements []*TypedFirmware `json:",omitempty"` // Metadata for extraction and recovery ExtractPath string Length uint64 // This is a pointer to the FlashRegion struct laid out in the ifd. FRegion *FlashRegion RegionType FlashRegionType // contains filtered or unexported fields }
BIOSRegion represents the Bios Region in the firmware. It holds all the FVs as well as padding
func (*BIOSRegion) Apply ¶
func (br *BIOSRegion) Apply(v Visitor) error
Apply calls the visitor on the BIOSRegion.
func (*BIOSRegion) ApplyChildren ¶
func (br *BIOSRegion) ApplyChildren(v Visitor) error
ApplyChildren calls the visitor on each child node of BIOSRegion.
func (*BIOSRegion) Buf ¶
func (br *BIOSRegion) Buf() []byte
Buf returns the buffer. Used mostly for things interacting with the Firmware interface.
func (*BIOSRegion) FirstFV ¶
func (br *BIOSRegion) FirstFV() (*FirmwareVolume, error)
FirstFV finds the first firmware volume in the BIOSRegion.
func (*BIOSRegion) FlashRegion ¶
func (br *BIOSRegion) FlashRegion() (fr *FlashRegion)
FlashRegion gets the Flash Region.
func (*BIOSRegion) SetBuf ¶
func (br *BIOSRegion) SetBuf(buf []byte)
SetBuf sets the buffer. Used mostly for things interacting with the Firmware interface.
func (*BIOSRegion) SetFlashRegion ¶
func (br *BIOSRegion) SetFlashRegion(fr *FlashRegion)
SetFlashRegion sets the Flash Region.
func (*BIOSRegion) Type ¶
func (br *BIOSRegion) Type() FlashRegionType
Type returns the flash region type.
type DepExOp ¶
type DepExOp struct { OpCode DepExOpCode GUID *guid.GUID `json:",omitempty"` }
DepExOp contains one operation for the dependency expression.
type DepExOpCode ¶
type DepExOpCode string
DepExOpCode is one opcode for the dependency expression section.
type FVFileType ¶
type FVFileType uint8
FVFileType represents the different types possible in an EFI file.
const ( FVFileTypeAll FVFileType = iota FVFileTypeRaw FVFileTypeFreeForm FVFileTypeSECCore FVFileTypePEICore FVFileTypeDXECore FVFileTypePEIM FVFileTypeDriver FVFileTypeCombinedPEIMDriver FVFileTypeApplication FVFileTypeSMM FVFileTypeVolumeImage FVFileTypeCombinedSMMDXE FVFileTypeSMMCore FVFileTypeSMMStandalone FVFileTypeSMMCoreStandalone FVFileTypeOEMMin FVFileType = 0xC0 FVFileTypeOEMMax FVFileType = 0xDF FVFileTypeDebugMin FVFileType = 0xE0 FVFileTypeDebugMax FVFileType = 0xEF FVFileTypePad FVFileType = 0xF0 FVFileTypeFFSMin FVFileType = 0xF0 FVFileTypeFFSMax FVFileType = 0xFF )
UEFI FV File types.
func (FVFileType) String ¶
func (f FVFileType) String() string
String creates a string representation for the file type.
type File ¶
type File struct { Header FileHeaderExtended Type string Sections []*Section `json:",omitempty"` ExtractPath string DataOffset uint64 // contains filtered or unexported fields }
File represents an EFI File.
func CreatePadFile ¶
CreatePadFile creates an empty pad file in order to align the next file.
func NewFile ¶
NewFile parses a sequence of bytes and returns a File object, if a valid one is passed, or an error. If no error is returned and the File pointer is nil, it means we've reached the volume free space at the end of the FV.
func (*File) ApplyChildren ¶
ApplyChildren calls the visitor on each child node of File.
func (*File) Buf ¶
Buf returns the buffer. Used mostly for things interacting with the Firmware interface.
func (*File) ChecksumAndAssemble ¶
ChecksumAndAssemble takes in the fileData and assembles the file binary
func (*File) ChecksumHeader ¶
ChecksumHeader returns a checksum of the header.
func (*File) HeaderLen ¶
HeaderLen returns the length of the file header depending on the file size.
type FileHeader ¶
type FileHeader struct { GUID guid.GUID // This is the GUID of the file. Checksum IntegrityCheck `json:"-"` Type FVFileType Attributes fileAttr Size [3]uint8 `json:"-"` State uint8 `json:"-"` }
FileHeader represents an EFI File header.
type FileHeaderExtended ¶
type FileHeaderExtended struct { FileHeader ExtendedSize uint64 `json:"-"` }
FileHeaderExtended represents an EFI File header with the large file attribute set. We also use this as the generic header for all EFI files, regardless of whether they are actually large. This makes it easier for us to just return one type All sizes are also copied into the ExtendedSize field so we only have to check once
type Firmware ¶
type Firmware interface { Buf() []byte SetBuf(buf []byte) // Apply a visitor to the Firmware. Apply(v Visitor) error // Apply a visitor to all the direct children of the Firmware // (excluding the Firmware itself). ApplyChildren(v Visitor) error }
Firmware is an interface to describe generic firmware types. When the firmware is parsed, all the Firmware objects are laid out in a tree (similar to an AST). This interface represents one node in said tree. The implementations (e.g. Flash image, or FirmwareVolume) must implement this interface.
func Parse ¶
Parse exposes a high-level parser for generic firmware types. It does not implement any parser itself, but it calls known parsers that implement the Firmware interface.
func UnmarshalFirmware ¶
UnmarshalFirmware unmarshals the firmware element from JSON, using the type information at the top.
type FirmwareVolume ¶
type FirmwareVolume struct { FirmwareVolumeFixedHeader // there must be at least one that is zeroed and indicates the end of the // block list // We don't really have to care about blocks because we just read everything in. Blocks []Block FirmwareVolumeExtHeader Files []*File `json:",omitempty"` // Variables not in the binary for us to keep track of stuff/print DataOffset uint64 FVOffset uint64 // Byte offset from start of BIOS region. ExtractPath string Resizable bool // Determines if this FV is resizable. FreeSpace uint64 `json:"-"` // contains filtered or unexported fields }
FirmwareVolume represents a firmware volume. It combines the fixed header and a variable list of blocks
func NewFirmwareVolume ¶
func NewFirmwareVolume(data []byte, fvOffset uint64, resizable bool) (*FirmwareVolume, error)
NewFirmwareVolume parses a sequence of bytes and returns a FirmwareVolume object, if a valid one is passed, or an error
func (*FirmwareVolume) Apply ¶
func (fv *FirmwareVolume) Apply(v Visitor) error
Apply calls the visitor on the FirmwareVolume.
func (*FirmwareVolume) ApplyChildren ¶
func (fv *FirmwareVolume) ApplyChildren(v Visitor) error
ApplyChildren calls the visitor on each child node of FirmwareVolume.
func (*FirmwareVolume) Buf ¶
func (fv *FirmwareVolume) Buf() []byte
Buf returns the buffer. Used mostly for things interacting with the Firmware interface.
func (*FirmwareVolume) GetErasePolarity ¶
func (fv *FirmwareVolume) GetErasePolarity() uint8
GetErasePolarity gets the erase polarity
func (*FirmwareVolume) InsertFile ¶
func (fv *FirmwareVolume) InsertFile(alignedOffset uint64, fBuf []byte) error
InsertFile appends the file to the end of the buffer according to alignment requirements.
func (*FirmwareVolume) SetBuf ¶
func (fv *FirmwareVolume) SetBuf(buf []byte)
SetBuf sets the buffer. Used mostly for things interacting with the Firmware interface.
type FirmwareVolumeExtHeader ¶
FirmwareVolumeExtHeader contains the fields of an extended firmware volume header
type FirmwareVolumeFixedHeader ¶
type FirmwareVolumeFixedHeader struct { FileSystemGUID guid.GUID Length uint64 Signature uint32 Attributes uint32 // UEFI PI spec volume 3.2.1 EFI_FIRMWARE_VOLUME_HEADER HeaderLen uint16 Checksum uint16 ExtHeaderOffset uint16 Reserved uint8 `json:"-"` Revision uint8 // contains filtered or unexported fields }
FirmwareVolumeFixedHeader contains the fixed fields of a firmware volume header
type FlashDescriptor ¶
type FlashDescriptor struct { DescriptorMapStart uint RegionStart uint MasterStart uint DescriptorMap *FlashDescriptorMap Region *FlashRegionSection Master *FlashMasterSection //Metadata for extraction and recovery ExtractPath string // contains filtered or unexported fields }
FlashDescriptor is the main structure that represents an Intel Flash Descriptor.
func (*FlashDescriptor) Apply ¶
func (fd *FlashDescriptor) Apply(v Visitor) error
Apply calls the visitor on the FlashDescriptor.
func (*FlashDescriptor) ApplyChildren ¶
func (fd *FlashDescriptor) ApplyChildren(v Visitor) error
ApplyChildren calls the visitor on each child node of FlashDescriptor.
func (*FlashDescriptor) Buf ¶
func (fd *FlashDescriptor) Buf() []byte
Buf returns the buffer. Used mostly for things interacting with the Firmware interface.
func (*FlashDescriptor) ParseFlashDescriptor ¶
func (fd *FlashDescriptor) ParseFlashDescriptor() error
ParseFlashDescriptor parses the ifd from the buffer
func (*FlashDescriptor) SetBuf ¶
func (fd *FlashDescriptor) SetBuf(buf []byte)
SetBuf sets the buffer. Used mostly for things interacting with the Firmware interface.
type FlashDescriptorMap ¶
type FlashDescriptorMap struct { // FLMAP0 ComponentBase uint8 NumberOfFlashChips uint8 RegionBase uint8 NumberOfRegions uint8 // FLMAP1 MasterBase uint8 NumberOfMasters uint8 PchStrapsBase uint8 NumberOfPchStraps uint8 // FLMAP2 ProcStrapsBase uint8 NumberOfProcStraps uint8 IccTableBase uint8 NumberOfIccTableEntries uint8 // FLMAP3 DmiTableBase uint8 NumberOfDmiTableEntries uint8 Reserved0 uint8 Reserved1 uint8 }
FlashDescriptorMap represent an Intel flash descriptor. This object provides accessors to the various descriptor fields.
func NewFlashDescriptorMap ¶
func NewFlashDescriptorMap(buf []byte) (*FlashDescriptorMap, error)
NewFlashDescriptorMap initializes a FlashDescriptor from a slice of bytes.
func (*FlashDescriptorMap) String ¶
func (d *FlashDescriptorMap) String() string
type FlashFrequency ¶
type FlashFrequency uint
FlashFrequency is the type used for Frequency fields
const ( Freq20MHz FlashFrequency = 0 Freq33MHz FlashFrequency = 1 Freq48MHz FlashFrequency = 2 Freq50MHz30MHz FlashFrequency = 4 Freq17MHz FlashFrequency = 6 )
Flash frequency constants
type FlashImage ¶
type FlashImage struct { // Holds the Flash Descriptor IFD FlashDescriptor // Actual regions Regions []*TypedFirmware `json:",omitempty"` // Metadata for extraction and recovery ExtractPath string FlashSize uint64 // contains filtered or unexported fields }
FlashImage is the main structure that represents an Intel Flash image. It implements the Firmware interface.
func NewFlashImage ¶
func NewFlashImage(buf []byte) (*FlashImage, error)
NewFlashImage tries to create a FlashImage structure, and returns a FlashImage and an error if any. This only works with images that operate in Descriptor mode.
func (*FlashImage) Apply ¶
func (f *FlashImage) Apply(v Visitor) error
Apply calls the visitor on the FlashImage.
func (*FlashImage) ApplyChildren ¶
func (f *FlashImage) ApplyChildren(v Visitor) error
ApplyChildren calls the visitor on each child node of FlashImage.
func (*FlashImage) Buf ¶
func (f *FlashImage) Buf() []byte
Buf returns the buffer. Used mostly for things interacting with the Firmware interface.
func (*FlashImage) FindSignature ¶
func (f *FlashImage) FindSignature() (int, error)
FindSignature looks for the Intel flash signature, and returns its offset from the start of the image. The PCH images are located at offset 16, while in ICH8/9/10 they start at 0. If no signature is found, it returns -1.
func (*FlashImage) IsPCH ¶
func (f *FlashImage) IsPCH() bool
IsPCH returns whether the flash image has the more recent PCH format, or not. PCH images have the first 16 bytes reserved, and the 4-bytes signature starts immediately after. Older images (ICH8/9/10) have the signature at the beginning. TODO: Check this. What if we have the signature in both places? I feel like the check should be IsICH because I expect the ICH to override PCH if the signature exists in 0:4 since in that case 16:20 should be data. If that's the case, FindSignature needs to be fixed as well
func (*FlashImage) SetBuf ¶
func (f *FlashImage) SetBuf(buf []byte)
SetBuf sets the buffer. Used mostly for things interacting with the Firmware interface.
func (*FlashImage) String ¶
func (f *FlashImage) String() string
type FlashMasterSection ¶
type FlashMasterSection struct { BIOS RegionPermissions ME RegionPermissions GBE RegionPermissions }
FlashMasterSection holds all the IDs and read/write permissions for other regions This controls whether the bios region can read/write to the ME for example.
func NewFlashMasterSection ¶
func NewFlashMasterSection(buf []byte) (*FlashMasterSection, error)
NewFlashMasterSection parses a sequence of bytes and returns a FlashMasterSection object, if a valid one is passed, or an error
func (*FlashMasterSection) String ¶
func (m *FlashMasterSection) String() string
type FlashParams ¶
type FlashParams [4]byte
FlashParams is a 4-byte object that holds the flash parameters information.
func NewFlashParams ¶
func NewFlashParams(buf []byte) (*FlashParams, error)
NewFlashParams initializes a FlashParam struct from a slice of bytes
func (*FlashParams) DualOutputFastReadSupported ¶
func (p *FlashParams) DualOutputFastReadSupported() uint
DualOutputFastReadSupported returns if Dual Output Fast Read is supported.
func (*FlashParams) FastReadEnabled ¶
func (p *FlashParams) FastReadEnabled() uint
FastReadEnabled returns if FastRead is enabled.
func (*FlashParams) FastReadFrequency ¶
func (p *FlashParams) FastReadFrequency() FlashFrequency
FastReadFrequency returns the frequency under FastRead.
func (*FlashParams) FirstChipDensity ¶
func (p *FlashParams) FirstChipDensity() uint
FirstChipDensity returns the size of the first chip.
func (*FlashParams) FlashReadStatusFrequency ¶
func (p *FlashParams) FlashReadStatusFrequency() FlashFrequency
FlashReadStatusFrequency returns the chip frequency while reading the flash status.
func (*FlashParams) FlashWriteFrequency ¶
func (p *FlashParams) FlashWriteFrequency() FlashFrequency
FlashWriteFrequency returns the chip frequency for writing.
func (*FlashParams) ReadClockFrequency ¶
func (p *FlashParams) ReadClockFrequency() FlashFrequency
ReadClockFrequency returns the chip frequency while reading from the flash.
func (*FlashParams) SecondChipDensity ¶
func (p *FlashParams) SecondChipDensity() uint
SecondChipDensity returns the size of the second chip.
func (*FlashParams) String ¶
func (p *FlashParams) String() string
type FlashRegion ¶
type FlashRegion struct { Base uint16 // Index of first 4KiB block Limit uint16 // Index of last block }
FlashRegion holds the base and limit of every type of region. Each region such as the bios region should point back to it. TODO: figure out of block sizes are read from some location on flash or fixed. Right now we assume they're fixed to 4KiB
func (*FlashRegion) BaseOffset ¶
func (r *FlashRegion) BaseOffset() uint32
BaseOffset calculates the offset into the flash image where the Region begins
func (*FlashRegion) EndOffset ¶
func (r *FlashRegion) EndOffset() uint32
EndOffset calculates the offset into the flash image where the Region ends
func (*FlashRegion) String ¶
func (r *FlashRegion) String() string
func (*FlashRegion) Valid ¶
func (r *FlashRegion) Valid() bool
Valid checks to see if a region is valid
type FlashRegionSection ¶
type FlashRegionSection struct { FlashBlockEraseSize uint16 // This isn't documented anywhere, but I've only seen images with 16 slots for FlashRegion entries, with the // FlashMasterSection coming immediately after, so I'm assuming that's the max for now. FlashRegions [15]FlashRegion // contains filtered or unexported fields }
FlashRegionSection holds the metadata of all the different flash regions like PDR, Gbe and the Bios region.
func NewFlashRegionSection ¶
func NewFlashRegionSection(data []byte) (*FlashRegionSection, error)
NewFlashRegionSection initializes a FlashRegionSection from a slice of bytes
func (*FlashRegionSection) String ¶
func (f *FlashRegionSection) String() string
func (*FlashRegionSection) ValidRegions ¶
func (f *FlashRegionSection) ValidRegions() []string
ValidRegions returns a list of names of the regions with non-zero size.
type FlashRegionType ¶
type FlashRegionType int
FlashRegionType represents the different types possible in a flash region.
const ( RegionTypeBIOS FlashRegionType = iota RegionTypeME RegionTypeGBE RegionTypePD RegionTypeDevExp1 RegionTypeBIOS2 RegionTypeMicrocode RegionTypeEC RegionTypeDevExp2 RegionTypeIE RegionTypeTGBE1 RegionTypeTGBE2 RegionTypeReserved1 RegionTypeReserved2 RegionTypePTT RegionTypeUnknown FlashRegionType = -1 )
IFD Region types. This also corresponds to their index in the flash region section. Referenced from github.com/LongSoft/UEFITool, common/descriptor.h.
func (FlashRegionType) String ¶
func (rt FlashRegionType) String() string
type GUIDEDSectionAttribute ¶
type GUIDEDSectionAttribute uint16
GUIDEDSectionAttribute holds a GUIDED section attribute bitfield
const ( GUIDEDSectionProcessingRequired GUIDEDSectionAttribute = 0x01 GUIDEDSectionAuthStatusValid GUIDEDSectionAttribute = 0x02 )
UEFI GUIDED Section Attributes
type IntegrityCheck ¶
IntegrityCheck holds the two 8 bit checksums for the file header and body separately.
type ROMAttributes ¶
type ROMAttributes struct {
ErasePolarity byte // Either 0xFF or 0
}
ROMAttributes is used to hold global variables that apply across the whole image. We have to do this to avoid passing too many things down each time.
type RawRegion ¶
type RawRegion struct { // Metadata for extraction and recovery ExtractPath string // This is a pointer to the FlashRegion struct laid out in the ifd. FRegion *FlashRegion // Region Type as per the IFD RegionType FlashRegionType // contains filtered or unexported fields }
RawRegion implements Region for a raw chunk of bytes in the firmware image.
func (*RawRegion) ApplyChildren ¶
ApplyChildren calls the visitor on each child node of RawRegion.
func (*RawRegion) Buf ¶
Buf returns the buffer. Used mostly for things interacting with the Firmware interface.
func (*RawRegion) FlashRegion ¶
func (rr *RawRegion) FlashRegion() (fr *FlashRegion)
FlashRegion gets the flash region.
func (*RawRegion) SetBuf ¶
SetBuf sets the buffer. Used mostly for things interacting with the Firmware interface.
func (*RawRegion) SetFlashRegion ¶
func (rr *RawRegion) SetFlashRegion(fr *FlashRegion)
SetFlashRegion sets the flash region.
func (*RawRegion) Type ¶
func (rr *RawRegion) Type() FlashRegionType
Type returns the flash region type.
type Region ¶
type Region interface { Firmware Type() FlashRegionType FlashRegion() *FlashRegion SetFlashRegion(fr *FlashRegion) }
Region contains the start and end of a region in flash. This can be a BIOS, ME, PDR or GBE region.
func NewBIOSRegion ¶
func NewBIOSRegion(buf []byte, r *FlashRegion, _ FlashRegionType) (Region, error)
NewBIOSRegion parses a sequence of bytes and returns a Region object, if a valid one is passed, or an error. It also points to the Region struct uncovered in the ifd.
func NewRawRegion ¶
func NewRawRegion(buf []byte, r *FlashRegion, rt FlashRegionType) (Region, error)
NewRawRegion creates a new region.
type RegionPermissions ¶
RegionPermissions holds the read/write permissions for other regions.
func (*RegionPermissions) String ¶
func (r *RegionPermissions) String() string
type Section ¶
type Section struct { Header SectionExtHeader Type string // Metadata for extraction and recovery ExtractPath string FileOrder int `json:"-"` // Type specific fields // TODO: It will be simpler if this was not an interface TypeSpecific *TypeSpecificHeader `json:",omitempty"` // For EFI_SECTION_USER_INTERFACE Name string `json:",omitempty"` // For EFI_SECTION_VERSION BuildNumber uint16 `json:",omitempty"` Version string `json:",omitempty"` // For EFI_SECTION_DXE_DEPEX, EFI_SECTION_PEI_DEPEX, and EFI_SECTION_MM_DEPEX DepEx []DepExOp `json:",omitempty"` // Encapsulated firmware Encapsulated []*TypedFirmware `json:",omitempty"` // contains filtered or unexported fields }
Section represents a Firmware File Section
func CreateSection ¶
CreateSection creates a new section from minimal components. The guid is only used in the case of a GUID Defined section type.
func NewSection ¶
NewSection parses a sequence of bytes and returns a Section object, if a valid one is passed, or an error.
func (*Section) ApplyChildren ¶
ApplyChildren calls the visitor on each child node of Section.
func (*Section) Buf ¶
Buf returns the buffer. Used mostly for things interacting with the Firmware interface.
func (*Section) GenSecHeader ¶
GenSecHeader generates a full binary header for the section data. It assumes that the passed in section struct already contains section data in the buffer, the section type in the Type field, and the type specific header in the TypeSpecific field. It modifies the calling Section.
func (*Section) SetBuf ¶
SetBuf sets the buffer. Used mostly for things interacting with the Firmware interface.
func (*Section) SetType ¶
func (s *Section) SetType(t SectionType)
SetType sets the section type in the header and updates the string name.
type SectionExtHeader ¶
type SectionExtHeader struct { SectionHeader ExtendedSize uint32 `json:"-"` }
SectionExtHeader represents an EFI_COMMON_SECTION_HEADER2 as specified in UEFI PI Spec 3.2.4 Firmware File Section
type SectionGUIDDefined ¶
type SectionGUIDDefined struct { SectionGUIDDefinedHeader // Metadata Compression string }
SectionGUIDDefined contains the type specific fields for a EFI_SECTION_GUID_DEFINED section.
func (*SectionGUIDDefined) GetBinHeaderLen ¶
func (s *SectionGUIDDefined) GetBinHeaderLen() uint32
GetBinHeaderLen returns the length of the binary typ specific header
type SectionGUIDDefinedHeader ¶
SectionGUIDDefinedHeader contains the fields for a EFI_SECTION_GUID_DEFINED encapsulated section header.
type SectionHeader ¶
type SectionHeader struct { Size [3]uint8 `json:"-"` Type SectionType }
SectionHeader represents an EFI_COMMON_SECTION_HEADER as specified in UEFI PI Spec 3.2.4 Firmware File Section
type SectionType ¶
type SectionType uint8
SectionType holds a section type value
const ( SectionTypeAll SectionType = 0x00 SectionTypeCompression SectionType = 0x01 SectionTypeGUIDDefined SectionType = 0x02 SectionTypeDisposable SectionType = 0x03 SectionTypePE32 SectionType = 0x10 SectionTypePIC SectionType = 0x11 SectionTypeTE SectionType = 0x12 SectionTypeDXEDepEx SectionType = 0x13 SectionTypeVersion SectionType = 0x14 SectionTypeUserInterface SectionType = 0x15 SectionTypeCompatibility16 SectionType = 0x16 SectionTypeFirmwareVolumeImage SectionType = 0x17 SectionTypeFreeformSubtypeGUID SectionType = 0x18 SectionTypeRaw SectionType = 0x19 SectionTypePEIDepEx SectionType = 0x1b SectionMMDepEx SectionType = 0x1c )
UEFI Section types
func (SectionType) String ¶
func (s SectionType) String() string
String creates a string representation for the file type.
type TypeHeader ¶
type TypeHeader interface {
GetBinHeaderLen() uint32
}
TypeHeader interface forces type specific headers to report their length
type TypeSpecificHeader ¶
type TypeSpecificHeader struct { Type SectionType Header TypeHeader }
TypeSpecificHeader is used for marshalling and unmarshalling from JSON
func (*TypeSpecificHeader) UnmarshalJSON ¶
func (t *TypeSpecificHeader) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals a TypeSpecificHeader struct and correctly deduces the type of the interface.
type TypedFirmware ¶
TypedFirmware includes the Firmware interface's type when exporting it to JSON. The type is required when unmarshalling.
func MakeTyped ¶
func MakeTyped(f Firmware) *TypedFirmware
MakeTyped takes a Firmware interface and makes a (type, value) pair.
func (*TypedFirmware) UnmarshalJSON ¶
func (f *TypedFirmware) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals a TypedFirmware struct and correctly deduces the type of the interface.
type Visitor ¶
type Visitor interface { // Run wraps Visit. Additionally, it performs some setup and teardown // tasks. As a consumer of the visitor, Run is typically the function // you should call. Run(Firmware) error // Visit applies the visitor to the Firmware and (usually) recurses // over the children. Visit(Firmware) error }
Visitor represents an operation which can be applied to the Firmware. Typically, the Visit function contains a type switch for the different firmware types and a default case. For example:
func (v *Example) Visit(f uefi.Firmware) error { switch f := f.(type) { case *uefi.File: fmt.Println("f is a file") return f.ApplyChildren(v) // Children are recursed over case *uefi.Section: fmt.Println("f is a section") return nil // Children are not visited default: // The default action is to recurse over children. return f.ApplyChildren(v) } }