Update to bootloader-locator 0.0.3; cargo fmt; add QEMU run args

This commit is contained in:
Philipp Oppermann
2020-08-24 21:06:08 +02:00
parent fe23af5b3e
commit db307d89bc
5 changed files with 60 additions and 43 deletions

16
Cargo.lock generated
View File

@@ -37,14 +37,11 @@ version = "0.9.8"
[[package]]
name = "bootloader-locator"
version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28ad4c6eeee6c832cb7b2d11fab963674418878c8edaedbef67fcae403dae645"
version = "0.0.3"
dependencies = [
"cargo_metadata",
"locate-cargo-manifest",
"thiserror",
"toml",
]
[[package]]
@@ -132,8 +129,6 @@ checksum = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe"
[[package]]
name = "runner-utils"
version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9dc6848b056990cd51e72aa5556bdbea4a96013e8b18635d183c84159c2988f"
dependencies = [
"thiserror",
"wait-timeout",
@@ -229,15 +224,6 @@ dependencies = [
"syn",
]
[[package]]
name = "toml"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a"
dependencies = [
"serde",
]
[[package]]
name = "uart_16550"
version = "0.2.7"

View File

@@ -1,8 +1,19 @@
use std::{process::{ExitStatus, Command}, path::PathBuf, time::Duration};
use anyhow::anyhow;
use std::{
path::PathBuf,
process::{Command, ExitStatus},
time::Duration,
};
const TEST_ARGS: &[&str] = &["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-serial", "stdio",
"-display", "none"
const RUN_ARGS: &[&str] = &["-d", "int", "--no-reboot", "-s"];
const TEST_ARGS: &[&str] = &[
"-device",
"isa-debug-exit,iobase=0xf4,iosize=0x04",
"-serial",
"stdio",
"-display",
"none",
"--no-reboot",
];
const TEST_TIMEOUT_SECS: u64 = 10;
@@ -15,7 +26,9 @@ fn main() -> anyhow::Result<()> {
let disk_image = disk_image::create_disk_image(&kernel_binary_path, true)?;
let mut run_cmd = Command::new("qemu-system-x86_64");
run_cmd.arg("-drive").arg(format!("format=raw,file={}", disk_image.display()));
run_cmd
.arg("-drive")
.arg(format!("format=raw,file={}", disk_image.display()));
let binary_kind = runner_utils::binary_kind(&kernel_binary_path);
if binary_kind.is_test() {
@@ -23,10 +36,12 @@ fn main() -> anyhow::Result<()> {
let exit_status = run_test_command(run_cmd)?;
match exit_status.code() {
Some(33) => {}, // success
Some(33) => {} // success
other => return Err(anyhow!("Test failed (exit code: {:?})", other)),
}
} else {
run_cmd.args(RUN_ARGS);
let exit_status = run_cmd.status()?;
if !exit_status.success() {
std::process::exit(exit_status.code().unwrap_or(1));

View File

@@ -1,18 +1,26 @@
use std::{process::Command, path::{Path, PathBuf}};
use anyhow::anyhow;
use std::{
path::{Path, PathBuf},
process::Command,
};
pub fn create_disk_image(kernel_binary_path: &Path, bios_only: bool) -> anyhow::Result<PathBuf> {
let bootloader_info= bootloader_locator::locate_bootloader()?;
let bootloader_info = bootloader_locator::locate_bootloader()?;
let kernel_manifest_path = &bootloader_info.kernel_manifest_path;
let mut build_cmd = Command::new(env!("CARGO"));
build_cmd.current_dir(bootloader_info.package.manifest_path.parent().unwrap());
build_cmd.arg("builder");
build_cmd.arg("--kernel-manifest").arg(&kernel_manifest_path);
build_cmd
.arg("--kernel-manifest")
.arg(&kernel_manifest_path);
build_cmd.arg("--kernel-binary").arg(&kernel_binary_path);
build_cmd.arg("--features").args(bootloader_info.features);
build_cmd.arg("--target-dir").arg(kernel_manifest_path.parent().unwrap().join("target"));
build_cmd.arg("--out-dir").arg(kernel_binary_path.parent().unwrap());
build_cmd
.arg("--target-dir")
.arg(kernel_manifest_path.parent().unwrap().join("target"));
build_cmd
.arg("--out-dir")
.arg(kernel_binary_path.parent().unwrap());
build_cmd.arg("--quiet");
if bios_only {
build_cmd.arg("--firmware").arg("bios");
@@ -23,9 +31,15 @@ pub fn create_disk_image(kernel_binary_path: &Path, bios_only: bool) -> anyhow::
}
let kernel_binary_name = kernel_binary_path.file_name().unwrap().to_str().unwrap();
let disk_image = kernel_binary_path.parent().unwrap().join(format!("bootimage-bios-{}.bin", kernel_binary_name));
let disk_image = kernel_binary_path
.parent()
.unwrap()
.join(format!("bootimage-bios-{}.bin", kernel_binary_name));
if !disk_image.exists() {
return Err(anyhow!("Disk image does not exist at {} after bootloader build", disk_image.display()));
return Err(anyhow!(
"Disk image does not exist at {} after bootloader build",
disk_image.display()
));
}
Ok(disk_image)
}

View File

@@ -1,5 +1,5 @@
use std::process::Command;
use anyhow::anyhow;
use std::process::Command;
const TARGET_NAME: &str = "x86_64-blog_os";
const KERNEL_BINARIES: &[&str] = &["blog_os"];
@@ -10,7 +10,9 @@ fn main() -> anyhow::Result<()> {
build_cmd.arg("build");
build_cmd.arg("--release");
build_cmd.arg("-Zbuild-std=core");
build_cmd.arg("--target").arg(format!("{}.json", TARGET_NAME));
build_cmd
.arg("--target")
.arg(format!("{}.json", TARGET_NAME));
if !build_cmd.status()?.success() {
return Err(anyhow!("build failed"));
};
@@ -27,7 +29,11 @@ fn main() -> anyhow::Result<()> {
let disk_image = disk_image::create_disk_image(&binary_path, false)?;
println!("Created disk image for binary {} at {}", binary_name, disk_image.display());
println!(
"Created disk image for binary {} at {}",
binary_name,
disk_image.display()
);
}
Ok(())

View File

@@ -5,16 +5,13 @@
#![reexport_test_harness_main = "test_main"]
use blog_os::serial_println;
use core::{ptr, panic::PanicInfo, slice};
use core::{panic::PanicInfo, ptr, slice};
#[no_mangle]
pub extern "C" fn _start(boot_info: &'static mut bootloader::boot_info_uefi::BootInfo) -> ! {
pub extern "C" fn _start(boot_info: &'static mut bootloader::boot_info::BootInfo) -> ! {
#[cfg(test)]
test_main();
loop {
x86_64::instructions::hlt();
}
let mut framebuffer = {
let ptr = boot_info.framebuffer.start_addr as *mut u8;
let slice = unsafe { slice::from_raw_parts_mut(ptr, boot_info.framebuffer.len) };
@@ -23,7 +20,6 @@ pub extern "C" fn _start(boot_info: &'static mut bootloader::boot_info_uefi::Boo
//serial_println!("Hello World{}", "!");
for i in 0..boot_info.framebuffer.len {
framebuffer.index_mut(i).write(0x99);
}