From 5b9f765be086cdfab36b50b089650e34725acab8 Mon Sep 17 00:00:00 2001 From: lif <> Date: Mon, 6 May 2024 21:12:32 -0700 Subject: [PATCH] this is stupid. fatfs was leaking byteorder/std from xtask into efi-bin. --- .gitmodules | 3 + Cargo.lock | 163 ++++++++++++++++++++++++++++++++++++++++----- Cargo.toml | 16 +++-- efi-bin/Cargo.toml | 9 ++- rust-fatfs | 1 + xtask/Cargo.toml | 2 +- xtask/src/main.rs | 70 ++++++++++++++++--- 7 files changed, 228 insertions(+), 36 deletions(-) create mode 100644 .gitmodules create mode 160000 rust-fatfs diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..589d201 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "rust-fatfs"] + path = rust-fatfs + url = https://github.com/rafalh/rust-fatfs diff --git a/Cargo.lock b/Cargo.lock index 98a9981..80da4f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -26,6 +35,17 @@ dependencies = [ "critical-section", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.3.0" @@ -44,12 +64,6 @@ 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" @@ -88,9 +102,7 @@ checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", - "js-sys", "num-traits", - "wasm-bindgen", "windows-targets", ] @@ -110,7 +122,6 @@ checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" name = "efigife" version = "0.1.0" dependencies = [ - "byteorder", "embedded-graphics", "tinygif", "uefi", @@ -141,14 +152,26 @@ dependencies = [ ] [[package]] -name = "fatfs" -version = "0.3.6" +name = "env_logger" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05669f8e7e2d7badc545c513710f0eba09c2fbef683eb859fd79c46c355048e0" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" dependencies = [ - "bitflags 1.3.2", - "byteorder", + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "fatfs" +version = "0.4.0" +dependencies = [ + "bitflags", "chrono", + "env_logger", + "fscommon", "log", ] @@ -161,6 +184,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "fscommon" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "315ce685aca5ddcc5a3e7e436ef47d4a5d0064462849b6f0f628c28140103531" +dependencies = [ + "log", +] + [[package]] name = "hash32" version = "0.2.1" @@ -183,6 +215,21 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -237,6 +284,12 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + [[package]] name = "micromath" version = "2.1.0" @@ -296,6 +349,35 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + [[package]] name = "rustc_version" version = "0.4.0" @@ -354,6 +436,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "tinygif" version = "0.0.4" @@ -379,7 +470,7 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9c0a56dc9fed2589aad6ddca11c2584968fc21f227b5d7083bb8961d26a69fa" dependencies = [ - "bitflags 2.5.0", + "bitflags", "cfg-if", "log", "ptr_meta", @@ -416,7 +507,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "efa8716f52e8cab8bcedfd5052388a0f263b69fe5cc2561548dc6a530678333c" dependencies = [ - "bitflags 2.5.0", + "bitflags", "ptr_meta", "uguid", ] @@ -487,6 +578,37 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-core" version = "0.52.0" @@ -496,6 +618,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.52.5" diff --git a/Cargo.toml b/Cargo.toml index b79150b..1d3b699 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,11 +3,15 @@ members = ["efi-bin", "xtask"] resolver = "2" [profile.release] -strip = true -opt-level = "z" -lto = true -codegen-units = 1 -panic = "abort" +#strip = true +#opt-level = "z" +#lto = true +#codegen-units = 1 +#panic = "abort" [workspace.dependencies] -byteorder = { version = "*", default-features = false } +fatfs = { path = "rust-fatfs", default-features = false, features = ["alloc", "chrono"] } +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" diff --git a/efi-bin/Cargo.toml b/efi-bin/Cargo.toml index fd6e1e1..7f6f425 100644 --- a/efi-bin/Cargo.toml +++ b/efi-bin/Cargo.toml @@ -6,8 +6,7 @@ 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" +embedded-graphics.workspace = true +tinygif.workspace = true +uefi.workspace = true +uefi-graphics2.workspace = true diff --git a/rust-fatfs b/rust-fatfs new file mode 160000 index 0000000..85f06e0 --- /dev/null +++ b/rust-fatfs @@ -0,0 +1 @@ +Subproject commit 85f06e08edbd3368e1b0562f2fc1b6d178bf7b8a diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 5ed21f5..149ee61 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -fatfs = "0.3.6" +fatfs.workspace = true diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 47b803e..34f4f57 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,11 +1,14 @@ use std::{ collections::VecDeque, fs::File, - io::{Cursor, Read, Write}, + io::{Cursor, Read, Seek, Write}, process::{Command, Stdio}, }; -use fatfs::{FileSystem, FormatVolumeOptions, FsOptions}; +use fatfs::{ + FileSystem, FormatVolumeOptions, FsOptions, IoBase, IoError, Read as FatRead, Seek as FatSeek, + Write as FatWrite, +}; fn main() { let mut args: VecDeque<_> = std::env::args().skip(1).collect(); @@ -20,8 +23,58 @@ fn main() { } } -fn do_build(mut args: VecDeque) { - let build_success = Command::new(env!("CARGO")) +struct MyStdIoWrapper(T); +#[derive(Debug)] +struct MyStdIoError(std::io::Error); +impl IoError for MyStdIoError { + fn is_interrupted(&self) -> bool { + self.0.kind() == std::io::ErrorKind::Interrupted + } + + fn new_unexpected_eof_error() -> Self { + Self(std::io::Error::new( + std::io::ErrorKind::UnexpectedEof, + "failed to fill whole buffer", + )) + } + + fn new_write_zero_error() -> Self { + Self(std::io::Error::new( + std::io::ErrorKind::WriteZero, + "failed to write whole buffer", + )) + } +} +impl IoBase for MyStdIoWrapper { + type Error = MyStdIoError; +} +impl FatSeek for MyStdIoWrapper { + fn seek(&mut self, pos: fatfs::SeekFrom) -> Result { + let pos = match pos { + fatfs::SeekFrom::Start(x) => std::io::SeekFrom::Start(x), + fatfs::SeekFrom::End(x) => std::io::SeekFrom::End(x), + fatfs::SeekFrom::Current(x) => std::io::SeekFrom::Current(x), + }; + Seek::seek(&mut self.0, pos).map_err(MyStdIoError) + } +} +impl FatRead for MyStdIoWrapper { + fn read(&mut self, buf: &mut [u8]) -> Result { + Read::read(&mut self.0, buf).map_err(MyStdIoError) + } +} +impl FatWrite for MyStdIoWrapper { + fn write(&mut self, buf: &[u8]) -> Result { + Write::write(&mut self.0, buf).map_err(MyStdIoError) + } + + fn flush(&mut self) -> Result<(), Self::Error> { + Write::flush(&mut self.0).map_err(MyStdIoError) + } +} + +fn do_build(args: VecDeque) { + let build_success = Command::new("cargo") .arg("build") .arg("--bin") .arg("efigife") @@ -49,13 +102,14 @@ fn do_build(mut args: VecDeque) { 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_buf = vec![0; fat_disk_size]; + let mut fat_disk = MyStdIoWrapper(Cursor::new(&mut fat_disk_buf)); 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 fat_fs = FileSystem::new(fat_disk, FsOptions::new()).unwrap(); let boot_efi_name = "BOOTAA64.EFI"; // TODO: parameterize on arg let mut boot_efi = fat_fs .root_dir() @@ -66,7 +120,7 @@ fn do_build(mut args: VecDeque) { .create_file(boot_efi_name) .unwrap(); - boot_efi.write_all(&efi_bin_buf).unwrap(); + FatWrite::write_all(&mut boot_efi, &efi_bin_buf).unwrap(); drop(boot_efi); fat_fs.unmount().unwrap(); @@ -78,7 +132,7 @@ fn do_build(mut args: VecDeque) { 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()); + buf.extend(fat_disk_buf); let out_img_path = format!( "{}/../target/bad-apple.{}-efi.raw.gif",