From 8755d8ada628d6397c46d91e0539b4a8dc6eddcb Mon Sep 17 00:00:00 2001 From: Paul Scalise Date: Wed, 2 Dec 2026 02:43:33 -0600 Subject: [PATCH] Firmware: the A10 video encoder's firmware A recipe step, ave2-firmware-from-kernelcache@1, takes the AVE2 video encoder firmware from AppleAVE2's __TEXT.__const. That section holds one ARM image per chip family (iOS 14.5: "rhea" for the A10, and "cronus"). Each starts with a vector table, a branch and then seven branches to themselves, has "FFW Application" at 0x40 and runs to the next image or the section's end. The recipe's hash picks the image, as it does for the A8 GPU firmware. The A10 encoder driver speaks the build in iOS 14's kernelcache. iOS 15 moved the firmware to Firmware/ave/ in the restore image and changed its command structures, so recipes take iOS 14.5's kernelcache. Tested with the iPhone 7 (D10) and iPad 6 (J71b) recipe entry: the step makes apple/ave-t8010.bin from Apple's server with the recipe's hash, and the encoder runs with it. Assisted-by: LLM Signed-off-by: Paul Scalise --- CHANGELOG.md | 4 +++ crates/boards/src/peripheral.rs | 22 ++++++++++++ crates/formats/src/kernelcache.rs | 57 +++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e10967e..f18c271 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ is on main, the release is published with that section as its notes (AGENTS.md, tree now goes decrypted where its key is known, which an iBEC started from kDFU needs; a DFU mode that turns out to be the untouched boot ROM is said so instead of a timeout. +- Firmware recipes can take the A10 video encoder's firmware from the + AppleAVE2 kext in a kernelcache (`ave2-firmware-from-kernelcache@1`), + for hardware H.264 and HEVC encoding on the iPhone 7 and 7 Plus and the + iPads 6 and 7. ### Installer and launcher diff --git a/crates/boards/src/peripheral.rs b/crates/boards/src/peripheral.rs index 67bb278..5b72d76 100644 --- a/crates/boards/src/peripheral.rs +++ b/crates/boards/src/peripheral.rs @@ -51,6 +51,9 @@ enum Step { section: String, }, Vxd, + /// A10 video encoder firmware: the AVE2 image of AppleAVE2 whose hash is + /// the output's. + Ave2, AgxG9p, /// A9 GPU firmware, the one C0 image the driver knows. AgxG5p, @@ -229,6 +232,11 @@ fn run( Step::Vxd => { kernelcache::vxd(&Kernelcache::new(kernel(kernels, first, &data)?)?)?.to_vec() } + Step::Ave2 => pinned( + output, + kernelcache::ave2_images(&Kernelcache::new(kernel(kernels, first, &data)?)?)?, + "video encoder firmware", + )?, Step::AgxG9p => { kernelcache::agx_g9p(&Kernelcache::new(kernel(kernels, first, &data)?)?)?.to_vec() } @@ -530,6 +538,7 @@ fn parse(raw: &catalog::Step, recipe: &Recipe) -> Result> { &["bundle", "section", "segment"], ), "vxd-firmware-from-kernelcache@1" => (Step::Vxd, &[]), + "ave2-firmware-from-kernelcache@1" => (Step::Ave2, &[]), "agx-g9p-firmware-from-kernelcache@1" => (Step::AgxG9p, &[]), "agx-g5p-ldr-from-kernelcache@1" => (Step::AgxG5p, &[]), "agx-g4p-ldr-from-kernelcache@1" => (Step::AgxG4pLdr, &[]), @@ -669,6 +678,19 @@ mod tests { assert_eq!(plan.build[0].1, [Step::AgxG9p]); } + #[test] + fn the_video_encoder_step_takes_no_parameters() { + let recipe = recipe(&[("kernelcache", b"kernel")], vec![]); + let plain = step("ave2-firmware-from-kernelcache@1", Some("kernelcache"), &[]); + assert_eq!(parse(&plain, &recipe).unwrap(), Some(Step::Ave2)); + let extra = step( + "ave2-firmware-from-kernelcache@1", + Some("kernelcache"), + &[("chip", "rhea")], + ); + assert!(parse(&extra, &recipe).is_err()); + } + #[test] fn kext_section_step_takes_bundle_segment_and_section() { let params = [ diff --git a/crates/formats/src/kernelcache.rs b/crates/formats/src/kernelcache.rs index 43bdcd8..d9799a3 100644 --- a/crates/formats/src/kernelcache.rs +++ b/crates/formats/src/kernelcache.rs @@ -398,6 +398,35 @@ pub fn vxd<'a>(kc: &Kernelcache<'a>) -> Result<&'a [u8]> { } } +/// AVE2 video encoder firmware: the ARM images in AppleAVE2's +/// `__TEXT.__const`, one per chip family (iOS 14.5 has "rhea" for the A10 and +/// "cronus"). The recipe's hash picks one; see [`ave2_split`]. +pub fn ave2_images<'a>(kc: &Kernelcache<'a>) -> Result> { + let sections = kc.kext("com.apple.driver.AppleAVE2")?; + let constant = kc.section("__TEXT", "__const", §ions)?; + Ok(ave2_split(kc.read(constant.addr, constant.size)?)) +} + +/// The images in `constant`: each starts with an ARM vector table (a branch, +/// then seven branches to themselves) and has "FFW Application" at 0x40, and +/// it runs to the next image or the section's end. +fn ave2_split(constant: &[u8]) -> Vec<&[u8]> { + const SPIN: [u8; 4] = [0xfe, 0xff, 0xff, 0xea]; + let starts: Vec = (0..constant.len().saturating_sub(0x50)) + .filter(|&at| { + constant[at + 3] == 0xea + && constant[at + 4..at + 0x20].chunks(4).all(|w| w == SPIN) + && &constant[at + 0x40..at + 0x50] == b"FFW Application\0" + }) + .collect(); + let ends = starts.iter().skip(1).copied().chain([constant.len()]); + starts + .iter() + .zip(ends) + .map(|(&start, end)| &constant[start..end]) + .collect() +} + #[cfg(test)] mod tests { use super::*; @@ -644,6 +673,34 @@ mod tests { } } + /// An AVE2 image: its vector table, "FFW Application" at 0x40, `body`. + fn ave2(reset: u8, body: &[u8]) -> Vec { + let mut v = vec![reset, 0x58, 0x01, 0xea]; + (0..7).for_each(|_| v.extend([0xfe, 0xff, 0xff, 0xea])); + v.resize(0x40, 0); + v.extend(b"FFW Application\0"); + v.extend(body); + v + } + + #[test] + fn ave2_images_run_from_one_vector_table_to_the_next() { + let (one, two) = (ave2(0xe1, b"rhea"), ave2(0x3c, b"cronus, longer")); + let mut constant = vec![0x5a; 9]; + constant.extend(&one); + constant.extend(&two); + assert_eq!(ave2_split(&constant), vec![&one[..], &two[..]]); + + // Without its name, or with a vector that doesn't spin, it is data. + let mut unnamed = one.clone(); + unnamed[0x40] = b'f'; + let mut moving = one.clone(); + moving[8] = 0x10; + for data in [unnamed, moving, one[..0x4f].to_vec()] { + assert!(ave2_split(&data).is_empty()); + } + } + #[test] fn the_a7_ldr_is_found_as_the_a8_ldr_is() { let one = ldr(b"g3 firmware");