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.
This commit is contained in:
Matthew Leach
2026-01-06 21:57:29 +00:00
committed by Ashwin Naren
parent 9753639255
commit a2a37146ff
2 changed files with 12 additions and 5 deletions

View File

@@ -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"

View File

@@ -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<PathBuf>,
root_fs: Option<String>,
automounts: Vec<(PathBuf, String)>,
init_args: Vec<String>,
}
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();