Skip to content

[feature/patina-boot] patina_boot: Add discover_boot_options helper#1447

Open
kat-perez wants to merge 1 commit intoOpenDevicePartnership:feature/patina-bootfrom
kat-perez:kp/boot-option-discovery
Open

[feature/patina-boot] patina_boot: Add discover_boot_options helper#1447
kat-perez wants to merge 1 commit intoOpenDevicePartnership:feature/patina-bootfrom
kat-perez:kp/boot-option-discovery

Conversation

@kat-perez
Copy link
Copy Markdown
Contributor

@kat-perez kat-perez commented Apr 1, 2026

Description

Add discover_boot_options() helper to patina_boot::helpers that reads UEFI BootOrder and Boot#### variables to build a BootConfig from standard UEFI boot options.

This enables any BootOrchestrator implementation that consumes BootConfig to use UEFI-compliant boot variables instead of requiring platforms to hardcode device paths. The function:

  • Reads BootOrder to determine boot attempt order
  • Parses each Boot#### EFI_LOAD_OPTION structure to extract device paths
  • Filters out inactive boot options (LOAD_OPTION_ACTIVE)
  • Gracefully skips unreadable or malformed entries
  • Returns a populated BootConfig with discovered devices in priority order

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

  • Unit tests covering: single/multiple boot options, inactive option filtering, unreadable variable handling, truncated load option data, empty BootOrder, and hex variable name generation
  • Integration tested with patina-dxe-core-qemu feature/patina-boot on QEMU Q35 — full boot to UEFI Shell 2.0

Integration Instructions

Platforms can call discover_boot_options() with runtime services to automatically populate a BootConfig from UEFI boot variables instead of constructing device paths manually. This works with any BootOrchestrator implementation that accepts a BootConfig:

let config = discover_boot_options(&runtime_services)?;
add.component(BootDispatcher::new(SimpleBootManager::new(config)));

@patina-automation
Copy link
Copy Markdown
Contributor

patina-automation bot commented Apr 1, 2026

✅ QEMU Validation Passed

All QEMU validation jobs completed successfully.

Note: Q35 is only built on Windows hosts (QEMU boot is disabled due to a QEMU vfat issue).

Workflow run: https://github.com/OpenDevicePartnership/patina/actions/runs/23876918302

Boot Time to EFI Shell

Platform Elapsed
Q35 (Linux Host) 28.1s
SBSA (Linux Host) 1m 3s

Dependencies

Repository Ref
patina 5428475
patina-dxe-core-qemu 3eb6066
patina-fw-patcher 29264b2
patina-qemu firmware v3.0.0
patina-qemu build script bfc657f

This comment was automatically generated by the Patina QEMU PR Validation Post workflow.

@github-actions github-actions bot added impact:non-functional Does not have a functional impact impact:testing Affects testing labels Apr 1, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 96.87500% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
components/patina_boot/src/helpers.rs 96.88% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@kat-perez kat-perez force-pushed the kp/boot-option-discovery branch 2 times, most recently from 8cee855 to 1892744 Compare April 1, 2026 20:13
@kat-perez kat-perez force-pushed the feature/patina-boot branch from f168dff to d9458cb Compare April 1, 2026 20:29
@kat-perez kat-perez force-pushed the kp/boot-option-discovery branch from 1892744 to f39c078 Compare April 1, 2026 20:38
@kat-perez kat-perez marked this pull request as ready for review April 1, 2026 21:05
@kat-perez kat-perez changed the title patina_boot: Add discover_boot_options helper [feature/patina-boot] patina_boot: Add discover_boot_options helper Apr 1, 2026
const LOAD_OPTION_ACTIVE: u32 = 0x00000001;

/// Null-terminated UTF-16 `BootOrder` variable name.
const BOOT_ORDER_VARIABLE_NAME: &[u16] =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this on earlier ones, but for these various UEFI spec defined things, we should be taking them to r-efi as well. Hosting them here until they are merged there is fine.

name.push(c as u16);
}
for c in hex_chars {
name.push(c.to_ascii_uppercase() as u16);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't these all digits? What does to_ascii_uppercase do on a digit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

char::from_digit(n, 16) returns lowercase hex and UEFI variable names use uppercase. The to_ascii_uppercase was there to fix the casing. I changed this to use format!("Boot{:04X}", option_number) to specify more clearly that we want uppercase hex.

return None;
}

let attributes = u32::from_le_bytes([data[0], data[1], data[2], data[3]]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of from_le_bytes throughout all these changes. A place to use zerocopy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use zerocopy

@kat-perez kat-perez force-pushed the kp/boot-option-discovery branch from f39c078 to 97c8715 Compare April 1, 2026 23:44
Reads BootOrder and Boot#### UEFI variables to build a BootConfig from
UEFI-compliant boot options, enabling SimpleBootManager to use standard
boot variables instead of platform-hardcoded device paths.
@kat-perez kat-perez force-pushed the kp/boot-option-discovery branch from 97c8715 to 5428475 Compare April 1, 2026 23:51
@kat-perez kat-perez requested a review from os-d April 2, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:non-functional Does not have a functional impact impact:testing Affects testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants