Skip to content

Commit

Permalink
kernel: Allow kernel-specific cmdline snippets
Browse files Browse the repository at this point in the history
These are vendor provided at source and shouldn't be disabled, as they're
intended for an exact kernel release. Right now the motivation is for out
of tree modules such as the nvidia proprietary driver, but this also allows
a kernel to ship its own cmdline file that cannot be overriden.

Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeycode committed Dec 17, 2024
1 parent 5076b78 commit f3935d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion blsforme/src/bootloader/systemd_boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ impl<'a, 'b> Loader<'a, 'b> {
format!("{} ({})", schema.os_release().name, entry.kernel.version)
};
let vmlinuz = entry.installed_kernel_name(schema).expect("linux go boom");
let options = "".to_owned() + cmdline;
let options = if let Some(k_cmdline) = entry.kernel.cmdline.as_ref() {
format!("{cmdline} {k_cmdline}")
} else {
cmdline.to_string()
};
format!(
r###"title {title}
linux /EFI/{asset_dir}/{}{}
Expand Down
26 changes: 25 additions & 1 deletion blsforme/src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{

use serde::Deserialize;

use crate::{os_release::OsRelease, Error};
use crate::{file_utils::cmdline_snippet, os_release::OsRelease, Error};

/// Control kernel discovery mechanism
#[derive(Debug)]
Expand Down Expand Up @@ -70,6 +70,8 @@ pub struct Kernel {

/// Recorded variant type
pub variant: Option<String>,

pub cmdline: Option<String>,
}

/// Denotes the kind of auxiliary file
Expand Down Expand Up @@ -117,6 +119,24 @@ impl Schema<'_> {
}
}

fn load_cmdline(kernel: &Kernel) -> Result<String, Error> {
// Load local cmdline snippets for this kernel entry
let mut cmdline = String::new();
for snippet in kernel
.extras
.iter()
.filter(|e| matches!(e.kind, crate::AuxiliaryKind::Cmdline))
{
let snippet = cmdline_snippet(&snippet.path)?;
cmdline.push_str(&snippet);
cmdline.push(' ');
}

log::trace!("kernel-specific cmdline for {:?}: {cmdline}", kernel.image);

Ok(cmdline.trim().to_string())
}

/// Discover any legacy kernels
fn legacy_kernels(
namespace: &'static str,
Expand Down Expand Up @@ -151,6 +171,7 @@ impl Schema<'_> {
initrd: vec![],
extras: vec![],
variant: Some(variant.to_string()),
cmdline: None,
},
);
}
Expand Down Expand Up @@ -245,6 +266,7 @@ impl Schema<'_> {
kernel
.extras
.sort_by_key(|e| e.path.display().to_string().to_lowercase());
kernel.cmdline = Self::load_cmdline(kernel).ok().filter(|s| !s.is_empty());
}
Ok(kernels.into_values().collect::<Vec<_>>())
}
Expand All @@ -267,6 +289,7 @@ impl Schema<'_> {
initrd: vec![],
extras: vec![],
variant: None,
cmdline: None,
},
))
})
Expand Down Expand Up @@ -327,6 +350,7 @@ impl Schema<'_> {
kernel
.extras
.sort_by_key(|e| e.path.display().to_string().to_lowercase());
kernel.cmdline = Self::load_cmdline(kernel).ok().filter(|s| !s.is_empty());
}
}

Expand Down

0 comments on commit f3935d4

Please sign in to comment.