Impossible OS Docs

Boot Error History Ring -- Schema and Operator Guide

Wire format and operator-visible decode tables for the multi-attempt boot diagnostics ring shipped by the boot-error-history TODO sections in todo/01-boot-platform/TODO-03-bootloader-error-recovery.md. Producer: schema + 3 append sites + NVRAM cookie. Consumer: storage reader, kernel renderer, unit tests, and the cascade smoke fixture.

The ring captures the last 8 boot attempts so a cascade-failure sequence (retry storm, repeated kernel-load corruption, etc.) leaves an ordered trail instead of overwriting a single-slot record on each iteration. It complements the single-slot BootError channel: the single slot remains the operator's "what was the most recent boot fatal?" query; the ring answers "show me the attempt history."

Storage layout

Two UEFI variables under the IMPOSSIBLE_OS_VENDOR_GUID ({6F35D3A4-C0E6-4A82-B5D8-7C9D2E4F8A13}) namespace, both with NV+BS+RT attributes:

Variable name Size Description
BootHistorySeq 4 bytes u32 monotonic cookie. seq increments by 1 per append.
BootErrorHistory 128 bytes Fixed 8-entry ring. Slot selection prefers new_seq % 8 when empty or expired, and evicts the oldest committed entry across UINT32_MAX -> 1 wrap.

The 128-byte ring fits any UEFI NVRAM quota. The X:\Diag\boot-error-history.bin BlackBox-file path is reserved for future expansion (when the ring outgrows NVRAM); the current producer is NVRAM-only and the consumer reads NVRAM exclusively.

Per-entry layout (struct boot_error_history_entry, 16 bytes)

struct boot_error_history_entry {
    uint32_t boot_seq;        /* offset  0: monotonic from BootHistorySeq */
    uint32_t unix_time;       /* offset  4: epoch seconds (0 = no clock)  */
    uint16_t err_code;        /* offset  8: BOOT_ERR_* or 0 for sentinels */
    uint16_t source_section;  /* offset 10: phase code or BOOT_SECTION_*  */
    uint32_t _pad;            /* offset 12: zero on write, ignored on read*/
};

Layout pinned by _Static_assert blocks on both sides (include/kernel/boot_info.h + src/boot/uefi/boot_info_mirror.h). A failed assert means kernel + bootloader drifted; rebuild both before shipping.

UEFI 2.10 SetVariable is per-variable atomic; there is no transactional batch. The producer always:

  1. Reads existing cookie + ring (distinguishing confirmed absence EFI_NOT_FOUND, validated contents, malformed size/attrs repaired via delete, and operational read failures). On any operational read failure (EFI_DEVICE_ERROR, etc.), skips both writes so persisted NVRAM stays intact. When the cookie was absent or repaired, resets the in-memory ring to zero before starting at sequence 1 so surviving uncommitted high-sequence entries cannot become visible.
  2. Chooses the target slot via boot_history_pick_slot() (reuses a staged new_seq slot on torn-write retry, prefers new_seq % 8 when empty or out-of-window for mixed-version compatibility before rollover, otherwise evicts the oldest committed entry by circular age) and stamps the new entry with unix_time from RuntimeServices->GetTime() (0 if unavailable).
  3. Writes the ring variable first (full 128 bytes, NV+BS+RT).
  4. Writes the cookie second (4 bytes, NV+BS+RT).

A torn write between steps 3 and 4 leaves the cookie pointing at the previous sequence; readers filter entries to the circular committed window [committed_seq - 7 .. committed_seq] in [1 .. 0xFFFFFFFF] and sort oldest-to-newest by descending circular age, so the uncommitted entry is never exposed. Bounded loss; never UB.

new_seq = seq + 1; if new_seq == 0 (wrap from UINT32_MAX or an attacker-seeded cookie), the producer promotes new_seq to 1. This avoids a collision with the empty-slot sentinel boot_seq == 0 that the consumer's "count non-zero entries" pass uses to detect ring boundaries.

Append sites

Site source_section err_code
Bootloader boot_fatal() g_boot_section hint (0x01NN) BOOT_ERR_*
Bootloader EBS-success BOOT_SECTION_EBS_OK 0xFFFE 0
Kernel boot_phase3() BOOT_SECTION_KERNEL_PHASE3 0xFFFF 0

A clean boot writes 2 entries (EBS-success + kernel Phase-3); a fatal adds 1 fatal entry instead of the EBS-success / Phase-3 pair.

Source-section enum

Value Symbol Meaning
0x0101 BOOT_SECTION_BL_INIT efi_main entry
0x0102 BOOT_SECTION_BL_CONF parse_boot_conf
0x0103 BOOT_SECTION_BL_KERNEL load_kernel
0x0104 BOOT_SECTION_BL_PAGETABLES setup_page_tables
0x0105 BOOT_SECTION_BL_EBS EBS retry loop entry
0xFFFD BOOT_SECTION_UNKNOWN Hint never set (path-attribution gap; logged WARN)
0xFFFE BOOT_SECTION_EBS_OK Bootloader reached ExitBootServices
0xFFFF BOOT_SECTION_KERNEL_PHASE3 Kernel reached steady state

The 0x01NN range cannot collide with the BOOT_ERR_* registry (currently capped at 0x001B) or the three high sentinels. The BOOT_ERR_* registry lives in the err_code field, not in source_section; the producer never writes a BOOT_ERR_* value into source_section, so the consumer renderer's "fall back to section-0xNNNN" behavior for unknown values is correct for any future code that escapes the documented ranges.

Producer trust model

The producer-side reader treats the following as "found-but-malformed" and deletes the variable so the next write can land canonical attrs:

  • EFI_BUFFER_TOO_SMALL / STATUS_BUFFER_TOO_SMALL (oversized variable, e.g. seeded by a pre-OS tool).
  • Non-canonical attributes (any combo other than NV+BS+RT).
  • Wrong size on success.

Other EFI_ERROR codes (EFI_NOT_FOUND, unsupported, access denied) are treated as absent: no delete, ring stays zero-initialised.

Rejected-store record: BootStoreReject

A boot entry store that exists and cannot be used is not a fatal: the machine boots its fallback entry, and it does so again on every boot until the user fixes the file. So this condition stays out of the ring. Appending on each boot would evict every different error within 8 boots, and a SetVariable on each boot would wear NVRAM for as long as the file stays broken.

It gets a single 16-byte variable of its own under the same GUID, with NV+BS+RT attributes (boot_store_reject_record_t):

Offset Size Field Meaning
0 4 err_code BOOT_ERR_STORE_REJECTED (0x001A)
4 2 load_status boot_store_load_status_t, or 0xFFFF when policy allocation failed before the store was reached
6 2 reject_code boot_entries_reject_code_t, 0 when the parser never ran
8 4 line 1-based position of the rejection, 0 when the whole file is at fault
12 4 column Column of the rejection

The loader decides what to do on every boot (boot_store_record_intent, boot_store_record_decide):

This boot found Stored record Action
Store rejected or unreadable Same Nothing: a repeat costs no write
Store rejected or unreadable Different or none Write
Store rejected or unreadable Wrong size or attributes Delete, then write
Store accepted, or no file on a searched filesystem Any Delete
No filesystem on the boot device (PXE, UKI over HTTP) Any Nothing: this boot says nothing about the store on disk
Stored variable could not be read Any Nothing: it cannot be compared, and writing anyway would wear NVRAM

The write happens before the on-screen notice, because that eight-second dwell is when a user is most likely to power off. There is no timestamp, since a field that changes per boot would force the write the comparison avoids.

The kernel reads the variable after boot_history_render() and logs it as a warning on every boot until it is repaired (boot_store_reject_render): Boot entry store unusable: JSON_PARSE at line 2, col 1: the store is not valid JSON. It checks the size, attributes, err_code, load_status and reject_code first, since the variable lives under a public GUID, and only bounds line and column to the buffer. It never writes: the bootloader is the only writer. The words come from include/boot/boot_store_reject_text.h, so the log line matches the notice.

Known limit: the record does not name a device. Booting from a different disk whose ESP has a good store, or none, clears a record about the first disk.

Consumer renderer

boot_history_render() runs in boot_phase0 / boot_hw.c after uefi_vars_init() returns. It calls boot_history_read() and emits a klog block when the ring has at least one non-zero entry:

[BOOT] Recent boot history (N attempts):
  seq=K time=YYYY-MM-DDTHH:MM:SSZ src=<label> err=0xNNNN
  ...

Entries render oldest-first by boot_seq. Sentinels decode to stable labels (unknown, ebs-success, kernel-Phase3); bootloader phases decode to bl-init / bl-conf / bl-kernel / bl-pagetables / bl-ebs; everything else falls back to section-0xNNNN.

unix_time == 0 renders as (no clock).

Operator decode table: err_code -> recovery slug

The ring's err_code field reuses the BOOT_ERR_* namespace from the single-slot BootError channel. Operators looking up codes can scan the same recovery URLs that the QR-code error screen uses; the 4-hex-digit suffix in https://impossibleos.co/err/<NNNN> matches the err_code value rendered here.

Quota footprint

Per-machine NVRAM quota is typically 64 KiB on Lenovo-class firmware; the consumer cap is much higher. Total bytes spent by this feature plus the related BootError and ImpossibleBootProtoFault channels:

Variable Size
BootError 4 B
BootHistorySeq 4 B
BootErrorHistory 128 B
BootStoreReject 16 B
ImpossibleBootProtoFault 112 B
Total 264 B

Well below any per-machine quota.

Impossible OS is free software under the GPL-3.0-only license. Last updated Privacy Edit this page on GitHub