Skip to content

Commit 4c4bcfb

Browse files
composefs-backend/boot: Allow passing UKI addons as cli options
Allows installing only some or all of the addons depending upon the list of addons passed in as cli options. Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent 2e4a47b commit 4c4bcfb

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use cap_std_ext::{
1515
use clap::ValueEnum;
1616
use composefs::fs::read_file;
1717
use composefs::tree::{FileSystem, RegularFile};
18-
use composefs_boot::bootloader::{PEType, EFI_ADDON_DIR_EXT, EFI_EXT};
18+
use composefs_boot::bootloader::{PEType, EFI_ADDON_DIR_EXT, EFI_ADDON_FILE_EXT, EFI_EXT};
1919
use composefs_boot::BootOps;
2020
use fn_error_context::context;
2121
use ostree_ext::composefs::{
@@ -815,38 +815,31 @@ pub(crate) fn setup_composefs_uki_boot(
815815
id: &Sha256HashValue,
816816
entries: Vec<ComposefsBootEntry<Sha256HashValue>>,
817817
) -> Result<()> {
818-
let (root_path, esp_device, bootloader, is_insecure_from_opts) = match setup_type {
818+
let (root_path, esp_device, bootloader, is_insecure_from_opts, uki_addons) = match setup_type {
819819
BootSetupType::Setup((root_setup, state, ..)) => {
820820
if let Some(v) = &state.config_opts.karg {
821821
if v.len() > 0 {
822822
tracing::warn!("kargs passed for UKI will be ignored");
823823
}
824824
}
825825

826+
let Some(cfs_opts) = &state.composefs_options else {
827+
anyhow::bail!("ComposeFS options not found");
828+
};
829+
826830
let esp_part = root_setup
827831
.device_info
828832
.partitions
829833
.iter()
830834
.find(|p| p.parttype.as_str() == ESP_GUID)
831835
.ok_or_else(|| anyhow!("ESP partition not found"))?;
832836

833-
let bootloader = state
834-
.composefs_options
835-
.as_ref()
836-
.map(|opts| opts.bootloader.clone())
837-
.unwrap_or(Bootloader::default());
838-
839-
let is_insecure = state
840-
.composefs_options
841-
.as_ref()
842-
.map(|x| x.insecure)
843-
.unwrap_or(false);
844-
845837
(
846838
root_setup.physical_root_path.clone(),
847839
esp_part.node.clone(),
848-
bootloader,
849-
is_insecure,
840+
cfs_opts.bootloader.clone(),
841+
cfs_opts.insecure,
842+
cfs_opts.uki_addon.as_ref(),
850843
)
851844
}
852845

@@ -860,6 +853,7 @@ pub(crate) fn setup_composefs_uki_boot(
860853
get_esp_partition(&sysroot_parent)?.0,
861854
bootloader,
862855
false,
856+
None,
863857
)
864858
}
865859
};
@@ -876,6 +870,31 @@ pub(crate) fn setup_composefs_uki_boot(
876870
}
877871

878872
ComposefsBootEntry::Type2(entry) => {
873+
// If --uki-addon is not passed, we include all addons found
874+
if let Some(addons) = uki_addons {
875+
match entry.pe_type {
876+
PEType::Uki => { /* no-op */ }
877+
878+
PEType::UkiAddon => {
879+
let addon_name = entry
880+
.file_path
881+
.components()
882+
.last()
883+
.ok_or(anyhow::anyhow!("Could not get UKI addon name"))?;
884+
885+
let addon_name = addon_name.as_str()?;
886+
887+
let addon_name = addon_name.strip_suffix(EFI_ADDON_FILE_EXT).ok_or(
888+
anyhow::anyhow!("UKI addon doesn't end with {EFI_ADDON_DIR_EXT}"),
889+
)?;
890+
891+
if !addons.iter().any(|passed_addon| passed_addon == addon_name) {
892+
continue;
893+
}
894+
}
895+
}
896+
}
897+
879898
let ret = write_pe_to_esp(
880899
&repo,
881900
&entry.file,

crates/lib/src/install.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ pub(crate) struct InstallComposefsOpts {
238238
#[clap(long, default_value_t)]
239239
#[serde(default)]
240240
pub(crate) bootloader: Bootloader,
241+
242+
/// Name of the UKI addons to install without the ".efi.addon" suffix.
243+
/// This option can be provided multiple times if multiple addons are to be installed.
244+
/// If not passed, all addons are installed
245+
#[clap(long)]
246+
#[serde(default)]
247+
pub(crate) uki_addon: Option<Vec<String>>,
241248
}
242249

243250
#[cfg(feature = "install-to-disk")]

0 commit comments

Comments
 (0)