From 494a6a70593c5902aa58c4845fad4531228b9a59 Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Wed, 2 Dec 2026 12:41:41 +0900 Subject: [PATCH 1/3] kernelcache: take the A11's SmartIO firmware smartio-from-kernelcache@2 now accepts com.apple.driver.AppleT8015SmartIO, the iPhone 8, 8 Plus and X's SmartIO kext. Its firmware is the kext's __DATA.__firmware section, as on the other chips: on the iPhone X's iOS 16.7.16 kernelcache the step gives the same 616336 bytes as section-from-kernelcache@1 on that section. Assisted-by: LLM Co-Authored-By: Claude Opus 5.5 Signed-off-by: Menno van Leeuwen --- crates/boards/src/peripheral.rs | 32 +++++++++++++++++++++++++++++++ crates/formats/src/kernelcache.rs | 5 +++-- crates/formats/tests/steps.rs | 2 +- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/crates/boards/src/peripheral.rs b/crates/boards/src/peripheral.rs index 67bb278..ac841ea 100644 --- a/crates/boards/src/peripheral.rs +++ b/crates/boards/src/peripheral.rs @@ -669,6 +669,38 @@ mod tests { assert_eq!(plan.build[0].1, [Step::AgxG9p]); } + #[test] + fn smartio_step_takes_a_known_kext() { + let plan_of = |kext: &str| { + let recipe = recipe( + &[("kernelcache", b"kernel")], + vec![output( + "lib/firmware/apple/smartio.bin", + b"fw", + vec![step( + "smartio-from-kernelcache@2", + Some("kernelcache"), + &[("kext", kext)], + )], + )], + ); + Plan::new(&recipe).map(|plan| plan.build[0].1.clone()) + }; + for kext in kernelcache::SMARTIO_KEXTS { + assert_eq!( + plan_of(kext).unwrap(), + [Step::Smartio { + kext: (*kext).into() + }] + ); + } + assert!(kernelcache::SMARTIO_KEXTS.contains(&"com.apple.driver.AppleT8015SmartIO")); + assert_eq!( + plan_of("com.apple.driver.Other").unwrap_err().code, + Code::Format + ); + } + #[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..4bb404d 100644 --- a/crates/formats/src/kernelcache.rs +++ b/crates/formats/src/kernelcache.rs @@ -10,14 +10,15 @@ use crate::{im4p, img4, lzfse, lzss, Error, Result}; /// Decompressed kernels larger than this are refused. const MAX_KERNEL: usize = 256 << 20; -/// The bundle ids `smartio` accepts: A10, A9, A8 and A8X, A7, A10X. The -/// first is what `smartio-from-kernelcache@1` means. +/// The bundle ids `smartio` accepts: A10, A9, A8 and A8X, A7, A10X, A11. +/// The first is what `smartio-from-kernelcache@1` means. pub const SMARTIO_KEXTS: &[&str] = &[ "com.apple.driver.AppleT8010SmartIO", "com.apple.driver.AppleS8000SmartIO", "com.apple.driver.AppleT7000SmartIO", "com.apple.driver.AppleS5L8960XSmartIO", "com.apple.driver.AppleT8011SmartIO", + "com.apple.driver.AppleT8015SmartIO", ]; /// Decodes a kernelcache IM4P to the ARM64 kernel Mach-O. diff --git a/crates/formats/tests/steps.rs b/crates/formats/tests/steps.rs index 1ac567b..f197c10 100644 --- a/crates/formats/tests/steps.rs +++ b/crates/formats/tests/steps.rs @@ -117,5 +117,5 @@ fn smartio_of_a_kext_merged_into_the_kernel() { // A kext the kernel does not hold, and one the list does not know. assert!(kernelcache::smartio(&cache, "com.apple.driver.AppleT7000SmartIO").is_err()); assert!(kernelcache::smartio(&cache, "com.apple.driver.Other").is_err()); - assert_eq!(kernelcache::SMARTIO_KEXTS.len(), 5); + assert_eq!(kernelcache::SMARTIO_KEXTS.len(), 6); } From 0fbdc91ce8c31aaac06c5d2bcbef593621d918d6 Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Wed, 2 Dec 2026 12:41:50 +0900 Subject: [PATCH 2/3] kernelcache: A11 GPU firmware step agx-g10p-firmware-from-kernelcache@1 takes the A11's GPU (G10P) firmware from AGXFirmwareKextG10PRTBuddy. Its __TEXT.__const is laid out as the A10's G9P kext's: on the iPhone X's iOS 16.7.16 kernelcache it is "\0Release\0" and then the 0x5d320-byte ARM image, starting with an A32 vector table, that the kext's requestFirmwareBinary returns 9 bytes in. The A10's parsing is shared by both steps. Assisted-by: LLM Co-Authored-By: Claude Opus 5.5 Signed-off-by: Menno van Leeuwen --- crates/boards/src/peripheral.rs | 49 +++++++++++++++++++++---------- crates/formats/src/kernelcache.rs | 38 +++++++++++++++++++----- 2 files changed, 64 insertions(+), 23 deletions(-) diff --git a/crates/boards/src/peripheral.rs b/crates/boards/src/peripheral.rs index ac841ea..c31ca2c 100644 --- a/crates/boards/src/peripheral.rs +++ b/crates/boards/src/peripheral.rs @@ -52,6 +52,8 @@ enum Step { }, Vxd, AgxG9p, + /// A11 GPU firmware, laid out as the A10's. + AgxG10p, /// A9 GPU firmware, the one C0 image the driver knows. AgxG5p, /// A8 GPU firmware and its border colour table; the recipe's hash picks @@ -232,6 +234,9 @@ fn run( Step::AgxG9p => { kernelcache::agx_g9p(&Kernelcache::new(kernel(kernels, first, &data)?)?)?.to_vec() } + Step::AgxG10p => { + kernelcache::agx_g10p(&Kernelcache::new(kernel(kernels, first, &data)?)?)?.to_vec() + } Step::AgxG5p => { let image = kernelcache::agx_g5p(&Kernelcache::new(kernel(kernels, first, &data)?)?)?; @@ -531,6 +536,7 @@ fn parse(raw: &catalog::Step, recipe: &Recipe) -> Result> { ), "vxd-firmware-from-kernelcache@1" => (Step::Vxd, &[]), "agx-g9p-firmware-from-kernelcache@1" => (Step::AgxG9p, &[]), + "agx-g10p-firmware-from-kernelcache@1" => (Step::AgxG10p, &[]), "agx-g5p-ldr-from-kernelcache@1" => (Step::AgxG5p, &[]), "agx-g4p-ldr-from-kernelcache@1" => (Step::AgxG4pLdr, &[]), "agx-g4p-border-from-kernelcache@1" => (Step::AgxG4pBorder, &[]), @@ -651,22 +657,33 @@ mod tests { } #[test] - fn gpu_firmware_step_is_supported_without_parameters() { - let recipe = recipe( - &[("kernelcache", b"kernel")], - vec![output( - "lib/firmware/apple/gfx-t8010.bin", - b"gpu", - vec![step( - "agx-g9p-firmware-from-kernelcache@1", - Some("kernelcache"), - &[], - )], - )], - ); - let plan = Plan::new(&recipe).unwrap(); - assert!(plan.unsupported.is_empty()); - assert_eq!(plan.build[0].1, [Step::AgxG9p]); + fn gpu_firmware_steps_are_supported_without_parameters() { + let steps = [ + ("agx-g9p-firmware-from-kernelcache@1", "t8010", Step::AgxG9p), + ( + "agx-g10p-firmware-from-kernelcache@1", + "t8015", + Step::AgxG10p, + ), + ]; + for (name, chip, built) in steps { + let plan_of = |params: &[(&str, &str)]| { + let recipe = recipe( + &[("kernelcache", b"kernel")], + vec![output( + &format!("lib/firmware/apple/gfx-{chip}.bin"), + b"gpu", + vec![step(name, Some("kernelcache"), params)], + )], + ); + Plan::new(&recipe).map(|plan| { + assert!(plan.unsupported.is_empty()); + plan.build[0].1.clone() + }) + }; + assert_eq!(plan_of(&[]).unwrap(), [built]); + assert_eq!(plan_of(&[("x", "1")]).unwrap_err().code, Code::Format); + } } #[test] diff --git a/crates/formats/src/kernelcache.rs b/crates/formats/src/kernelcache.rs index 4bb404d..4c57ac3 100644 --- a/crates/formats/src/kernelcache.rs +++ b/crates/formats/src/kernelcache.rs @@ -190,12 +190,24 @@ pub fn smartio<'a>(kc: &Kernelcache<'a>, bundle: &str) -> Result<&'a [u8]> { /// A10 GPU firmware: a build-variant C string followed by an ARM image in /// AGXFirmwareKextG9PRTBuddy's __TEXT.__const. The recipe pins the image hash. pub fn agx_g9p<'a>(kc: &Kernelcache<'a>) -> Result<&'a [u8]> { - let sections = kc.kext("com.apple.AGXFirmwareKextG9PRTBuddy")?; + agx_rtbuddy(kc, "com.apple.AGXFirmwareKextG9PRTBuddy") +} + +/// A11 GPU firmware: laid out as the A10's, in AGXFirmwareKextG10PRTBuddy's +/// __TEXT.__const. The recipe pins the image hash. +pub fn agx_g10p<'a>(kc: &Kernelcache<'a>) -> Result<&'a [u8]> { + agx_rtbuddy(kc, "com.apple.AGXFirmwareKextG10PRTBuddy") +} + +fn agx_rtbuddy<'a>(kc: &Kernelcache<'a>, bundle: &str) -> Result<&'a [u8]> { + let sections = kc.kext(bundle)?; let section = kc.section("__TEXT", "__const", §ions)?; - agx_g9p_image(kc.read(section.addr, section.size)?) + agx_rtbuddy_image(kc.read(section.addr, section.size)?) } -fn agx_g9p_image(constant: &[u8]) -> Result<&[u8]> { +/// The image behind the build-variant C string (`\0Release\0` on A10 and +/// A11): what the kext's `requestFirmwareBinary` hands to the GPU. +fn agx_rtbuddy_image(constant: &[u8]) -> Result<&[u8]> { let start = constant .iter() .position(|b| *b != 0) @@ -589,15 +601,27 @@ mod tests { let start = constant.len(); constant.extend(vec![0; 4096]); constant[start..start + 4].copy_from_slice(&[0x0e, 0, 0, 0xea]); - assert_eq!(agx_g9p_image(&constant).unwrap(), &constant[start..]); - assert!(agx_g9p_image(&constant[..constant.len() - 1]).is_err()); + assert_eq!(agx_rtbuddy_image(&constant).unwrap(), &constant[start..]); + assert!(agx_rtbuddy_image(&constant[..constant.len() - 1]).is_err()); constant[start + 3] = 0; - assert!(agx_g9p_image(&constant).is_err()); + assert!(agx_rtbuddy_image(&constant).is_err()); for malformed in [b"".as_slice(), b"\0\0", b"Release", b"\x01\0", b"Release\0"] { - assert!(agx_g9p_image(malformed).is_err()); + assert!(agx_rtbuddy_image(malformed).is_err()); } } + #[test] + fn a11_gpu_firmware_is_laid_out_as_the_a10s() { + // AGXFirmwareKextG10PRTBuddy's __TEXT.__const: one NUL, the variant, + // then the image `requestFirmwareBinary` returns, 9 bytes in. + let mut constant = b"\0Release\0".to_vec(); + assert_eq!(constant.len(), 9); + let mut image = vec![0; 0x5d320]; + image[..8].copy_from_slice(&[0x06, 0, 0, 0xea, 0xfe, 0xff, 0xff, 0xea]); + constant.extend(&image); + assert_eq!(agx_rtbuddy_image(&constant).unwrap(), image); + } + /// A META LDR: header, one L1 record (command 0) and its L2 block. fn ldr(fill: &[u8]) -> Vec { let mut v = Vec::new(); From 2c54e75f83b1b76a6d319df97bf36de9dfcffe57 Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Wed, 2 Dec 2026 12:51:43 +0900 Subject: [PATCH 3/3] CHANGELOG: the A11's SmartIO and GPU firmware steps Assisted-by: LLM Co-Authored-By: Claude Opus 5.5 Signed-off-by: Menno van Leeuwen --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6feaa12..2425580 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ is on main, the release is published with that section as its notes (AGENTS.md, XR's audio codec from the IPSW (`cs42l75-clp@1`, from `Firmware/N841_CallanFirmware.im4p`): without it the XR's speakers stay silent under Linux. +- Firmware recipes can take the iPhone 8, 8 Plus and X's SmartIO firmware + (`smartio-from-kernelcache@2` with `com.apple.driver.AppleT8015SmartIO`) + and their GPU firmware (`agx-g10p-firmware-from-kernelcache@1`) from the + kernelcache. ### Installer and launcher