Skip to content

Commit f5baaaf

Browse files
committed
feat(extend_payload_to_esp):add payload to bootupd efi updates dir.
Bootup extend_payload_to_esp <path> will move the <path> to bootupd updates This features gives user ability to add payload though bootupd update stage,it also updates efi metadata. This will help in mounting uboot binaries to esp as required by rpi4. example usage: `bootupctl backend extend_payload_to_esp /usr/lib/mydata` will move the content of the dir to `usr/lib/bootupd/updates/EFI` and appends metadata to `/usr/lib/bootupd/updates/EFI.json`
1 parent 5e99cf6 commit f5baaaf

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

src/bios.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,7 @@ impl Component for Bios {
267267
fn get_efi_vendor(&self, _: &openat::Dir) -> Result<Option<String>> {
268268
Ok(None)
269269
}
270+
fn extend_payload(&self, _: &str, _: &str) -> Result<Option<bool>> {
271+
Ok(None)
272+
}
270273
}

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)]
@@ -109,6 +111,9 @@ impl CtlCommand {
109111
CtlVerb::Backend(CtlBackend::Install(opts)) => {
110112
super::bootupd::DCommand::run_install(opts)
111113
}
114+
CtlVerb::Backend(CtlBackend::ExtendPayload(opts)) => {
115+
super::bootupd::DCommand::run_extend_payload(opts)
116+
}
112117
CtlVerb::MigrateStaticGrubConfig => Self::run_migrate_static_grub_config(),
113118
}
114119
}

src/cli/bootupd.rs

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

4045
#[derive(Debug, Parser)]
@@ -82,12 +87,20 @@ pub struct GenerateOpts {
8287
sysroot: Option<String>,
8388
}
8489

90+
#[derive(Debug, Parser)]
91+
pub struct ExtendPayloadOpts {
92+
/// Source directory containing files to add
93+
#[clap(value_parser)]
94+
src_root: String,
95+
}
96+
8597
impl DCommand {
8698
/// Run CLI application.
8799
pub fn run(self) -> Result<()> {
88100
match self.cmd {
89101
DVerb::Install(opts) => Self::run_install(opts),
90102
DVerb::GenerateUpdateMetadata(opts) => Self::run_generate_meta(opts),
103+
DVerb::ExtendPayload(opts) => Self::run_extend_payload(opts),
91104
}
92105
}
93106

@@ -122,4 +135,17 @@ impl DCommand {
122135
.context("boot data installation failed")?;
123136
Ok(())
124137
}
138+
139+
pub(crate) fn run_extend_payload(opts: ExtendPayloadOpts) -> Result<()> {
140+
let components = crate::bootupd::get_components();
141+
let sysroot = "/";
142+
for component in components.values() {
143+
if let Some(updated) = component.extend_payload(sysroot, &opts.src_root)? {
144+
if updated {
145+
println!("Extended payload for {} successfully", component.name());
146+
}
147+
}
148+
}
149+
Ok(())
150+
}
125151
}

src/component.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ pub(crate) trait Component {
7979

8080
/// Locating efi vendor dir
8181
fn get_efi_vendor(&self, sysroot: &openat::Dir) -> Result<Option<String>>;
82+
83+
/// Extending payload from input dir
84+
fn extend_payload(&self, sysroot: &str, src_root: &str) -> Result<Option<bool>>;
8285
}
8386

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

src/efi.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,43 @@ impl Component for Efi {
454454
Ok(meta)
455455
}
456456

457+
fn extend_payload(&self, sysroot_path: &str, src_input: &str) -> Result<Option<bool>> {
458+
let ostreebootdir = Path::new(sysroot_path).join(ostreeutil::BOOT_PREFIX);
459+
let dest_efidir = component_updatedir(sysroot_path, self);
460+
461+
// move files to staged updates
462+
if ostreebootdir.exists() {
463+
let cruft = ["loader", "grub2"];
464+
for p in cruft.iter() {
465+
let p = ostreebootdir.join(p);
466+
if p.exists() {
467+
std::fs::remove_dir_all(&p)?;
468+
}
469+
}
470+
// mv src data to /usr/lib_bootupd/updates/EFI
471+
let efisrc = ostreebootdir.join(src_input);
472+
if !efisrc.exists() {
473+
bail!("Failed to find {:?}", &efisrc);
474+
}
475+
Command::new("mv").args([&efisrc, &dest_efidir]).run()?;
476+
}
477+
478+
// canocinal path information parsed
479+
let efidir = openat::Dir::open(&dest_efidir)
480+
.with_context(|| format!("Opening {}", dest_efidir.display()))?;
481+
let files = crate::util::filenames(&efidir)?.into_iter().map(|mut f| {
482+
f.insert_str(0, src_input);
483+
f
484+
});
485+
486+
// writes EFI.JSON with the timestamp and version
487+
let meta =
488+
packagesystem::query_files(sysroot_path, files).context("Querying RPM metadata")?;
489+
write_update_metadata(sysroot_path, self, &meta)?;
490+
491+
Ok(Some(true))
492+
}
493+
457494
fn query_update(&self, sysroot: &openat::Dir) -> Result<Option<ContentMetadata>> {
458495
get_component_update(sysroot, self)
459496
}

0 commit comments

Comments
 (0)