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] [alias]
xtask = "run --package xtask --" xtask = "run --package xtask --"

1
Cargo.lock generated
View file

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

View file

@ -2,3 +2,12 @@
members = ["efi-bin", "xtask"] members = ["efi-bin", "xtask"]
resolver = "2" 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 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
byteorder.workspace = true
embedded-graphics = "0.8.1" embedded-graphics = "0.8.1"
tinygif = { version = "0.0.4", features = ["8k"] } tinygif = { version = "0.0.4", features = ["8k"] }
uefi = { version = "0.28.0", features = ["global_allocator", "panic_handler", "alloc"] } uefi = { version = "0.28.0", features = ["global_allocator", "panic_handler", "alloc"] }
uefi-graphics2 = "0.1.3" 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}, process::{Command, Stdio},
}; };
use fatfs::{FileSystem, FsOptions}; use fatfs::{FileSystem, FormatVolumeOptions, FsOptions};
fn main() { fn main() {
let mut args: VecDeque<_> = std::env::args().collect(); let mut args: VecDeque<_> = std::env::args().skip(1).collect();
match args.pop_front() { match args.pop_front() {
Some(cmd) => match cmd.as_str() { Some(cmd) => match cmd.as_str() {
@ -16,26 +16,32 @@ fn main() {
"run" => do_run(args), "run" => do_run(args),
x => eprintln!("unknown command {:?}", x), 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>) { fn do_build(mut args: VecDeque<String>) {
let mut cmd = Command::new(env!("CARGO")); let build_success = Command::new(env!("CARGO"))
cmd.arg("build") .arg("build")
.arg("--bin") .arg("--bin")
.arg("efi-bin") .arg("efigife")
.arg("--release") // TODO: target according to arg .arg("--release")
.arg("--target")
.arg("aarch64-unknown-uefi") // TODO: target according to arg
.stdin(Stdio::inherit()) .stdin(Stdio::inherit())
.stdout(Stdio::inherit()) .stdout(Stdio::inherit())
.stderr(Stdio::inherit()) .stderr(Stdio::inherit())
.output() .output()
.unwrap(); .unwrap()
.status
.success();
assert!(build_success);
let efi_bin_path = concat!( let efi_bin_path = concat!(
env!("CARGO_MANIFEST_DIR"), 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_buf = Vec::new();
let mut efi_bin_file = File::open(efi_bin_path).unwrap(); 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); 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 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_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 boot_efi_name = "BOOTAA64.EFI"; // TODO: parameterize on arg
let mut boot_efi = fat_fs let mut boot_efi = fat_fs
.root_dir() .root_dir()
@ -55,12 +66,12 @@ fn do_build(mut args: VecDeque<String>) {
.create_file(boot_efi_name) .create_file(boot_efi_name)
.unwrap(); .unwrap();
boot_efi.write_all(&efi_bin_buf); boot_efi.write_all(&efi_bin_buf).unwrap();
drop(boot_efi); drop(boot_efi);
fat_fs.unmount().unwrap(); fat_fs.unmount().unwrap();
// TODO: do the gif format juggling to add the comment in this xtask // 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 src_gif_file = File::open(src_gif_path).unwrap();
let mut buf = Vec::new(); let mut buf = Vec::new();
let src_gif_size = src_gif_file.read_to_end(&mut buf).unwrap(); 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; let fat_start_sector = (src_gif_size + 511) / 512;
buf.extend(std::iter::repeat(0).take(fat_start_sector * 512 - buf.len())); buf.extend(std::iter::repeat(0).take(fat_start_sector * 512 - buf.len()));
buf.extend(fat_disk.into_inner()); 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()); do_build(args.clone());
let mut cmd = match args[0].as_str() { let mut cmd = match args[0].as_str() {
@ -89,12 +108,17 @@ fn do_run(mut args: VecDeque<String>) {
cmd cmd
} }
"x86_64" | "x64" => { "x86_64" | "x64" => {
let mut cmd = Command::new("qemu-system-x86_64"); //let mut cmd = Command::new("qemu-system-x86_64");
todo!(); todo!();
} }
x => unimplemented!("target cpu {:?}", x), 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()) .stdin(Stdio::inherit())
.stdout(Stdio::inherit()) .stdout(Stdio::inherit())
.stderr(Stdio::inherit()) .stderr(Stdio::inherit())