lanzatool: copy image to esp output dir

This commit is contained in:
nikstur 2022-11-23 17:26:56 +01:00
parent 5dbb8e7452
commit 24803a04a2
3 changed files with 15 additions and 5 deletions

View File

@ -5,18 +5,23 @@ pub struct EspPaths {
pub nixos: PathBuf, pub nixos: PathBuf,
pub kernel: PathBuf, pub kernel: PathBuf,
pub initrd: PathBuf, pub initrd: PathBuf,
pub linux: PathBuf,
pub lanzaboote_image: PathBuf,
} }
impl EspPaths { impl EspPaths {
pub fn new(esp: &str) -> Self { pub fn new(esp: &str) -> Self {
let esp = Path::new(esp); let esp = Path::new(esp);
let esp_nixos = esp.join("EFI/nixos"); let esp_nixos = esp.join("EFI/nixos");
let esp_linux = esp.join("EFI/Linux");
Self { Self {
esp: esp.to_owned(), esp: esp.to_owned(),
nixos: esp_nixos.clone(), nixos: esp_nixos.clone(),
kernel: esp_nixos.join("kernel"), kernel: esp_nixos.join("kernel"),
initrd: esp_nixos.join("initrd"), initrd: esp_nixos.join("initrd"),
linux: esp_linux.clone(),
lanzaboote_image: esp_linux.join("lanzaboote-image.efi"),
} }
} }
} }

View File

@ -14,7 +14,7 @@ pub fn install(_: &Path, bootspec: &Path, lanzaboote_bin: &Path) -> Result<()> {
let esp_paths = EspPaths::new(&bootspec_doc.v1.extension.esp); let esp_paths = EspPaths::new(&bootspec_doc.v1.extension.esp);
stub::assemble( let lanzaboote_image = stub::assemble(
lanzaboote_bin, lanzaboote_bin,
&bootspec_doc.v1.extension.os_release, &bootspec_doc.v1.extension.os_release,
&bootspec_doc.v1.kernel_params, &bootspec_doc.v1.kernel_params,
@ -27,6 +27,9 @@ pub fn install(_: &Path, bootspec: &Path, lanzaboote_bin: &Path) -> Result<()> {
fs::create_dir_all(&esp_paths.nixos)?; fs::create_dir_all(&esp_paths.nixos)?;
fs::copy(bootspec_doc.v1.kernel, esp_paths.kernel)?; fs::copy(bootspec_doc.v1.kernel, esp_paths.kernel)?;
fs::copy(bootspec_doc.v1.initrd, esp_paths.initrd)?; fs::copy(bootspec_doc.v1.initrd, esp_paths.initrd)?;
fs::create_dir_all(&esp_paths.linux)?;
fs::copy(lanzaboote_image, esp_paths.lanzaboote_image)?;
// install_systemd_boot(bootctl, &esp)?; // install_systemd_boot(bootctl, &esp)?;
Ok(()) Ok(())

View File

@ -1,6 +1,6 @@
use std::fs; use std::fs;
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
use std::path::Path; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use anyhow::Result; use anyhow::Result;
@ -12,7 +12,7 @@ pub fn assemble(
kernel_cmdline: &[String], kernel_cmdline: &[String],
kernel_path: &Path, kernel_path: &Path,
initrd_path: &Path, initrd_path: &Path,
) -> Result<()> { ) -> Result<PathBuf> {
// objcopy copies files into the PE binary. That's why we have to write the contents // objcopy copies files into the PE binary. That's why we have to write the contents
// of some bootspec properties to disk // of some bootspec properties to disk
let kernel_cmdline_file = Path::new("/tmp/kernel_cmdline"); let kernel_cmdline_file = Path::new("/tmp/kernel_cmdline");
@ -46,6 +46,8 @@ pub fn assemble(
let initrd_path_offs = kernel_cmdline_offs + file_size(kernel_cmdline_file)?; let initrd_path_offs = kernel_cmdline_offs + file_size(kernel_cmdline_file)?;
let kernel_path_offs = initrd_path_offs + file_size(initrd_path_file)?; let kernel_path_offs = initrd_path_offs + file_size(initrd_path_file)?;
let lanzaboote_image = PathBuf::from("/tmp/lanzaboote-image.efi");
let args = vec![ let args = vec![
String::from("--add-section"), String::from("--add-section"),
format!(".osrel={}", path_to_string(os_release)), format!(".osrel={}", path_to_string(os_release)),
@ -64,7 +66,7 @@ pub fn assemble(
String::from("--change-section-vma"), String::from("--change-section-vma"),
format!(".kernelp={:#x}", kernel_path_offs), format!(".kernelp={:#x}", kernel_path_offs),
path_to_string(lanzaboote_bin), path_to_string(lanzaboote_bin),
String::from("lanzaboote-image.efi"), path_to_string(&lanzaboote_image),
]; ];
let status = Command::new("objcopy").args(&args).status()?; let status = Command::new("objcopy").args(&args).status()?;
@ -72,7 +74,7 @@ pub fn assemble(
return Err(anyhow::anyhow!("Failed to build stub with args `{:?}`", &args).into()); return Err(anyhow::anyhow!("Failed to build stub with args `{:?}`", &args).into());
} }
Ok(()) Ok(lanzaboote_image)
} }
// All Linux file paths should be convertable to strings // All Linux file paths should be convertable to strings