Skip to content

Commit fb08c0a

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

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: 36 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,32 @@ pub(crate) fn setup_composefs_uki_boot(
876870
}
877871

878872
ComposefsBootEntry::Type2(entry) => {
873+
// If --uki-addon is not passed, we don't install any addon
874+
if matches!(entry.pe_type, PEType::UkiAddon) {
875+
let Some(addons) = uki_addons else {
876+
continue;
877+
};
878+
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 =
888+
addon_name
889+
.strip_suffix(EFI_ADDON_FILE_EXT)
890+
.ok_or(anyhow::anyhow!(
891+
"UKI addon doesn't end with {EFI_ADDON_DIR_EXT}"
892+
))?;
893+
894+
if !addons.iter().any(|passed_addon| passed_addon == addon_name) {
895+
continue;
896+
}
897+
}
898+
879899
let ret = write_pe_to_esp(
880900
&repo,
881901
&entry.file,

crates/lib/src/install.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ pub(crate) struct InstallComposefsOpts {
256256
#[clap(long, default_value_t)]
257257
#[serde(default)]
258258
pub(crate) bootloader: Bootloader,
259+
260+
/// Name of the UKI addons to install without the ".efi.addon" suffix.
261+
/// This option can be provided multiple times if multiple addons are to be installed.
262+
#[clap(long)]
263+
#[serde(default)]
264+
pub(crate) uki_addon: Option<Vec<String>>,
259265
}
260266

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

0 commit comments

Comments
 (0)