diff --git a/Cargo.lock b/Cargo.lock index eadb0fb..9e843c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,7 +142,6 @@ version = "0.1.0" dependencies = [ "aligned-vec", "embedded-graphics", - "log", "tinygif", "uefi", "uefi-graphics2", diff --git a/Cargo.toml b/Cargo.toml index 29a71eb..51e9768 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,16 +3,16 @@ 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] +aligned-vec = { version = "0.5.0", default-features = false } fatfs = { path = "rust-fatfs", default-features = false, features = ["alloc", "chrono"] } embedded-graphics = "0.8.1" -log = "0.4.21" mbrs = "0.3.1" tinygif = { version = "0.0.4", features = ["8k"] } uefi = { version = "0.28.0", features = ["global_allocator", "panic_handler", "alloc"] } diff --git a/bad-apple.gif b/bad-apple.gif new file mode 100644 index 0000000..955acc0 Binary files /dev/null and b/bad-apple.gif differ diff --git a/efi-bin/Cargo.toml b/efi-bin/Cargo.toml index de4f258..4b091dc 100644 --- a/efi-bin/Cargo.toml +++ b/efi-bin/Cargo.toml @@ -6,9 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -aligned-vec = { version = "0.5.0", default-features = false } +aligned-vec.workspace = true embedded-graphics.workspace = true -log.workspace = true tinygif.workspace = true uefi.workspace = true uefi-graphics2.workspace = true diff --git a/efi-bin/src/bad-apple.gif b/efi-bin/src/bad-apple.gif deleted file mode 100644 index 955acc0..0000000 Binary files a/efi-bin/src/bad-apple.gif and /dev/null differ diff --git a/efi-bin/src/bad-apple.gif b/efi-bin/src/bad-apple.gif new file mode 120000 index 0000000..5efe543 --- /dev/null +++ b/efi-bin/src/bad-apple.gif @@ -0,0 +1 @@ +../../kirby_angy_sit.gif \ No newline at end of file diff --git a/efi-bin/src/main.rs b/efi-bin/src/main.rs index 946ef7b..e3809e2 100644 --- a/efi-bin/src/main.rs +++ b/efi-bin/src/main.rs @@ -4,31 +4,23 @@ extern crate alloc; use aligned_vec::{AVec, ConstAlign}; -use alloc::borrow::ToOwned; use alloc::vec::Vec; -use core::time::Duration; use uefi::proto::device_path::build::media::HardDrive; use uefi::proto::device_path::build::DevicePathBuilder; use uefi::proto::device_path::media::{PartitionFormat, PartitionSignature}; -use uefi::{prelude::*, println, CStr16}; +use uefi::{prelude::*, println}; use uefi::proto::console::gop::GraphicsOutput; use uefi::proto::device_path::{DeviceType, LoadedImageDevicePath}; -use uefi::proto::loaded_image::LoadedImage; -use uefi::proto::media::block::{BlockIO, BlockIOMedia, Lba}; -use uefi::proto::media::disk::DiskIo; -use uefi::proto::media::file::{File, FileSystemVolumeLabel}; -use uefi::proto::media::fs::SimpleFileSystem; -use uefi::proto::media::partition::PartitionInfo; -use uefi::proto::misc::Timestamp; +use uefi::proto::media::block::{BlockIO, Lba}; use uefi::table::boot::{OpenProtocolAttributes, OpenProtocolParams}; use uefi_graphics2::embedded_graphics::{pixelcolor::Rgb888, prelude::*}; use uefi_graphics2::UefiDisplay; const GIF_SIZE: usize = ((include_bytes!("bad-apple.gif").len() + 511) / 512) * 512; -const VOLUME_LABEL: &CStr16 = cstr16!("EFIGIFEDEMO"); +//const VOLUME_LABEL: &CStr16 = cstr16!("EFIGIFEDEMO"); #[entry] fn main(_image_handle: Handle, mut boot_system_table: SystemTable) -> Status { @@ -42,36 +34,35 @@ fn main(_image_handle: Handle, mut boot_system_table: SystemTable) -> Stat let boot_services = boot_system_table.boot_services(); - boot_services.stall(1_000_000); - let img_handle = boot_services.image_handle(); - let loaded_image = boot_services - .open_protocol_exclusive::(img_handle) - .expect("loaded image"); + // let loaded_image = boot_services + // .open_protocol_exclusive::(img_handle) + // .expect("loaded image"); let loaded_image_dev_path = boot_services .open_protocol_exclusive::(img_handle) .expect("loaded image dev path"); - println!("{:?}", loaded_image.file_path()); - - for dev_path_inst in loaded_image_dev_path.instance_iter() { - println!("inst: {:?}", dev_path_inst); - } - + /* + { + let fat_dev = loaded_image.device().expect("loaded image device"); + let fat_block = unsafe { + boot_services.open_protocol::( + OpenProtocolParams { + handle: fat_dev, + agent: img_handle, + controller: None, + }, + OpenProtocolAttributes::GetProtocol, + ) + } + .expect("fat block io"); + let fat_start_lba = fat_block.media().lowest_aligned_lba(); + assert_eq!(fat_start_lba, GIF_SIZE); + } + */ let mut dev_path_buf = Vec::new(); let mut dev_path_builder = DevicePathBuilder::with_vec(&mut dev_path_buf); for dev_path_node in loaded_image_dev_path.node_iter() { - println!("node: {:?}", dev_path_node); - println!( - "{}", - dev_path_node - .to_string( - &boot_services, - uefi::proto::device_path::text::DisplayOnly(false), - uefi::proto::device_path::text::AllowShortcuts(false), - ) - .unwrap() - ); if dev_path_node.device_type() == DeviceType::MEDIA { break; } else { @@ -92,35 +83,9 @@ fn main(_image_handle: Handle, mut boot_system_table: SystemTable) -> Stat .expect("push hard drive"); let mut dev_path = dev_path_builder.finalize().expect("finalize dev path"); let device_handle = boot_services - .locate_device_path::(&mut dev_path) + .locate_device_path::(&mut dev_path) .expect("locate dev path"); - //let mut device_handle = loaded_image.device().expect("device handle"); - - let disk_io = boot_services - .open_protocol_exclusive::(device_handle) - .expect("disk io"); - /* - let handles = boot_services - .find_handles::() - .expect("sfs handle"); - for handle in handles { - let mut sfs = boot_services - .open_protocol_exclusive::(handle) - .expect("sfs proto"); - let mut root_dir = sfs.open_volume().expect("open volume"); - let vol_info = root_dir - .get_boxed_info::() - .expect("root dir label"); - if vol_info.volume_label() == VOLUME_LABEL { - assert_eq!(device_handle, handle); - } - } - */ - - // TODO boot_services.locate_device_path() - // FIXME we currently have the fat partition, need the parent disk - let block_io = unsafe { boot_services.open_protocol::( OpenProtocolParams { @@ -135,18 +100,12 @@ fn main(_image_handle: Handle, mut boot_system_table: SystemTable) -> Stat let mut gif_buf: AVec> = AVec::with_capacity(512, GIF_SIZE); for _ in 0..GIF_SIZE { - //for _ in 0..512 { gif_buf.push(0u8); } - disk_io - .read_disk(block_io.media().media_id(), 0, &mut gif_buf) - .expect("read disk"); - /* block_io .read_blocks(block_io.media().media_id(), Lba::from(0u64), &mut gif_buf) .expect("read blocks"); - */ let gif = tinygif::Gif::::from_slice(&gif_buf).expect("gif from slice"); @@ -160,6 +119,7 @@ fn main(_image_handle: Handle, mut boot_system_table: SystemTable) -> Stat // Create UefiDisplay for mode in gop.modes(&boot_services).collect::>() { + println!("{:?}", mode.info()); let (w, h) = mode.info().resolution(); if w >= gif.width() as usize && h >= gif.height() as usize { match mode.info().pixel_format() { @@ -182,6 +142,11 @@ fn main(_image_handle: Handle, mut boot_system_table: SystemTable) -> Stat // Tint the entire screen cyan display.fill_entire(Rgb888::BLACK).expect("fill black"); + let translation = Point::new( + (res_w as i32 - gif.width() as i32) / 2, + (res_h as i32 - gif.height() as i32) / 2, + ); + /* let timer_handle = boot_services .get_handle_for_protocol::() .expect("timestamp handle"); @@ -198,34 +163,40 @@ fn main(_image_handle: Handle, mut boot_system_table: SystemTable) -> Stat || Duration::from_secs_f64((timer.get_timestamp() - start_timestamp) as f64 / timer_hz); let mut skipped_flushes = 0; - let translation = Point::new( - (res_w as i32 - gif.width() as i32) / 2, - (res_h as i32 / gif.height() as i32) / 2, - ); - for frame in gif.frames() { - frame - .draw(&mut display.translated(translation)) - .expect("frame draw"); - gif_elapsed += Duration::from_millis(frame.delay_centis as u64 * 10); - - // skip flush to catch up - if gif_elapsed > get_real_elapsed() { + */ + loop { + for frame in gif.frames() { + frame + .draw(&mut display.translated(translation)) + .expect("frame draw"); display.flush(); - if let Some(time_diff) = get_real_elapsed().checked_sub(gif_elapsed) { - boot_services.stall(time_diff.as_micros() as usize); - } - } else { - skipped_flushes += 1; - if skipped_flushes == 5 { - // don't skip more than 5 frames at a time - // so you can actually still see anything - skipped_flushes = 0; + boot_services.stall(frame.delay_centis as usize * 10); + /* + gif_elapsed += Duration::from_millis(frame.delay_centis as u64 * 10); + + // skip flush to catch up + if gif_elapsed > get_real_elapsed() { display.flush(); + if let Some(time_diff) = get_real_elapsed().checked_sub(gif_elapsed) { + boot_services.stall(time_diff.as_micros() as usize); + } + } else { + skipped_flushes += 1; + if skipped_flushes == 5 { + // don't skip more than 5 frames at a time + // so you can actually still see anything + skipped_flushes = 0; + display.flush(); + } } + */ + } + if gif.frames().count() == 1 { + boot_services.stall(1_000_000_000); } } - Status::SUCCESS + // Status::SUCCESS } /* diff --git a/xtask/src/main.rs b/xtask/src/main.rs index aad4fff..7e406e7 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -11,7 +11,7 @@ use fatfs::{ }; use mbrs::{Mbr, PartInfo, PartType}; -const RELEASE: bool = false; +const RELEASE: bool = true; const VOLUME_LABEL: [u8; 11] = *b"EFIGIFEDEMO"; #[derive(Copy, Clone)] @@ -131,7 +131,7 @@ fn do_build(cpu: Cpu, _args: VecDeque) { 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 fat_disk_size = 64 * 1024; // todo!("get size from efi_bin_size"); let mut fat_disk_buf = vec![0; fat_disk_size]; let mut fat_disk = MyStdIoWrapper(Cursor::new(&mut fat_disk_buf)); @@ -237,6 +237,8 @@ fn do_run(cpu: Cpu, args: VecDeque) { .arg("512") .arg("-device") .arg("virtio-gpu-pci") + .arg("-serial") + .arg("stdio") .args(&args); let out_img_path = format!( "{}/../target/bad-apple.{}-efi.raw.gif",