33 stable releases (8 major)
Uses new Rust 2024
| new 19.0.5 | Jan 21, 2026 |
|---|---|
| 19.0.0 | Dec 17, 2025 |
| 18.1.0 | Dec 10, 2025 |
| 17.1.0 | Dec 4, 2025 |
| 11.4.1 | Oct 17, 2025 |
#1363 in Hardware support
306 downloads per month
Used in 2 crates
16MB
21K
SLoC
Patina FIrmware File System (FFS) Crate
Rust support for the UEFI Platform Initialization (PI) Specification defined Firmware File System (FFS). Offers zero-copy inspection helpers for firmware volumes, files, and sections together with serialization to spec-compliant byte streams. It targets firmware environments that run without the Rust standard library.
Key Capabilities
- Parse firmware volumes, firmware files, and sections directly from immutable byte slices using
VolumeRef,FileRef, andSection. - Compose new firmware content with builders (
Volume,File,Section) that enforce header layout, checksum calculation, erase polarity, and inter-section padding. - Provide trait-based extension points (
SectionExtractor,SectionComposer) so platforms can plug in custom decompression or guided-section handling. - Return consistent errors through
FirmwareFileSystemError, which maps to Patina’sEfiErrorandefi::Status.
Core Data Types
VolumeRef<'a>– A view over a firmware volume that validates headers, block maps, and extended headers, and exposes iterators over contained files. It also supports creation from a physical address (unsafe fn new_from_address).Volume– A firmware volume builder that accepts a block map and a collection of files and emits byte streams.FileRef<'a>andFile– Read and compose firmware files, including large-file headers, checksum enforcement, and section traversal.SectionandSectionHeader– Represent leaf and encapsulation sections, track dirty state, and serialize with the correct header variant (standard or extended).SectionIteratorwalks a serialized section list with 4-byte alignment handling.SectionExtractor– Trait that defines interfaces to expand encapsulated sections (for example Brotli or UEFI Compress), with implementations available in thepatina_ffs_extractorscompanion crate.SectionComposer– Trait for turning higher-level inputs into serialized section payloads before they are inserted into aFile.
Example: Scanning FIrmware Volumes (FVs)
use core::ffi::c_void;
use patina_dxe_core::Core;
use patina_ffs::volume::VolumeRef;
use patina_ffs_extractors::BrotliSectionExtractor;
# fn get_fv_bytes() -> &'static [u8] { unimplemented!() }
fn inspect_firmware(fv_bytes: &'static [u8]) {
let fv = VolumeRef::new(fv_bytes).expect("valid firmware volume");
for file in fv.files() {
let file = file.expect("valid file");
for section in file.sections_with_extractor(&BrotliSectionExtractor::default()).unwrap() {
// Analyze payload, locate PE32 images, or feed data to the dispatcher.
}
}
}
#[cfg_attr(target_os = "uefi", export_name = "efi_main")]
pub extern "efiapi" fn _start(physical_hob_list: *const c_void) -> ! {
Core::default()
.init_memory(physical_hob_list)
.with_service(BrotliSectionExtractor::default())
.start()
.unwrap();
loop {}
}
Example: Compsosing a Driver File
use alloc::vec::Vec;
use patina::pi::fw_fs::ffs;
use patina_ffs::file::File;
use patina_ffs::section::{Section, SectionHeader};
use r_efi::efi;
fn build_driver_section(pe_image: Vec<u8>) -> File {
let mut file = File::new(efi::Guid::from_bytes(&[0u8; 16]), ffs::file::raw::r#type::DRIVER);
let section = Section::new_from_header_with_data(
SectionHeader::Standard(ffs::section::raw_type::PE32, pe_image.len() as u32),
pe_image,
)
.expect("section build");
file.sections_mut().push(section);
file.set_data_checksum(true);
file
}
Dependencies
~6.5MB
~91K SLoC