Skip to content

Device path

device_path

This is a python implementation of the UEFI Specification Device Paths

C Implementations may be found here: https://github.com/tianocore/edk2/blob/00ccd99d46068c87e73e8e521afea09e19419885/MdePkg/Include/Protocol/DevicePath.h

DevicePathHeader dataclass

DevicePathHeader class represents the header of a device path in UEFI.

Attributes:

Name Type Description
dev_type int

The type of the device path.

dev_subtype int

The subtype of the device path.

dev_length int

The length of the device path.

dev_data bytes

The data associated with the device path.

EfiDevicePathProtocol

Represents the EFI Device Path Protocol, which is used to describe the location of a device in the system.

Attributes:

Name Type Description
dev_type int

The type of the device path.

dev_subtype int

The subtype of the device path.

dev_length int

The length of the device path.

dev_data bytes

The data associated with the device path.

__init__

__init__(header: DevicePathHeader)

Initializes a DevicePath object with the given header. Args: header (DevicePathHeader): The header containing device path information.

decode staticmethod

decode(binary) -> DevicePathHeader

Decodes a binary representation of an EFI device path.

Parameters:

Name Type Description Default
binary bytes

The binary data representing the EFI device path.

required

Returns:

Name Type Description
DevicePathHeader DevicePathHeader

An object containing the type, subtype, length, and data of the device path.

UnimplementedDevicePath

UnimplementedDevicePath class represents a device path node that is not implemented. This class inherits from EfiDevicePathProtocol and provides a way to handle unimplemented device path nodes by storing the header and providing a dictionary representation of the device path type and subtype.

Attributes:

Name Type Description
header DevicePathHeader

The header of the device path node.

__init__

__init__(header: DevicePathHeader)

Initializes the UnimplementedDevicePath instance with the given header.

Parameters:

Name Type Description Default
header DevicePathHeader

The header containing device path information.

required

from_binary classmethod

from_binary(
    header: DevicePathHeader,
) -> UnimplementedDevicePath

Creates an UnimplementedDevicePath instance from a binary representation.

Parameters:

Name Type Description Default
header DevicePathHeader

The header containing device path information.

required

Returns:

Name Type Description
UnimplementedDevicePath UnimplementedDevicePath

An instance of UnimplementedDevicePath.

PciDevicePath

Represents a PCI Device Path in the UEFI (Unified Extensible Firmware Interface) environment.

Attributes:

Name Type Description
header EfiDevicePathProtocol

The header of the device path.

function int

The function number of the PCI device.

device int

The device number of the PCI device.

__init__

__init__(header, function, device)

Initializes the PciDevicePath instance with the given header, function, and device.

Parameters:

Name Type Description Default
header EfiDevicePathProtocol

The header containing device path information.

required
function int

The function number of the PCI device.

required
device int

The device number of the PCI device.

required

PccardDevicePath

Represents a PC Card device path in the UEFI environment.

Attributes:

Name Type Description
function_number UINT8

The function number of the PC Card device.

__init__

__init__(header: DevicePathHeader, function_number: UINT8)

Initializes the PccardDevicePath instance with the given header and function number.

Args:
    header (DevicePathHeader): The header containing device path information.
    function_number (UINT8): The function number of the PC Card device.

AcpiHidDevicePath

Represents an ACPI HID Device Path in the UEFI device path protocol.

Attributes:

Name Type Description
header EfiDevicePathProtocol

The EFI device path protocol header.

hid int

Device's PnP hardware ID stored in a numeric 32-bit compressed EISA-type ID. This value must match the corresponding _HID in the ACPI name space.

uid int

Unique ID required by ACPI if two devices have the same _HID. This value must also match the corresponding _UID/_HID pair in the ACPI name space. Only the 32-bit numeric value type of _UID is supported.

__init__

__init__(header: EfiDevicePathProtocol, hid, uid)

Initializes the AcpiHidDevicePath instance with the given header, HID, and UID.

Parameters:

Name Type Description Default
header EfiDevicePathProtocol

The header containing device path information.

required
hid int

Device's PnP hardware ID stored in a numeric 32-bit compressed EISA-type ID.

required
uid int

Unique ID required by ACPI if two devices have the same _HID.

required

UsbDevicePath

Represents a USB Device Path in the UEFI (Unified Extensible Firmware Interface) environment.

Attributes:

Name Type Description
header EfiDevicePathProtocol

The header of the device path.

parent_port_number int

The USB Parent Port Number.

interface_number int

The USB Interface Number.

__init__

__init__(header, parent_port_number, interface_number)

Initializes the UsbDevicePath instance with the given header, parent port number, and interface number.

Parameters:

Name Type Description Default
header EfiDevicePathProtocol

The header containing device path information.

required
parent_port_number int

The USB Parent Port Number.

required
interface_number int

The USB Interface Number.

required

EfiMacAddress

Represents a MAC address in the UEFI (Unified Extensible Firmware Interface) environment.

Attributes:

Name Type Description
addr list

The MAC address for a network interface padded with 0s.

MacAddrDevicePath

Represents a MAC Address Device Path in the UEFI (Unified Extensible Firmware Interface) environment.

Attributes:

Name Type Description
header EfiDevicePathProtocol

The header of the device path.

mac_address EfiMacAddress

The MAC address for a network interface padded with 0s.

if_type int

The network interface type (i.e., 802.3, FDDI).

EfiIpv4Address

Represents an IPv4 address in the UEFI (Unified Extensible Firmware Interface) environment.

Attributes:

Name Type Description
addr list

The IPv4 address.

__init__

__init__(addr)

Initializes the EfiIpv4Address instance with the given address.

Parameters:

Name Type Description Default
addr list

The IPv4 address.

required

Ipv4DevicePath

Represents an IPv4 Device Path in the UEFI (Unified Extensible Firmware Interface) environment.

Attributes:

Name Type Description
header EfiDevicePathProtocol

The header of the device path.

local_ip_address EfiIpv4Address

The local IPv4 address.

remote_ip_address EfiIpv4Address

The remote IPv4 address.

local_port int

The local port number.

remote_port int

The remote port number.

protocol int

The network protocol (i.e., UDP, TCP).

static_ip_address bool

Indicates if the source IP address is statically bound.

gateway_ip_address EfiIpv4Address

The gateway IP address.

subnet_mask EfiIpv4Address

The subnet mask.

__init__

__init__(
    header,
    local_ip_address,
    remote_ip_address,
    local_port,
    remote_port,
    protocol,
    static_ip_address,
    gateway_ip_address,
    subnet_mask,
)

Initializes the Ipv4DevicePath instance with the given header, local IP address, remote IP address, local port, remote port, protocol, static IP address, gateway IP address, and subnet mask.

Parameters:

Name Type Description Default
header DevicePathHeader

The header containing device path information.

required
local_ip_address EfiIpv4Address

The local IPv4 address.

required
remote_ip_address EfiIpv4Address

The remote IPv4 address.

required
local_port int

The local port number.

required
remote_port int

The remote port number.

required
protocol int

The network protocol (i.e., UDP, TCP).

required
static_ip_address bool

Indicates if the source IP address is statically bound.

required
gateway_ip_address EfiIpv4Address

The gateway IP address.

required
subnet_mask EfiIpv4Address

The subnet mask.

required

SataDevicePath

Represents a SATA Device Path.

Attributes:

Name Type Description
hba_port_number int

The HBA port number that facilitates the connection.

port_multiplier_port_number int

The port multiplier port number.

lun int

Logical Unit Number.

__init__

__init__(
    header,
    hba_port_number,
    port_multiplier_port_number,
    lun,
)

Initializes the SataDevicePath instance with the given header, HBA port number, port multiplier port number, and LUN.

Parameters:

Name Type Description Default
header DevicePathHeader

The header containing device path information.

required
hba_port_number int

The HBA port number that facilitates the connection.

required
port_multiplier_port_number int

The port multiplier port number.

required
lun int

Logical Unit Number.

required

NvmeOfNamespaceDevicePath

Represents an NVMe over Fabrics (NVMe-oF) Namespace Device Path.

Attributes:

Name Type Description
namespace_id_type int

The type of the namespace identifier.

namespace_id bytes

The namespace identifier.

subsystem_nqn str

The NVMe Qualified Name (NQN) of the subsystem.

__init__

__init__(
    header, namespace_id_type, namespace_id, subsystem_nqn
)

Initializes the NvmeOfNamespaceDevicePath instance with the given header, namespace ID type, namespace ID, and subsystem NQN.

Parameters:

Name Type Description Default
header DevicePathHeader

The header containing device path information.

required
namespace_id_type int

The type of the namespace identifier.

required
namespace_id bytes

The namespace identifier.

required
subsystem_nqn str

The NVMe Qualified Name (NQN) of the subsystem.

required

HardDriveDevicePath

Represents a hard drive device path in the UEFI (Unified Extensible Firmware Interface) specification.

Attributes:

Name Type Description
partition_number int

The partition number on the hard drive.

partition_start int

The starting LBA (Logical Block Addressing) of the partition.

partition_size int

The size of the partition in blocks.

signature bytes

The unique signature of the partition.

MBR_type int

The type of MBR (Master Boot Record).

signature_type int

The type of signature used.

__init__

__init__(
    header: DevicePathHeader,
    partition_number: int,
    partition_start: int,
    partition_size: int,
    signature: bytes,
    MBR_type: int,
    signature_type: int,
)

Initializes the HardDriveDevicePath instance with the given header, partition number, partition start, partition size, signature, MBR type, and signature type.

Parameters:

Name Type Description Default
header DevicePathHeader

The header containing device path information.

required
partition_number int

The partition number on the hard drive.

required
partition_start int

The starting LBA of the partition.

required
partition_size int

The size of the partition in blocks.

required
signature bytes

The unique signature of the partition.

required
MBR_type int

The type of MBR.

required
signature_type int

The type of signature used.

required

from_binary classmethod

from_binary(
    header: EfiDevicePathProtocol,
) -> HardDriveDevicePath

Creates a HardDriveDevicePath instance from a binary representation.

Parameters:

Name Type Description Default
header EfiDevicePathProtocol

The header containing device path information.

required

FilepathDevicePath

Represents a file path device path in the UEFI device path protocol.

Attributes:

Name Type Description
path_name str

The file path name associated with the device path.

__init__

__init__(header: DevicePathHeader, path_name: str)

Initializes the FilepathDevicePath instance with the given header and path name.

Parameters:

Name Type Description Default
header DevicePathHeader

The header containing device path information.

required
path_name str

The file path name associated with the device path.

required

from_binary classmethod

from_binary(
    header: EfiDevicePathProtocol,
) -> FilepathDevicePath

Creates a FilepathDevicePath instance from a binary representation.

Parameters:

Name Type Description Default
header EfiDevicePathProtocol

The header containing device path information.

required

Returns:

Name Type Description
FilepathDevicePath FilepathDevicePath

An instance of FilepathDevicePath.

FwVolPathDevicePath

Represents a Media Firmware Volume Path Device Path in the UEFI specification.

Attributes:

Name Type Description
fv_name UUID

The firmware volume name.

__init__

__init__(header: DevicePathHeader, fv_name)

Initializes the FwVolPathDevicePath instance with the given header and firmware volume name.

Parameters:

Name Type Description Default
header DevicePathHeader

The header containing device path information.

required
fv_name UUID

The firmware volume name.

required

from_binary classmethod

from_binary(
    header: EfiDevicePathProtocol,
) -> FwVolPathDevicePath

Creates a FwVolPathDevicePath instance from a binary representation.

Parameters:

Name Type Description Default
header EfiDevicePathProtocol

The header containing device path information.

required

Returns:

Name Type Description
FwVolPathDevicePath FwVolPathDevicePath

An instance of FwVolPathDevicePath.

MediaFwVolFilePathDevicePath

Represents a Media Firmware Volume File Path Device Path in the UEFI specification.

Attributes:

Name Type Description
fv_file_name UUID

The firmware volume file name.

__init__

__init__(header: DevicePathHeader, fv_file_name)

Initializes the MediaFwVolFilePathDevicePath instance with the given header and firmware volume file name.

Parameters:

Name Type Description Default
header DevicePathHeader

The header containing device path information.

required
fv_file_name UUID

The firmware volume file name.

required

from_binary classmethod

from_binary(
    header: EfiDevicePathProtocol,
) -> MediaFwVolFilePathDevicePath

Creates a MediaFwVolFilePathDevicePath instance from a binary representation.

Parameters:

Name Type Description Default
header EfiDevicePathProtocol

The header containing device path information.

required

Returns:

Name Type Description
MediaFwVolFilePathDevicePath MediaFwVolFilePathDevicePath

An instance of MediaFwVolFilePathDevicePath.

MediaRelativeOffsetRangeDevicePath

Represents a MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH in the UEFI (Unified Extensible Firmware Interface) environment.

Attributes:

Name Type Description
header EfiDevicePathProtocol

The header of the device path.

reserved int

Reserved field.

starting_offset int

The starting offset.

ending_offset int

The ending offset.

__init__

__init__(header, reserved, starting_offset, ending_offset)

Initializes the MediaRelativeOffsetRangeDevicePath instance with the given header, reserved, starting offset, and ending offset.

Parameters:

Name Type Description Default
header EfiDevicePathProtocol

The header containing device path information.

required
reserved int

Reserved field.

required
starting_offset int

The starting offset.

required
ending_offset int

The ending offset.

required

from_binary classmethod

from_binary(
    header: EfiDevicePathProtocol,
) -> MediaRelativeOffsetRangeDevicePath

Creates a MediaRelativeOffsetRangeDevicePath instance from a binary representation.

Parameters:

Name Type Description Default
header EfiDevicePathProtocol

The header containing device path information.

required

Returns:

Name Type Description
MediaRelativeOffsetRangeDevicePath MediaRelativeOffsetRangeDevicePath

An instance of MediaRelativeOffsetRangeDevicePath.

EndOfHardwareDevicePath

EndOfHardwareDevicePath represents the end of a hardware device path in the UEFI specification.

Attributes:

Name Type Description
header DevicePathHeader

The header of the device path.

__init__

__init__(header: DevicePathHeader)

Initializes the EndOfHardwareDevicePath instance with the given header.

Parameters:

Name Type Description Default
header DevicePathHeader

The header containing device path information.

required

from_binary classmethod

from_binary(
    header: EfiDevicePathProtocol,
) -> EndOfHardwareDevicePath

Creates an EndOfHardwareDevicePath instance from a binary representation.

Parameters:

Name Type Description Default
header EfiDevicePathHeader

The header containing device path information.

required

DevicePathFactory

A factory class for creating device path objects from binary data.

from_binary staticmethod

from_binary(binary: bytes) -> List[EfiDevicePathProtocol]

Parses a binary stream into a list of EfiDevicePathProtocol objects.

Parameters:

Name Type Description Default
binary bytes

The binary data to parse.

required

Returns:

Type Description
List[EfiDevicePathProtocol]

List[EfiDevicePathProtocol]: A list of parsed EfiDevicePathProtocol objects.

Raises:

Type Description
ValueError

If an invalid header length is encountered.