Skip to content

Commit

Permalink
aa64: Minor fix for efi vendordir
Browse files Browse the repository at this point in the history
Minor fix for coreos/bootupd#633
  • Loading branch information
HuijingHei committed Mar 27, 2024
1 parent f361266 commit 5b8e7f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/efi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub(crate) const ESP_MOUNTS: &[&str] = &["boot/efi", "efi", "boot"];

/// The binary to change EFI boot ordering
const EFIBOOTMGR: &str = "efibootmgr";
#[cfg(target_arch = "aarch64")]
pub(crate) const SHIM: &str = "shimaa64.efi";

#[cfg(target_arch = "x86_64")]
pub(crate) const SHIM: &str = "shimx64.efi";

/// The ESP partition label on Fedora CoreOS derivatives
Expand Down Expand Up @@ -484,7 +488,7 @@ pub(crate) fn set_efi_current(device: &str, espdir: &openat::Dir, vendordir: &st
if espdir.exists(&shim)? {
anyhow::bail!("Failed to find {SHIM}");
}
let loader = format!("\\EFI\\{}\\shimx64.efi", vendordir);
let loader = format!("\\EFI\\{}\\{SHIM}", vendordir);
let st = Command::new(EFIBOOTMGR)
.args([
"--create",
Expand Down
12 changes: 7 additions & 5 deletions src/grubconfigs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use anyhow::{anyhow, Context, Result};
use fn_error_context::context;
use openat_ext::OpenatDirExt;

use crate::efi::SHIM;

/// The subdirectory of /boot we use
const GRUB2DIR: &str = "grub2";
const CONFIGDIR: &str = "/usr/lib/bootupd/grub2-static";
Expand All @@ -22,13 +24,13 @@ pub(crate) fn find_efi_vendordir(efidir: &openat::Dir) -> Result<PathBuf> {
let dir = efidir.sub_dir(d.file_name())?;
for entry in dir.list_dir(".")? {
let entry = entry?;
if entry.file_name() != super::efi::SHIM {
if entry.file_name() != SHIM {
continue;
}
return Ok(d.file_name().into());
}
}
anyhow::bail!("Failed to find EFI vendor dir")
anyhow::bail!("Failed to find EFI vendor dir that contains {SHIM}")
}

/// Install the static GRUB config files.
Expand Down Expand Up @@ -159,15 +161,15 @@ mod tests {

std::fs::write(efidir.join("dell").join("foo"), "foo data")?;
std::fs::write(efidir.join("fedora").join("grub.cfg"), "grub config")?;
std::fs::write(efidir.join("fedora").join("shimx64.efi"), "shim data")?;
std::fs::write(efidir.join("fedora").join(SHIM), "shim data")?;

assert!(td.exists("BOOT")?);
assert!(td.exists("dell/foo")?);
assert!(td.exists("fedora/grub.cfg")?);
assert!(td.exists("fedora/shimx64.efi")?);
assert!(td.exists(format!("fedora/{SHIM}"))?);
assert_eq!(find_efi_vendordir(&td)?.to_str(), Some("fedora"));

std::fs::remove_file(efidir.join("fedora").join("shimx64.efi"))?;
std::fs::remove_file(efidir.join("fedora").join(SHIM))?;
let x = find_efi_vendordir(&td);
assert_eq!(x.is_err(), true);
Ok(())
Expand Down

0 comments on commit 5b8e7f1

Please sign in to comment.