tool: implement general architecture support - for aarch64, x86 for now

This commit is contained in:
Raito Bezarius 2023-04-25 01:53:46 +02:00 committed by nikstur
parent 4521ae21fc
commit 7acb1b218a
2 changed files with 46 additions and 3 deletions

View File

@ -3,10 +3,46 @@ use std::{
path::{Path, PathBuf},
};
use anyhow::{Context, Result};
use anyhow::{Context, Result, bail};
use crate::generation::Generation;
/// Supported system
#[allow(dead_code)]
#[non_exhaustive]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum Architecture {
X86,
AArch64,
}
impl System {
pub fn systemd_filename(&self) -> &Path {
Path::new(match self {
Self::X86 => "systemd-bootx64.efi",
Self::AArch64 => "systemd-bootaa64.efi"
})
}
pub fn efi_fallback_filename(&self) -> &Path {
Path::new(match self {
Self::X86 => "BOOTX64.EFI",
Self::AArch64 => "BOOTAA64.EFI",
})
}
}
impl Architecture {
/// Converts from a NixOS system double to a supported system
pub fn from_nixos_system(system_double: &str) -> Result<Self> {
Ok(match system_double {
"x86_64-linux" => Self::X86,
"aarch64-linux" => Self::AArch64,
_ => bail!("Unsupported NixOS system double: {}, please open an issue or a PR if you think this should be supported.", system_double)
})
}
}
/// Generic ESP paths which can be specific to a bootloader
pub trait EspPaths<const N: usize> {
/// Build an ESP path structure out of the ESP root directory
@ -35,6 +71,12 @@ impl EspGenerationPaths {
generation: &Generation,
) -> Result<Self> {
let bootspec = &generation.spec.bootspec.bootspec;
let bootspec_system: Architecture = Architecture::from_nixos_system(&bootspec.system)?;
assert_eq!(
system, bootspec_system,
"Bootspec's system differs from provided target system, unsupported usecase!"
);
Ok(Self {
kernel: esp_paths

View File

@ -12,7 +12,7 @@ use tempfile::TempDir;
use crate::esp::SystemdEspPaths;
use crate::version::SystemdVersion;
use lanzaboote_tool::esp::{EspGenerationPaths, EspPaths};
use lanzaboote_tool::esp::{EspGenerationPaths, EspPaths, Architecture};
use lanzaboote_tool::gc::Roots;
use lanzaboote_tool::generation::{Generation, GenerationLink};
use lanzaboote_tool::os_release::OsRelease;
@ -335,7 +335,8 @@ impl Installer {
fn install_systemd_boot(&self) -> Result<()> {
let systemd_boot = self
.systemd
.join("lib/systemd/boot/efi/systemd-bootx64.efi");
.join("lib/systemd/boot/efi")
.join(self.arch.systemd_filename());
let paths = [
(&systemd_boot, &self.esp_paths.efi_fallback),