Skip to content

shim: board hooks (soc_hooks.h), opt-in per SoC (split plan #3, A2) - #4

Draft
flo071 wants to merge 2 commits into
PixOS-Project:mainfrom
flo071:split/a2-board-hooks
Draft

flo071 wants to merge 2 commits into
PixOS-Project:mainfrom
flo071:split/a2-board-hooks

Conversation

@flo071

@flo071 flo071 commented Dec 4, 2026 •

Copy link
Copy Markdown

What and why

First shared-code PR of the cheetah (Pixel 7 Pro, gs201) split agreed in #3 (step A2). It adds the points where the shared shim
flow hands over to SoC code, and nothing that uses them: no SoC on main opts in, so the bluejay build is unchanged
(proof below).

What changed

  • Opt-in (tools/boards.py): a SoC sets "shim_hooks": true in soc/<vendor>/<soc>/soc.json. Only then is
    #define SOC_SHIM_HOOKS 1 emitted into board_config.h (after the SOC_* family macros) and
    boards.py BOARD --get shim_hooks prints 1 (else 0). The key is refused in a board.json and when it is not a JSON
    boolean.

  • shim/soc_hooks.h: the hook API with its rules (read-only unless audited, bounded waits, no hook on the stop
    path) and when each hook runs. Hooks, each derived from a gs201 call site on the reference branch:

    Hook Where gs201 use on the reference branch
    soc_hook_entry(dtb) -> SOC_ENTRY_USB_EARLY first line of bluejay_probe fixed pstore checkpoint, watchdog measure, early USB live log
    soc_hook_video(&video) before con_set_video display enable; may keep the console off the panel
    soc_hook_console(&video) after the FB line framebuffer report
    soc_hook_pstore_fallback() pstore_init(dtb) found no zone fixed zone from board.json
    soc_hook_probes() after checkpoint 1 the gs201 probe sections
    soc_hook_pre_xnu() first step of --boot-xnu display survey
    soc_hook_payload, soc_hook_bootflags, soc_hook_before_jump loader_boot() payload in the Image, XNU gs201 boot flag, pre-jump steps
  • Call sites (shim/shim.c): all under #if SOC_SHIM_HOOKS, a capability flag, not a SoC name. The loader hooks
    are SOC_HOOK_* macros (included through loader.h) that expand to exactly the replaced code without hooks and sit
    on existing lines, so loader.c keeps its line numbers.

  • Probe flow widened by capability: the probe section, try_write32 and the exception-handler fault skip now
    build for SHIM_PROBE = SOC_GS101 || SOC_SHIM_HOOKS (on gs101 that is 1, as SOC_GS101 was). The gs101-only steps
    inside keep SOC_GS101 guards (DECON re-arm, PMU CPU prep), REBOOT_BL is an #error on any other SoC, and
    reset()/shim_halt() take a PSCI-only branch on a hook SoC instead of sweet's Qualcomm restart words.

  • shim/build.sh: compiles and links soc/<vendor>/<soc>/shim/soc_hooks.c only when --get shim_hooks is 1
    (also in the ABS64 relocation check). Because no SoC sets the key, the host-test block also compiles shim.c and
    loader.c for a non-gs101 hook SoC (this board's header with SOC_GS101 0 + SOC_SHIM_HOOKS 1, into
    $O/hookcheck/) and checks that every always-built hook is referenced, so the hook code cannot rot unbuilt.

Not in this PR (listed per file in a classification, available on request): every gs201 body (goes to
soc/google/gs201/shim/soc_hooks.c in the board PRs), and the generic changes the reference branch carries that are
useful to all boards but change bluejay bytes (console no-framebuffer guard, pstore_init_fixed, USB log drain before
the jump, SCTLR_EL1 reset in start.S, WDT_ARMED, PANEL_QUIET/BOOT_LOGO, Wi-Fi header fixes). Those come as
separate PRs with their own proof. The type/style pass is dropped as asked.

Hardware evidence

Not tested on hardware: no bluejay byte changes and no SoC uses the hooks yet.

Bluejay (Pixel 6a) impact

Shared code changed; the bluejay build is unchanged (observed, build host, 2026-12-03).

Method: two worktrees at the same HEAD b5baf08 (so both embed build id b5baf08): clean origin/main, and
origin/main + this PR's diff uncommitted. tools/pix build bluejay in each, then sha256sum of every object the
build compiles, shim.elf, Image, Image.lz4, shim-boot.img, shim-boot-lz4.img, ramdisk.bin,
board_config.h, wlan_seq.h. Second pair: same with __LINE__ replaced by 0 in SHIM_ASSERT
(shim/shim_assert.h). Script: a2-compare.sh (at the end of this description).

Pair Result
normal all 48 objects, shim.elf, Image, Image.lz4, board_config.h, wlan_seq.h identical; ramdisk.bin and the two boot images differ
__LINE__ = 0 same: everything identical except ramdisk.bin and the two boot images

The ramdisk.bin difference is not this PR: build.sh packs an empty placeholder directory with
find . \| cpio \| gzip, so the cpio header carries that directory's inode and mtime and the gzip header a
timestamp; two builds of the same main tree differ the same way. Re-packing both trees' Image/Image.lz4 with one
fixed ramdisk and build.sh's exact mkbootimg arguments gives identical boot images in both pairs
(fixedrd-* rows). Because the normal pair is already identical, no object of the default build depends on a
shifted __LINE__: loader.c keeps its line numbers, and shim.c's only SHIM_ASSERT (line 65 -> 66, below the new
#include) is compiled only with --touch-probe=dvfs, which this comparison does not build.

Key hashes (normal pair; the same value in the main and the PR build; full lists for all four builds on request):

e1273407b2756983a2767381be55c2d74674d3d10fc4c833ff4bf57683a10b7e  shim.o
29bfaf1003c2af09b165cddfb7b977f76fc18a78891a0ac940f6fc4d05d9f521  loader.o
c5ad911ae78b1aad07926f6569c6b8f51c7ae1253e83108bee8bec1e3c6ca27d  shim.elf
5cd9605facb434fb2ea9f6a77f01084a866df81ae1305e0fd3812930d6f925a6  Image
83b4d25f0e89dbe839088c6df3720f95dd7da472ca62e5bb686de49de61fee82  Image.lz4
7eee76bc0cf6f211fe437b967b090236d4305071aa1f8e8eb0650e2515155921  board_config.h
aa8fc36bfa82b5f787c2c7580cab6213e9f4828998172ca382b83c5e06ddd57c  fixedrd-shim-boot.img
6185bb23619c8da7f0ecac78041c3a0ae8a6344d9d5863cadfdd509ed6af94de  fixedrd-shim-boot-lz4.img

__LINE__ = 0 pair, same in both: shim.elf 093d50e9460f6fbe..., Image 3e95b69e155fbf5a...,
fixedrd-shim-boot.img 98a89847f82d1571... (these differ from the normal pair, so the neutralised builds were fresh).

The __LINE__ = 0 builds end with FAIL shim_assert_host_test (it checks the real line number); that is expected
and happens on main too; the images are linked before the host tests run.

Tests and gate

  • tools/test_boards_shim_hooks.py (new, 6 tests): trunk headers carry no macro and --get prints 0; a copied tree
    without the key renders identical headers for every board; opting gs101 in adds exactly one line after the SOC_*
    macros (other SoCs untouched) and --get prints 1; false equals absent; non-boolean values and a board.json key
    are refused, also through the CLI.

  • shim/build.sh host-test block: soc_hooks call sites (shim.c, hook SoC), (loader.c, hook SoC),
    soc_hooks call sites reference every always-built hook: PASS.

  • tools/lint-c --style --base origin/main: RESULT: PASS style new=0 baseline=1468.

  • .github/scripts/pr_rules.py --profile kernel origin/main HEAD: RESULT: PASS 7 files, 0 rule(s) failed (on the final head).

  • tools/check-all.sh on this head (observed, build host, 2026-12-04; run with LINT_STYLE_BASE=origin/main GATE_JOBS=2 GATE_STEP_TIMEOUT=2400 --keep-going):
    GATE FAIL 8751e11 unit failed: test_devd_mutants.py, test_safety_xrun.py, test_adversary_matrix.py +22 more.
    Every other step passes (all 12 build variants, host-tests, boot-safety, validate, rules, public-guard, shellcheck,
    lint-c, xnu-build, stack-apply, mutant-needles, boot-markers, lint-silent, consumed, inputs, wlan-mutants), and
    test_boards_shim_hooks.py passes in its shard. Why the knobs: this host's local main branch is 346 commits
    behind origin/main, so the style ratchet's default base counts every function changed since then
    (style new=238, validate fails the same way on a clean origin/main checkout); with the default 6 parallel
    builds the build steps hit the 900 s step timeout on this machine.
    No GATE PASS on this host. Per your rule in Pixel 7 Pro (cheetah, gs201) port: split plan for #2 and pixelios-userland#1 #3, here is every failure: the unit step counts 26 = 14 failing
    files + 11 skips not pinned in tools/unit-skip-allow.txt (4 files) + 1 COUNT MISMATCH (2382 collected vs 2377
    run: the 5 tests of test_safety_xrun.py, whose setUpClass errors). Each failing file, run standalone on
    origin/main and on this head, gives the same result on both:

    Unit file main PR cause on this host
    test_agent_guard.py FAIL (2) FAIL (2) needs the super repo's tools/triage-settle-guard
    test_devd_hardening.py, test_devd_mutants.py rc 2 rc 2 devd environment
    test_gate_unit_shards_order.py FAIL (1) FAIL (1) duration ordering on a loaded host
    test_heavy_job_r3.py, test_job_wake.py, test_phone_lock_wake.py FAIL FAIL no tools/wake / wake hook here
    test_normal_runs_silent.py FAIL (1) FAIL (1) test_usbroot_host environment
    test_ota_extract.py FAIL (10) FAIL (10) git rev-parse outside a repo in its temp dirs
    test_safety_xrun.py ERROR (1) ERROR (1) unshare -r -n -m not permitted
    test_xnu_src_mirror.py FAIL (1) FAIL (1) mirror environment
    test_mkdevoverlay.py FAIL (1) FAIL (1) test_guard_refuses_a_root_image_file: this host's "standard root image" (newest line of flashed-userdata.txt) is a cheetah root without /usr/local/bin/wifid-probe; reproduced on a clean origin/main worktree
    test_adversary_matrix.py, test_check_all_stub.py OK OK fail only inside the loaded gate, on timing: case 25 "Process failed to terminate cleanly" and "gate still running 10 s after the signal" (gate steps ran 10-25x over budget on this host)
    test_mg_key.py, test_phone_lock.py, test_golden_gpu_analyze.py, test_qrl2.py OK + skips OK + skips skips not allowed by the gate: capstone, opencv/numpy, golden dir, unshare missing

    None of these files or the code they test is touched by this PR. A GATE PASS from a machine with the full environment
    would still be welcome.

  • Hardware: none. This PR changes no bluejay byte, and no SoC uses the hooks yet; nothing was run on a phone.

Size: 7 files, +347 / -19 lines (of which 135 test, 89 the documented header).

Safety checklist

  • No write outside userdata; no new UFS write path in the shim
  • tools/check-all.sh prints GATE PASS (not on this host: only the unit step fails, every failure listed above and the same on main)
  • One concern, under ~1500 added code lines and 40 files (step A2 of the split plan in Pixel 7 Pro (cheetah, gs201) port: split plan for #2 and pixelios-userland#1 #3)
  • Existing xnu/patches/ untouched; changes come as new numbered patches (no patch touched)
  • No prebuilt binaries; everything builds from source
  • Safety audits and phone tools untouched, or the change was agreed in the linked issue (tools/test-bluejay-boot.py not edited)
  • Board-specific code gated on the board; other boards' build output unchanged (gated on the shim_hooks capability; bluejay proof above)
  • No serials, dumps, keys, firmware or Apple artifacts in the diff
  • Constants cite their source; claims are tagged observed / read / guess (no new constants)
  • AI assistance: what was generated, what a human checked: AI assistance: the code, the test, the builds and checks above and this description were done by Claude (Claude Code) on my behalf; I reviewed the diff.
a2-compare.sh
#!/bin/bash
# A2 proof: bluejay build of origin/main (b5baf08, clean) vs the PR (same HEAD b5baf08 + the A2 diff uncommitted,
# so both embed the same build id). Pairs: normal, and with __LINE__ neutralised in SHIM_ASSERT (shim/shim_assert.h).
# The placeholder ramdisk (build.sh: cpio of an empty dir | gzip) carries the directory's inode and mtime, so
# ramdisk.bin and with it shim-boot*.img differ between ANY two builds; the boot images are therefore also re-packed
# here with one fixed ramdisk (main's), using build.sh's exact mkbootimg arguments ("fixedrd" lines).
set -u
S=${WORK:?set WORK to a dir holding the worktrees a2-omain (origin/main) and a2-pr (origin/main + this diff)}
P=$S/a2-proof
cp "$S/a2-omain/shim/out/ramdisk.bin" "$P/fixed-ramdisk.bin" 2>/dev/null || true
hashes() {	# $1 tree, $2 name
	local o=$S/$1/shim/out mk
	mk=$S/$1/tools/third_party/mkbootimg.py; [ -e "$mk" ] || mk=$S/a2-omain/tools/third_party/mkbootimg.py
	python3 "$mk" --header_version 4 --kernel $o/Image --ramdisk "$P/fixed-ramdisk.bin" --pagesize 4096 --os_version 12.0.0 \
		--os_patch_level 2022-07 --cmdline "console=null" -o $o/fixedrd-shim-boot.img
	python3 "$mk" --header_version 4 --kernel $o/Image.lz4 --ramdisk "$P/fixed-ramdisk.bin" --pagesize 4096 --os_version 12.0.0 \
		--os_patch_level 2022-07 --cmdline "console=null" -o $o/fixedrd-shim-boot-lz4.img
	# only the objects build.sh compiles for the image (host-test objects such as acpm_*.o exist only when host tests ran uncached)
	(cd $o && sha256sum $(ls *.o | grep -v '^acpm_\(dvfs_ro\|dvfs_rw\|gpuclk\|mifclk\|mifclk_level\|ro\|sweetprobe\)\.o$') \
		shim.elf Image Image.lz4 shim-boot.img shim-boot-lz4.img fixedrd-shim-boot.img fixedrd-shim-boot-lz4.img ramdisk.bin board_config.h wlan_seq.h) > "$P/hash-$2.txt"
}
build() {	# $1 tree, $2 name
	(cd $S/$1 && timeout 1800 tools/heavy-job run --class build --label "a2-$2" --wait 3600 -- tools/pix build bluejay) > "$P/build-$2.log" 2>&1
	echo "$2 build rc=$? $(grep -a 'RESULT: .*label=' "$P/build-$2.log" | tail -1)"
	hashes "$1" "$2"
}
[ "${1:-}" = skip-main-normal ] && hashes a2-omain main-normal || build a2-omain main-normal
build a2-pr pr-normal
for t in a2-omain:main a2-pr:pr; do
	tree=${t%%:*}; n=${t##*:}
	sed -i 's/shim_assert_fail(__FILE__, __LINE__, #cond)/shim_assert_fail(__FILE__, 0, #cond)/' $S/$tree/shim/shim_assert.h
	grep -c 'shim_assert_fail(__FILE__, 0, #cond)' $S/$tree/shim/shim_assert.h
	build $tree $n-noline
	(cd $S/$tree && git checkout -q -- shim/shim_assert.h)
done
cd $P
for pair in normal noline; do
	if diff hash-main-$pair.txt hash-pr-$pair.txt > diff-$pair.txt; then echo "$pair: IDENTICAL ($(wc -l < hash-main-$pair.txt) files)"; else echo "$pair: DIFFERS:"; cat diff-$pair.txt; fi
done

🤖 Generated with Claude Code

flo071 and others added 2 commits December 3, 2026 20:23
A SoC opts into the shim board hooks (shim/soc_hooks.h, next commit) with
"shim_hooks": true in its soc.json. boards.py then emits
`#define SOC_SHIM_HOOKS 1` into board_config.h, after the SOC_* family
macros, and `--get shim_hooks` prints 1 (else 0) for shim/build.sh. The key
is refused in a board.json and when it is not a JSON boolean. No SoC sets it,
so every generated header is unchanged (bluejay's board_config.h compared
byte for byte).

Test: tools/test_boards_shim_hooks.py (trunk headers carry no macro; a
copied tree without the key renders identical headers; opting gs101 in adds
exactly one line; false == absent; non-bool and board.json values refused,
also through the CLI).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shim/soc_hooks.h declares the points where the shared flow hands over to SoC
code, with the rules for them (read-only unless audited, bounded waits, no
hook on the stop path): soc_hook_entry (top of the probe, may ask for the USB
live log early), soc_hook_video / soc_hook_console (around con_set_video),
soc_hook_pstore_fallback (pstore_init found no zone), soc_hook_probes (after
checkpoint 1), soc_hook_pre_xnu (first step of --boot-xnu), and in the loader
soc_hook_payload, soc_hook_bootflags, soc_hook_before_jump. The loader ones
are SOC_HOOK_* macros that expand to the replaced code without hooks and sit
on existing lines, so loader.c keeps its line numbers (SHIM_ASSERT __LINE__).

Every call site is under `#if SOC_SHIM_HOOKS`, a capability flag from
tools/boards.py (soc.json "shim_hooks"), never a SoC name. The probe flow
(bluejay_probe, try_write32, the exception skip) now builds for
SHIM_PROBE = SOC_GS101 || SOC_SHIM_HOOKS, identical to SOC_GS101 on gs101; its
gs101-only steps keep SOC_GS101 guards (DECON re-arm, PMU CPU prep; REBOOT_BL
is an #error elsewhere) and reset()/shim_halt() take a PSCI-only branch on a
hook SoC instead of sweet's Qualcomm words.

build.sh compiles and links soc/<vendor>/<soc>/shim/soc_hooks.c only when
`boards.py --get shim_hooks` is 1 (also in the ABS64 list), and its host-test
block compiles shim.c/loader.c for a non-gs101 hook SoC into $O/hookcheck and
checks every always-built hook is referenced, because no SoC on trunk sets the
key. Inert on trunk: bluejay objects, shim.elf and Image are byte-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant