Skip to content

Commit e1f8322

Browse files
committed
bootupd way of extending payload to esp
1 parent f7b48bd commit e1f8322

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

src/bios.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,7 @@ impl Component for Bios {
224224
fn get_efi_vendor(&self, _: &openat::Dir) -> Result<Option<String>> {
225225
Ok(None)
226226
}
227+
fn extend_payload(&self,_: &str,_: &str) -> Result<Option<bool>> {
228+
Ok(None)
229+
}
227230
}

src/cli/bootupctl.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ pub enum CtlBackend {
7373
Generate(super::bootupd::GenerateOpts),
7474
#[clap(name = "install", hide = true)]
7575
Install(super::bootupd::InstallOpts),
76+
#[clap(name = "extend-payload-to-esp", hide = true)]
77+
ExtendPayload(super::bootupd::ExtendPayloadOpts),
7678
}
7779

7880
#[derive(Debug, Parser)]
@@ -102,6 +104,9 @@ impl CtlCommand {
102104
CtlVerb::Backend(CtlBackend::Install(opts)) => {
103105
super::bootupd::DCommand::run_install(opts)
104106
}
107+
CtlVerb::Backend(CtlBackend::ExtendPayload(opts)) => {
108+
super::bootupd::DCommand::run_extend_payload(opts)
109+
}
105110
CtlVerb::MigrateStaticGrubConfig => Self::run_migrate_static_grub_config(),
106111
}
107112
}

src/cli/bootupd.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub enum DVerb {
3535
GenerateUpdateMetadata(GenerateOpts),
3636
#[clap(name = "install", about = "Install components")]
3737
Install(InstallOpts),
38+
#[clap(name = "extend-payload-to-esp", about = "Extend bootloader payload with additional files")]
39+
ExtendPayload(ExtendPayloadOpts),
3840
}
3941

4042
#[derive(Debug, Parser)]
@@ -82,12 +84,36 @@ pub struct GenerateOpts {
8284
sysroot: Option<String>,
8385
}
8486

87+
#[derive(Debug, Parser)]
88+
pub struct ExtendPayloadOpts {
89+
/// System root directory
90+
#[clap(value_parser, default_value_t = String::from("/"))]
91+
sysroot: String,
92+
93+
/// Source directory containing files to add
94+
#[clap(value_parser)]
95+
src_root: String,
96+
}
97+
98+
#[derive(Debug, Parser)]
99+
pub struct InstallToFilesystemOpts {
100+
#[clap(long, default_value_t = String::from("/") , help = "Source root directory")]
101+
src_root: String,
102+
103+
#[clap(long, help = "Destination root directory")]
104+
dest_root: String,
105+
106+
#[clap(value_parser, help = "file relative path")]
107+
file_path: String,
108+
}
109+
85110
impl DCommand {
86111
/// Run CLI application.
87112
pub fn run(self) -> Result<()> {
88113
match self.cmd {
89114
DVerb::Install(opts) => Self::run_install(opts),
90115
DVerb::GenerateUpdateMetadata(opts) => Self::run_generate_meta(opts),
116+
DVerb::ExtendPayload(opts) => Self::run_extend_payload(opts),
91117
}
92118
}
93119

@@ -122,4 +148,16 @@ impl DCommand {
122148
.context("boot data installation failed")?;
123149
Ok(())
124150
}
151+
152+
pub(crate) fn run_extend_payload(opts: ExtendPayloadOpts) -> Result<()> {
153+
let components = crate::bootupd::get_components();
154+
for component in components.values() {
155+
if let Some(updated) = component.extend_payload(&opts.sysroot, &opts.src_root)? {
156+
if updated {
157+
println!("Extended payload for {} successfully", component.name());
158+
}
159+
}
160+
}
161+
Ok(())
162+
}
125163
}

src/component.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ pub(crate) trait Component {
7575

7676
/// Locating efi vendor dir
7777
fn get_efi_vendor(&self, sysroot: &openat::Dir) -> Result<Option<String>>;
78+
79+
/// Extending payload from input dir
80+
fn extend_payload(&self,sysroot: &str,src_root: &str) -> Result<Option<bool>>;
81+
7882
}
7983

8084
/// Given a component name, create an implementation.

src/efi.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,44 @@ impl Component for Efi {
415415
Ok(meta)
416416
}
417417

418+
fn extend_payload(&self,sysroot_path: &str,src_input: &str) -> Result<Option<bool>> {
419+
let ostreebootdir = Path::new(sysroot_path).join(ostreeutil::BOOT_PREFIX);
420+
let dest_efidir = component_updatedir(sysroot_path, self);
421+
422+
// move files to staged updates
423+
if ostreebootdir.exists() {
424+
let cruft = ["loader", "grub2"];
425+
for p in cruft.iter() {
426+
let p = ostreebootdir.join(p);
427+
if p.exists() {
428+
std::fs::remove_dir_all(&p)?;
429+
}
430+
}
431+
// mv src data to /usr/lib_bootupd/updates/EFI
432+
let efisrc = ostreebootdir.join(src_input);
433+
if !efisrc.exists() {
434+
bail!("Failed to find {:?}", &efisrc);
435+
}
436+
Command::new("mv").args([&efisrc, &dest_efidir]).run()?;
437+
}
438+
439+
// canocinal path information parsed
440+
let efidir = openat::Dir::open(&dest_efidir)
441+
.with_context(|| format!("Opening {}", dest_efidir.display()))?;
442+
let files = crate::util::filenames(&efidir)?.into_iter().map(|mut f| {
443+
f.insert_str(0, src_input);
444+
f
445+
});
446+
447+
// writes EFI.JSON with the timestamp and version
448+
let meta = packagesystem::query_files(sysroot_path, files)
449+
.context("Querying RPM metadata")?;
450+
write_update_metadata(sysroot_path, self, &meta)?;
451+
452+
Ok(Some(true))
453+
454+
}
455+
418456
fn query_update(&self, sysroot: &openat::Dir) -> Result<Option<ContentMetadata>> {
419457
get_component_update(sysroot, self)
420458
}

0 commit comments

Comments
 (0)