universalpayload

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Overview

Package universalpayload supports to load FIT (Flat Image Tree) image. FIT is a common Payload image format to facilitate the loading process, and defined in UniversalPayload Specification. More Details about UniversalPayload Specification, please refer: https://github.com/universalpayload/spec

Index

Constants

View Source
const (
	EFIHOBHandoffInfoVersion          EFIHOBHandoffInfoVersionType = 0x09
	EFIHOBHandoffInfoBootMode         EFIHOBHandOffBootModeType    = 0x0
	EFIHOBHandoffInfoEFIMemoryTop     EFIPhysicalAddress           = 0x4E00000
	EFIHOBHandoffInfoEFIMemoryBottom  EFIPhysicalAddress           = 0x800000
	EFIHOBHandoffInfoFreeEFIMemoryTop EFIPhysicalAddress           = 0x4E00000
	EFIHOBHandoffInfoFreeMemoryBottom EFIPhysicalAddress           = 0xE00000
)

EFIHOBHandoffInfoTable values

View Source
const (
	UniversalPayloadSerialPortInfoGUID       = "0d197eaa-21be-0944-8e67-a2cd0f61e170"
	UniversalPayloadSerialPortInfoRevision   = 1
	UniversalPayloadSerialPortRegisterStride = 1
	UniversalPayloadSerialPortBaudRate       = 115200
	UniversalPayloadSerialPortRegisterBase   = 0x3f8
)
View Source
const (
	UniversalPayloadAcpiTableGUID     = "06959a9f-9755-1545-bab6-8bcde784ba87"
	UniversalPayloadAcpiTableRevision = 1
)
View Source
const (
	UniversalPayloadSmbiosTableGUID     = "260d0a59-e506-204d-8a82-59ea1b34982d"
	UniversalPayloadSmbiosTableRevision = 1
)
View Source
const (
	FirstLevelNodeName     = "images"
	SecondLevelNodeName    = "tianocore"
	LoadAddrPropertyName   = "load"
	EntryAddrPropertyName  = "entry-start"
	DataOffsetPropertyName = "data-offset"
	DataSizePropertyName   = "data-size"
)

Properties to be fetched from device tree.

View Source
const (
	// Relocation Types
	IMAGE_REL_BASED_ABSOLUTE = 0
	IMAGE_REL_BASED_HIGHLOW  = 3
	IMAGE_REL_BASED_DIR64    = 10
)
View Source
const (
	FbIotclVscreeninfo    = 0x4600
	FbIoctlGetFscreenInfo = 0x4602
)

Definitions for ioctl and framebuffer structures in Go

View Source
const (
	ACPIMCFGSysFilePath                 = "/sys/firmware/acpi/tables/MCFG"
	ACPIMCFGPciSegInfoStructureSize     = 0xC
	ACPIMCFGPciSegInfoDataLength        = 0xA
	ACPIMCFGBaseAddressAllocationLenth  = 0x10
	ACPIMCFGBaseAddressAllocationOffset = 0x2c
	ACPIMCFGSignature                   = "MCFG"
)
View Source
const (
	PCISearchPath   = "/sys/devices/"
	PCIMMIO64Attr   = 0x140204
	PCIMMIO32Attr   = 0x40200
	PCIIOPortAttr   = 0x40100
	PCIIOPortRes    = 0x100
	PCIMMIOReadOnly = 0x4000
	PCIMMIO64Type   = "MMIO64"
	PCIMMIO32Type   = "MMIO32"
	PCIIOPortType   = "IOPORT"

	PCIInvalidBase = 0xFFFF_FFFF_FFFF_FFFF
)
View Source
const (
	DefaultIOAddressSize uint8 = 16
)

Common Constants According to Intel SDM Volume 1 Chapter 19.3 "I/O ADDRESS SPACE": The I/O address space consists of 2^16 (64K) individually addressable 8-bit I/O ports, numbered 0 through FFFFH. Set the default IO Address size to 16

View Source
const (
	UniversalPayloadBaseGUID = "1dc6d403-1327-c54e-a1cc-883be9dc18e5"
)

Variables

View Source
var (
	ErrParseGUIDFail                   = errors.New("failed to parse GUID")
	ErrFailToGetSmbiosTable            = errors.New("failed to get smbios base")
	ErrWriteHOBBufMemoryMap            = errors.New("failed to write memory map to buffer")
	ErrWriteHOBBufSerialPort           = errors.New("failed to append serial port hob to buffer")
	ErrWriteHOBBufUniversalPayloadBase = errors.New("failed to append universal payload base to buffer")
	ErrWriteHOBBufAcpiTable            = errors.New("failed to append acpi table to buffer")
	ErrWriteHOBSmbiosTable             = errors.New("failed to append smbios table to buffer")
	ErrWriteHOBEFICPU                  = errors.New("failed to append CPU HOB to buffer")
	ErrWriteHOBBufList                 = errors.New("failed to append HOB list to buffer")
	ErrWriteHOBLengthNotMatch          = errors.New("length mismatch when appending")
	ErrKexecLoadFailed                 = errors.New("kexec.Load() failed")
	ErrKexecExecuteFailed              = errors.New("kexec.Execute() failed")
	ErrMemMapIoMemExecuteFailed        = errors.New("failed to get memory from /proc/iomem")
	ErrComponentsSizeOverflow          = errors.New("reserved components size overflow")
)
View Source
var (
	ErrFailToReadFdtFile           = errors.New("failed to read fdt file")
	ErrNodeImagesNotFound          = fmt.Errorf("failed to find '%s' node", FirstLevelNodeName)
	ErrNodeTianocoreNotFound       = fmt.Errorf("failed to find '%s' node", SecondLevelNodeName)
	ErrNodeLoadNotFound            = fmt.Errorf("failed to find get '%s' property", LoadAddrPropertyName)
	ErrNodeEntryStartNotFound      = fmt.Errorf("failed to find get '%s' property", EntryAddrPropertyName)
	ErrNodeDataOffsetNotFound      = fmt.Errorf("failed to find get '%s' property", DataOffsetPropertyName)
	ErrNodeDataSizeNotFound        = fmt.Errorf("failed to find get '%s' property", DataSizePropertyName)
	ErrFailToConvertLoad           = fmt.Errorf("failed to convert property '%s' to u64", LoadAddrPropertyName)
	ErrFailToConvertEntryStart     = fmt.Errorf("failed to convert property '%s' to u64", EntryAddrPropertyName)
	ErrFailToConvertDataOffset     = fmt.Errorf("failed to convert property '%s' to u32", DataOffsetPropertyName)
	ErrFailToConvertDataSize       = fmt.Errorf("failed to convert property '%s' to u32", DataSizePropertyName)
	ErrPeFailToGetPageRVA          = fmt.Errorf("failed to read pagerva during pe file relocation")
	ErrPeFailToGetBlockSize        = fmt.Errorf("failed to read block size during pe file relocation")
	ErrPeFailToGetEntry            = fmt.Errorf("failed to get entry during pe file relocation")
	ErrPeFailToCreatePeFile        = fmt.Errorf("failed to create pe file")
	ErrPeFailToGetRelocData        = fmt.Errorf("failed to get .reloc section data")
	ErrPeUnsupportedPeHeader       = fmt.Errorf("unsupported pe header format")
	ErrPeRelocOutOfBound           = fmt.Errorf("relocation address out of bounds during pe file relocation")
	ErrFBOpenFileFailed            = fmt.Errorf("failed opening framebuffer device")
	ErrFBGetVscreenInfoFailed      = fmt.Errorf("error getting variable screen info")
	ErrFBGetFscreenInfoFailed      = fmt.Errorf("error getting fixed screen info")
	ErrFBGetDevResrouceFailed      = fmt.Errorf("failed to get framebuffer mmio resource")
	ErrGfxOpenFileFailed           = fmt.Errorf("failed opening graphic device")
	ErrGfxReadVendorIDFailed       = fmt.Errorf("failed to read vendor id")
	ErrGfxReadDeviceIDFailed       = fmt.Errorf("failed to device vendor id")
	ErrGfxReadRevisionIDFailed     = fmt.Errorf("failed to revision vendor id")
	ErrGfxReadSubSysVendorIDFailed = fmt.Errorf("failed to read subsystem vendor id")
	ErrGfxReadSubSysDeviceIDFailed = fmt.Errorf("failed to read subsystem device id")
	ErrGfxNoDeviceInfoFound        = fmt.Errorf("no graphic device info found")
	ErrSMBIOS3NotFound             = fmt.Errorf("no smbios3 region found")
	ErrDTRsdpLenOverBound          = fmt.Errorf("rsdp table length too large")
	ErrDTRsdpTableNotFound         = fmt.Errorf("no acpi rsdp table found")
	ErrRsvdMemoryMapNotFound       = fmt.Errorf("failed to retrieve reserved memory map")
	ErrAlignPadRange               = errors.New("failed to align pad size, out of range")
	ErrCPUAddressConvert           = errors.New("failed to convert physical bits size")
	ErrCPUAddressRead              = errors.New("failed to read 'address sizes'")
	ErrCPUAddressNotFound          = errors.New("'address sizes' information not found")
	ErrMcfgDataLenthTooShort       = errors.New("acpi mcfg data lenth too short")
	ErrMcfgSignatureMismatch       = errors.New("acpi mcfg signature mismatch")
	ErrMcfgBaseAddrAllocCorrupt    = errors.New("acpi mcfg base address allocation data corrupt")
	ErrMcfgBaseAddrAllocDecode     = errors.New("failed to decode mcfg base address allocation structure")
)

Errors returned by utilities

Functions

func Exec

func Exec() error

func GetDisplayDeviceInfo

func GetDisplayDeviceInfo() ([]map[string]string, error)

GetDisplayDeviceInfo retrieves information about the display device from sysfs

func Load

func Load(name string, dbg func(string, ...interface{})) (error, error)

Types

type EFIHOBCPU

type EFIHOBCPU struct {
	Header            EFIHOBGenericHeader
	SizeOfMemorySpace uint8
	SizeOfIOSpace     uint8
	Reserved          [6]byte
}

EFIHOBCPU describes CPU information

type EFIHOBFirmwareVolume

type EFIHOBFirmwareVolume struct {
	Header      EFIHOBGenericHeader
	BaseAddress EFIPhysicalAddress
	Length      uint64
}

EFIHOBFirmwareVolume describes the location of firmware locations

type EFIHOBGUIDType

type EFIHOBGUIDType struct {
	Header EFIHOBGenericHeader
	Name   guid.UUID
}

EFIHOBGUIDType describes the extension information which allows writing executable content in the HOB producer phase.

type EFIHOBGenericHeader

type EFIHOBGenericHeader struct {
	HOBType   EFIHOBType
	HOBLength EFIHOBLength
	Reserved  EFIHOBReserved
}

EFIHOBGenericHeader describes the format and size of the data inside the HOB

type EFIHOBHandOffBootModeType

type EFIHOBHandOffBootModeType uint32

type EFIHOBHandoffInfoTable

type EFIHOBHandoffInfoTable struct {
	Header           EFIHOBGenericHeader
	Version          EFIHOBHandoffInfoVersionType
	BootMode         EFIHOBHandOffBootModeType
	MemoryTop        EFIPhysicalAddress
	MemoryBottom     EFIPhysicalAddress
	FreeMemoryTop    EFIPhysicalAddress
	FreeMemoryBottom EFIPhysicalAddress
	EndOfHOBList     EFIPhysicalAddress
}

EFIHOBHandoffInfoTable appears in the first in HOB list, which contains some general information

type EFIHOBHandoffInfoVersionType

type EFIHOBHandoffInfoVersionType uint32

type EFIHOBLength

type EFIHOBLength uint16

EFIHOBGenericHeader types

type EFIHOBReserved

type EFIHOBReserved uint32

EFIHOBGenericHeader types

type EFIHOBResourceDescriptor

type EFIHOBResourceDescriptor struct {
	Header            EFIHOBGenericHeader
	Owner             guid.UUID // EFI GUID (assuming a byte array for simplicity)
	ResourceType      EFIResourceType
	ResourceAttribute EFIResourceAttributeType
	PhysicalStart     EFIPhysicalAddress
	ResourceLength    uint64
}

EFIHOBResourceDescriptor describes all resource properties found on the processor host bus

type EFIHOBType

type EFIHOBType uint16

EFIHOBGenericHeader types

const (
	EFIHOBTypeHandoff            EFIHOBType = 0x0001
	EFIHOBTypeMemoryAllocation   EFIHOBType = 0x0002
	EFIHOBTypeResourceDescriptor EFIHOBType = 0x0003
	EFIHOBTypeGUIDExtension      EFIHOBType = 0x0004
	EFIHOBTypeFv                 EFIHOBType = 0x0005
	EFIHOBTypeCPU                EFIHOBType = 0x0006
	EFIHOBTypeMemoryPool         EFIHOBType = 0x0007
	EFIHOBTypeFv2                EFIHOBType = 0x0009
	EFIHOBTypeLoadPeimUnused     EFIHOBType = 0x000A
	EFIHOBTypeUEFICapsule        EFIHOBType = 0x000B
	EFIHOBTypeFv3                EFIHOBType = 0x000C
	EFIHOBTypeUnused             EFIHOBType = 0xFFFE
	EFIHOBTypeEndOfHOBList       EFIHOBType = 0xFFFF
)

EFIHOBType values

type EFIMemoryMapHOB

type EFIMemoryMapHOB []EFIHOBResourceDescriptor

type EFIPhysicalAddress

type EFIPhysicalAddress uint64

type EFIResourceAttributeType

type EFIResourceAttributeType uint32
const (
	EFIResourceAttributePresent               EFIResourceAttributeType = 0x00000001
	EFIResourceAttributeInitialized           EFIResourceAttributeType = 0x00000002
	EFIResourceAttributeTested                EFIResourceAttributeType = 0x00000004
	EFIResourceAttributeReadProtected         EFIResourceAttributeType = 0x00000080
	EFIResourceAttributeWriteProtected        EFIResourceAttributeType = 0x00000100
	EFIResourceAttributeExecutionProtected    EFIResourceAttributeType = 0x00000200
	EFIResourceAttributePersistent            EFIResourceAttributeType = 0x00800000
	EFIResourceAttributeSingleBitECC          EFIResourceAttributeType = 0x00000008
	EFIResourceAttributeMultipleBitECC        EFIResourceAttributeType = 0x00000010
	EFIResourceAttributeECCReserved1          EFIResourceAttributeType = 0x00000020
	EFIResourceAttributeECCReserved2          EFIResourceAttributeType = 0x00000040
	EFIResourceAttributeUncacheable           EFIResourceAttributeType = 0x00000400
	EFIResourceAttributeWriteCombineable      EFIResourceAttributeType = 0x00000800
	EFIResourceAttributeWriteThroughCacheable EFIResourceAttributeType = 0x00001000
	EFIResourceAttributeWriteBackCacheable    EFIResourceAttributeType = 0x00002000
	EFIResourceAttribute16BitIO               EFIResourceAttributeType = 0x00004000
	EFIResourceAttribute32BitIO               EFIResourceAttributeType = 0x00008000
	EFIResourceAttribute64BitIO               EFIResourceAttributeType = 0x00010000
	EFIResourceAttributeUncachedExported      EFIResourceAttributeType = 0x00020000
	EFIResourceAttributeReadProtectable       EFIResourceAttributeType = 0x00100000
	EFIResourceAttributeWriteProtectable      EFIResourceAttributeType = 0x00200000
	EFIResourceAttributeExecutionProtectable  EFIResourceAttributeType = 0x00400000
	EFIResourceAttributePersistable           EFIResourceAttributeType = 0x01000000
	EFIResourceAttributeReadOnlyProtected     EFIResourceAttributeType = 0x00040000
	EFIResourceAttributeReadOnlyProtectable   EFIResourceAttributeType = 0x00080000
	EFIResourceAttributeEncrypted             EFIResourceAttributeType = 0x04000000
	EFIResourceAttributeSpecialPurpose        EFIResourceAttributeType = 0x08000000
	EFIResourceAttributeMoreReliable          EFIResourceAttributeType = 0x02000000
)

EFIResourceAttributeType values

type EFIResourceType

type EFIResourceType uint32
const (
	EFIResourceSystemMemory       EFIResourceType = 0x00000000
	EFIResourceMemoryMappedIO     EFIResourceType = 0x00000001
	EFIResourceIO                 EFIResourceType = 0x00000002
	EFIResourceEFIFirmwareDevice  EFIResourceType = 0x00000003
	EFIResourceMemoryMappedIOPort EFIResourceType = 0x00000004
	EFIResourceMemoryReserved     EFIResourceType = 0x00000005
	EFIResourceIOReserved         EFIResourceType = 0x00000006
	EFIResourceMemoryUnaccepted   EFIResourceType = 0x00000007
	EFIResourceMaxMemoryType      EFIResourceType = 0x00000008
	EFIResourceUnimplemented      EFIResourceType = 0x00000008
)

EFIResourceType values

type FbBitfield

type FbBitfield struct {
	Offset   uint32 // beginning of bitfield
	Length   uint32 // length of bitfield
	MsbRight uint32 // != 0 : Most significant bit is right
}

type FbFixScreenInfo

type FbFixScreenInfo struct {
	ID           [16]byte
	SmemStart    uint64
	SmemLen      uint32
	Type         uint32
	TypeAux      uint32
	Visual       uint32
	Xpanstep     uint16
	Ypanstep     uint16
	Ywrapstep    uint16
	LineLength   uint32
	MmioStart    uint64
	MmioLen      uint32
	Accel        uint32
	Capabilities uint16
	Reserved     [2]uint16
}

type FbVarScreenInfo

type FbVarScreenInfo struct {
	Xres         uint32
	Yres         uint32
	XresVirtual  uint32
	YresVirtual  uint32
	Xoffset      uint32
	Yoffset      uint32
	BitsPerPixel uint32
	Grayscale    uint32
	Red          FbBitfield
	Green        FbBitfield
	Blue         FbBitfield
	Transp       FbBitfield
	Nonstd       uint32
	Activate     uint32
	Height       uint32
	Width        uint32
	AccelFlags   uint32
	PixClock     uint32
	LeftMargin   uint32
	RightMargin  uint32
	UpperMargin  uint32
	LowerMargin  uint32
	HsyncLen     uint32
	VsyncLen     uint32
	Sync         uint32
	Vmode        uint32
	Rotate       uint32
	Colorspace   uint32
	Reserved     [4]uint32
}

type FdtLoad

type FdtLoad struct {
	Load       uint64
	EntryStart uint64
	DataOffset uint32
	DataSize   uint32
}

func GetFdtInfo

func GetFdtInfo(name string) (*FdtLoad, error)

GetFdtInfo Device Tree Blob resides at the start of FIT binary. In order to get the expected load and entry point address, need to walk through DTB to get value of properties 'load' and 'entry-start'.

The simplified device tree layout is:

/{
    images {
        tianocore {
            data-offset = <0x00001000>;
            data-size = <0x00010000>;
            entry-start = <0x00000000 0x00805ac3>;
            load = <0x00000000 0x00800000>;
        }
    }
 }

type MCFGBaseAddressAllocation

type MCFGBaseAddressAllocation struct {
	BaseAddr  EFIPhysicalAddress
	PCISegGrp uint16
	StartBus  uint8
	EndBus    uint8
	Reserved  uint32
}

type ResourceInfo

type ResourceInfo struct {
	Type        string
	BaseAddress string
	EndAddress  string
	Attributes  string
}

type ResourceRegions

type ResourceRegions struct {
	MMIO64Base uint64
	MMIO64End  uint64
	MMIO32Base uint64
	MMIO32End  uint64
	IOPortBase uint64
	IOPortEnd  uint64
	StartBus   uint32
	EndBus     uint32
}

type UniversalPayloadAcpiTable

type UniversalPayloadAcpiTable struct {
	Header UniversalPayloadGenericHeader
	Rsdp   EFIPhysicalAddress
}

type UniversalPayloadBase

type UniversalPayloadBase struct {
	Header UniversalPayloadGenericHeader
	Pad    [4]byte
	Entry  EFIPhysicalAddress
}

Structure member 'Pad' is introduced to match the offset of 'Entry' in structure UNIVERSAL_PAYLOAD_BASE which is defined in EDK2 UPL.

type UniversalPayloadGenericHeader

type UniversalPayloadGenericHeader struct {
	Revision uint8
	Reserved uint8
	Length   uint16
}

type UniversalPayloadSerialPortInfo

type UniversalPayloadSerialPortInfo struct {
	Header         UniversalPayloadGenericHeader
	UseMmio        uint8
	RegisterStride uint8
	BaudRate       uint32
	RegisterBase   EFIPhysicalAddress
}

type UniversalPayloadSmbiosTable

type UniversalPayloadSmbiosTable struct {
	Header           UniversalPayloadGenericHeader
	SmBiosEntryPoint EFIPhysicalAddress
}

Jump to

Keyboard shortcuts

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