From a2a37146ff2e4ef00c590cc8fafd00846ad899e9 Mon Sep 17 00:00:00 2001 From: Matthew Leach Date: Tue, 6 Jan 2026 21:57:29 +0000 Subject: [PATCH] main: init: add arg init option Add a new option `--init-arg` which allows arguments to be passed to init when invoked by the kernel. This allows the `-i` parameter to be passed through to bash such that it will be started in interactive mode. --- scripts/qemu-runner.sh | 6 +++--- src/main.rs | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/qemu-runner.sh b/scripts/qemu-runner.sh index bfb1a9d..96a2ee5 100755 --- a/scripts/qemu-runner.sh +++ b/scripts/qemu-runner.sh @@ -10,9 +10,9 @@ if [ $# -lt 1 ]; then fi if [ -n "$2" ]; then - init_script="$2" + append_args="--init=$2" else - init_script="/bin/bash" + append_args="--init=/bin/bash --init-arg=-i" fi @@ -23,4 +23,4 @@ bin="${elf%.elf}.bin" # Convert to binary format aarch64-none-elf-objcopy -O binary "$elf" "$bin" -qemu-system-aarch64 -M virt,gic-version=3 -initrd moss.img -cpu cortex-a72 -m 2G -smp 4 -nographic -s -kernel "$bin" -append "--init=$init_script --rootfs=ext4fs --automount=/dev,devfs --automount=/tmp,tmpfs --automount=/proc,procfs" +qemu-system-aarch64 -M virt,gic-version=3 -initrd moss.img -cpu cortex-a72 -m 2G -smp 4 -nographic -s -kernel "$bin" -append "$append_args --rootfs=ext4fs --automount=/dev,devfs --automount=/tmp,tmpfs --automount=/proc,procfs" diff --git a/src/main.rs b/src/main.rs index 1e7eed6..0d642db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,7 +67,7 @@ fn on_panic(info: &PanicInfo) -> ! { ArchImpl::power_off(); } -async fn launch_init(opts: KOptions) { +async fn launch_init(mut opts: KOptions) { let init = opts .init .unwrap_or_else(|| panic!("No init specified in kernel command line")); @@ -163,7 +163,11 @@ async fn launch_init(opts: KOptions) { drop(task); - process::exec::kernel_exec(inode, vec![init.as_str().to_string()], vec![]) + let mut init_args = vec![init.as_str().to_string()]; + + init_args.append(&mut opts.init_args); + + process::exec::kernel_exec(inode, init_args, vec![]) .await .expect("Could not launch init process"); } @@ -172,6 +176,7 @@ struct KOptions { init: Option, root_fs: Option, automounts: Vec<(PathBuf, String)>, + init_args: Vec, } fn parse_args(args: &str) -> KOptions { @@ -179,6 +184,7 @@ fn parse_args(args: &str) -> KOptions { init: None, root_fs: None, automounts: Vec::new(), + init_args: Vec::new(), }; let mut opts = Options::new(args.split(" ")); @@ -187,6 +193,7 @@ fn parse_args(args: &str) -> KOptions { match opts.next_opt() { Ok(Some(arg)) => match arg { Opt::Long("init") => kopts.init = Some(PathBuf::from(opts.value().unwrap())), + Opt::Long("init-arg") => kopts.init_args.push(opts.value().unwrap().to_string()), Opt::Long("rootfs") => kopts.root_fs = Some(opts.value().unwrap().to_string()), Opt::Long("automount") => { let string = opts.value().unwrap();