rework create-image to put inis objects into the detached swap region

This commit is contained in:
bunnie 2024-04-04 18:34:00 +08:00
parent eb1cb4a253
commit a662f5edcb

View file

@ -8,6 +8,7 @@ use std::fs::File;
use clap::{App, Arg}; use clap::{App, Arg};
use tools::elf::{read_minielf, read_program}; use tools::elf::{read_minielf, read_program};
use tools::swap_writer::SwapWriter;
use tools::tags::bflg::Bflg; use tools::tags::bflg::Bflg;
use tools::tags::inie::IniE; use tools::tags::inie::IniE;
use tools::tags::inif::IniF; use tools::tags::inif::IniF;
@ -166,6 +167,13 @@ fn main() {
.value_name("OFFSET:SIZE") .value_name("OFFSET:SIZE")
.help("Swap offset and size, in the form of [offset]:[size]; note: offset and size have platform-dependent interpretations") .help("Swap offset and size, in the form of [offset]:[size]; note: offset and size have platform-dependent interpretations")
) )
.arg(
Arg::with_name("swap-name")
.long("swap-name")
.takes_value(true)
.value_name("OUTPUT")
.help("Output file to store swap image data")
)
.arg( .arg(
Arg::with_name("debug") Arg::with_name("debug")
.short("d") .short("d")
@ -342,6 +350,7 @@ fn main() {
} }
let mut args = XousArguments::new(ram_config.offset, ram_config.size, ram_config.name); let mut args = XousArguments::new(ram_config.offset, ram_config.size, ram_config.name);
let mut swap_args: Option<XousArguments> = None;
if !ram_config.regions.is_empty() { if !ram_config.regions.is_empty() {
if let Some(s) = swap { if let Some(s) = swap {
@ -360,6 +369,7 @@ fn main() {
} }
// Note that other configurations don't split RAM, since the swap is provisioned directly // Note that other configurations don't split RAM, since the swap is provisioned directly
// in hardware, and thus, no post-processing is required. // in hardware, and thus, no post-processing is required.
swap_args = Some(XousArguments::new(s.offset, s.size, s.name));
args.add(s); args.add(s);
args.add(ram_config.regions); args.add(ram_config.regions);
@ -412,19 +422,23 @@ fn main() {
} }
if let Some(init_paths) = matches.values_of("inis") { if let Some(init_paths) = matches.values_of("inis") {
for init_path in init_paths { if let Some(ref mut sargs) = swap_args {
let program_name = std::path::Path::new(init_path); for init_path in init_paths {
process_names.set( let program_name = std::path::Path::new(init_path);
pid, process_names.set(
program_name pid,
.file_stem() program_name
.expect("program had no name") .file_stem()
.to_str() .expect("program had no name")
.expect("program name is not valid utf-8"), .to_str()
); .expect("program name is not valid utf-8"),
pid += 1; );
let init = read_minielf(init_path).expect("couldn't parse init file"); pid += 1;
args.add(IniS::new(init.entry_point, init.sections, init.program, init.alignment_offset)); let init = read_minielf(init_path).expect("couldn't parse init file");
sargs.add(IniS::new(init.entry_point, init.sections, init.program, init.alignment_offset));
}
} else {
println!("Warning: inis regions specified, but no swap region specified. Ignoring inis regions!");
} }
} }
@ -452,6 +466,18 @@ fn main() {
println!("Arguments: {}", args); println!("Arguments: {}", args);
if let Some(mut sargs) = swap_args {
let mut swap_buffer = SwapWriter::new();
sargs.write(&mut swap_buffer).expect("Couldn't write out swap args");
let swap_filename = matches.value_of("swap-name").expect("swap filename not present");
let sf = File::create(swap_filename)
.unwrap_or_else(|_| panic!("Couldn't create output file {}", swap_filename));
swap_buffer.encrypt_to(sf).expect("Couldn't flush swap buffer to disk");
println!("Swap arguments: {}", sargs);
println!("Swap data created in file {}", swap_filename);
}
println!("Runtime will require {} bytes to track memory allocations", ram_config.memory_required); println!("Runtime will require {} bytes to track memory allocations", ram_config.memory_required);
if let Some(s) = swap { if let Some(s) = swap {
println!("Runtime will also require {} bytes to track swap", s.size / 4096); println!("Runtime will also require {} bytes to track swap", s.size / 4096);