From 346d3a91667bfd05e65091ca6239481aeb313cdd Mon Sep 17 00:00:00 2001 From: TheOddGarlic Date: Thu, 18 Aug 2022 12:16:37 +0300 Subject: [PATCH] repbuild: generate disk image with limine --- .gitignore | 4 +- ableos/.cargo/config.toml | 1 - ableos/Cargo.toml | 46 ----- base/README.md | 4 + base/boot/limine.cfg | 17 ++ base/home/able/bins/aos_test.wasm | Bin 0 -> 739 bytes base/home/able/bins/weealloc_test.wasm | Bin 0 -> 2528 bytes base/home/able/configs/qwerty.keymap | 252 +++++++++++++++++++++++ base/home/able/kernel.md | 4 + base/home/able/layout.txt | 14 ++ repbuild/src/main.rs | 263 ++++++++++++++++++++++++- sfdisk-config | 1 + 12 files changed, 555 insertions(+), 51 deletions(-) create mode 100644 base/README.md create mode 100644 base/boot/limine.cfg create mode 100755 base/home/able/bins/aos_test.wasm create mode 100755 base/home/able/bins/weealloc_test.wasm create mode 100644 base/home/able/configs/qwerty.keymap create mode 100644 base/home/able/kernel.md create mode 100644 base/home/able/layout.txt create mode 100644 sfdisk-config diff --git a/.gitignore b/.gitignore index 32fa216..8a4757c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ -userland/root_fs/mnt/ target/ .gdb_history !*/.gitkeep __pycache__/ debug.log +/disk/ +/limine/ +/disk.img diff --git a/ableos/.cargo/config.toml b/ableos/.cargo/config.toml index b747c1c..7b397ba 100644 --- a/ableos/.cargo/config.toml +++ b/ableos/.cargo/config.toml @@ -8,7 +8,6 @@ build-std-features = ["compiler-builtins-mem"] [target.'cfg(target_arch = "x86_64")'] rustflags = ["-C", "target-feature=+rdrand"] -runner = "bootimage runner" [target.riscv64gc-unknown-none-elf] rustflags = "-C link-arg=-Tableos/src/arch/riscv/virt.lds" diff --git a/ableos/Cargo.toml b/ableos/Cargo.toml index 5c0639f..9536237 100644 --- a/ableos/Cargo.toml +++ b/ableos/Cargo.toml @@ -8,52 +8,6 @@ version = "0.1.1" panic = "abort" [package.metadata.bootimage] -run-command = [ - "qemu-system-x86_64", - - "-device", - "piix4-ide,id=ide", - - "-drive", - "file={},format=raw,if=none,id=disk", - - "-device", - "ide-hd,drive=disk,bus=ide.0" -] -run-args = [ - # "--nodefaults", - "-cpu", - "Broadwell-v3", - "-m", - "4G", - "-serial", - "stdio", - "-smp", - "cores=2", - - - "-soundhw", - "pcspk", - - - # "-device", - # "VGA", - # "-device", - # "virtio-gpu-pci", - - "-device", - "vmware-svga", - - "-device", - "sb16", - - - # "-machine", "pcspk-audiodev=0", - - # "-qmp", - # "unix:../qmp-sock,server,nowait", -] - test-args = [ "-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", diff --git a/base/README.md b/base/README.md new file mode 100644 index 0000000..c251711 --- /dev/null +++ b/base/README.md @@ -0,0 +1,4 @@ +# Base Root Filesystem + +This is the base root filesystem for ableOS. It's used by tepbuild while +building the disk image. diff --git a/base/boot/limine.cfg b/base/boot/limine.cfg new file mode 100644 index 0000000..2229358 --- /dev/null +++ b/base/boot/limine.cfg @@ -0,0 +1,17 @@ +${ABLEOS_KERNEL}=boot:///boot/kernel +# TODO: Make a boot background image for ableOS +# ${WALLPAPER_PATH}=boot:///boot/bg.bmp + +DEFAULT_ENTRY=1 +TIMEOUT=3 +VERBOSE=yes + +# Terminal related settings +# TERM_WALLPAPER=${WALLPAPER_PATH} +TERM_BACKDROP=008080 + +:ableOS + COMMENT=Default ableOS boot entry. + PROTOCOL=limine + KERNEL_PATH=${ABLEOS_KERNEL} + KERNEL_CMDLINE= diff --git a/base/home/able/bins/aos_test.wasm b/base/home/able/bins/aos_test.wasm new file mode 100755 index 0000000000000000000000000000000000000000..b9350d9a61d55856c1c45612a2b5c3915eefc943 GIT binary patch literal 739 zcmY+CF^|(Q6vyAQo3_M380iEBArT!&Y;@vIV!}5wvb(;<+@&OGX)LBz+TT!TWVroMr5{^RaV{1x%Xe!Iug&~4M!3JUYnT3{Ep+*Rk>OII)PwHm}@y7Vm89zGs-oaT1=T5juqRl|`K+$c1KZrp1_z_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jFJZ*c}8IBGCvV4?{cRp>zvjBr~cw==0ok%Te?LPP#rWCbY0+~FLee{2QoUr zD&>*qUCk!Kja3mV?Td<;-ke{_M&YeIl_$UubjYM##m^ z$pR9xXUUU=#fZ5gXmdi$bA?D0UO_hj#{d;#p`Z{Bq>pthVuw9?26D7rpd#2(71GjK znnA*~+29v<_RH#G~84W#@ihh>g#kHdPOLw84CmFcULK4b}F#gRU=%yab7 zVx|x5?$ZaB4F)y%29*964a&vN?#{`2Ucr+4|Ej33@Dmc#N`0gIpide3vN0;|NTu>J*C_;)J+ literal 0 HcmV?d00001 diff --git a/base/home/able/configs/qwerty.keymap b/base/home/able/configs/qwerty.keymap new file mode 100644 index 0000000..95db614 --- /dev/null +++ b/base/home/able/configs/qwerty.keymap @@ -0,0 +1,252 @@ +# Able doesn't have a full keyboard +0-NONE +1- +2- +3-BACKSPACE +4- +5- +6- +7- +8- +9-TAB +10- +11- +12- +13-ENTER +14- +15- +16-SHIFT +17-CONTROL +18-ALT +19-PAUSE +20-CAPS_LOCK +21- +22- +23- +24- +25- +26- +27- +28- +29- +30- +31- +32-SPACE +33-PAGE_UP +34-PAGE_DOWN +35-END +36-HOME +37-ARROW_LEFT +38-ARROW_UP +39-ARROW_RIGHT +40-ARROW_DOWN +41- +42- +43- +44- +45-INSERT +46-DELETE +47- +48-0 +49-1 +50-2 +51-3 +52-4 +53-5 +54-6 +55-7 +56-8 +57-9 +58- +59-SEMICOLON +60- +61-EQUAL +62- +63- +64- +65-a +66-b +67-c +68-d +69-e +70-f +71-g +72-h +73-i +74-j +75-k +76-l +77-m +78-n +79-o +80-p +81-q +82-r +83-s +84-t +85-u +86-v +87-w +88-x +89-y +90-z +91- +92- +93- +94- +95- +96- +97- +98- +99- +100- +101- +102- +103- +106- +107- +108- +109- +110- +111- +112-FUNCTION_1 +113-FUNCTION_2 +114-FUNCTION_3 +115-FUNCTION_4 +116-FUNCTION_5 +117-FUNCTION_6 +118-FUNCTION_7 +119-FUNCTION_8 +120-FUNCTION_9 +121-FUNCTION_10 +122-FUNCTION_11 +123-FUNCTION_12 +124- +125- +126- +127- +128- +129- +130- +131- +132- +134- +135- +136- +137- +138- +139- +140- +141- +142- +143- +145-SCROLL_LOCK +146- +147- +148- +149- +150- +151- +152- +153- +154- +155- +156- +157- +158- +159- +160- +161- +162- +163- +164- +165- +166- +167- +168- +169- +170- +171- +172- +173-MINUS +174- +175- +176- +177- +178- +179- +180- +181- +182- +183- +184- +185- +186- +187- +188-COMMA +189- +190-PERIOD +191-FORWARD_SLASH +192-GRAVE +193- +194- +195- +196- +197- +198- +199- +200- +201- +202- +203- +204- +205- +206- +207- +208- +209- +210- +211- +212- +213- +214- +215- +216- +218- +219-BRACKET_LEFT +220-BACK_SLASH +221-BRACKET_RIGHT +222-QUOTE +223- +224- +225- +226- +227- +228- +229- +230- +231- +232- +233- +234- +235- +236- +237- +238- +239- +240- +241- +242- +243- +244- +245- +246- +247- +248- +249- +250- +251- +252- +253- +254- +255- diff --git a/base/home/able/kernel.md b/base/home/able/kernel.md new file mode 100644 index 0000000..b4b1e54 --- /dev/null +++ b/base/home/able/kernel.md @@ -0,0 +1,4 @@ +Hi there :>$RED$ +hi +$GREEN$ +hi 3 diff --git a/base/home/able/layout.txt b/base/home/able/layout.txt new file mode 100644 index 0000000..73c3402 --- /dev/null +++ b/base/home/able/layout.txt @@ -0,0 +1,14 @@ +boot/ +├─ kernel.img +home/ +├─ able/ +│ ├─ bins/ +│ ├─ config/ +│ │ ├─ able_edit/ +│ │ │ ├─ config.toml +│ ├─ irl_pic.png +│ ├─ password.txt +system/ +├─ bins/ +├─ configs/ +│ ├─ kernel.toml \ No newline at end of file diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index bc4d571..990e469 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -5,7 +5,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -use std::{fs, process::Command}; +use std::{fs::{self, File}, process::Command}; use colored::*; @@ -15,6 +15,7 @@ struct Options { } enum Subcommand { + BuildImage, Doc, Help, Run, @@ -27,6 +28,7 @@ enum Subcommand { impl Subcommand { fn from_str>(str: S) -> Subcommand { match str.as_ref() { + "build-image" => Subcommand::BuildImage, "doc" => Subcommand::Doc, "help" => Subcommand::Help, "run" | "r" => Subcommand::Run, @@ -48,6 +50,142 @@ fn main() { let options = options(); match options.subcommand { + Subcommand::BuildImage => { + let machine_text = options.arguments.get(0).cloned().unwrap_or_default(); + + match machine(machine_text) { + MachineType::X86_64 => { + // Cleanup + // NOTE: we are not unwrapping these, as we don't want this to fail if they + // don't exist yet, probably not the best idea tho. + // FIXME: figure out a better way to ignore errors about these not existing + #[allow(unused_must_use)] + { + fs::remove_dir_all("./limine"); + fs::remove_dir_all("./disk"); + fs::remove_file("./disk.img"); + } + + // Build ableOS in release mode + Command::new("cargo") + .args(["build", "--release"]) + .current_dir(fs::canonicalize("./ableos").unwrap()) + .status() + .unwrap(); + + // Create disk directory + fs::create_dir("./disk").unwrap(); + + // Clone limine 3.X binaries + Command::new("git") + .arg("clone") + .arg("https://github.com/limine-bootloader/limine.git") + .arg("--branch=v3.0-branch-binary") + .arg("--depth=1") + .status() + .unwrap(); + + println!("{}", "Building limine".bold()); + Command::new("make") + .args(["-C", "limine"]) + .status() + .unwrap(); + + println!("{}", "Allocating new disk image".bold()); + Command::new("dd") + .args(["if=/dev/zero", "of=disk.img", "count=1", "bs=256MiB"]) + .status() + .unwrap(); + + println!("{}", "Partitioning disk image".bold()); + Command::new("sudo") + .args(["sfdisk", "disk.img"]) + .stdin(File::open("./sfdisk-config").unwrap()) + .status() + .unwrap(); + + // Setup loopback device for disk.img, with partitions + // FIXME: don't assume that /dev/loop0 is empty + Command::new("sudo") + .arg("losetup") + .args(["-P", "/dev/loop0", "disk.img"]) + .status() + .unwrap(); + + println!("{}", "Creating ext2 filesystem on /dev/loop0p1".bold()); + Command::new("sudo") + .arg("mkfs.ext2") + .arg("/dev/loop0p1") + .status() + .unwrap(); + + println!("{}", "Mounting filesystem".bold()); + Command::new("sudo") + .arg("mount") + .args(["/dev/loop0p1", "./disk"]) + .status() + .unwrap(); + + // copy ./base/* over to ./disk + Command::new("sudo") + .args(["sh", "-c"]) + .arg("cp -r ./base/* ./disk") + .status() + .unwrap(); + + // copy ./limine/limine.sys over to ./disk/boot + Command::new("sudo") + .arg("cp") + .args(["./limine/limine.sys", "./disk/boot"]) + .status() + .unwrap(); + + // copy the kernel over to ./disk/boot/kernel + Command::new("sudo") + .arg("cp") + .arg("./target/x86_64-ableos/release/ableos") + .arg("./disk/boot/kernel") + .status() + .unwrap(); + + // TODO: build the userspace programs and copy them over + + // unmount the fs + Command::new("sudo") + .arg("umount") + .arg("./disk") + .status() + .unwrap(); + + // remove the loopback device + Command::new("sudo") + .arg("losetup") + .args(["-d", "/dev/loop0"]) + .status() + .unwrap(); + + println!("{}", "Deploying limine".bold()); + Command::new("./limine/limine-deploy") + .arg("./disk.img") + .status() + .unwrap(); + } + MachineType::Unknown(unknown) => { + eprintln!( + "{}: unknown machine type `{}`", + "error".red().bold(), + unknown.bold(), + ); + eprintln!("expected one of x86_64, riscv64 or aarch64"); + } + _ => { + eprintln!( + "{}: build-image not implemented for this machine type", + "error".red().bold(), + ); + } + } + } Subcommand::Test => { Command::new("cargo") .args(["test", "--target=json_targets/x86_64-ableos.json"]) @@ -100,18 +238,137 @@ fn main() { match machine(machine_text) { MachineType::X86_64 if debug => { + // Build ableOS Command::new("cargo") - .args(["run", "--", "-S", "-gdb", "tcp:9000"]) + .arg("build") .current_dir(fs::canonicalize("./ableos").unwrap()) .status() .unwrap(); + + // Setup loopback device for disk.img, with partitions + // FIXME: don't do ths if running without changes + Command::new("sudo") + .arg("losetup") + .args(["-P", "/dev/loop0", "disk.img"]) + .status() + .unwrap(); + + // mount the root fs to ./disk + Command::new("sudo") + .arg("mount") + .args(["/dev/loop0p1", "./disk"]) + .status() + .unwrap(); + + // copy the kernel over to ./disk/boot/kernel + Command::new("sudo") + .arg("cp") + .arg("./target/x86_64-ableos/debug/ableos") + .arg("./disk/boot/kernel") + .status() + .unwrap(); + + // unmount the root fs + Command::new("sudo") + .arg("umount") + .arg("./disk") + .status() + .unwrap(); + + // remove loopback device + Command::new("sudo") + .arg("losetup") + .args(["-d", "/dev/loop0"]) + .status() + .unwrap(); + + // run qemu with "-S", "-gdb", "tcp:9000" + Command::new("qemu-system-x86_64") + .args(["-device", "piix4-ide,id=ide"]) + .arg("-drive") + .arg("file=./disk.img,format=raw,if=none,id=disk") + .args(["-device", "ide-hd,drive=disk,bus=ide.0"]) + // .arg("--nodefaults") + .args(["-cpu", "Broadwell-v3"]) + .args(["-m", "4G"]) + .args(["-serial", "stdio"]) + .args(["-smp", "cores=2"]) + .args(["-soundhw", "pcspk"]) + // .args(["-device", "VGA"]) + // .args(["-device", "virtio-gpu-pci"]) + .args(["-device", "vmware-svga"]) + .args(["-device", "sb16"]) + // .args(["-machine", "pcspk-audiodev=0"]) + // .args(["-qmp", "unix:../qmp-sock,server,nowait"]) + .args(["-S", "-gdb", "tcp:9000"]) + .status() + .unwrap(); } MachineType::X86_64 => { + // Build ableOS Command::new("cargo") - .args(["run", "--release"]) + .args(["build", "--release"]) .current_dir(fs::canonicalize("./ableos").unwrap()) .status() .unwrap(); + + // Setup loopback device for disk.img, with partitions + // FIXME: don't do ths if running without changes + Command::new("sudo") + .arg("losetup") + .args(["-P", "/dev/loop0", "disk.img"]) + .status() + .unwrap(); + + // mount the root fs to ./disk + Command::new("sudo") + .arg("mount") + .args(["/dev/loop0p1", "./disk"]) + .status() + .unwrap(); + + // copy the kernel over to ./disk/boot/kernel + Command::new("sudo") + .arg("cp") + .arg("./target/x86_64-ableos/release/ableos") + .arg("./disk/boot/kernel") + .status() + .unwrap(); + + // unmount the root fs + Command::new("sudo") + .arg("umount") + .arg("./disk") + .status() + .unwrap(); + + // remove loopback device + Command::new("sudo") + .arg("losetup") + .args(["-d", "/dev/loop0"]) + .status() + .unwrap(); + + // run qemu + Command::new("qemu-system-x86_64") + .args(["-device", "piix4-ide,id=ide"]) + .arg("-drive") + .arg("file=./disk.img,format=raw,if=none,id=disk") + .args(["-device", "ide-hd,drive=disk,bus=ide.0"]) + // .arg("--nodefaults") + .args(["-cpu", "Broadwell-v3"]) + .args(["-m", "4G"]) + .args(["-serial", "stdio"]) + .args(["-smp", "cores=2"]) + .args(["-soundhw", "pcspk"]) + // .args(["-device", "VGA"]) + // .args(["-device", "virtio-gpu-pci"]) + .args(["-device", "vmware-svga"]) + .args(["-device", "sb16"]) + // .args(["-machine", "pcspk-audiodev=0"]) + // .args(["-qmp", "unix:../qmp-sock,server,nowait"]) + .status() + .unwrap(); } MachineType::RiscV64 if debug => { eprintln!( diff --git a/sfdisk-config b/sfdisk-config new file mode 100644 index 0000000..8785fdb --- /dev/null +++ b/sfdisk-config @@ -0,0 +1 @@ +,,,-