feat(bls): parse the devicetree key

This commit is contained in:
alex authored and Alex Zenla committed 2026-10-03 20:23:57 -07:00
1 parent 5b345c82d1
commit ef14e5bd98
1 file changed
+28
+28
View File
@@ -34,6 +34,8 @@ pub struct BlsEntry {
pub efi: Option<String>, pub efi: Option<String>,
/// The path to a unified kernel image. /// The path to a unified kernel image.
pub uki: Option<String>, pub uki: Option<String>,
/// The path to the flattened devicetree to boot with.
pub devicetree: Option<String>,
/// The profile of the unified kernel image to boot. /// The profile of the unified kernel image to boot.
pub profile: Option<String>, pub profile: Option<String>,
/// The architecture the entry is for, such as `x64` or `aa64`. /// The architecture the entry is for, such as `x64` or `aa64`.
@@ -67,6 +69,7 @@ impl FromStr for BlsEntry {
let mut initrd: Vec<String> = Vec::new(); let mut initrd: Vec<String> = Vec::new();
let mut efi: Option<String> = None; let mut efi: Option<String> = None;
let mut uki: Option<String> = None; let mut uki: Option<String> = None;
let mut devicetree: Option<String> = None;
let mut profile: Option<String> = None; let mut profile: Option<String> = None;
let mut architecture: Option<String> = None; let mut architecture: Option<String> = None;
let mut sort_key: Option<String> = None; let mut sort_key: Option<String> = None;
@@ -127,6 +130,11 @@ impl FromStr for BlsEntry {
efi = Some(value.trim().to_string()); efi = Some(value.trim().to_string());
} }
// The path to the flattened devicetree to boot with.
"devicetree" => {
devicetree = Some(value.trim().to_string());
}
// The path to a unified kernel image. // The path to a unified kernel image.
"uki" => { "uki" => {
uki = Some(value.trim().to_string()); uki = Some(value.trim().to_string());
@@ -169,6 +177,7 @@ impl FromStr for BlsEntry {
initrd, initrd,
efi, efi,
uki, uki,
devicetree,
profile, profile,
architecture, architecture,
sort_key, sort_key,
@@ -227,6 +236,14 @@ impl BlsEntry {
.map(|path| path.replace('/', "\\").trim_start_matches('\\').to_string()) .map(|path| path.replace('/', "\\").trim_start_matches('\\').to_string())
} }
/// Fetches the path to the devicetree to boot with, if any.
/// It also converts / to \\ to match EFI path style.
pub fn devicetree_path(&self) -> Option<String> {
self.devicetree
.as_ref()
.map(|path| path.replace('/', "\\").trim_start_matches('\\').to_string())
}
/// Fetches the paths to the initrds to pass to the kernel, in order. /// Fetches the paths to the initrds to pass to the kernel, in order.
/// It also converts / to \\ to match EFI path style. /// It also converts / to \\ to match EFI path style.
pub fn initrd_paths(&self) -> Vec<String> { pub fn initrd_paths(&self) -> Vec<String> {
@@ -1139,6 +1156,17 @@ mod tests {
assert!(resolve_default_flags(&[]).is_empty()); assert!(resolve_default_flags(&[]).is_empty());
} }
#[test]
fn parse_devicetree_and_convert_the_path() {
let entry: BlsEntry = "linux /vmlinuz\ndevicetree /dtb/board.dtb\n"
.parse()
.unwrap();
assert_eq!(entry.devicetree.as_deref(), Some("/dtb/board.dtb"));
assert_eq!(entry.devicetree_path().as_deref(), Some("dtb\\board.dtb"));
let entry: BlsEntry = "linux /vmlinuz\n".parse().unwrap();
assert_eq!(entry.devicetree_path(), None);
}
#[test] #[test]
fn parse_architecture_uki_and_profile() { fn parse_architecture_uki_and_profile() {
let entry: BlsEntry = "uki /EFI/Linux/a.efi\narchitecture x64\nprofile 2\n" let entry: BlsEntry = "uki /EFI/Linux/a.efi\narchitecture x64\nprofile 2\n"