diff --git a/efi-bin/src/main.rs b/efi-bin/src/main.rs index cf114d5..946ef7b 100644 --- a/efi-bin/src/main.rs +++ b/efi-bin/src/main.rs @@ -4,16 +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::*, CStr16}; +use uefi::{prelude::*, println, CStr16}; 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, Lba}; +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::table::boot::{OpenProtocolAttributes, OpenProtocolParams}; @@ -38,14 +45,61 @@ fn main(_image_handle: Handle, mut boot_system_table: SystemTable) -> Stat 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_dev_path = boot_services .open_protocol_exclusive::(img_handle) - .expect("loaded image"); + .expect("loaded image dev path"); - loaded_image_dev_path.get() - - let mut device_handle = loaded_image.device().expect("device handle"); + println!("{:?}", loaded_image.file_path()); + for dev_path_inst in loaded_image_dev_path.instance_iter() { + println!("inst: {:?}", dev_path_inst); + } + + 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 { + dev_path_builder = dev_path_builder + .push(&dev_path_node) + .expect("push existing node"); + } + } + let harder_drive = HardDrive { + partition_number: 0, + partition_start: 0, + partition_size: GIF_SIZE as u64 / 512, + partition_signature: PartitionSignature::None, + partition_format: PartitionFormat::MBR, + }; + dev_path_builder = dev_path_builder + .push(&harder_drive) + .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) + .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::() @@ -80,16 +134,19 @@ fn main(_image_handle: Handle, mut boot_system_table: SystemTable) -> Stat .expect("block io"); let mut gif_buf: AVec> = AVec::with_capacity(512, GIF_SIZE); - // for _ in 0..GIF_SIZE { - for _ in 0..512 { + 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"); - - panic!("{:x?}", &gif_buf[..32]); + */ let gif = tinygif::Gif::::from_slice(&gif_buf).expect("gif from slice");