From 7acb1b218a58c4dcec00f636f2f7a080d7b89d0a Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Tue, 25 Apr 2023 01:53:46 +0200 Subject: [PATCH] tool: implement general architecture support - for aarch64, x86 for now --- rust/tool/shared/src/esp.rs | 44 +++++++++++++++++++++++++++++++- rust/tool/systemd/src/install.rs | 5 ++-- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/rust/tool/shared/src/esp.rs b/rust/tool/shared/src/esp.rs index 27cd071..3087d4c 100644 --- a/rust/tool/shared/src/esp.rs +++ b/rust/tool/shared/src/esp.rs @@ -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 { + 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 { /// Build an ESP path structure out of the ESP root directory @@ -35,6 +71,12 @@ impl EspGenerationPaths { generation: &Generation, ) -> Result { 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 diff --git a/rust/tool/systemd/src/install.rs b/rust/tool/systemd/src/install.rs index 789cb3f..36c528a 100644 --- a/rust/tool/systemd/src/install.rs +++ b/rust/tool/systemd/src/install.rs @@ -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),