1
0
Fork 0
forked from koniifer/ableos
ableos-framebuffer/repbuild/src/main.rs

157 lines
4.4 KiB
Rust
Raw Normal View History

2022-07-28 07:07:23 -05:00
use std::io::stdin;
use anyhow::{Error, Ok};
2021-11-16 22:52:17 -06:00
use clap::Parser;
2021-11-16 00:09:27 -06:00
2021-11-16 22:52:17 -06:00
#[derive(clap::Parser, Debug)]
2022-04-11 15:34:40 -05:00
// #[clap(version = clap::crate_version!(), author = clap::crate_authors!("\n"))]
2021-11-16 22:52:17 -06:00
/// Hello Remember this is a feature
2021-11-16 00:09:27 -06:00
enum Command {
2022-02-18 10:04:10 -06:00
Run {
#[clap(long, short)]
debug: bool,
2022-07-31 01:54:01 -05:00
#[clap(long, short)]
profile: bool,
2021-11-16 22:52:17 -06:00
2022-02-18 10:04:10 -06:00
#[clap(long, short, arg_enum)]
machine: Option<MachineType>,
},
2021-11-21 02:13:50 -06:00
2022-02-18 10:04:10 -06:00
Doc {
#[clap(long, short, arg_enum)]
machine: Option<MachineType>,
},
Mount {
#[clap(long, short)]
path: Option<String>,
},
Unmount {
#[clap(long, short)]
path: Option<String>,
},
2022-07-28 07:07:23 -05:00
MakeFS {},
2021-11-16 00:09:27 -06:00
}
2021-11-16 22:52:17 -06:00
#[derive(clap::ArgEnum, Debug, Clone)]
enum MachineType {
2022-02-18 10:04:10 -06:00
X86,
Riscv,
Arm,
2021-11-16 00:09:27 -06:00
}
fn main() -> anyhow::Result<()> {
2022-02-18 10:04:10 -06:00
let args = Command::parse();
2021-11-16 00:09:27 -06:00
2022-02-18 10:04:10 -06:00
match args {
2022-07-31 01:54:01 -05:00
Command::Run {
debug,
profile,
machine,
} => {
2022-02-18 10:04:10 -06:00
let _dir = xshell::pushd("./ableos");
2021-11-16 00:09:27 -06:00
2022-02-18 10:04:10 -06:00
let _debug_log: &[&str] = match debug {
true => &["-D", "debug.log"],
false => &[],
};
match machine.unwrap_or(MachineType::X86) {
MachineType::X86 => {
xshell::cmd!("cargo run --release").run()?;
2022-07-31 01:54:01 -05:00
if profile {
xshell::cmd!("python qprofiler.py --path=qmp-sock --filename=target/x86_64-ableos/release/ableos").run()?;
}
2022-02-18 10:04:10 -06:00
}
MachineType::Arm => {
2022-02-18 10:04:10 -06:00
xshell::cmd!("cargo build --release --target=json_targets/aarch64-ableos.json")
.run()?;
#[rustfmt::skip]
2022-07-31 01:54:01 -05:00
xshell::cmd!(
"qemu-system-aarch64
-machine virt
-m 1024M
2021-11-16 22:52:17 -06:00
-cpu cortex-a53
-kernel target/aarch64-ableos/release/ableos
-device virtio-keyboard
"
).run()?;
2022-02-18 10:04:10 -06:00
}
MachineType::Riscv => {
2022-02-18 10:04:10 -06:00
xshell::cmd!("cargo build --release --target=riscv64gc-unknown-none-elf")
.run()?;
#[rustfmt::skip]
2021-11-16 22:52:17 -06:00
xshell::cmd!(
"qemu-system-riscv64
2022-07-31 01:54:01 -05:00
-machine virt
-cpu rv64
-smp 8
-m 128M
-bios src/arch/riscv/firmwear/opensbi-riscv64-generic-fw_jump.bin
-kernel target/riscv64gc-unknown-none-elf/release/ableos
"
// -serial stdio
).run()?;
2022-02-18 10:04:10 -06:00
}
2021-11-16 22:52:17 -06:00
}
2022-02-18 10:04:10 -06:00
}
2021-11-21 02:13:50 -06:00
2022-02-18 10:04:10 -06:00
Command::Doc { machine } => {
let _dir = xshell::pushd("./ableos");
2021-11-21 02:13:50 -06:00
2022-02-18 10:04:10 -06:00
match machine.unwrap_or(MachineType::X86) {
MachineType::X86 => {
xshell::cmd!("cargo doc --open").run()?;
}
MachineType::Arm => {
2022-02-18 10:04:10 -06:00
xshell::cmd!("cargo doc --open --target=json_targets/aarch64-ableos.json")
.run()?;
}
MachineType::Riscv => {
2022-02-18 10:04:10 -06:00
xshell::cmd!("cargo doc --open --target=riscv64gc-unknown-none-elf").run()?;
}
2021-11-21 02:13:50 -06:00
}
2022-02-18 10:04:10 -06:00
}
Command::Mount { path } => {
let path = path.unwrap_or_else(|| "./userland/root_fs/mnt".to_string());
xshell::cmd!("sudo mount userland/root_fs/ext2.img {path}").run()?;
2022-04-11 15:34:40 -05:00
}
Command::Unmount { path } => {
let path = path.unwrap_or_else(|| "./userland/root_fs/mnt".to_string());
xshell::cmd!("sudo umount {path}").run()?;
2022-04-11 15:34:40 -05:00
}
2022-07-28 07:07:23 -05:00
Command::MakeFS {} => match make_fs() {
Result::Ok(_) => {}
Err(err) => println!("{}", err),
},
2022-02-18 10:04:10 -06:00
}
2021-11-16 00:09:27 -06:00
2022-02-18 10:04:10 -06:00
Ok(())
2021-11-16 00:09:27 -06:00
}
2022-07-28 07:07:23 -05:00
pub fn make_fs() -> Result<(), Error> {
xshell::cmd!("sh repbuild/assets/mkfs.sh").run()?;
println!("Make changes in root_fs");
let mut input = String::new();
println!("Press enter when ready:");
stdin().read_line(&mut input).unwrap();
// build
// xshell::cmd!("rm -rf root").run()?;
Ok(())
}
pub fn make_user(user: String) -> Result<(), Error> {
xshell::mkdir_p(user)?;
Ok(())
}