mirror of
https://github.com/hexagonal-sun/moss-kernel.git
synced 2026-01-29 16:41:43 -05:00
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:
committed by
Ashwin Naren
parent
9753639255
commit
a2a37146ff
@@ -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"
|
||||
|
||||
11
src/main.rs
11
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<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();
|
||||
|
||||
Reference in New Issue
Block a user