Help us shape the future of Go! Take the 2026 Go Developer Survey

cbfs

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2023 License: BSD-3-Clause Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	HeaderMagic   = 0x4F524243
	HeaderV1      = 0x31313131
	HeaderV2      = 0x31313132
	HeaderVersion = HeaderV2
	Alignment     = 64
)
View Source
const FileMagic = "LARCHIVE"
View Source
const FileSize = 24
View Source
const MasterHeaderLen = 32

this is the master cbfs header - it must be located somewhere available to bootblock (to load romstage). The last 4 bytes in the image contain its relative offset from the end of the image (as a 32-bit signed integer).

Variables

View Source
var (
	Master = []byte{}/* 696 elements not displayed */

	ListOutput = `` /* 784-byte string literal not displayed */

)
View Source
var CbfsHeaderMagicNotFound = errors.New("CBFS header magic doesn't match")
View Source
var Debug = func(format string, v ...interface{}) {}
View Source
var SegReaders = make(map[FileType]*SegReader)

Functions

func Read

func Read(r io.Reader, f interface{}) error

Read reads things in in BE format, which they are supposed to be in.

func ReadAttributes

func ReadAttributes(r io.Reader, f *File) error

ReadAttributes reads the variable length CBFS attribute list.

func ReadData

func ReadData(r io.ReadSeeker, f *File) error

ReadData reads the variable length CBFS file data.

func ReadLE

func ReadLE(r io.Reader, f interface{}) error

ReadLE reads things in LE format, which the spec says it is not in.

func ReadName

func ReadName(r io.Reader, f *File, size uint32) error

ReadName reads the variable length CBFS name.

func RegisterFileReader

func RegisterFileReader(f *SegReader) error

func Write

func Write(w io.Writer, f interface{}) error

Write reads things in in BE format, which they are supposed to be in.

func WriteLE

func WriteLE(r io.Writer, f interface{}) error

WriteLE reads things in LE format, which the spec says it is not in.

Types

type Architecture

type Architecture uint32
const (
	X86 Architecture = 1
	ARM Architecture = 0x10
)

type BootBlockRecord

type BootBlockRecord struct {
	File
}

func (*BootBlockRecord) GetFile

func (r *BootBlockRecord) GetFile() *File

func (*BootBlockRecord) Read

func (r *BootBlockRecord) Read(in io.ReadSeeker) error

func (*BootBlockRecord) String

func (r *BootBlockRecord) String() string

func (*BootBlockRecord) Write

func (r *BootBlockRecord) Write(w io.Writer) error

type BootSplashRecord added in v1.1.0

type BootSplashRecord struct {
	File
}

func (*BootSplashRecord) GetFile added in v1.1.0

func (r *BootSplashRecord) GetFile() *File

File returns a pointer to the corresponding File

func (*BootSplashRecord) Read added in v1.1.0

func (r *BootSplashRecord) Read(in io.ReadSeeker) error

func (*BootSplashRecord) String added in v1.1.0

func (r *BootSplashRecord) String() string

func (*BootSplashRecord) Write added in v1.1.0

func (r *BootSplashRecord) Write(w io.Writer) error

type CMOSLayoutRecord

type CMOSLayoutRecord struct {
	File
}

func (*CMOSLayoutRecord) GetFile

func (r *CMOSLayoutRecord) GetFile() *File

func (*CMOSLayoutRecord) Read

func (r *CMOSLayoutRecord) Read(in io.ReadSeeker) error

func (*CMOSLayoutRecord) String

func (r *CMOSLayoutRecord) String() string

func (*CMOSLayoutRecord) Write

func (r *CMOSLayoutRecord) Write(w io.Writer) error

type CMOSRecord added in v1.1.0

type CMOSRecord struct {
	File
}

func (*CMOSRecord) GetFile added in v1.1.0

func (r *CMOSRecord) GetFile() *File

func (*CMOSRecord) Read added in v1.1.0

func (r *CMOSRecord) Read(in io.ReadSeeker) error

func (*CMOSRecord) String added in v1.1.0

func (r *CMOSRecord) String() string

func (*CMOSRecord) Write added in v1.1.0

func (r *CMOSRecord) Write(w io.Writer) error

type Compression

type Compression uint32
const (
	None Compression = iota
	LZMA
	LZ4
)

func (Compression) String

func (c Compression) String() string

type EmptyRecord

type EmptyRecord struct {
	File
}

func (*EmptyRecord) GetFile

func (r *EmptyRecord) GetFile() *File

func (*EmptyRecord) Read

func (r *EmptyRecord) Read(in io.ReadSeeker) error

func (*EmptyRecord) String

func (r *EmptyRecord) String() string

func (*EmptyRecord) Write

func (r *EmptyRecord) Write(w io.Writer) error

type FSPRecord

type FSPRecord struct {
	File
}

func (*FSPRecord) GetFile

func (r *FSPRecord) GetFile() *File

File returns a pointer to the corresponding File

func (*FSPRecord) Read

func (r *FSPRecord) Read(in io.ReadSeeker) error

func (*FSPRecord) String

func (r *FSPRecord) String() string

func (*FSPRecord) Write

func (r *FSPRecord) Write(w io.Writer) error

type File

type File struct {
	FileHeader
	RecordStart uint32
	Name        string
	Attr        []byte
	FData       []byte
}

func NewFile added in v1.2.0

func NewFile(r io.ReadSeeker) (*File, error)

NewFile reads in the CBFS file at current offset On success it seeks to the end of the file. On error the current offset withing the ReadSeeker is undefined.

func (*File) Compression added in v1.2.0

func (f *File) Compression() Compression

Compression returns the algorithm used to compress FData. If no compression attribute is found or on error it returns 'None'

func (*File) Decompress added in v1.2.0

func (f *File) Decompress() ([]byte, error)

Decompress returns the decompressed FData If FData is not compressed it returns FData

func (*File) FindAttribute added in v1.2.0

func (f *File) FindAttribute(t Tag) ([]byte, error)

FindAttribute returns the attribute with given tag as []byte. It has the size as specified by the tag. Returns an error if not found or could not read in total.

func (*File) MarshalJSON

func (f *File) MarshalJSON() ([]byte, error)

type FileAttr

type FileAttr struct {
	Tag  uint32
	Size uint32 // inclusize of Tag and Size
}

The common fields of extended cbfs file attributes. Attributes are expected to start with tag/len, then append their specific fields.

type FileAttrAlign

type FileAttrAlign struct {
	Tag   Tag
	Size  uint32 // includes everything including data.
	Align uint32
}

type FileAttrCompression

type FileAttrCompression struct {
	Tag              Tag
	Size             uint32
	Compression      Compression
	DecompressedSize uint32
}

type FileAttrHash

type FileAttrHash struct {
	Tag      Tag
	Size     uint32 // includes everything including data.
	HashType uint32
	Data     []byte
}

type FileAttrPos

type FileAttrPos struct {
	Tag  Tag
	Size uint32 // includes everything including data.
	Pos  uint32
}

type FileAttrStageHeader

type FileAttrStageHeader struct {
	Tag         Tag
	Size        uint32
	LoadAddress uint64
	EntryOffset uint32
	MemSize     uint32
}

func (*FileAttrStageHeader) String

func (h *FileAttrStageHeader) String() string

type FileHeader

type FileHeader struct {
	Magic           [8]byte
	Size            uint32
	Type            FileType
	AttrOffset      uint32
	SubHeaderOffset uint32
}

func (*FileHeader) Deleted

func (h *FileHeader) Deleted() bool

type FileType

type FileType uint32

These are standard component types for well known

components (i.e - those that coreboot needs to consume.
Users are welcome to use any other value for their
components.
const (
	// FOV
	TypeDeleted2    FileType = 0xffffffff
	TypeDeleted     FileType = 0
	TypeBootBlock   FileType = 0x1
	TypeMaster      FileType = 0x2
	TypeLegacyStage FileType = 0x10
	TypeStage       FileType = 0x11
	TypeSELF        FileType = 0x20
	TypeFIT         FileType = 0x21
	TypeOptionRom   FileType = 0x30
	TypeBootSplash  FileType = 0x40
	TypeRaw         FileType = 0x50
	TypeVSA         FileType = 0x51 // very, very obsolete Geode thing
	TypeMBI         FileType = 0x52
	TypeMicroCode   FileType = 0x53
	TypeFSP         FileType = 0x60
	TypeMRC         FileType = 0x61
	TypeMMA         FileType = 0x62
	TypeEFI         FileType = 0x63
	TypeStruct      FileType = 0x70
	TypeCMOS        FileType = 0xaa
	TypeSPD         FileType = 0xab
	TypeMRCCache    FileType = 0xac
	TypeCMOSLayout  FileType = 0x1aa
)

func (FileType) String

func (f FileType) String() string

type Image

type Image struct {
	Segs []ReadWriter
	// Scarf away the fmap info.
	FMAP         *fmap.FMap
	FMAPMetadata *fmap.Metadata
	Area         *fmap.Area
	// And all the data.
	Data []byte
}

func NewImage

func NewImage(rs io.ReadSeeker) (*Image, error)

func Open

func Open(n string) (*Image, error)

func (*Image) MarshalJSON

func (i *Image) MarshalJSON() ([]byte, error)

func (*Image) Remove

func (i *Image) Remove(n string) error

func (*Image) String

func (i *Image) String() string

func (*Image) Update

func (i *Image) Update() error

Update creates a new []byte for the cbfs. It is complicated a lot by the fact that endianness is not consistent in cbfs images.

func (*Image) WriteFile

func (i *Image) WriteFile(name string, perm os.FileMode) error

type LegacyStageRecord

type LegacyStageRecord struct {
	File
	StageHeader
	Data []byte
}

func (*LegacyStageRecord) GetFile

func (r *LegacyStageRecord) GetFile() *File

func (*LegacyStageRecord) MarshalJSON

func (h *LegacyStageRecord) MarshalJSON() ([]byte, error)

func (*LegacyStageRecord) Read

func (r *LegacyStageRecord) Read(in io.ReadSeeker) error

func (*LegacyStageRecord) String

func (h *LegacyStageRecord) String() string

func (*LegacyStageRecord) Write

func (r *LegacyStageRecord) Write(w io.Writer) error

type MasterHeader

type MasterHeader struct {
	Magic         uint32
	Version       uint32
	RomSize       uint32
	BootBlockSize uint32
	Align         uint32 // always 64 bytes -- FOV
	Offset        uint32
	Architecture  Architecture // integer, not name -- FOV
	// contains filtered or unexported fields
}

type MasterRecord

type MasterRecord struct {
	File
	MasterHeader
}

func (*MasterRecord) GetFile

func (r *MasterRecord) GetFile() *File

func (*MasterRecord) Read

func (r *MasterRecord) Read(in io.ReadSeeker) error

func (*MasterRecord) String

func (r *MasterRecord) String() string

func (*MasterRecord) Write

func (r *MasterRecord) Write(w io.Writer) error

type MicrocodeRecord

type MicrocodeRecord struct {
	File
}

func (*MicrocodeRecord) GetFile

func (r *MicrocodeRecord) GetFile() *File

Header returns a pointer to the corresponding File

func (*MicrocodeRecord) Read

func (r *MicrocodeRecord) Read(in io.ReadSeeker) error

func (*MicrocodeRecord) String

func (r *MicrocodeRecord) String() string

func (*MicrocodeRecord) Write

func (r *MicrocodeRecord) Write(w io.Writer) error

type OptionROMRecord added in v1.1.0

type OptionROMRecord struct {
	File
}

func (*OptionROMRecord) GetFile added in v1.1.0

func (r *OptionROMRecord) GetFile() *File

func (*OptionROMRecord) Read added in v1.1.0

func (r *OptionROMRecord) Read(in io.ReadSeeker) error

func (*OptionROMRecord) String added in v1.1.0

func (r *OptionROMRecord) String() string

func (*OptionROMRecord) Write added in v1.1.0

func (r *OptionROMRecord) Write(w io.Writer) error

type OptionRom

type OptionRom struct {
	File
	Compression Compression
	Size        uint32
}

type PayloadHeader

type PayloadHeader struct {
	Type        SegmentType
	Compression Compression
	Offset      uint32
	LoadAddress uint64
	Size        uint32
	MemSize     uint32
}

func (*PayloadHeader) String

func (r *PayloadHeader) String() string

type PayloadRecord

type PayloadRecord struct {
	File
	Segs []PayloadHeader
	Data []byte
}

func (*PayloadRecord) GetFile

func (r *PayloadRecord) GetFile() *File

func (*PayloadRecord) Read

func (p *PayloadRecord) Read(in io.ReadSeeker) error

func (*PayloadRecord) String

func (h *PayloadRecord) String() string

func (*PayloadRecord) Write

func (r *PayloadRecord) Write(w io.Writer) error

type Props

type Props struct {
	Offset uint32
	Size   uint32
}

type RawRecord

type RawRecord struct {
	File
}

func (*RawRecord) GetFile

func (r *RawRecord) GetFile() *File

func (*RawRecord) Read

func (r *RawRecord) Read(in io.ReadSeeker) error

func (*RawRecord) String

func (r *RawRecord) String() string

func (*RawRecord) Write

func (r *RawRecord) Write(w io.Writer) error

type ReadWriter

type ReadWriter interface {
	GetFile() *File
	String() string
	Read(r io.ReadSeeker) error
	Write(f io.Writer) error
}

Each CBFS file type must implement at least this interface.

func NewBootBlock

func NewBootBlock(f *File) (ReadWriter, error)

func NewBootSplash added in v1.1.0

func NewBootSplash(f *File) (ReadWriter, error)

NewBootSplash returns a ReadWriter interface for the CBFS type TypeBootSplash

func NewCMOS added in v1.1.0

func NewCMOS(f *File) (ReadWriter, error)

func NewCMOSLayout

func NewCMOSLayout(f *File) (ReadWriter, error)

func NewEmptyRecord

func NewEmptyRecord(f *File) (ReadWriter, error)

func NewFSP

func NewFSP(f *File) (ReadWriter, error)

NewFSP returns a ReadWriter interface for the CBFS type TypeFSP

func NewLegacyStageRecord

func NewLegacyStageRecord(f *File) (ReadWriter, error)

func NewMaster

func NewMaster(f *File) (ReadWriter, error)

func NewMicrocode

func NewMicrocode(f *File) (ReadWriter, error)

NewMicrocode returns a ReadWriter interface for the CBFS type TypeMicroCode

func NewOptionROM added in v1.1.0

func NewOptionROM(f *File) (ReadWriter, error)

func NewPayloadRecord

func NewPayloadRecord(f *File) (ReadWriter, error)

func NewRaw

func NewRaw(f *File) (ReadWriter, error)

func NewSPD

func NewSPD(f *File) (ReadWriter, error)

NewSPD returns a ReadWriter for the CBFS type TypeSPD

func NewStageRecord

func NewStageRecord(f *File) (ReadWriter, error)

func NewUnknownRecord added in v1.2.0

func NewUnknownRecord(f *File) (ReadWriter, error)

type SPDRecord

type SPDRecord struct {
	File
}

func (*SPDRecord) GetFile

func (r *SPDRecord) GetFile() *File

Header returns a pointer to the corresponding File

func (*SPDRecord) Read

func (r *SPDRecord) Read(in io.ReadSeeker) error

func (*SPDRecord) String

func (r *SPDRecord) String() string

func (*SPDRecord) Write

func (r *SPDRecord) Write(w io.Writer) error

type SegReader

type SegReader struct {
	Type FileType
	New  func(f *File) (ReadWriter, error)
	Name string
}

type SegmentType

type SegmentType uint32

fix this mess later to use characters, not constants. I had done this once and it never made it into coreboot and I still don't know why.

const (
	SegCode   SegmentType = 0x434F4445
	SegData   SegmentType = 0x44415441
	SegBSS    SegmentType = 0x42535320
	SegParams SegmentType = 0x50415241
	SegEntry  SegmentType = 0x454E5452
)

func (SegmentType) String

func (s SegmentType) String() string

type StageHeader

type StageHeader struct {
	Compression Compression
	Entry       uint64
	LoadAddress uint64
	Size        uint32
	MemSize     uint32
}

func (*StageHeader) String

func (h *StageHeader) String() string

type StageRecord

type StageRecord struct {
	File
	FileAttrStageHeader
	Data []byte
}

func (*StageRecord) GetFile

func (r *StageRecord) GetFile() *File

func (*StageRecord) Read

func (r *StageRecord) Read(in io.ReadSeeker) error

func (*StageRecord) String

func (h *StageRecord) String() string

func (*StageRecord) Write

func (r *StageRecord) Write(w io.Writer) error

type Tag

type Tag uint32
const (
	Unused     Tag = 0
	Unused2    Tag = 0xffffffff
	Compressed Tag = 0x42435a4c
	Hash       Tag = 0x68736148
	PSCB       Tag = 0x42435350
	ALCB       Tag = 0x42434c41
	SHCB       Tag = 0x53746748
)

type UnknownRecord added in v1.2.0

type UnknownRecord struct {
	File
}

func (*UnknownRecord) GetFile added in v1.2.0

func (r *UnknownRecord) GetFile() *File

func (*UnknownRecord) Read added in v1.2.0

func (r *UnknownRecord) Read(in io.ReadSeeker) error

func (*UnknownRecord) String added in v1.2.0

func (r *UnknownRecord) String() string

func (*UnknownRecord) Write added in v1.2.0

func (r *UnknownRecord) Write(w io.Writer) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL