tool: implement general architecture support - for aarch64, x86 for now
This commit is contained in:
parent
4521ae21fc
commit
7acb1b218a
|
@ -3,10 +3,46 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result, bail};
|
||||||
|
|
||||||
use crate::generation::Generation;
|
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
|
/// Generic ESP paths which can be specific to a bootloader
|
||||||
pub trait EspPaths<const N: usize> {
|
pub trait EspPaths<const N: usize> {
|
||||||
/// Build an ESP path structure out of the ESP root directory
|
/// Build an ESP path structure out of the ESP root directory
|
||||||
|
@ -35,6 +71,12 @@ impl EspGenerationPaths {
|
||||||
generation: &Generation,
|
generation: &Generation,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let bootspec = &generation.spec.bootspec.bootspec;
|
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 {
|
Ok(Self {
|
||||||
kernel: esp_paths
|
kernel: esp_paths
|
||||||
|
|
|
@ -12,7 +12,7 @@ use tempfile::TempDir;
|
||||||
|
|
||||||
use crate::esp::SystemdEspPaths;
|
use crate::esp::SystemdEspPaths;
|
||||||
use crate::version::SystemdVersion;
|
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::gc::Roots;
|
||||||
use lanzaboote_tool::generation::{Generation, GenerationLink};
|
use lanzaboote_tool::generation::{Generation, GenerationLink};
|
||||||
use lanzaboote_tool::os_release::OsRelease;
|
use lanzaboote_tool::os_release::OsRelease;
|
||||||
|
@ -335,7 +335,8 @@ impl Installer {
|
||||||
fn install_systemd_boot(&self) -> Result<()> {
|
fn install_systemd_boot(&self) -> Result<()> {
|
||||||
let systemd_boot = self
|
let systemd_boot = self
|
||||||
.systemd
|
.systemd
|
||||||
.join("lib/systemd/boot/efi/systemd-bootx64.efi");
|
.join("lib/systemd/boot/efi")
|
||||||
|
.join(self.arch.systemd_filename());
|
||||||
|
|
||||||
let paths = [
|
let paths = [
|
||||||
(&systemd_boot, &self.esp_paths.efi_fallback),
|
(&systemd_boot, &self.esp_paths.efi_fallback),
|
||||||
|
|
Loading…
Reference in New Issue