mirror of
https://github.com/realmicrosoft/windows.git
synced 2024-08-14 22:46:44 +00:00
added a few things
This commit is contained in:
parent
4870d85d5e
commit
62905d08ca
9 changed files with 398 additions and 30 deletions
11
simple_boot/Cargo.toml
Normal file
11
simple_boot/Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "simple_boot"
|
||||
version = "0.1.0"
|
||||
authors = ["Philipp Oppermann <dev@phil-opp.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bootloader-locator = "0.0.4" # for locating the `bootloader` dependency on disk
|
||||
locate-cargo-manifest = "0.2.0" # for locating the kernel's `Cargo.toml`
|
78
simple_boot/src/main.rs
Normal file
78
simple_boot/src/main.rs
Normal file
|
@ -0,0 +1,78 @@
|
|||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
};
|
||||
|
||||
const RUN_ARGS: &[&str] = &["--no-reboot", "-s"];
|
||||
|
||||
fn main() {
|
||||
let mut args = std::env::args().skip(1); // skip executable name
|
||||
|
||||
let kernel_binary_path = {
|
||||
let path = PathBuf::from(args.next().unwrap());
|
||||
path.canonicalize().unwrap()
|
||||
};
|
||||
let no_boot = if let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--no-run" => true,
|
||||
other => panic!("unexpected argument `{}`", other),
|
||||
}
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let bios = create_disk_images(&kernel_binary_path);
|
||||
|
||||
if no_boot {
|
||||
println!("Created disk image at `{}`", bios.display());
|
||||
return;
|
||||
}
|
||||
|
||||
let mut run_cmd = Command::new("qemu-system-x86_64");
|
||||
run_cmd
|
||||
.arg("-drive")
|
||||
.arg(format!("format=raw,file={}", bios.display()));
|
||||
run_cmd.args(RUN_ARGS);
|
||||
|
||||
let exit_status = run_cmd.status().unwrap();
|
||||
if !exit_status.success() {
|
||||
std::process::exit(exit_status.code().unwrap_or(1));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_disk_images(kernel_binary_path: &Path) -> PathBuf {
|
||||
let bootloader_manifest_path = bootloader_locator::locate_bootloader("bootloader").unwrap();
|
||||
let kernel_manifest_path = locate_cargo_manifest::locate_manifest().unwrap();
|
||||
|
||||
let mut build_cmd = Command::new(env!("CARGO"));
|
||||
build_cmd.current_dir(bootloader_manifest_path.parent().unwrap());
|
||||
build_cmd.arg("builder");
|
||||
build_cmd
|
||||
.arg("--kernel-manifest")
|
||||
.arg(&kernel_manifest_path);
|
||||
build_cmd.arg("--kernel-binary").arg(&kernel_binary_path);
|
||||
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 !build_cmd.status().unwrap().success() {
|
||||
panic!("build failed");
|
||||
}
|
||||
|
||||
let kernel_binary_name = kernel_binary_path.file_name().unwrap().to_str().unwrap();
|
||||
let disk_image = kernel_binary_path
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join(format!("boot-bios-{}.img", kernel_binary_name));
|
||||
if !disk_image.exists() {
|
||||
panic!(
|
||||
"Disk image does not exist at {} after bootloader build",
|
||||
disk_image.display()
|
||||
);
|
||||
}
|
||||
disk_image
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue