uefi

package
v0.0.0-...-b79a0d8 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package uefi manipulates UEFI boot entries and other variables. It can also determine whether the system booted in UEFI mode or legacy.

Index

Constants

View Source
const (
	BootLabelFR    BootLabel = "Forced Factory Restore"
	BootLabelNorm            = "Normal Boot"
	BootLabelErase           = "Data Erase (DANGER!)"
)

Variables

View Source
var (
	Verbose bool

	EParse    = errors.New("parse error")
	ENotFound = errors.New("Described device not found")
	EUnimpl   = errors.New("Not implemented")
)

Functions

func AddBootEntry

func AddBootEntry(b BootEntry)

add a boot entry. efibootmgr sets it as primary

func BootEntryFilter

func BootEntryFilter(uuid, name string) bool

A VarNameFilter passing boot entries. These are a subset of the vars returned by BootVarFilter.

func BootVarFilter

func BootVarFilter(uuid, name string) bool

A VarNameFilter passing boot-related vars. These are a superset of those returned by BootEntryFilter.

func BootedUEFI

func BootedUEFI() bool

return true if the system booted via UEFI (as opposed to legacy)

func DriveIsBootable

func DriveIsBootable(mountpoint string) bool

Check if given drive contains /efi/boot/bootx64.efi (case insensitive). Does not try to determine if bootx64.efi is valid, if the firmware supports the filesystem type, etc.

func RemoveBootEntry

func RemoveBootEntry(num uint16) error

Types

type BootCurrentVar

type BootCurrentVar struct {
	EfiVar
	Current uint16
}

func ReadBootCurrent

func ReadBootCurrent() *BootCurrentVar

type BootEntry

type BootEntry struct {
	Device  string
	PartNum uint
	Label   BootLabel
	AbsPath string
	Args    string
	// contains filtered or unexported fields
}

type BootEntryVar

type BootEntryVar struct {
	Number uint16 //from the var name
	EfiLoadOption
}

A boot entry. Will have the name BootXXXX where XXXX is hexadecimal

func ReadBootVar

func ReadBootVar(num uint16) (b *BootEntryVar)

Gets BootXXXX var, if it exists

func ReadCurrentBootVar

func ReadCurrentBootVar() (b *BootEntryVar)

Reads BootCurrent, and from there gets the BootXXXX var referenced.

func (BootEntryVar) IsOurs

func (b BootEntryVar) IsOurs() bool

func (BootEntryVar) Remove

func (b BootEntryVar) Remove() error

func (BootEntryVar) String

func (b BootEntryVar) String() string

type BootEntryVars

type BootEntryVars []*BootEntryVar

func AllBootEntryVars

func AllBootEntryVars() BootEntryVars

returns list of boot entries (BootXXXX) note that BootCurrent, BootOptionSupport, BootNext, BootOrder, etc do not count as boot entries.

func (BootEntryVars) CheckMissing

func (entries BootEntryVars) CheckMissing() (haveNormal, haveFR, haveErase bool)

func (BootEntryVars) FixMissing

func (entries BootEntryVars) FixMissing(baseEntry BootEntry, extraOpts string)

func (BootEntryVars) Ours

func (entries BootEntryVars) Ours() (bootvars BootEntryVars)

filter list of boot entries to exclude entries we didn't create

func (BootEntryVars) OursPresent

func (entries BootEntryVars) OursPresent() bool

type BootLabel

type BootLabel string

type DppAcpiDevPath

type DppAcpiDevPath struct {
	Hdr      EfiDevicePathProtocolHdr
	HID, UID []byte //both length 4; not sure of endianness
}

func ParseDppAcpiDevPath

func ParseDppAcpiDevPath(h EfiDevicePathProtocolHdr, b []byte) (*DppAcpiDevPath, error)

func (*DppAcpiDevPath) Header

func (*DppAcpiDevPath) ProtoSubTypeStr

func (e *DppAcpiDevPath) ProtoSubTypeStr() string

func (*DppAcpiDevPath) Resolver

func (e *DppAcpiDevPath) Resolver() (EfiPathSegmentResolver, error)

func (*DppAcpiDevPath) String

func (e *DppAcpiDevPath) String() string

type DppAcpiExDevPath

type DppAcpiExDevPath struct {
	Hdr                    EfiDevicePathProtocolHdr
	HID, UID, CID          []byte //all length 4; not sure of endianness
	HIDSTR, UIDSTR, CIDSTR string
}

func ParseDppAcpiExDevPath

func ParseDppAcpiExDevPath(h EfiDevicePathProtocolHdr, b []byte) (*DppAcpiExDevPath, error)

func (*DppAcpiExDevPath) Header

func (*DppAcpiExDevPath) ProtoSubTypeStr

func (e *DppAcpiExDevPath) ProtoSubTypeStr() string

func (*DppAcpiExDevPath) Resolver

func (*DppAcpiExDevPath) String

func (e *DppAcpiExDevPath) String() string

type DppHwPci

type DppHwPci struct {
	Hdr              EfiDevicePathProtocolHdr
	Function, Device uint8
}

struct in EfiDevicePathProtocol for DppHTypePCI

func ParseDppHwPci

func ParseDppHwPci(h EfiDevicePathProtocolHdr, b []byte) (*DppHwPci, error)

func (*DppHwPci) Header

func (e *DppHwPci) Header() EfiDevicePathProtocolHdr

func (*DppHwPci) ProtoSubTypeStr

func (e *DppHwPci) ProtoSubTypeStr() string

func (*DppHwPci) Resolver

func (e *DppHwPci) Resolver() (EfiPathSegmentResolver, error)

func (*DppHwPci) String

func (e *DppHwPci) String() string

type DppMediaFilePath

type DppMediaFilePath struct {
	Hdr EfiDevicePathProtocolHdr

	PathNameDecoded string //stored as utf16
}

struct in EfiDevicePathProtocol for DppMTypeFilePath. if multiple are included in a load option, concatenate them.

func ParseDppMediaFilePath

func ParseDppMediaFilePath(h EfiDevicePathProtocolHdr, b []byte) (*DppMediaFilePath, error)

func (*DppMediaFilePath) Header

func (*DppMediaFilePath) ProtoSubTypeStr

func (e *DppMediaFilePath) ProtoSubTypeStr() string

func (*DppMediaFilePath) Resolver

func (*DppMediaFilePath) String

func (e *DppMediaFilePath) String() string

type DppMediaHDD

type DppMediaHDD struct {
	Hdr EfiDevicePathProtocolHdr

	PartNum   uint32         //index into partition table for MBR or GPT; 0 indicates entire disk
	PartStart uint64         //starting LBA. only used for MBR?
	PartSize  uint64         //size in LB's. only used for MBR?
	PartSig   guid.MixedGuid //format determined by SigType below. unused bytes must be 0x0.
	PartFmt   uint8          //0x01 for MBR, 0x02 for GPT
	SigType   uint8          //0x00 - none; 0x01 - 32bit MBR sig (@ 0x1b8); 0x02 - GUID
}

struct in EfiDevicePathProtocol for DppMTypeHdd

func ParseDppMediaHdd

func ParseDppMediaHdd(h EfiDevicePathProtocolHdr, b []byte) (*DppMediaHDD, error)

func (*DppMediaHDD) Header

func (*DppMediaHDD) ProtoSubTypeStr

func (e *DppMediaHDD) ProtoSubTypeStr() string

func (*DppMediaHDD) Resolver

func (e *DppMediaHDD) Resolver() (EfiPathSegmentResolver, error)

func (*DppMediaHDD) String

func (e *DppMediaHDD) String() string

type DppMediaPIWGFF

type DppMediaPIWGFF struct {
	Hdr EfiDevicePathProtocolHdr
	Ff  []byte
}

struct in EfiDevicePathProtocol for DppMTypePIWGFF

func ParseDppMediaPIWGFF

func ParseDppMediaPIWGFF(h EfiDevicePathProtocolHdr, b []byte) (*DppMediaPIWGFF, error)

func (*DppMediaPIWGFF) Header

func (*DppMediaPIWGFF) ProtoSubTypeStr

func (e *DppMediaPIWGFF) ProtoSubTypeStr() string

func (*DppMediaPIWGFF) Resolver

func (e *DppMediaPIWGFF) Resolver() (EfiPathSegmentResolver, error)

func (*DppMediaPIWGFF) String

func (e *DppMediaPIWGFF) String() string

type DppMediaPIWGFV

type DppMediaPIWGFV struct {
	Hdr EfiDevicePathProtocolHdr
	Fv  []byte
}

struct in EfiDevicePathProtocol for DppMTypePIWGFV

func ParseDppMediaPIWGFV

func ParseDppMediaPIWGFV(h EfiDevicePathProtocolHdr, b []byte) (*DppMediaPIWGFV, error)

func (*DppMediaPIWGFV) Header

func (*DppMediaPIWGFV) ProtoSubTypeStr

func (e *DppMediaPIWGFV) ProtoSubTypeStr() string

func (*DppMediaPIWGFV) Resolver

func (e *DppMediaPIWGFV) Resolver() (EfiPathSegmentResolver, error)

func (*DppMediaPIWGFV) String

func (e *DppMediaPIWGFV) String() string

type DppMsgATAPI

type DppMsgATAPI struct {
	Hdr             EfiDevicePathProtocolHdr
	Primary, Master bool
	LUN             uint16
}

pg 293

func ParseDppMsgATAPI

func ParseDppMsgATAPI(h EfiDevicePathProtocolHdr, b []byte) (*DppMsgATAPI, error)

func (*DppMsgATAPI) Header

func (*DppMsgATAPI) ProtoSubTypeStr

func (e *DppMsgATAPI) ProtoSubTypeStr() string

func (*DppMsgATAPI) Resolver

func (e *DppMsgATAPI) Resolver() (EfiPathSegmentResolver, error)

func (*DppMsgATAPI) String

func (e *DppMsgATAPI) String() string

type DppMsgMAC

type DppMsgMAC struct {
	Hdr    EfiDevicePathProtocolHdr
	Mac    [32]byte //0-padded
	IfType uint8    //RFC3232; seems ethernet is 6
}

pg 300

func ParseDppMsgMAC

func ParseDppMsgMAC(h EfiDevicePathProtocolHdr, b []byte) (*DppMsgMAC, error)

func (*DppMsgMAC) Header

func (e *DppMsgMAC) Header() EfiDevicePathProtocolHdr

func (*DppMsgMAC) ProtoSubTypeStr

func (e *DppMsgMAC) ProtoSubTypeStr() string

func (*DppMsgMAC) Resolver

func (e *DppMsgMAC) Resolver() (EfiPathSegmentResolver, error)

func (*DppMsgMAC) String

func (e *DppMsgMAC) String() string

type EfiDevPathEnd

type EfiDevPathEnd struct {
	Hdr EfiDevicePathProtocolHdr
}

marks end of EfiDevicePathProtocol

func (*EfiDevPathEnd) Header

func (*EfiDevPathEnd) ProtoSubTypeStr

func (e *EfiDevPathEnd) ProtoSubTypeStr() string

func (*EfiDevPathEnd) Resolver

func (e *EfiDevPathEnd) Resolver() (EfiPathSegmentResolver, error)

func (*EfiDevPathEnd) String

func (e *EfiDevPathEnd) String() string

type EfiDevPathProtoSubType

type EfiDevPathProtoSubType uint8

we only define media and end subtypes; others exist in spec

type EfiDevPathProtoType

type EfiDevPathProtoType uint8
const (
	DppTypeHw        EfiDevPathProtoType = iota + 1 //0x01, pg 288
	DppTypeACPI                                     //0x02, pg 290
	DppTypeMessaging                                //0x03, pg 293
	DppTypeMedia                                    //0x04, pg 319
	DppTypeBBS                                      //0x05, pg 287
	DppTypeEnd       EfiDevPathProtoType = 0x7f
)

func (EfiDevPathProtoType) String

func (e EfiDevPathProtoType) String() string

type EfiDevPathRaw

type EfiDevPathRaw struct {
	Hdr EfiDevicePathProtocolHdr
	Raw []byte
}

func (*EfiDevPathRaw) Header

func (*EfiDevPathRaw) ProtoSubTypeStr

func (e *EfiDevPathRaw) ProtoSubTypeStr() string

func (*EfiDevPathRaw) Resolver

func (e *EfiDevPathRaw) Resolver() (EfiPathSegmentResolver, error)

func (*EfiDevPathRaw) String

func (e *EfiDevPathRaw) String() string

type EfiDevicePathProtocol

type EfiDevicePathProtocol interface {
	Header() EfiDevicePathProtocolHdr

	//subtype as human readable
	ProtoSubTypeStr() string

	//path as human readable
	String() string

	//returns an EfiPathSegmentResolver; in the case of filesystems, this locates and mounts the device.
	Resolver() (EfiPathSegmentResolver, error)
}

An EfiDevicePathProtocol identifies a device path.

type EfiDevicePathProtocolHdr

type EfiDevicePathProtocolHdr struct {
	ProtoType    EfiDevPathProtoType
	ProtoSubType EfiDevPathProtoSubType
	Length       uint16
}

EfiDevicePathProtocolHdr - all variants start with the following three fields:

typedef struct _EFI_DEVICE_PATH_PROTOCOL {
    UINT8 Type;
    UINT8 SubType;
    UINT8 Length[2];
} EFI_DEVICE_PATH_PROTOCOL;

It seems that the only relevant Type (for booting) is media.

https://uefi.org/sites/default/files/resources/UEFI_Spec_2_8_A_Feb14.pdf pg 286 +

type EfiDevicePathProtocolList

type EfiDevicePathProtocolList []EfiDevicePathProtocol

func ParseFilePathList

func ParseFilePathList(in []byte) (EfiDevicePathProtocolList, error)

func (EfiDevicePathProtocolList) String

func (list EfiDevicePathProtocolList) String() string

type EfiDppACPISubType

type EfiDppACPISubType EfiDevPathProtoSubType
const (
	DppAcpiTypeDevPath EfiDppACPISubType = iota + 1
	DppAcpiTypeExpandedDevPath
	DppAcpiTypeADR
	DppAcpiTypeNVDIMM
)

func (EfiDppACPISubType) String

func (e EfiDppACPISubType) String() string

type EfiDppEndSubType

type EfiDppEndSubType EfiDevPathProtoSubType
const (
	//DppTypeEnd, pg 287-288
	DppETypeEndStartNew EfiDppEndSubType = 0x01 //only for DppTypeHw?
	DppETypeEndEntire   EfiDppEndSubType = 0xff
)

func (EfiDppEndSubType) String

func (e EfiDppEndSubType) String() string

type EfiDppHwSubType

type EfiDppHwSubType EfiDevPathProtoSubType
const (
	DppHTypePCI EfiDppHwSubType = iota + 1
	DppHTypePCCARD
	DppHTypeMMap
	DppHTypeVendor
	DppHTypeCtrl
	DppHTypeBMC
)

func (EfiDppHwSubType) String

func (s EfiDppHwSubType) String() string

type EfiDppMediaSubType

type EfiDppMediaSubType EfiDevPathProtoSubType
const (
	//DppTypeMedia, pg 319 +
	DppMTypeHdd      EfiDppMediaSubType = iota + 1 //0x01
	DppMTypeCd                                     //0x02
	DppMTypeVendor                                 //0x03
	DppMTypeFilePath                               //0x04 //p321
	DppMTypeMedia                                  //0x05 //media protocol i.e. filesystem format??
	DppMTypePIWGFF                                 //0x06
	DppMTypePIWGFV                                 //0x07
	DppMTypeRelOff                                 //0x08
	DppMTypeRAM                                    //0x09
)

func (EfiDppMediaSubType) String

func (e EfiDppMediaSubType) String() string

type EfiDppMsgSubType

type EfiDppMsgSubType EfiDevPathProtoSubType
const (
	DppMsgTypeATAPI    EfiDppMsgSubType = iota + 1
	DppMsgTypeSCSI                      //2
	DppMsgTypeFibreCh                   //3
	DppMsgTypeFirewire                  //4
	DppMsgTypeUSB                       //5
	DppMsgTypeIIO                       //6

	DppMsgTypeInfiniband //9
	DppMsgTypeVendor     //10 //uart flow control, sas are subtypes
	DppMsgTypeMAC        //11
	DppMsgTypeIP4        //12
	DppMsgTypeIP6        //13
	DppMsgTypeUART       //14
	DppMsgTypeUSBClass   //15
	DppMsgTypeUSBWWID    //16
	DppMsgTypeDevLU      //17
	DppMsgTypeSATA       //18
	DppMsgTypeISCSI      //19
	DppMsgTypeVLAN       //20

	DppMsgTypeSASEx  //22
	DppMsgTypeNVME   //23
	DppMsgTypeURI    //24
	DppMsgTypeUFS    //25
	DppMsgTypeSD     //26
	DppMsgTypeBT     //27
	DppMsgTypeWiFi   //28
	DppMsgTypeeMMC   //29
	DppMsgTypeBLE    //30
	DppMsgTypeDNS    //31
	DppMsgTypeNVDIMM //32
	DppMsgTypeRest   //documented as 32, likely 33
)

func (EfiDppMsgSubType) String

func (e EfiDppMsgSubType) String() string

type EfiLoadOption

type EfiLoadOption struct {
	Attributes         uint32
	FilePathListLength uint16
	Description        string
	FilePathList       EfiDevicePathProtocolList
	OptionalData       []byte
}
EfiLoadOption defines the data struct used for vars such as BootXXXX.

As defined in UEFI spec v2.8A:

typedef struct _EFI_LOAD_OPTION {
    UINT32 Attributes;
    UINT16 FilePathListLength;
    // CHAR16 Description[];
    // EFI_DEVICE_PATH_PROTOCOL FilePathList[];
    // UINT8 OptionalData[];
} EFI_LOAD_OPTION;

type EfiPathSegmentResolver

type EfiPathSegmentResolver interface {
	//Returns description, does not require cleanup
	String() string

	//Mount fs, etc. You must call Cleanup() eventually.
	Resolve(suggestedBasePath string) (string, error)

	//For devices, returns BlkInfo. Returns nil otherwise.
	BlockInfo() *block.BlkInfo

	//Unmount fs, free resources, etc
	Cleanup()
}

type EfiVar

type EfiVar struct {
	// contains filtered or unexported fields
}

a generic efi var

func ReadVar

func ReadVar(uuid, name string) (e EfiVar, err error)

func (EfiVar) BootVar

func (v EfiVar) BootVar() (b *BootEntryVar)

decodes an efivar as a boot entry. use IsBootEntry() to screen first.

func (EfiVar) IsBootEntry

func (e EfiVar) IsBootEntry() bool

type EfiVars

type EfiVars []EfiVar

func AllBootVars

func AllBootVars() EfiVars

Return all boot-related uefi vars

func AllVars

func AllVars() (vars EfiVars)

Returns all efi variables

func ReadVars

func ReadVars(filt VarFilter) (vars EfiVars)

Returns efi variables matching filter

func (EfiVars) BootCurrent

func (vars EfiVars) BootCurrent() *BootCurrentVar

returns the BootCurrent var

func (EfiVars) BootEntries

func (vars EfiVars) BootEntries() (bootvars BootEntryVars)

from a list of efi vars, parse any that are boot entries and return list of them

func (EfiVars) Filter

func (vars EfiVars) Filter(filt VarFilter) EfiVars

type HddResolver

type HddResolver struct {
	block.BlkInfo
	// contains filtered or unexported fields
}

func (*HddResolver) BlockInfo

func (e *HddResolver) BlockInfo() *block.BlkInfo

func (*HddResolver) Cleanup

func (r *HddResolver) Cleanup()

func (*HddResolver) Resolve

func (r *HddResolver) Resolve(basePath string) (string, error)

func (*HddResolver) String

func (r *HddResolver) String() string

type PathResolver

type PathResolver string

func (*PathResolver) BlockInfo

func (r *PathResolver) BlockInfo() *block.BlkInfo

func (*PathResolver) Cleanup

func (r *PathResolver) Cleanup()

func (*PathResolver) Resolve

func (r *PathResolver) Resolve(basePath string) (string, error)

func (*PathResolver) String

func (r *PathResolver) String() string

type VarFilter

type VarFilter func(uuid, name string) bool

A type of function used to filter efi vars

func AndFilter

func AndFilter(filters ...VarFilter) VarFilter

Returns true only if all given filters return true.

func NotFilter

func NotFilter(f VarFilter) VarFilter

Returns a filter negating the given filter.

Jump to

Keyboard shortcuts

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