From 83d1f95e37a83e70087d5839564ce55c808c7c1d Mon Sep 17 00:00:00 2001 From: lifning <> Date: Sun, 5 May 2024 11:14:45 -0700 Subject: [PATCH] xtask stuff --- .cargo/config.toml | 2 + Cargo.lock | 247 ++++++++++++++++++++++++++++- Cargo.toml | 21 +-- efi-bin/Cargo.toml | 19 +++ {src => efi-bin/src}/bad-apple.gif | Bin {src => efi-bin/src}/main.rs | 0 xtask/Cargo.toml | 9 ++ xtask/src/main.rs | 103 ++++++++++++ 8 files changed, 381 insertions(+), 20 deletions(-) create mode 100644 efi-bin/Cargo.toml rename {src => efi-bin/src}/bad-apple.gif (100%) rename {src => efi-bin/src}/main.rs (100%) create mode 100644 xtask/Cargo.toml create mode 100644 xtask/src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index 6207835..652c4cb 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,5 @@ [build] target = "aarch64-unknown-uefi" +[alias] +xtask = "run --package xtask --" diff --git a/Cargo.lock b/Cargo.lock index 6d1fc4d..deef902 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "atomic-polyfill" version = "1.0.3" @@ -29,24 +44,62 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "byteorder" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "cc" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd" + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + [[package]] name = "critical-section" version = "1.1.2" @@ -86,6 +139,18 @@ dependencies = [ "byteorder", ] +[[package]] +name = "fatfs" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05669f8e7e2d7badc545c513710f0eba09c2fbef683eb859fd79c46c355048e0" +dependencies = [ + "bitflags 1.3.2", + "byteorder", + "chrono", + "log", +] + [[package]] name = "float-cmp" version = "0.9.0" @@ -117,6 +182,44 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + [[package]] name = "lock_api" version = "0.4.12" @@ -148,6 +251,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + [[package]] name = "proc-macro2" version = "1.0.81" @@ -269,7 +378,7 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9c0a56dc9fed2589aad6ddca11c2584968fc21f227b5d7083bb8961d26a69fa" dependencies = [ - "bitflags", + "bitflags 2.5.0", "cfg-if", "log", "ptr_meta", @@ -306,7 +415,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "efa8716f52e8cab8bcedfd5052388a0f263b69fe5cc2561548dc6a530678333c" dependencies = [ - "bitflags", + "bitflags 2.5.0", "ptr_meta", "uguid", ] @@ -322,3 +431,137 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.60", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + +[[package]] +name = "xtask" +version = "0.1.0" +dependencies = [ + "fatfs", +] diff --git a/Cargo.toml b/Cargo.toml index 05fcc4c..acfb009 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,19 +1,4 @@ -[package] -name = "efigife" -version = "0.1.0" -edition = "2021" +[workspace] +members = ["efi-bin", "xtask"] +resolver = "2" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -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" diff --git a/efi-bin/Cargo.toml b/efi-bin/Cargo.toml new file mode 100644 index 0000000..05fcc4c --- /dev/null +++ b/efi-bin/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "efigife" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +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" diff --git a/src/bad-apple.gif b/efi-bin/src/bad-apple.gif similarity index 100% rename from src/bad-apple.gif rename to efi-bin/src/bad-apple.gif diff --git a/src/main.rs b/efi-bin/src/main.rs similarity index 100% rename from src/main.rs rename to efi-bin/src/main.rs diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml new file mode 100644 index 0000000..5ed21f5 --- /dev/null +++ b/xtask/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "xtask" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +fatfs = "0.3.6" diff --git a/xtask/src/main.rs b/xtask/src/main.rs new file mode 100644 index 0000000..ca82811 --- /dev/null +++ b/xtask/src/main.rs @@ -0,0 +1,103 @@ +use std::{ + collections::VecDeque, + fs::File, + io::{Cursor, Read, Write}, + process::{Command, Stdio}, +}; + +use fatfs::{FileSystem, FsOptions}; + +fn main() { + let mut args: VecDeque<_> = std::env::args().collect(); + + match args.pop_front() { + Some(cmd) => match cmd.as_str() { + "build" => do_build(args), + "run" => do_run(args), + x => eprintln!("unknown command {:?}", x), + }, + None => eprintln!("usage: cargo xtask [build|run]"), + } +} + +fn do_build(mut args: VecDeque) { + let mut cmd = Command::new(env!("CARGO")); + cmd.arg("build") + .arg("--bin") + .arg("efi-bin") + .arg("--release") // TODO: target according to arg + .stdin(Stdio::inherit()) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .output() + .unwrap(); + + let efi_bin_path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/target/aarch64-unknown-uefi/efi-bin.efi" + ); + 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); + drop(efi_bin_file); + + 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(); + let boot_efi_name = "BOOTAA64.EFI"; // TODO: parameterize on arg + let mut boot_efi = fat_fs + .root_dir() + .create_dir("EFI") + .unwrap() + .create_dir("BOOT") + .unwrap() + .create_file(boot_efi_name) + .unwrap(); + + boot_efi.write_all(&efi_bin_buf); + 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 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(); + drop(src_gif_file); + 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()); +} + +fn do_run(mut args: VecDeque) { + do_build(args.clone()); + + let mut cmd = match args[0].as_str() { + "aarch64" | "arm64" => { + let mut cmd = Command::new("qemu-system-aarch64"); + cmd.arg("-drive") + .arg("if=none,id=code,format=raw,file=/usr/share/qemu/edk2-aarch64-code.fd,readonly=on") + .arg("-M") + .arg("virt,pflash0=code,accel=kvm,gic-version=3") + .arg("-cpu") + .arg("host") + .arg("-m") + .arg("512") + .arg("-device") + .arg("virtio-gpu-pci"); + cmd + } + "x86_64" | "x64" => { + let mut cmd = Command::new("qemu-system-x86_64"); + todo!(); + } + x => unimplemented!("target cpu {:?}", x), + }; + cmd.arg(todo!("disk image")) + .stdin(Stdio::inherit()) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .output() + .unwrap(); +}