From e7b46f639c2f898ef5111c2c38423f74bc406ca9 Mon Sep 17 00:00:00 2001 From: able Date: Wed, 19 Jul 2023 10:55:58 -0500 Subject: [PATCH] SUBMODULE: Removed it temporarily --- .gitmodules | 5 -- kernel/.cargo/config.toml | 3 +- limine | 1 - repbuild/Cargo.toml | 2 +- repbuild/src/main.rs | 147 +++++++++++++++++--------------------- 5 files changed, 69 insertions(+), 89 deletions(-) delete mode 160000 limine diff --git a/.gitmodules b/.gitmodules index 9afcf066..e69de29b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +0,0 @@ -[submodule "limine"] - path = limine - url = https://github.com/limine-bootloader/limine.git - branch = v5.x-branch-binary - shallow = true diff --git a/kernel/.cargo/config.toml b/kernel/.cargo/config.toml index 8b608a11..5e82bd2d 100644 --- a/kernel/.cargo/config.toml +++ b/kernel/.cargo/config.toml @@ -3,8 +3,7 @@ build-std = ["core", "compiler_builtins", "alloc"] build-std-features = ["compiler-builtins-mem"] [build] -# target = "./targets/x86_64-ableos.json" -target = "./targets/aarch64-virt-ableos.json" +target = "./targets/x86_64-ableos.json" [target.'cfg(target_arch = "x86_64")'] rustflags = ["-C", "target-feature=+rdrand"] diff --git a/limine b/limine deleted file mode 160000 index 751e802e..00000000 --- a/limine +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 751e802e173392e8637759e2b3c96bbf59456f87 diff --git a/repbuild/Cargo.toml b/repbuild/Cargo.toml index 592ec4bc..edc3ad51 100644 --- a/repbuild/Cargo.toml +++ b/repbuild/Cargo.toml @@ -9,7 +9,7 @@ derive_more = "0.99" env_logger = "0.10" error-stack = "0.2" fatfs = "0.3" -log = "0.4" +log = "0.4" # remove me rpm = "0.11" # remove me zstd = "0.12" # remove me diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 0fbe9121..31abb4cb 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -2,17 +2,10 @@ use { derive_more::Display, error_stack::{bail, report, Context, IntoReport, Result, ResultExt}, fatfs::{FileSystem, FormatVolumeOptions, FsOptions, ReadWriteSeek}, - std::{ - fmt::Display, - fs::File, - io::{self, Write}, - path::Path, - process::Command, - }, + std::{fmt::Display, fs::File, io, path::Path, process::Command}, }; fn main() -> Result<(), Error> { - env_logger::init(); let mut args = std::env::args(); args.next(); @@ -33,7 +26,7 @@ fn main() -> Result<(), Error> { release = true; } else if arg == "rv64" || arg == "riscv64" || arg == "riscv64-virt" { target = Target::Riscv64Virt; - } else if arg == "aarch" || arg == "arm64" { + } else if arg == "arm64" || arg == "aarch64" || arg == "aarch64-virt" { target = Target::Aarch64; } else { return Err(report!(Error::InvalidSubCom)); @@ -50,7 +43,7 @@ fn main() -> Result<(), Error> { release = true; } else if arg == "rv64" || arg == "riscv64" || arg == "riscv64-virt" { target = Target::Riscv64Virt; - } else if arg == "aarch" || arg == "arm64" { + } else if arg == "arm64" || arg == "aarch64" || arg == "aarch64-virt" { target = Target::Aarch64; } else { return Err(report!(Error::InvalidSubCom)); @@ -145,8 +138,6 @@ fn get_fs() -> Result, io::Error> { } fn build(release: bool, target: Target) -> Result<(), Error> { - fetch_ovmf().change_context(Error::OvmfFetch)?; - let fs = get_fs().change_context(Error::Io)?; let mut com = Command::new("cargo"); com.current_dir("kernel"); @@ -168,14 +159,16 @@ fn build(release: bool, target: Target) -> Result<(), Error> { _ => (), } - if target != Target::Aarch64 { - todo!() - } + let kernel_dir = match target { + Target::X86_64 => "target/x86_64-ableos", + Target::Riscv64Virt => "target/riscv64-virt-ableos", + Target::Aarch64 => "target/aarch64-virt-ableos", + }; (|| -> std::io::Result<_> { io::copy( &mut File::open( - Path::new("target/aarch64-virt-ableos") + Path::new(kernel_dir) .join(if release { "release" } else { "debug" }) .join("kernel"), )?, @@ -193,60 +186,45 @@ fn run(release: bool, target: Target) -> Result<(), Error> { Target::Riscv64Virt => Command::new("qemu-system-riscv64"), Target::Aarch64 => Command::new("qemu-system-aarch64"), }; + let ovmf_path = fetch_ovmf(target); - if target == Target::X86_64 { - #[rustfmt::skip] - com.args([ - "-bios", "target/OVMF_CODE.fd", - "-drive", "file=target/disk.img,format=raw", - "-m", "4G", - // "-serial", "stdio", - "-smp", "cores=4", - // "-vga", "cirrus", - // "-device", "ati-vga", - // "-device", "virtio-gpu-pci", - - // "-device", "virtio-serial,id=virtio-serial0", - // "-chardev", "stdio,id=char0,mux=on", - // "-device", "virtconsole,chardev=char0", - // "-device", "virtio-mouse-pci", - - // "-device", "ati-vga", "model=rage128p" - ]); - - #[cfg(target_os = "linux")] - { - // com.args(["-enable-kvm", "-cpu", "host"]); + match target { + Target::X86_64 => { + #[rustfmt::skip] + com.args([ + "-bios", &ovmf_path.change_context(Error::OvmfFetch)?, + "-drive", "file=target/disk.img,format=raw", + "-m", "4G", + "-smp", "cores=4", + ]); + } + Target::Riscv64Virt => { + #[rustfmt::skip] + com.args([ + "-M", "virt", + "-m", "128M", + "-serial", "stdio", + "-kernel", + if release { + "target/riscv64-virt-ableos/release/kernel" + } else { + "target/riscv64-virt-ableos/debug/kernel" + } + ]); + } + Target::Aarch64 => { + #[rustfmt::skip] + com.args([ + "-M", "virt", + "-cpu", "cortex-a72", + "-device", "ramfb", + "-device", "qemu-xhci", + "-device", "usb-kbd", + "-m", "2G", + "-bios", &ovmf_path.change_context(Error::OvmfFetch)?, + "-drive", "file=target/disk.img,format=raw", + ]); } - } - - if target == Target::Riscv64Virt { - #[rustfmt::skip] - com.args([ - "-M", "virt", - "-m", "128M", - "-serial", "stdio", - "-kernel", - if release { - "target/riscv64-virt-ableos/release/kernel" - } else { - "target/riscv64-virt-ableos/debug/kernel" - } - ]); - } - - if target == Target::Aarch64 { - #[rustfmt::skip] - com.args([ - "-M", "virt", - "-cpu", "cortex-a72", - "-device", "ramfb", - "-device", "qemu-xhci", - "-device", "usb-kbd", - "-m", "2G", - "-bios", "target/AARCH64_OVMF.fd", - "-drive", "file=target/disk.img,format=raw", - ]); } match com @@ -259,39 +237,48 @@ fn run(release: bool, target: Target) -> Result<(), Error> { } } -fn fetch_ovmf() -> Result<(), OvmfFetchError> { - const OVMF_AARCH64_URL: &str = - "https://retrage.github.io/edk2-nightly/bin/RELEASEAARCH64_QEMU_EFI.fd"; +fn fetch_ovmf(target: Target) -> Result { + let (ovmf_url, ovmf_path) = match target { + Target::X86_64 => ( + "https://retrage.github.io/edk2-nightly/bin/RELEASEX64_OVMF.fd", + "target/RELEASEX64_OVMF.fd", + ), + Target::Riscv64Virt => return Err(OvmfFetchError::Empty.into()), + Target::Aarch64 => ( + "https://retrage.github.io/edk2-nightly/bin/RELEASEAARCH64_QEMU_EFI.fd", + "target/RELEASEAARCH64_QEMU_EFI.fd", + ), + }; - let mut file = match std::fs::metadata("target/AARCH64_OVMF.fd") { + let mut file = match std::fs::metadata(ovmf_path) { Err(e) if e.kind() == std::io::ErrorKind::NotFound => std::fs::OpenOptions::new() .create(true) .write(true) .read(true) - .open("target/AARCH64_OVMF.fd") + .open(ovmf_path) .into_report() .change_context(OvmfFetchError::Io)?, - Ok(_) => return Ok(()), + Ok(_) => return Ok(ovmf_path.to_owned()), Err(e) => return Err(report!(e).change_context(OvmfFetchError::Io)), }; - - log::info!("No OVMF found, downloading…"); - - let bytes = std::convert::identity((|| reqwest::blocking::get(OVMF_AARCH64_URL)?.bytes())()) + let mut bytes = reqwest::blocking::get(ovmf_url) .into_report() .change_context(OvmfFetchError::Fetch)?; - file.write_all(&bytes) + bytes + .copy_to(&mut file) .into_report() .change_context(OvmfFetchError::Io)?; - Ok(()) + Ok(ovmf_path.to_owned()) } #[derive(Debug, Display)] enum OvmfFetchError { #[display(fmt = "Failed to fetch OVMF package")] Fetch, + #[display(fmt = "No OVMF package available")] + Empty, #[display(fmt = "IO Error")] Io, }