Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Rikitav/Unified.Firmware/llms.txt
Use this file to discover all available pages before exploring further.
IFirmwareBackend is the platform abstraction layer that decouples high-level UEFI logic from OS-specific system calls. Every operation that touches firmware — checking availability, locating the EFI System Partition, reading NVRAM variables, writing NVRAM variables — is funnelled through a single implementation of this interface. The library ships two built-in implementations selected automatically by FirmwareInterface.CurrentBackend, but the interface is public so you can supply your own backend for custom platforms, unit testing, or CI environments.
Namespace: Unified.Firmware
Built-in Implementations
Win32PlatformBackend
Targets Windows (PlatformID.Win32NT). NVRAM reads and writes are performed via the Win32 API functions GetFirmwareEnvironmentVariableExW and SetFirmwareEnvironmentVariableExW, which require the SE_SYSTEM_ENVIRONMENT_NAME privilege (Administrator). The EFI System Partition is located by enumerating volumes and sending an IOCTL_STORAGE_GET_DEVICE_NUMBER + partition-type query to identify the GPT ESP entry.
LinuxPlatfromBackend
Targets Linux (PlatformID.Unix). NVRAM variables are read from and written to the kernel’s efivars filesystem at /sys/firmware/efi/efivars/. Each variable is represented as a file named <VarName>-<VendorGUID>. The EFI System Partition is located by enumerating block devices and inspecting GPT partition type GUIDs via ioctl. Root privileges or CAP_SYS_ADMIN are required.
FirmwareInterface.CurrentBackend selects the correct implementation automatically based on Environment.OSVersion.Platform. You never need to instantiate a backend class directly unless you are supplying a custom implementation.Methods
CheckFirmwareAvailablity
Returnstrue if the system is running in UEFI mode and the firmware is accessible, or false if the system booted in Legacy BIOS mode or the required OS APIs are unavailable.
true if UEFI firmware is available and accessible; false otherwise.FindEfiSystemPartition
Locates the EFI System Partition among the system volumes and returns aVolumePath that identifies it. On Windows this is a volume GUID path (e.g. \\?\Volume{...}\); on Linux it is the mount point or block device path for the ESP.
A
VolumePath value identifying the EFI System Partition. FirmwareInterface.SystemPartition wraps this result as a DirectoryInfo.| Throws | Condition |
|---|---|
PlatformNotSupportedException | No EFI System Partition was found, or the system is not UEFI. |
FirmwareEnvironmentException | The partition enumeration failed at the OS layer. |
ReadEnvironmentVariable
Reads a UEFI NVRAM variable and returns a pointer to a heap-allocated buffer containing the raw variable bytes. The caller is responsible for freeing this memory withMarshal.FreeHGlobal once the data has been consumed.
The name of the firmware environment variable to read. Must not be null or empty.
The GUID identifying the variable namespace (vendor). Pass
FirmwareVendors.GlobalVariable for standard UEFI variables, or a vendor-specific GUID for OEM variables.Output parameter. Contains the
VariableAttributes flags for the variable when the method returns.The maximum number of bytes to allocate and read into the buffer. Must be large enough to hold the variable value;
FirmwareEnvironment passes Marshal.SizeOf<T>() for structs and 2 * 1024 for strings.Output parameter. Contains the actual byte size of the data written into the buffer when the method returns. Used by
ReadArrayVariable to determine array element count.A pointer to a heap-allocated block of memory containing the raw variable data. The caller must free this pointer with
Marshal.FreeHGlobal.| Throws | Condition |
|---|---|
PlatformNotSupportedException | The firmware is unavailable or the OS API is not accessible. |
FirmwareEnvironmentException | The variable was not found or the read operation failed. |
WriteEnvironmentVariable
Writes a raw byte buffer to NVRAM as a UEFI variable. The variable is stored non-volatilely (subject to theattributes flags) and will persist across reboots.
The name of the firmware environment variable to write. Must not be null or empty.
The GUID identifying the variable namespace (vendor).
The attribute flags to associate with the variable. Use
NON_VOLATILE | BOOTSERVICE_ACCESS | RUNTIME_ACCESS for standard persistent UEFI variables.A pointer to the buffer containing the bytes to write. The buffer must remain valid and pinned for the duration of this call.
The number of bytes in
valueBuffer to write.| Throws | Condition |
|---|---|
PlatformNotSupportedException | The firmware is unavailable or the OS API is not accessible. |
FirmwareEnvironmentException | The write operation failed (for example, insufficient privilege, read-only variable, or invalid attributes). |
Custom Implementation Skeleton
ImplementIFirmwareBackend to support a platform that neither of the built-in backends covers — for example, an embedded environment, a firmware emulator, or a test double.