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
- Variables
- func AddBootEntry(b BootEntry)
- func BootEntryFilter(uuid, name string) bool
- func BootVarFilter(uuid, name string) bool
- func BootedUEFI() bool
- func DecodeUTF16(b []byte) (string, error)
- func DriveIsBootable(mountpoint string) bool
- func RemoveBootEntry(num uint16) error
- type BootCurrentVar
- type BootEntry
- type BootEntryVar
- type BootEntryVars
- type BootLabel
- type DppAcpiDevPath
- type DppAcpiExDevPath
- type DppHwPci
- type DppMediaFilePath
- type DppMediaHDD
- type DppMediaPIWGFF
- type DppMediaPIWGFV
- type DppMsgATAPI
- type DppMsgMAC
- type EfiDevPathEnd
- type EfiDevPathProtoSubType
- type EfiDevPathProtoType
- type EfiDevPathRaw
- type EfiDevicePathProtocol
- type EfiDevicePathProtocolHdr
- type EfiDevicePathProtocolList
- type EfiDppACPISubType
- type EfiDppEndSubType
- type EfiDppHwSubType
- type EfiDppMediaSubType
- type EfiDppMsgSubType
- type EfiLoadOption
- type EfiPathSegmentResolver
- type EfiVar
- type EfiVars
- type HddResolver
- type PathResolver
- type VarFilter
Constants ¶
const ( BootLabelFR BootLabel = "Forced Factory Restore" BootLabelNorm = "Normal Boot" BootLabelErase = "Data Erase (DANGER!)" )
Variables ¶
Functions ¶
func BootEntryFilter ¶
A VarNameFilter passing boot entries. These are a subset of the vars returned by BootVarFilter.
func BootVarFilter ¶
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 DecodeUTF16 ¶
func DriveIsBootable ¶
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 ¶
Types ¶
type BootCurrentVar ¶
func ReadBootCurrent ¶
func ReadBootCurrent() *BootCurrentVar
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 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 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 (e *DppAcpiDevPath) Header() EfiDevicePathProtocolHdr
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 (e *DppAcpiExDevPath) Header() EfiDevicePathProtocolHdr
func (*DppAcpiExDevPath) ProtoSubTypeStr ¶
func (e *DppAcpiExDevPath) ProtoSubTypeStr() string
func (*DppAcpiExDevPath) Resolver ¶
func (e *DppAcpiExDevPath) Resolver() (EfiPathSegmentResolver, error)
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 (*DppHwPci) Resolver ¶
func (e *DppHwPci) Resolver() (EfiPathSegmentResolver, error)
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 (e *DppMediaFilePath) Header() EfiDevicePathProtocolHdr
func (*DppMediaFilePath) ProtoSubTypeStr ¶
func (e *DppMediaFilePath) ProtoSubTypeStr() string
func (*DppMediaFilePath) Resolver ¶
func (e *DppMediaFilePath) Resolver() (EfiPathSegmentResolver, error)
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 (e *DppMediaHDD) Header() EfiDevicePathProtocolHdr
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 (e *DppMediaPIWGFF) Header() EfiDevicePathProtocolHdr
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 (e *DppMediaPIWGFV) Header() EfiDevicePathProtocolHdr
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 (e *DppMsgATAPI) Header() EfiDevicePathProtocolHdr
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 (*DppMsgMAC) Resolver ¶
func (e *DppMsgMAC) Resolver() (EfiPathSegmentResolver, error)
type EfiDevPathEnd ¶
type EfiDevPathEnd struct {
Hdr EfiDevicePathProtocolHdr
}
marks end of EfiDevicePathProtocol
func (*EfiDevPathEnd) Header ¶
func (e *EfiDevPathEnd) Header() EfiDevicePathProtocolHdr
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 (e *EfiDevPathRaw) Header() EfiDevicePathProtocolHdr
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 (EfiVar) BootVar ¶
func (v EfiVar) BootVar() (b *BootEntryVar)
decodes an efivar as a boot entry. use IsBootEntry() to screen first.
func (EfiVar) IsBootEntry ¶
type EfiVars ¶
type EfiVars []EfiVar
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
type HddResolver ¶
func (*HddResolver) BlockInfo ¶
func (e *HddResolver) BlockInfo() *block.BlkInfo
func (*HddResolver) Cleanup ¶
func (r *HddResolver) Cleanup()
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) String ¶
func (r *PathResolver) String() string