Skip to content

Detect Apple Silicon generations from device tree - #326

Open
CptPanko wants to merge 2 commits into
omacom:quattrofrom
CptPanko:feat/apple-silicon-generation-detection
Open

CptPanko wants to merge 2 commits into
omacom:quattrofrom
CptPanko:feat/apple-silicon-generation-detection

Conversation

@CptPanko

@CptPanko CptPanko commented Sep 2, 2026

Copy link
Copy Markdown

Summary

  • add a hidden identity command that maps exact Apple device-tree SoC records from M1 through evidence-confirmed base M4
  • fail closed for malformed, ambiguous, conflicting, future, and unconfirmed records
  • keep M4 Pro and M4 Max identifiers reserved but unconfirmed until primary root-DTS or live device-tree evidence exists
  • provide byte-safe diagnostics without invoking package, privilege, policy, or setup commands

Scope

This is identity detection only. It does not enable installation, change setup policy, or claim native M3/M4 support.

Mappings are grounded in the pinned Asahi SoC table and literal compatible records in the pinned Asahi Linux Apple DTS tree.

Testing

  • test/shell.d/apple-silicon-generation-test.sh (27 assertions under macOS Bash 3.2, Homebrew Bash, and Ubuntu 24.04)
  • exhaustive control/high-byte, empty, truncated, malformed, duplicate, conflict, FIFO, and unconfirmed-record probes
  • planted mapping mutation fails the focused suite
  • bin/omarchy commands --check under modern Bash
  • parser-aware syntax checks for every bin/omarchy-* command
  • git diff --check

The aggregate suite remains bounded by existing macOS host/tooling incompatibilities; the changed focused suite and Linux run pass.

@scottjones scottjones left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed this against #343, which adds a second device-tree SoC detector. Ran both on an M2 Max (apple,j414c, t6021) and against stubbed trees for the IDs where the two tables disagree.

Your table is the better one, and it is the part I would keep. It has t6032 (M3 Ultra), which #343 omits entirely — so a Mac Studio M3 Ultra fails detection there outright. And keeping t6040/t6041 as unconfirmed-compatible rather than guessing, with the pinned Asahi SoC table and DTS tree cited in the description, is the right call; #343 claims those plus t6050/t6051 as m4 with no source. Refusing to state what you cannot evidence is worth more here than coverage.

bug: the command ignores OMARCHY_APPLE_COMPATIBLE, so nothing else can stub it.

The production entry point hardcodes the path:

--key)      omarchy_apple_silicon_generation_parse "/proc/device-tree/compatible" "key" ;;
--diagnose) omarchy_apple_silicon_generation_parse "/proc/device-tree/compatible" "diagnose" ;;

I found this the hard way: I pointed OMARCHY_APPLE_COMPATIBLE at five different stub trees and got m2-max every time, because it was reading this machine's real device tree and ignoring me. I had to source the file and call the parser directly, the way your own tests do, to get real answers.

That is a convention break with real consequences. omarchy-hw-apple-silicon in #331 takes OMARCHY_APPLE_COMPATIBLE; omarchy-hw-apple-soc in #343 takes it; omarchy-hw-dp-altmode in #289 takes OMARCHY_DEVICE_TREE. A hidden identity command exists so other code can branch on it, and other code's tests then need to stub it. As written, they cannot — only this file's own tests can, and only by sourcing it. Reading the path from ${OMARCHY_APPLE_COMPATIBLE:-/proc/device-tree/compatible} costs one line and makes the command testable from outside.

suggestion: 197 lines and ten distinct failure codes is a lot of parser for a file the kernel generates. The conflicting-compatible and ambiguous-compatible cases are legitimate — two different SoC selectors in one tree is a real thing to refuse. But non-ascii-compatible, truncated-record via an od byte inspection, and the per-byte printf '%d' escape loop defend against a malformed device tree on a machine that would not have booted. It is also the file most likely to confuse the next reader. Not blocking, and I would rather have this than the opposite failure, but it is worth asking which of those ten states can actually occur.

The duplication

Three device-tree detectors are now in flight:

PR command does
#331 (@malik-na) omarchy-hw-apple-silicon boolean: is this Apple Silicon
this omarchy-hw-apple-silicon-generation device tree -> granular (m2-max)
#343 (@staccDOTsol) omarchy-hw-apple-soc device tree -> m1..m4 + codename + --gpu

Different filenames, so git will not stop any of them and all three could land. My read is that #343 has the better shape and this PR has the better table. #343 is env-stubbable, 96 lines against 197, and has a --gpu check that asks whether the Asahi GPU driver is actually bound rather than inferring capability from generation — I verified that one on hardware and it is correct. Keying decisions off the binding means a generation table cannot go stale underneath them.

The merge of the two is the command I would want: #343's interface with your table and your sourcing discipline.

Granularity is a genuine decision someone should make deliberately rather than by merge order — m2 plus --codename versus m2-max. Both are defensible; shipping both means callers pick arbitrarily. Worth you and @staccDOTsol settling it between you, and #331's boolean is the third piece both of these arguably should build on.

I am marking this changes-requested for the env-override line, which is a small concrete fix. The duplication question is not mine to decide alone and should not block you on its own.

@malik-na

malik-na commented Sep 9, 2026

Copy link
Copy Markdown
Member

The existing blocker remains: the executable entrypoint still hardcodes /proc/device-tree/compatible. Use OMARCHY_APPLE_COMPATIBLE so callers can stub it, then reconcile the public shape with #343 before either detector lands.

@wesleygrimes wesleygrimes added the defer Parked. Needs a decision, or may die with the fork. Do not close or port yet. label Sep 12, 2026
@malik-na malik-na added the US label Sep 20, 2026
@eXsoR65

eXsoR65 commented Nov 4, 2026

Copy link
Copy Markdown

Tested fix for the blocker in #326 (comment) — the hardcoded /proc/device-tree/compatible.

What changed

The entry point now resolves the source once and honours OMARCHY_APPLE_COMPATIBLE, matching install/hardware/apple/video-decode.sh and install/hardware/apple/audio.sh:

compatible=${OMARCHY_APPLE_COMPATIBLE:-/proc/device-tree/compatible}

Diff: CptPanko/omarchy-mac@feat/apple-silicon-generation-detection...eXsoR65:omarchy-mac:fix/apple-compatible-override

Branch: eXsoR65/omarchy-mac:fix/apple-compatible-override, one commit (9d231b9) on top of f2573a4.

Worth flagging separately

The focused test currently asserts the hardcoded behaviour and uses a different variable name:

if overridden=$(OMARCHY_DEVICE_TREE_COMPATIBLE="$fixture" ...)
...
[[ $direct_status == "$override_status" ]] || fail "executable ignores source environment override"
pass "executable hardcodes default source and rejects overrides"

So the test locks in the opposite of what was requested. I rewrote that block to check that the override resolves apple,t8103 to m1, that --diagnose reports the overridden source, and that the fallback to /proc/device-tree/compatible still fails closed with missing-compatible when no file is present.

Verification

  • test/shell.d/apple-silicon-generation-test.sh: 25/25 ok, no failures.
  • Entry point against fixtures: apple,t8132 → m4 (exit 0); apple,t6040 and apple,t6041 → unconfirmed-compatible (exit 1). Run on an M4 Pro Mac mini (target-type J773s), which is exactly the case the unconfirmed-compatible arm exists for.
  • Full ./test/shell does not pass on my machine, but only on unrelated environment failures (missing jq/magick, display tests). The generation suite itself is green.

Happy to open this as a PR against your branch, or cherry-pick 9d231b9 directly. I did not rename OMARCHY_DEVICE_TREE_COMPATIBLE — reconciling the two names with #343 looks like a separate decision rather than part of this fix.

@malik-na

malik-na commented Nov 4, 2026

Copy link
Copy Markdown
Member

Thanks @eXsoR65, this fixes the blocker. I checked it against quattro: the entry point now reads ${OMARCHY_APPLE_COMPATIBLE:-/proc/device-tree/compatible} exactly like install/hardware/apple/video-decode.sh, audio.sh and bin/omarchy-hw-apple (same name, same default, empty falls back). No other hardcoded /proc/device-tree/compatible reads are left in this PR. 9d231b9 also merges cleanly onto current quattro.

What I ran:

  • Focused suite on 9d231b9: all green. I count 29 ok, not 25, but nothing fails. Same on a local merge with quattro, and the video-decode and audio tests still pass there.
  • Reverted the entry point to the hardcoded path, renamed the variable, and dropped the override from --key and --diagnose separately. The rewritten test failed every time, so it really guards the override now.
  • --diagnose reports the overridden source. Unset or empty override falls back to /proc/device-tree/compatible and fails closed with missing-compatible (exit 1). commands --check passes, and shellcheck reports nothing new beyond notes.

Two small optional follow-ups, not blocking:

  1. The fallback check (test lines ~180-191) doesn't pin the default path. On a machine without a device tree, a typo like /proc/device-tree/compatibl still yields missing-compatible and passes. On a Mac the readable branch asserts nothing. Asserting source=/proc/device-tree/compatible from --diagnose with the var unset catches this on any host. I tried it and it fails on the typo as expected.
  2. --diagnose now prints the source path raw (printf 'source=%s\n'). Since that path comes from the env, a path with newlines can inject a fake key=/reason= line (exit status stays correct). Escaping it like the records, or using %q, would keep the byte-safe diagnostics promise.

@CptPanko, happy for you to cherry-pick 9d231b9 onto your branch. That clears the hardcoded-path blocker from my side.

@eXsoR65

eXsoR65 commented Nov 4, 2026

Copy link
Copy Markdown

Thanks — and you're right about the count. It is 29, not 25. My number came from a truncated tail of the run, not from counting; the suite was green either way but the figure was wrong.

Both follow-ups are implemented, and I verified each one the way you did — by making it fail.

1. The default path is now pinned. The gap was real: the fallback branch only distinguishes "missing" from "readable", so any typo in the literal still produced missing-compatible and passed. --diagnose reports the source whether or not the file exists, so the test now asserts the literal with the override unset and empty:

env -u OMARCHY_APPLE_COMPATIBLE "$parser_bash" -c '"$1" --diagnose' ...
grep -Fqx 'source=/proc/device-tree/compatible' "$test_tmp/default-diag-err" ||
  fail "unset override falls back to the live device tree path" ...

Mutation-checked: changing the default to /proc/device-tree/compatibl now fails with not ok - unset override falls back to the live device tree path, on this host, which has no device tree at all.

2. --diagnose quotes the source. printf 'source=%s\n' became printf 'source=%q\n'. %q left every ordinary path untouched, so the existing source=$fixture assertions did not change, and it renders a newline as \n inside $'...' rather than emitting a real line break.

New test builds a path containing a newline followed by key=injected, then asserts exactly one line each starting with source=, key= and reason=. Mutation-checked: reverting %q to %s fails with not ok - diagnose source cannot inject a key line.

State

  • 91fc23e6, still one commit on top of f2573a4. I amended and force-pushed my fork branch, so the sha moved from 9d231b9 — if you would rather cherry-pick one clean commit per change, say so and I will split it into the base fix plus a follow-up commit instead.
  • Focused suite: 31 ok, nothing failing (29 as you counted, plus one for each new guard).
  • bin/omarchy commands --check passes (457 commands), bash -n clean, shellcheck reports nothing.
  • Unchanged: --key still rejects a source-path argument, the unset/empty fallback still fails closed with missing-compatible and exit 1.

One thing I did not act on, since it is your call rather than a fix: OMARCHY_DEVICE_TREE_COMPATIBLE still exists in electron-gl.sh and is now dead in this test. Reconciling the two names with #343 still looks like a separate decision.

@malik-na

malik-na commented Nov 4, 2026

Copy link
Copy Markdown
Member

Thanks @eXsoR65, both follow-ups look good. I checked 91fc23e: still one commit on f2573a4, it merges cleanly onto current quattro, and the diff from 9d231b9 is just the %q line and the two new test blocks.

What I ran:

  • Focused suite: 31 ok, nothing failing. Same on a local merge with quattro, and the video-decode and asahi-audio tests still pass there. commands --check and bash -n are clean, and shellcheck has nothing at warning level.
  • Typo'd the default to /proc/device-tree/compatibl: the new pin fails, while the old fallback check still passes on its own, so the gap was real. Reverting %q to %s fails the injection test. Changing :- to - fails the empty-override check too.

One small nit, not blocking: with %q, lines 145 and 177 of the test compare against the raw $fixture, so the suite fails if TMPDIR has a space in it (9d231b9 passed that). Comparing against "source=$(printf %q "$fixture")" fixes it. I tried it and it's 31/31 both ways.

On splitting: I'd keep it as one commit. Nobody has picked up 9d231b9 yet, so it's one cherry-pick either way. If you fix the nit, amend it in.

On OMARCHY_DEVICE_TREE_COMPATIBLE: it's no longer used in this PR, but it isn't dead. Both electron-gl.sh scripts read it and their tests set it. Agreed it's a separate change.

@CptPanko, 91fc23e is the one to cherry-pick now instead of 9d231b9.

@eXsoR65

eXsoR65 commented Nov 4, 2026

Copy link
Copy Markdown

Nit fixed, and you were right about the cause — it was a regression I introduced with %q, not a pre-existing gap.

Reproduced first: TMPDIR="/tmp/space dir" on 91fc23e6 gives not ok - diagnose reports source, because %q renders the space as \ and the test compared against the raw $fixture.

Both comparisons now go through the quoted form:

grep -Fqx "source=$(printf %q "$fixture")" "$stderr_file" || fail "diagnose reports source"
...
grep -Fqx "source=$(printf %q "$fixture")" "$test_tmp/override-diag-err" || fail "diagnose reports the overridden source" ...

I added a comment above the first one so the next person does not simplify it back to $fixture.

Checked three TMPDIR values, 31 ok each, nothing failing:

  • ordinary path
  • /tmp/space dir
  • /tmp/d$llar dir

commands --check (457 commands), bash -n and shellcheck at warning level are all clean.

Kept it as one commit as you suggested, so 9d231b9 → 91fc23e6 → 6fe9ccac, still one commit on f2573a4.

@CptPanko — 6fe9ccac is the one to cherry-pick; it supersedes both earlier shas and is the only one with the TMPDIR fix.

On OMARCHY_DEVICE_TREE_COMPATIBLE: you are right and I overstated it. I said it was "dead in this test", which was meant literally but reads as "dead", and it is not — both electron-gl.sh scripts read it and their tests set it. Unused here, still live there, and reconciling the two names stays out of this change.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

defer Parked. Needs a decision, or may die with the fork. Do not close or port yet. US

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants