This commit is contained in:
lifning 2024-05-05 14:27:07 -07:00
parent 83d1f95e37
commit 7b93a2a301
5 changed files with 50 additions and 25 deletions

View file

@ -1,5 +1,2 @@
[build]
target = "aarch64-unknown-uefi"
[alias]
xtask = "run --package xtask --"

1
Cargo.lock generated
View file

@ -110,6 +110,7 @@ checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216"
name = "efigife"
version = "0.1.0"
dependencies = [
"byteorder",
"embedded-graphics",
"tinygif",
"uefi",

View file

@ -2,3 +2,12 @@
members = ["efi-bin", "xtask"]
resolver = "2"
[profile.release]
strip = true
opt-level = "z"
lto = true
codegen-units = 1
panic = "abort"
[workspace.dependencies]
byteorder = { version = "*", default-features = false }

View file

@ -6,14 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
byteorder.workspace = true
embedded-graphics = "0.8.1"
tinygif = { version = "0.0.4", features = ["8k"] }
uefi = { version = "0.28.0", features = ["global_allocator", "panic_handler", "alloc"] }
uefi-graphics2 = "0.1.3"
[profile.release]
strip = true
opt-level = "z"
lto = true
codegen-units = 1
panic = "abort"

View file

@ -5,10 +5,10 @@ use std::{
process::{Command, Stdio},
};
use fatfs::{FileSystem, FsOptions};
use fatfs::{FileSystem, FormatVolumeOptions, FsOptions};
fn main() {
let mut args: VecDeque<_> = std::env::args().collect();
let mut args: VecDeque<_> = std::env::args().skip(1).collect();
match args.pop_front() {
Some(cmd) => match cmd.as_str() {
@ -16,26 +16,32 @@ fn main() {
"run" => do_run(args),
x => eprintln!("unknown command {:?}", x),
},
None => eprintln!("usage: cargo xtask [build|run]"),
None => eprintln!("usage: cargo xtask [build|run] [x86_64|aarch64]"),
}
}
fn do_build(mut args: VecDeque<String>) {
let mut cmd = Command::new(env!("CARGO"));
cmd.arg("build")
let build_success = Command::new(env!("CARGO"))
.arg("build")
.arg("--bin")
.arg("efi-bin")
.arg("--release") // TODO: target according to arg
.arg("efigife")
.arg("--release")
.arg("--target")
.arg("aarch64-unknown-uefi") // TODO: target according to arg
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.unwrap();
.unwrap()
.status
.success();
assert!(build_success);
let efi_bin_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/target/aarch64-unknown-uefi/efi-bin.efi"
"/../target/aarch64-unknown-uefi/release/efigife.efi"
);
eprintln!("{}", efi_bin_path);
let mut efi_bin_buf = Vec::new();
let mut efi_bin_file = File::open(efi_bin_path).unwrap();
let efi_bin_size = efi_bin_file.read_to_end(&mut efi_bin_buf);
@ -44,7 +50,12 @@ fn do_build(mut args: VecDeque<String>) {
let fat_disk_size = 256 * 1024; // todo!("get size from efi_bin_size");
let mut fat_disk = Cursor::new(vec![0; fat_disk_size]);
let mut fat_fs = FileSystem::new(&mut fat_disk, FsOptions::new()).unwrap();
fatfs::format_volume(
&mut fat_disk,
FormatVolumeOptions::new().fat_type(fatfs::FatType::Fat12),
)
.unwrap();
let fat_fs = FileSystem::new(&mut fat_disk, FsOptions::new()).unwrap();
let boot_efi_name = "BOOTAA64.EFI"; // TODO: parameterize on arg
let mut boot_efi = fat_fs
.root_dir()
@ -55,12 +66,12 @@ fn do_build(mut args: VecDeque<String>) {
.create_file(boot_efi_name)
.unwrap();
boot_efi.write_all(&efi_bin_buf);
boot_efi.write_all(&efi_bin_buf).unwrap();
drop(boot_efi);
fat_fs.unmount().unwrap();
// TODO: do the gif format juggling to add the comment in this xtask
let src_gif_path = concat!(env!("CARGO_MANIFEST_DIR"), "/efi-bin/src/bad-apple.gif");
let src_gif_path = concat!(env!("CARGO_MANIFEST_DIR"), "/../efi-bin/src/bad-apple.gif");
let mut src_gif_file = File::open(src_gif_path).unwrap();
let mut buf = Vec::new();
let src_gif_size = src_gif_file.read_to_end(&mut buf).unwrap();
@ -68,9 +79,17 @@ fn do_build(mut args: VecDeque<String>) {
let fat_start_sector = (src_gif_size + 511) / 512;
buf.extend(std::iter::repeat(0).take(fat_start_sector * 512 - buf.len()));
buf.extend(fat_disk.into_inner());
let out_img_path = format!(
"{}/../target/bad-apple.{}-efi.raw.gif",
env!("CARGO_MANIFEST_DIR"),
"aarch64"
);
let mut out_img_file = File::create(out_img_path).unwrap();
out_img_file.write_all(&buf).unwrap();
}
fn do_run(mut args: VecDeque<String>) {
fn do_run(args: VecDeque<String>) {
do_build(args.clone());
let mut cmd = match args[0].as_str() {
@ -89,12 +108,17 @@ fn do_run(mut args: VecDeque<String>) {
cmd
}
"x86_64" | "x64" => {
let mut cmd = Command::new("qemu-system-x86_64");
//let mut cmd = Command::new("qemu-system-x86_64");
todo!();
}
x => unimplemented!("target cpu {:?}", x),
};
cmd.arg(todo!("disk image"))
let out_img_path = format!(
"{}/../target/bad-apple.{}-efi.raw.gif",
env!("CARGO_MANIFEST_DIR"),
"aarch64"
);
cmd.arg(out_img_path)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())