diff --git a/crates/bls/src/lib.rs b/crates/bls/src/lib.rs index 7808da9..6f1c0e9 100644 --- a/crates/bls/src/lib.rs +++ b/crates/bls/src/lib.rs @@ -34,6 +34,8 @@ pub struct BlsEntry { pub efi: Option, /// The path to a unified kernel image. pub uki: Option, + /// The path to the flattened devicetree to boot with. + pub devicetree: Option, /// The profile of the unified kernel image to boot. pub profile: Option, /// The architecture the entry is for, such as `x64` or `aa64`. @@ -67,6 +69,7 @@ impl FromStr for BlsEntry { let mut initrd: Vec = Vec::new(); let mut efi: Option = None; let mut uki: Option = None; + let mut devicetree: Option = None; let mut profile: Option = None; let mut architecture: Option = None; let mut sort_key: Option = None; @@ -127,6 +130,11 @@ impl FromStr for BlsEntry { 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. "uki" => { uki = Some(value.trim().to_string()); @@ -169,6 +177,7 @@ impl FromStr for BlsEntry { initrd, efi, uki, + devicetree, profile, architecture, sort_key, @@ -227,6 +236,14 @@ impl BlsEntry { .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 { + 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. /// It also converts / to \\ to match EFI path style. pub fn initrd_paths(&self) -> Vec { @@ -1139,6 +1156,17 @@ mod tests { 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] fn parse_architecture_uki_and_profile() { let entry: BlsEntry = "uki /EFI/Linux/a.efi\narchitecture x64\nprofile 2\n"