Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/cfsctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ async fn main() -> Result<()> {
entry,
&id,
bootdir,
None,
entry_id.as_deref(),
&cmdline_refs,
)?;
Expand Down
11 changes: 9 additions & 2 deletions crates/composefs-boot/src/bootloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl<ObjectID: FsVerityHashValue> Type1Entry<ObjectID> {
// This is a bit of a strange operation: for each file mentioned in the bootloader entry, move
// the file into the given 'entry_id' pathname and rename the entry file itself to
// "{entry_id}.conf".
pub fn relocate(&mut self, entry_id: &str) {
pub fn relocate(&mut self, boot_subdir: Option<&str>, entry_id: &str) {
self.filename = Box::from(format!("{entry_id}.conf").as_ref());
for line in &mut self.entry.lines {
for key in ["linux", "initrd", "efi"] {
Expand All @@ -159,7 +159,14 @@ impl<ObjectID: FsVerityHashValue> Type1Entry<ObjectID> {

let new = format!("/{entry_id}/{basename}");
let range = substr_range(line, value).unwrap();
line.replace_range(range, &new);

let final_entry_path = if let Some(boot_subdir) = boot_subdir {
format!("/{boot_subdir}{new}")
} else {
new.clone()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess you could just move (and duplicate) the line.replace_range() into the if to avoid the clone if it bothers you ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

duplication bothers me a bit more than a String clone :)

};

line.replace_range(range, &final_entry_path);

if let Some(file) = file {
self.files.insert(new.into_boxed_str(), file);
Expand Down
66 changes: 60 additions & 6 deletions crates/composefs-boot/src/write_boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ use crate::{
pub fn write_t1_simple<ObjectID: FsVerityHashValue>(
mut t1: Type1Entry<ObjectID>,
bootdir: &Path,
boot_subdir: Option<&str>,
root_id: &ObjectID,
cmdline_extra: &[&str],
repo: &Repository<ObjectID>,
) -> Result<()> {
let bootdir = if let Some(subdir) = boot_subdir {
let subdir_path = Path::new(subdir);
bootdir.join(subdir_path.strip_prefix("/").unwrap_or(subdir_path))
} else {
bootdir.to_path_buf()
};

t1.entry
.adjust_cmdline(Some(&root_id.to_hex()), cmdline_extra);

Expand Down Expand Up @@ -63,32 +71,78 @@ pub fn write_t2_simple<ObjectID: FsVerityHashValue>(
Ok(())
}

/// Writes boot entry to the boot partition
///
/// # Arguments
///
/// * repo - The composefs repository
/// * entry - Boot entry variant to be written
/// * root_id - The content hash of the generated EROFS image id
/// * boot_partition - Path to the boot partition/directory
/// * boot_subdir - If `Some(path)`, the path is prepended to `initrd` and `linux` keys in the BLS entry
///
/// For example, if `boot_partition = "/boot"` and `boot_subdir = Some("1")` ,
/// the BLS entry will contain
///
/// ```text
/// linux /boot/1/<entry_id>/linux
/// initrd /boot/1/<entry_id>/initrd
/// ```
///
/// If `boot_partition = "/boot"` and `boot_subdir = None` , the BLS entry will contain
///
/// ```text
/// linux /<entry_id>/linux
/// initrd /<entry_id>/initrd
/// ```
///
/// * entry_id - In case of a BLS entry, the name of file to be generated in `loader/entries`
/// * cmdline_extra - Extra kernel command line arguments
///
pub fn write_boot_simple<ObjectID: FsVerityHashValue>(
repo: &Repository<ObjectID>,
entry: BootEntry<ObjectID>,
root_id: &ObjectID,
bootdir: &Path,
boot_partition: &Path,
boot_subdir: Option<&str>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Order again: boot_partition, boot_subdir, entry_id.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is correct, no?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. I think I wrote that to a previous iteration.

entry_id: Option<&str>,
cmdline_extra: &[&str],
) -> Result<()> {
match entry {
BootEntry::Type1(mut t1) => {
if let Some(name) = entry_id {
t1.relocate(name);
t1.relocate(boot_subdir, name);
}
write_t1_simple(t1, bootdir, root_id, cmdline_extra, repo)?;
write_t1_simple(
t1,
boot_partition,
boot_subdir,
root_id,
cmdline_extra,
repo,
)?;
}
BootEntry::Type2(mut t2) => {
if let Some(name) = entry_id {
t2.rename(name);
}
ensure!(cmdline_extra.is_empty(), "Can't add --cmdline args to UKIs");
write_t2_simple(t2, bootdir, root_id, repo)?;
write_t2_simple(t2, boot_partition, root_id, repo)?;
}
BootEntry::UsrLibModulesUki(_entry) => todo!(),
BootEntry::UsrLibModulesVmLinuz(entry) => {
let t1 = entry.into_type1(entry_id);
write_t1_simple(t1, bootdir, root_id, cmdline_extra, repo)?;
let mut t1 = entry.into_type1(entry_id);
if let Some(name) = entry_id {
t1.relocate(boot_subdir, name);
}
write_t1_simple(
t1,
boot_partition,
boot_subdir,
root_id,
cmdline_extra,
repo,
)?;
}
};

Expand Down
Loading