Skip to content
Snippets Groups Projects
Commit cbdea61a authored by Ivan Tan's avatar Ivan Tan
Browse files

add option for variable size of EFI system partition

parent c5335d4a
No related branches found
No related tags found
1 merge request!26add option for variable size of EFI system partition
...@@ -11,7 +11,7 @@ extern crate toml; ...@@ -11,7 +11,7 @@ extern crate toml;
use pkgar::{PackageHead, ext::EntryExt}; use pkgar::{PackageHead, ext::EntryExt};
use pkgar_core::PackageSrc; use pkgar_core::PackageSrc;
use pkgar_keys::PublicKeyFile; use pkgar_keys::PublicKeyFile;
use redox_installer::{Config, with_whole_disk}; use redox_installer::{Config, with_whole_disk, DiskOption};
use std::{ use std::{
ffi::OsStr, ffi::OsStr,
fs, fs,
...@@ -302,7 +302,13 @@ fn main() { ...@@ -302,7 +302,13 @@ fn main() {
} }
}; };
let res = with_whole_disk(&disk_path, &bootloader_bios, &bootloader_efi, password_opt.as_ref().map(|x| x.as_bytes()), |mount_path| -> Result<(), failure::Error> { let disk_option = DiskOption {
bootloader_bios: &bootloader_bios,
bootloader_efi: &bootloader_efi,
password_opt: password_opt.as_ref().map(|x| x.as_bytes()),
efi_partition_size: None,
};
let res = with_whole_disk(&disk_path, &disk_option, |mount_path| -> Result<(), failure::Error> {
let mut config: Config = { let mut config: Config = {
let path = root_path.join("filesystem.toml"); let path = root_path.join("filesystem.toml");
match fs::read_to_string(&path) { match fs::read_to_string(&path) {
......
...@@ -3,4 +3,5 @@ pub struct GeneralConfig { ...@@ -3,4 +3,5 @@ pub struct GeneralConfig {
pub prompt: bool, pub prompt: bool,
// Allow config to specify cookbook recipe or binary package as default // Allow config to specify cookbook recipe or binary package as default
pub repo_binary: Option<bool>, pub repo_binary: Option<bool>,
pub efi_partition_size: Option<u32>, //MiB
} }
...@@ -38,6 +38,13 @@ use std::{ ...@@ -38,6 +38,13 @@ use std::{
pub(crate) type Result<T> = std::result::Result<T, Error>; pub(crate) type Result<T> = std::result::Result<T, Error>;
pub struct DiskOption<'a> {
pub bootloader_bios: &'a [u8],
pub bootloader_efi: &'a [u8],
pub password_opt: Option<&'a [u8]>,
pub efi_partition_size: Option<u32>, //MiB
}
const REMOTE: &'static str = "https://static.redox-os.org/pkg"; const REMOTE: &'static str = "https://static.redox-os.org/pkg";
fn get_target() -> String { fn get_target() -> String {
...@@ -353,7 +360,7 @@ pub fn fetch_bootloaders<S: AsRef<str>>(config: &Config, cookbook: Option<S>, li ...@@ -353,7 +360,7 @@ pub fn fetch_bootloaders<S: AsRef<str>>(config: &Config, cookbook: Option<S>, li
} }
//TODO: make bootloaders use Option, dynamically create BIOS and EFI partitions //TODO: make bootloaders use Option, dynamically create BIOS and EFI partitions
pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader_efi: &[u8], password_opt: Option<&[u8]>, callback: F) pub fn with_whole_disk<P, F, T>(disk_path: P, disk_option: &DiskOption, callback: F)
-> Result<T> where -> Result<T> where
P: AsRef<Path>, P: AsRef<Path>,
F: FnOnce(&Path) -> Result<T> F: FnOnce(&Path) -> Result<T>
...@@ -393,7 +400,8 @@ pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader ...@@ -393,7 +400,8 @@ pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader
// Second megabyte of the disk is reserved for EFI partition // Second megabyte of the disk is reserved for EFI partition
let efi_start = bios_end + 1; let efi_start = bios_end + 1;
let efi_end = efi_start + (mibi / block_size) - 1; let efi_size = if let Some(size) = disk_option.efi_partition_size { size as u64 } else { 1 };
let efi_end = efi_start + (efi_size * mibi / block_size) - 1;
// The rest of the disk is RedoxFS, reserving the GPT table mirror at the end of disk // The rest of the disk is RedoxFS, reserving the GPT table mirror at the end of disk
let redoxfs_start = efi_end + 1; let redoxfs_start = efi_end + 1;
...@@ -402,9 +410,9 @@ pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader ...@@ -402,9 +410,9 @@ pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader
// Format and install BIOS partition // Format and install BIOS partition
{ {
// Write BIOS bootloader to disk // Write BIOS bootloader to disk
eprintln!("Write bootloader with size {:#x}", bootloader_bios.len()); eprintln!("Write bootloader with size {:#x}", disk_option.bootloader_bios.len());
disk_file.seek(SeekFrom::Start(0))?; disk_file.seek(SeekFrom::Start(0))?;
disk_file.write_all(&bootloader_bios)?; disk_file.write_all(&disk_option.bootloader_bios)?;
// Replace MBR tables with protective MBR // Replace MBR tables with protective MBR
let mbr_blocks = ((disk_size + block_size - 1) / block_size) - 1; let mbr_blocks = ((disk_size + block_size - 1) / block_size) - 1;
...@@ -487,11 +495,11 @@ pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader ...@@ -487,11 +495,11 @@ pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader
let efi_dir = root_dir.open_dir("EFI")?; let efi_dir = root_dir.open_dir("EFI")?;
efi_dir.create_dir("BOOT")?; efi_dir.create_dir("BOOT")?;
eprintln!("Writing EFI/BOOT/{} file with size {:#x}", bootloader_efi_name, bootloader_efi.len()); eprintln!("Writing EFI/BOOT/{} file with size {:#x}", bootloader_efi_name, disk_option.bootloader_efi.len());
let boot_dir = efi_dir.open_dir("BOOT")?; let boot_dir = efi_dir.open_dir("BOOT")?;
let mut file = boot_dir.create_file(bootloader_efi_name)?; let mut file = boot_dir.create_file(bootloader_efi_name)?;
file.truncate()?; file.truncate()?;
file.write_all(&bootloader_efi)?; file.write_all(&disk_option.bootloader_efi)?;
} }
// Format and install RedoxFS partition // Format and install RedoxFS partition
...@@ -503,7 +511,7 @@ pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader ...@@ -503,7 +511,7 @@ pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader
)?); )?);
with_redoxfs( with_redoxfs(
disk_redoxfs, disk_redoxfs,
password_opt, disk_option.password_opt,
callback callback
) )
} }
...@@ -519,7 +527,13 @@ pub fn install<P, S>(config: Config, output: P, cookbook: Option<S>, live: bool) ...@@ -519,7 +527,13 @@ pub fn install<P, S>(config: Config, output: P, cookbook: Option<S>, live: bool)
install_dir(config, output, cookbook) install_dir(config, output, cookbook)
} else { } else {
let (bootloader_bios, bootloader_efi) = fetch_bootloaders(&config, cookbook.as_ref(), live)?; let (bootloader_bios, bootloader_efi) = fetch_bootloaders(&config, cookbook.as_ref(), live)?;
with_whole_disk(output, &bootloader_bios, &bootloader_efi, None, let disk_option = DiskOption {
bootloader_bios: &bootloader_bios,
bootloader_efi: &bootloader_efi,
password_opt: None,
efi_partition_size: config.general.efi_partition_size,
};
with_whole_disk(output, &disk_option,
move |mount_path| { move |mount_path| {
install_dir(config, mount_path, cookbook) install_dir(config, mount_path, cookbook)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment