Skip to main content

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.

UEFI firmware maintains a key-value store in non-volatile RAM (NVRAM) that persists across power cycles. Each variable is identified by a Unicode name and a vendor GUID, so different vendors or subsystems can use the same variable name without collision. Variables carry attribute flags that control whether they survive a reboot, whether they are accessible only during boot services, or whether they can be read at runtime by the operating system. FirmwareEnvironment is Unified.Firmware’s typed interface over this store.

FirmwareEnvironment Class

FirmwareEnvironment is constructed with an IFirmwareBackend and a vendor GUID that scopes all variable operations to a single namespace.
// Scope to the UEFI global namespace
var env = new FirmwareEnvironment(
    FirmwareInterface.CurrentBackend,
    FirmwareVendors.GlobalVariable);

// Scope to a vendor-specific namespace
var appleEnv = new FirmwareEnvironment(
    FirmwareInterface.CurrentBackend,
    FirmwareVendors.AppleVendor);
The two key properties exposed on every instance are:
PropertyTypeDescription
BackendIFirmwareBackendThe platform backend used for all reads and writes
VendorGuidGuidThe GUID namespace all variable operations are scoped to

Typed Read/Write Methods

All methods marshal data through unmanaged memory internally. Callers work entirely with managed types — structs, strings, and arrays.

ReadVariable<T> / WriteVariable<T>

Read or write a single blittable struct value.
T ReadVariable<T>(string varName, out VariableAttributes attributes)
    where T : struct;

void WriteVariable<T>(string varName, T value, VariableAttributes attributes)
    where T : struct;
// Read the firmware's boot manager timeout (in seconds)
ushort timeout = env.ReadVariable<ushort>(
    "Timeout",
    out VariableAttributes attrs);

Console.WriteLine($"Boot timeout: {timeout}s  (attrs: {attrs})");

// Shorten the timeout and write it back
env.WriteVariable(
    "Timeout",
    (ushort)3,
    VariableAttributes.NON_VOLATILE |
    VariableAttributes.BOOTSERVICE_ACCESS |
    VariableAttributes.RUNTIME_ACCESS);

ReadStringVariable / WriteStringVariable

Read or write a null-terminated Unicode (UTF-16LE) string variable.
string ReadStringVariable(string varName, out VariableAttributes attributes);

void WriteStringVariable(string varName, string value, VariableAttributes attributes);
string lang = env.ReadStringVariable("PlatformLang", out _);
Console.WriteLine($"Platform language: {lang}");  // e.g. "en-US"

ReadArrayVariable<T> / WriteArrayVariable<T>

Read or write a contiguous array of blittable structs, such as the boot order index list.
T[] ReadArrayVariable<T>(string varName, out VariableAttributes attributes)
    where T : struct;

void WriteArrayVariable<T>(string varName, T[] value, VariableAttributes attributes)
    where T : struct;
// Read the current boot order
ushort[] bootOrder = env.ReadArrayVariable<ushort>(
    "BootOrder",
    out VariableAttributes attrs);

Console.WriteLine("Boot order: " + string.Join(", ", bootOrder));

// Reverse the order and write it back
Array.Reverse(bootOrder);
env.WriteArrayVariable(
    "BootOrder",
    bootOrder,
    VariableAttributes.NON_VOLATILE |
    VariableAttributes.BOOTSERVICE_ACCESS |
    VariableAttributes.RUNTIME_ACCESS);

GlobalFirmwareEnvironment

GlobalFirmwareEnvironment is a subclass of FirmwareEnvironment that is pre-configured with FirmwareVendors.GlobalVariable as its namespace. It exposes the standard UEFI globally-defined variables as strongly-typed C# properties so you never have to remember variable names or marshal types by hand. Access it through the FirmwareEnvironment.Global static property, which is lazily initialised once using FirmwareInterface.CurrentBackend:
public static GlobalFirmwareEnvironment Global { get; }
// Read-only global state
Console.WriteLine($"Booted from entry: Boot{FirmwareEnvironment.Global.BootCurrent:X4}");
Console.WriteLine($"Secure Boot active: {FirmwareEnvironment.Global.SecureBoot}");
Console.WriteLine($"Setup Mode: {FirmwareEnvironment.Global.SetupMode}");

// Read/write global state
Console.WriteLine($"Current timeout: {FirmwareEnvironment.Global.Timeout}s");
FirmwareEnvironment.Global.Timeout = 5;

// One-shot override for the next boot
FirmwareEnvironment.Global.BootNext = 0x0002;

Key Properties on GlobalFirmwareEnvironment

BootCurrent

ushort — Index of the boot option that started the current OS session. Read-only (BS, RT).

BootNext

ushort — One-time boot override for the next reboot only. Read/write (NV, BS, RT).

BootOrder

ushort[] — Ordered list of all active boot option indices. Read/write (NV, BS, RT).

OsIndications

OsIndications — Flags the OS sets to request firmware actions (e.g. boot to UI). Read/write (NV, BS, RT).

OsIndicationsSupported

OsIndications — Bitmask of features the firmware supports. Read-only (BS, RT).

SecureBoot

bool — Whether Secure Boot enforcement is active. Read-only (BS, RT).

SetupMode

bool — Whether the platform is in Secure Boot setup mode. Read-only (BS, RT).

Timeout

ushort — Boot manager countdown in seconds before the default entry is selected. Read/write (NV, BS, RT).

FirmwareVendors

FirmwareVendors is a static class holding the well-known vendor GUIDs you pass when constructing a FirmwareEnvironment for a specific namespace.
MemberGUIDPurpose
GlobalVariable8BE4DF61-…Standard UEFI global namespace (BootOrder, Timeout, SecureBoot, …)
ImageSecurityDatabaseD719B2CB-…Secure Boot key databases (db, dbx, dbt)
MicrosoftVendor77FA9ABD-…Microsoft-specific variables (BitLocker, kernel policy, …)
LenovoVendorC020489E-…Lenovo/ThinkPad BIOS settings
DellVendor4BCFDDBD-…Dell power profiles and component inventory
HpVendor577FA4AD-…HP SureStart and security tokens
AsusVendor20C731A8-…ASUS ROG memory/LED/overclocking profiles
AppleVendor7C436110-…Mac EFI boot device, Bluetooth pairings
// Read a custom Dell variable
var dellEnv = new FirmwareEnvironment(
    FirmwareInterface.CurrentBackend,
    FirmwareVendors.DellVendor);

string policy = dellEnv.ReadStringVariable("CurrentPolicy", out _);
Console.WriteLine($"Dell policy: {policy}");

VariableAttributes

Every UEFI variable carries a set of attribute flags that govern its storage and visibility:
FlagMeaning
NON_VOLATILEValue survives a power cycle (written to NVRAM flash)
BOOTSERVICE_ACCESSAccessible during boot services (before ExitBootServices())
RUNTIME_ACCESSAccessible at OS runtime via firmware runtime services
AUTHENTICATED_WRITE_ACCESSWrites must be signed with a platform key
For the full flag enumeration, see VariableAttributes.
// Standard NV + BS + RT combination used for most persistent variables
var standardAttrs =
    VariableAttributes.NON_VOLATILE |
    VariableAttributes.BOOTSERVICE_ACCESS |
    VariableAttributes.RUNTIME_ACCESS;
Writing to the wrong vendor GUID does not raise an error — the firmware silently creates a new variable in that namespace. If you later query it with the correct GUID you will not find your data. Always double-check the GUID before calling any write method.

Build docs developers (and LLMs) love