Allow embedding bootstrap code into the initfs blob

This may in the future allow booting using non-redox specific bootloaders.
This commit is contained in:
bjorn3
2024-03-10 19:28:09 +01:00
parent b9e856a4ab
commit ada6cfc973
3 changed files with 31 additions and 8 deletions
+1
View File
@@ -14,6 +14,7 @@ fn archive_and_read() -> Result<()> {
let args = self::archive::Args {
destination_path: Path::new("out.img"),
source: Path::new("data"),
bootstrap_code: None,
max_size: self::archive::DEFAULT_MAX_SIZE,
};
self::archive::archive(&args).context("failed to archive")?;
+22 -8
View File
@@ -355,8 +355,16 @@ pub struct Args<'a> {
pub destination_path: &'a Path,
pub max_size: u64,
pub source: &'a Path,
pub bootstrap_code: Option<&'a Path>,
}
pub fn archive(&Args { destination_path, max_size, source }: &Args) -> Result<()> {
pub fn archive(
&Args {
destination_path,
max_size,
source,
bootstrap_code,
}: &Args,
) -> Result<()> {
let previous_extension = destination_path.extension().map_or("", |ext| {
ext.to_str()
.expect("expected destination path to be valid UTF-8")
@@ -407,15 +415,21 @@ pub fn archive(&Args { destination_path, max_size, source }: &Args) -> Result<()
log::debug!("there are {} inodes", state.inode_count);
// NOTE: The header is always stored at offset zero.
let header_offset = bump_alloc(
&mut state,
std::mem::size_of::<initfs::Header>()
.try_into()
.expect("expected header size to fit"),
"allocate header",
)?;
let header_offset = bump_alloc(&mut state, 4096, "allocate header")?;
assert_eq!(header_offset, 0);
if let Some(bootstrap_code) = bootstrap_code {
allocate_and_write_file(
&mut state,
&File::open(bootstrap_code).with_context(|| {
anyhow!(
"failed to open bootstrap code file `{}`",
bootstrap_code.to_string_lossy(),
)
})?,
)?;
};
let inode_table_length = {
let inode_entry_size: u64 = std::mem::size_of::<initfs::InodeHeader>()
.try_into()
+8
View File
@@ -24,6 +24,11 @@ fn main() -> Result<()> {
.required(true)
.help("Specify the source directory to build the image from."),
)
.arg(
Arg::new("BOOTSTRAP_CODE")
.required(false)
.help("Specify the bootstrap ELF file to include in the image.")
)
.arg(
Arg::new("OUTPUT")
.required(true)
@@ -47,12 +52,15 @@ fn main() -> Result<()> {
.get_one::<String>("SOURCE")
.expect("expected the required arg SOURCE to exist");
let bootstrap_code = matches.get_one::<String>("BOOTSTRAP_CODE");
let destination = matches
.get_one::<String>("OUTPUT")
.expect("expected the required arg OUTPUT to exist");
let args = Args {
source: Path::new(source),
bootstrap_code: bootstrap_code.map(|bootstrap_code| Path::new(bootstrap_code)),
destination_path: Path::new(destination),
max_size,
};