asdfasdfasdf

This commit is contained in:
lif 2024-05-07 17:37:23 -07:00
parent 82109dc98e
commit 8ce377784c
7 changed files with 70 additions and 99 deletions

1
Cargo.lock generated
View file

@ -142,7 +142,6 @@ version = "0.1.0"
dependencies = [
"aligned-vec",
"embedded-graphics",
"log",
"tinygif",
"uefi",
"uefi-graphics2",

View file

@ -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"] }

BIN
bad-apple.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 MiB

View file

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 MiB

After

Width:  |  Height:  |  Size: 24 B

1
efi-bin/src/bad-apple.gif Symbolic link
View file

@ -0,0 +1 @@
../../kirby_angy_sit.gif

Before

Width:  |  Height:  |  Size: 22 MiB

After

Width:  |  Height:  |  Size: 24 B

View file

@ -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<Boot>) -> Status {
@ -42,36 +34,35 @@ fn main(_image_handle: Handle, mut boot_system_table: SystemTable<Boot>) -> 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::<LoadedImage>(img_handle)
.expect("loaded image");
// let loaded_image = boot_services
// .open_protocol_exclusive::<LoadedImage>(img_handle)
// .expect("loaded image");
let loaded_image_dev_path = boot_services
.open_protocol_exclusive::<LoadedImageDevicePath>(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::<BlockIO>(
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<Boot>) -> 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::<DiskIo>(&mut dev_path)
.locate_device_path::<BlockIO>(&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::<DiskIo>(device_handle)
.expect("disk io");
/*
let handles = boot_services
.find_handles::<uefi::proto::media::fs::SimpleFileSystem>()
.expect("sfs handle");
for handle in handles {
let mut sfs = boot_services
.open_protocol_exclusive::<SimpleFileSystem>(handle)
.expect("sfs proto");
let mut root_dir = sfs.open_volume().expect("open volume");
let vol_info = root_dir
.get_boxed_info::<FileSystemVolumeLabel>()
.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::<BlockIO>(
OpenProtocolParams {
@ -135,18 +100,12 @@ fn main(_image_handle: Handle, mut boot_system_table: SystemTable<Boot>) -> Stat
let mut gif_buf: AVec<u8, ConstAlign<512>> = 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::<Rgb888>::from_slice(&gif_buf).expect("gif from slice");
@ -160,6 +119,7 @@ fn main(_image_handle: Handle, mut boot_system_table: SystemTable<Boot>) -> Stat
// Create UefiDisplay
for mode in gop.modes(&boot_services).collect::<Vec<_>>() {
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<Boot>) -> 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::<Timestamp>()
.expect("timestamp handle");
@ -198,34 +163,40 @@ fn main(_image_handle: Handle, mut boot_system_table: SystemTable<Boot>) -> 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
}
/*

View file

@ -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<String>) {
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<String>) {
.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",