Skip to content

spi: apple-qspi: admit NVRAM writes by the DT partition and the part - #2817

Open
sithglan wants to merge 1 commit into
aurora-silicon:mainfrom
sithglan:thomas/qspi-nvram-generic
Open

sithglan wants to merge 1 commit into
aurora-silicon:mainfrom
sithglan:thomas/qspi-nvram-generic

Conversation

@sithglan

@sithglan sithglan commented Nov 22, 2026 •

Copy link
Copy Markdown

Closes #2815. Follow-up to #2772, as Ryan and Dj asked there: the write path no longer needs apple_qspi_boards[]. Instead the facts come from the machine, and the device tree's partition is checked against the flash before anything is written.

Change

  • Window: the node's one nvram partition (apple_qspi_window_valid()). It must not be read-only, must be a whole number of 64 KiB NVRAM banks from a 4 KiB boundary, and must lie within three-byte addressing.
  • Part: the JEDEC ID read before every program or erase must be in a part table: W25Q64, Macronix 2B27, W25Q16 and GD25UF16E. The table gives the size and the block-protect bits the part's firmware leaves set. The window must end within the part.
  • Qualification: this happens before the first program or erase and is latched per controller.
    • The SFDP density must equal the table's size.
    • Every bank of the window must start with a v3 store header (3VVN, version 1, store size within the bank) or be blank throughout (0xff over the whole 64 KiB), and at least one bank must be a store. A partition over firmware, a stale one, or one running into padding or into an image that starts partway through a bank, admits nothing.
    • SR1 is decoded (BP0-BP2, Winbond TB/SEC), and every bank the protected range reaches, even in part, is dropped from the writable banks (apple_qspi_unprotected_banks()). On the J700, BP0 covers [0x1f0000, 0x200000), so writes go to [0x24000, 0x1e4000) and the last bank [0x1e4000, 0x1f4000) is never written. A bank erase therefore can't stop halfway with its header already gone. Protection over the whole window admits nothing.
  • Per request: a program or erase outside the writable banks is refused before WREN. SR1 is also decoded against each request, as a second check.
  • Unchanged: the read-only default and the root opt-in, the opcode, range, page and erase checks, the readback verify and the fault latch.
  • Logging: the probe line is nvram window [start, end): N stores, writes in [start, end), part ID. Refusals log NVRAM denied: reason=part|part-size|sfdp|window|protected|status, rate limited.

Boards

All 138 Apple DTBs at this head, checked with the driver's partition rule (controller enabled, CS0 jedec,spi-nor, one usable nvram partition, T8122 probe gate):

Window Admitted, subject to the part, SFDP and bank checks
0x700000 +1 MiB J613 (25G83 DT), J713, J715, J604, J623, J624, J773g, J616s, J614s, J773s, J614c, J616c, J704, J813, J815
0x24000 +0x1d0000 J700, J873g

Testing

  • KUnit apple-qspi-nvram-policy: 17/17 (UML). It covers the window rule, bank headers, the part table and size bound, protected ranges, the banks they leave writable, and SFDP parsing.
  • tools/asahi/qspi-nvram-tests.py, alone and through run-host-tests.py --only qspi: all checks pass.
    • The flash model has SFDP and NVRAM banks. It covers qualification and its latching, banks that are blank only at the header, the J700 window under BP0, TB ranges, protection over the whole window, and the per-request decode.
    • 30 changed-guard controls, 11 of them new (part-id, protected, bank-invalid, bank-none, bank-latch, bank-blank, protected-bank, protected-qualify, sfdp-size, window-read-only, window-bank). All fail as they should.
  • W=1 build clean, checkpatch --strict clean.
  • J813 at this head: one trial boot of clean integration/aurora eb6d9ec + this PR (7.3.0-aurora-j813-q2817+). The DTB adds only a read-only nor-low partition over [0, 0x700000), for hashing.
    • nvram window [0x700000, 0x800000): 16 stores, writes in [0x700000, 0x800000), part ef6517.
    • aurora-bless set next boot "Macintosh HD", read it back and cleared it. read_only was Y before and after each step.
    • NOR outside the window unchanged: sha256 428be7f9…74bf before and after.
    • No denial and no write fault. 0 AVC denials (no SELinux), 0 failed units, 0 new kernel errors.
    • The previous head a909103 gave the same result.
  • J700 at this head, run by niteria (row): one trial boot of clean integration/aurora 880a97a merged with this PR, default command line.
    • nvram window [0x24000, 0x1f4000): 29 stores, writes in [0x24000, 0x1e4000), part ef6515: BP0 dropped the last bank, as intended.
    • aurora-bless set the next boot, read it back and cleared it, and the default boot was unchanged. Only the active bank changed. The dropped bank, syscfg and the rest of the NOR hashed the same before and after.
    • 0 denials, 0 write faults, 0 AVC denials (no SELinux), 0 failed units, 0 new kernel errors. KUnit 17/17 and the host test 37/37 on the merged tree.
  • tools/asahi/qspi-nvram-tests.py on the merge with integration/aurora 7946d189a56f: 37/37.

Still to run

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

Read at 05a27bd. Moving the key from the board to the part is the right direction, and the opcode/range/page/erase policy, readback and fault latch are untouched. Because this NOR holds the boot firmware, I don't think the DT partition can be the only bound on the window yet:

  • Nothing cross-checks the window. apple_qspi_nvram_window() (spi-apple-qspi.c:914-962) only checks one nvram label, CS0, 4 KiB alignment and end <= 16 MiB; the per-op check adds end <= part size (:721-725); probe makes any such window a candidate (:1001). A partition of <0x0 0x800000> on a W25Q64 or the Macronix part passes, and with read_only=N a 20h erase at 0x0 is admitted. The removed table was what refused a wrong or stale partition. The bank-header check planned in spi: apple-qspi: admit NVRAM writes by DT window and probed part; retire apple_qspi_boards[] #2815 (item 3) isn't in the diff. Suggest, at probe and latched: the window is a whole number of NVRAM banks, every bank start holds a valid v3 bank header (magic and checksum) or is erased, and at least one is valid. Where the loader states the window (ADT anvram, /chosen nvram-bank-count/size), require the DT to match it.
  • read-only on the partition is ignored. t6050-k114c.dts:603-607 marks its nvram partition read-only ("no program or erase reaches the flash until a later change lifts it"). It binds through apple,t8140-qspi, so it becomes a write candidate here. Please treat read-only as no window in apple_qspi_nvram_window().
  • More boards are admitted than the description lists. Not listed: J614s (t604x-j614-j616.dtsi:326), J614c/J616c/J575c (t6041-j614c-j616c.dtsi:2733), J773s (t6040-j773s.dts:232), J815 (t8142-j813-peripherals.dtsi:150, which spi: apple-qspi: cover the J813's NOR status in KUnit #2772 deliberately left out for lack of a NOR check), K114c (above) and J775d once the loader fills its partition. Please list them with the window and part each was checked against, or exclude them until they are checked.
  • BP0 on the J700 covers part of its window. On the W25Q16JV and GD25UF16E, BP0 with TB/SEC/CMP clear protects 0x1f0000-0x1fffff. The J700 window is [0x24000, 0x1f4000) (t8140-j700.dts:590-593), so a program or erase in its last 16 KiB fails readback and latches read-only for the boot. The mask (bp_ok = 0x1c, :125/:127, policy.h:62) can't see this. Decoding the protected range against the window, as spi: apple-qspi: admit NVRAM writes by DT window and probed part; retire apple_qspi_boards[] #2815 planned, would refuse or clamp it. The mask itself is safe: extra protection only blocks writes, and 01h/31h/11h/50h stay refused (policy.h:46-47).
  • The part sizes are asserted. SZ_8M for c22b27 (:123) has no datasheet or SFDP source, and the size bound is what stops the wrap. Reading the SFDP density (5Ah is already an admitted read) and requiring it to match the table would make it a measured fact.
  • Tests. The KUnit suite is unchanged, and the Python harness doesn't extract apple_qspi_nvram_window(). That function is now the only authority on the window, and nothing tests its refusals: two nvram labels, status = "disabled", read-only, misaligned start/end, end past 16 MiB, three reg cells. Please add KUnit cases for those, and for the part lookup and size bound.
  • Minor: an unknown part or oversized window returns -ENODEV without a log (:722-725); a ratelimited reason=part denial would help bring-up on new boards. policy.h:9 still says "the board's nvram partition".

Checked and fine: the end <= size bound is exact; page programs can't cross a page; erases are aligned 4 KiB inside the window; the windows and parts of the boards in the old table are unchanged; the J613 probe gate still keeps the J615 off this path.

Rows: besides the J813 row, the J700 (Neo), J616s (Macronix ID) and J713 at this head. On each: aurora-bless set, read back and clear, with a sha256 of the whole NOR outside the nvram window taken before and after, which shows nothing outside the window changed.

Assisted-by: LLM (Claude:Opus 5.5)

@sithglan
sithglan force-pushed the thomas/qspi-nvram-generic branch from 05a27bd to a909103 Compare November 22, 2026 18:11
@sithglan

Copy link
Copy Markdown
Author

Thanks for the thorough review. a909103 (amended) addresses it point by point:

  • Cross-check of the window. Before the first program or erase, and latched per controller (apple_qspi_qualify()):
    • The part's SFDP density must equal the part table's size. The basic parameter table is read with 5Ah, and its density DWORD is decoded.
    • Every 64 KiB bank of the window must start with a v3 store header or be erased, and at least one must be a store. The v3 header is 3VVN, version 1, store size from 24 bytes up to the bank. It has no checksum of its own; each variable carries a CRC32.
    • A partition at <0x0 0x800000> therefore hits firmware in its first bank and admits nothing. The host test runs exactly that case: an erase at 0 is refused before WREN.
    • The loaders don't state the window: neither aura nor m1n1 puts an nvram bank count or size in /chosen, and the ADT anvram stays with the loader. So the flash contents are the cross-check for now. If the loader starts stating the window, requiring the DT to match it is an easy addition.
  • read-only partition. It is not a window (apple_qspi_window_valid()). That excludes K114c, and the J615 25G83 variant too. The window must also be a whole number of 64 KiB banks now.
  • BP0 on the J700. SR1 is decoded against each request (apple_qspi_protected_range()): BP0-BP2, Winbond TB and SEC, sizes from the part. A program or erase in the protected range is refused before WREN with reason=protected, instead of failing readback and latching. On the J700 window that is [0x1f0000, 0x1f4000) with BP0 set.
  • Part sizes. They are no longer only asserted: the SFDP density has to match, as described above. For c22b27 the 8 MiB stays the table value until a J616s reads its SFDP; with a different density it is refused.
  • Tests.
    • KUnit: 5 new cases, 16/16 pass. They cover the window rule (two labels, disabled, read-only, misaligned start, partial bank, end past 16 MiB, three reg cells, empty), bank headers, the part table and size bound, protected ranges and SFDP parsing. The rules moved into spi-apple-qspi-policy.h so KUnit can reach them.
    • Host test: the flash model now has SFDP and NVRAM banks and covers qualification, latching, protection and the J700 window. The 8 new changed-guard controls (part-id, protected, bank-invalid, bank-none, bank-latch, sfdp-size, window-read-only, window-bank) all fail as they should.
  • Minor points. Refusals for part, size, SFDP, window and protection log NVRAM denied: reason=..., rate limited. policy.h now says "write window".

Boards whose DT gives the driver a usable window at this head:

Window Boards
0x700000 +1 MiB J613 (25G83 DT), J713, J715, J604, J623, J624, J773g, J616s, J614s, J773s, J614c, J616c, J704, J813, J815
0x24000 +0x1d0000 J700, J873g
  • The old table had J613, J713, J715, J604, J623, J624, J773g, J616s and J700. The new ones are J614s, J773s, J614c, J616c, J704, J815 and J873g.
  • Not admitted: K114c and J615-25G83 (read-only), J775d (disabled zero-size partition), J575c and the other T6050 boards (controller disabled), and the T8122 boards without the J613 probe gate.
  • None of the new boards has a row. On each, nothing is written unless its part is in the table, its SFDP density matches and the window holds NVRAM banks. I'm not aware of any SFDP or bank layout that would let a wrong window through those three.

J813 row. One trial boot of 7.3.0-aurora-j813-q2817+: clean integration/aurora eb6d9ec plus this PR, J813 DTB from the tree. The DTB adds only a read-only nor-low partition over [0, 0x700000), so the NOR outside the window can be hashed.

  • spi-nor spi0.0: nvram window [0x700000, 0x800000): 16 stores, part ef6517: SFDP matched, and all 16 banks are stores.
  • aurora-bless set "Macintosh HD" as next boot, read it back and cleared it. read_only was Y before and after each step. The nvram partition changed with the set: b6f12df1 → 63e12c30.
  • The NOR outside the window was unchanged before and after: 428be7f9…74bf (sha256 of [0, 0x700000)).
  • No denial and no write fault.
  • 0 AVC denials (no SELinux on this install), 0 failed units, 0 new kernel errors (12 error lines, all also on the default boot). Back on the default kernel afterwards.

J700, J616s and J713 rows. I don't have those machines. The script I used is below, if your team can run it at this head. On non-J813 boards, change 3a5118000.spi, and on the J700 the window and nor-low size.

row.sh (J813)
#!/bin/bash
# row.sh: linux#2817 J813 row, on the one-shot trial boot of 7.3.0-aurora-j813-q2817+
# (clean integration/aurora + #2817). Run as root. The DTB adds a read-only partition
# "nor-low" over [0, 0x700000) next to "nvram", for the hashes.
set -u
B=/usr/local/bin/aurora-bless
P=/sys/module/spi_apple_qspi/parameters/read_only
mtd() { grep "\"$1\"" /proc/mtd | cut -d: -f1; }
hash() { dd if=/dev/$(mtd $1)ro bs=64k 2>/dev/null | sha256sum | cut -d' ' -f1; }
low0=$(hash nor-low); nv0=$(hash nvram)
$B --next --set-boot "Macintosh HD" -y && $B --get-boot --next && $B --clear-next && $B --get-boot --next
low1=$(hash nor-low); nv1=$(hash nvram)
echo "nor-low $low0 -> $low1"; echo "nvram $nv0 -> $nv1"; cat $P
dmesg | grep -E "nvram window|NVRAM denied|write fault"

Assisted-by: LLM (Claude:Opus 5.5)

sithglan added a commit to sithglan/aurora-linux that referenced this pull request Nov 22, 2026
The J813 (MacBook Air 13-inch, M5) reads a Winbond W25Q64 (ef6517) with
QE set and the SR3 drive strength at its default, and no block
protection:

  flash_status: jedec=ef6517 sr1=00 sr2=02 sr3=60

Since aurora-silicon#2817 the J813 is a write candidate through its device tree's
nvram partition (0x700000, 1 MiB, the ADT anvram) and its probed part,
with no board entry. Check in KUnit that these status registers pass
the write policy for a part that tolerates no block-protect bits.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@RyanTheTide

Copy link
Copy Markdown

Re-read at a909103. Thanks, this covers most of the last round:

  • Fixed: the window is now checked against the flash before the first write (SFDP density, a v3 store or blank at every bank start, at least one store), so a partition over the firmware is refused. read-only partitions are refused (K114c stays read-only). The SFDP density now backs the part sizes. The protected range is decoded and refused before WREN (the decode matches the W25Q16JV and GD25UF16E tables). Refusals are logged with a reason, and KUnit covers the window rule, the bank header, the part table, the protected ranges and the SFDP parsing.
  • Both of these need fixing before merge. A bank only has to look blank. apple_qspi_nvram_bank_state() (spi-apple-qspi-policy.h:146-149) calls a bank erased when its first 24 bytes are 0xff. A partition that runs past the real NVRAM into padding, or into an image that starts partway through a 64 KiB block, still qualifies if one real store is inside. 4 KiB erases anywhere in those banks are then admitted. Requiring a state-0 bank to be all 0xff at qualify time (at most 1 MiB, read once) would close this. So would admitting only banks that held a store or are fully blank.
  • The J700's last bank straddles BP0. Its window ends at 0x1f4000 and BP0 protects [0x1f0000, 0x200000), so the last bank [0x1e4000, 0x1f4000) is a quarter protected. The per-op refusal (spi-apple-qspi.c:786-792) stops the fault latch, but a 64 KiB bank erase issued as 4 KiB sectors still erases 0x1e4000-0x1effff, header included, and then fails at 0x1f0000. That leaves a half-erased bank, which the header check then counts as blank. Please refuse or drop, at qualify time, any bank that overlaps the protected range. Or show from the J700 ADT anvram that the window really ends at 0x1f4000, and how the firmware writes that bank with BP0 set. The overlap suggests the DT window may be 16 KiB too long.
  • The PR description still describes the previous head: the window checked only for alignment, and J704/J813/J873g as the only new boards. Please bring it in line with the commit message. Any board whose partition passes is now admitted, which includes J614s, J614c/J616c/J575c, J773s, J815 and J775d once its loader fills the partition.

Rows still needed at this head: the J813 row, plus J700 (Neo, ideally both part variants), J616s (Macronix ID) and J713. On each Mac: the new nvram window ... stores probe line, then aurora-bless set, read back and clear, and a sha256 of the NOR outside the window before and after.

Assisted-by: LLM (Claude:Opus 5.5)

A controller became a write candidate only through a row of
apple_qspi_boards[]: controller and machine compatible, controller
base, the nvram window the device tree had to describe exactly, the
JEDEC IDs and the block-protect bits the firmware leaves set. Each new
Mac needed a row, and five of the ten rows were assumed rather than
checked against an ADT and a probe.

Take those facts from the machine instead, and check the device tree's
partition against the flash before anything is written to it:

- The window is the node's one "nvram" partition, if it is not marked
  read-only, is a whole number of 64 KiB NVRAM banks from a 4 KiB
  boundary and lies within three-byte addressing
  (apple_qspi_window_valid()).
- The part is read back before every program or erase and must be in a
  short part table (W25Q64, Macronix 2B27, W25Q16, GD25UF16E), which
  gives its size and the block-protect bits its firmware leaves set.
  The window must end within the part: a three-byte address past it
  wraps around into the start of the flash.
- Before the first program or erase, and latched for the controller:
  the part's SFDP density must be the size the table bounds the window
  with, and every bank of the window must start with a v3 NVRAM store
  header ("3VVN", version 1, a store size within the bank) or be blank
  throughout, with at least one store. A partition over firmware, a
  stale one, or one running into padding or an image partway through a
  bank, admits nothing.
- Also at that point, the block-protect bits are decoded, and a bank
  they reach even in part is dropped from the writable banks. A program
  or erase there is refused before WREN, so a bank erase cannot stop
  halfway with the bank's header already gone. On the J700, BP0 covers
  the top 64 KiB, so the window's last bank [0x1e4000, 0x1f4000) is
  never written. The bits are decoded against each request as well:
  one in the protected range is refused before WREN instead of failing
  its readback and latching read-only.

The read-only default and the root opt-in, the opcode, range, page and
erase checks, the readback verify and the fault latch are unchanged.
Refusals for the part, its size, SFDP, the window and protection are
logged, rate limited, with the reason.

The boards the table admitted keep their window and part. Any other
board whose device tree describes a usable nvram partition is admitted
by these checks alone.

The rules live in spi-apple-qspi-policy.h, where KUnit covers the window
rule, the bank header, the part table, the protected ranges, the banks
they leave writable and SFDP parsing. tools/asahi/qspi-nvram-tests.py
runs the driver's write path against a flash model with SFDP and NVRAM
banks, with changed-guard controls for each new check.

Closes: aurora-silicon#2815
Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@sithglan
sithglan force-pushed the thomas/qspi-nvram-generic branch from a909103 to 44a1bae Compare November 22, 2026 18:33
sithglan added a commit to sithglan/aurora-linux that referenced this pull request Nov 22, 2026
The J813 (MacBook Air 13-inch, M5) reads a Winbond W25Q64 (ef6517) with
QE set and the SR3 drive strength at its default, and no block
protection:

  flash_status: jedec=ef6517 sr1=00 sr2=02 sr3=60

Since aurora-silicon#2817 the J813 is a write candidate through its device tree's
nvram partition (0x700000, 1 MiB, the ADT anvram) and its probed part,
with no board entry. Check in KUnit that these status registers pass
the write policy for a part that tolerates no block-protect bits.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@sithglan

Copy link
Copy Markdown
Author

Thanks. 44a1bae (amended) fixes both:

  • A bank only had to look blank. A bank whose header bytes are blank now has to be 0xff throughout. The whole bank is read once at qualification, in 4 KiB reads; on the J813 all 16 banks are stores, so nothing extra is read there. Anything else refuses the whole window with reason=window, and the refusal is latched. In the host test, a zero byte at 0x7a1234 inside an otherwise blank bank is refused before WREN, and so is 0x7f at the window's last byte. The new changed-guard control is bank-blank.
  • The J700's last bank. At qualification, SR1 is decoded and every bank the protected range reaches, even in part, is dropped. apple_qspi_unprotected_banks() returns the writable banks, and a program or erase outside them is refused before WREN with reason=protected.
    • With BP0, the J700 writes in [0x24000, 0x1e4000). The first sector erase of [0x1e4000, 0x1f4000) is already refused, so a bank erase can't stop halfway.
    • A TB range drops banks from the bottom instead: TB+BP0+BP1 leaves [0x44000, 0x1f4000).
    • Protection over the whole window refuses it, latched.
    • The per-request SR1 decode stays as a second check.
    • The probe line now says writes in [start, end).
    • I can't read the J700's ADT anvram, so I can't show where the firmware's window ends. With the bank dropped, that no longer decides safety: if the DT window is 16 KiB too long, its last bank is simply never written.
    • New: the KUnit case qspi_policy_unprotected_banks, and the controls protected-bank and protected-qualify.
  • Description. It now matches this head. For the board list, I ran the driver's partition rule over all 138 Apple DTBs at this head. J614s, J614c/J616c, J773s and J815 are listed as admitted.
    • J575c is not admitted. Its QSPI controller is disabled and has no flash node: t6041-j575c.dts doesn't include t6041-j614c-j616c.dtsi.
    • J775d's partition is disabled and zero-size. Once its loader fills it in, it goes through the same checks as any other board.
  • Tests. KUnit 17/17. The host test passes all checks and all 30 controls, alone and through run-host-tests.py --only qspi. checkpatch --strict and W=1 are clean.

#2772 is rebased onto this head (87650bc: still only the J813 status-register KUnit case). The J813 row at this head comes next; the kernel is built. J700, J616s and J713 still need someone with those machines.

Assisted-by: LLM (Claude:Opus 5.5)

@sithglan

Copy link
Copy Markdown
Author

J813 row at 44a1bae: ALL PASS. One trial boot of 7.3.0-aurora-j813-q2817+, which is clean integration/aurora eb6d9ec plus this PR. The DTB is the same as in the last row: it only adds a read-only nor-low partition over [0, 0x700000).

  • Probe line: spi-nor spi0.0: nvram window [0x700000, 0x800000): 16 stores, writes in [0x700000, 0x800000), part ef6517. The W25Q64 tolerates no BP bits, so the writable banks are the whole window. All 16 banks are stores, so no extra blank-bank reads were needed.
  • Status before the writes: jedec=ef6517 sr1=00 sr2=02 sr3=60.
  • aurora-bless:
    • set next boot "Macintosh HD": rc 0, read back as "Macintosh HD", default boot still Stub;
    • clear: rc 0, next boot back to Stub;
    • read_only was Y before and after each step.
  • The nvram partition changed with the writes: d279c46b → 9b67c891.
  • The NOR outside the window was unchanged: 428be7f97850fe36dee1b84aec7e6125cf754100eaf53dfe12d4744169b574bf before and after (sha256 of [0, 0x700000)).
  • The window was qualified once, with no denial and no write fault.
  • 0 AVC denials (no SELinux on this install), 0 failed units, 0 new kernel errors: the 11 error lines also appear on the default boot.
  • Back on the default kernel afterwards.

CI host-tests passes at this head. The J700, J616s and J713 rows are still open.

Assisted-by: LLM (Claude:Opus 5.5)

@funkzy

funkzy commented Nov 22, 2026

Copy link
Copy Markdown

Thanks, this replaces the board table we were about to add a J775D row to, so we're dropping that change in favour of this PR.

One part is missing for the M5 Ultra: the J775D (Mac Studio) boot NOR reads JEDEC ID c8 83 17, a GigaDevice GD25UF64E (64 Mbit, 8 MiB), the same part #2625 adds for the J773g. On the J775D it has no block protection left set: SR1 0x00, SR2 0x02 (QE only), SR3 0x20. Its nvram partition is the ADT's anvram, 0xc0000 at 0x700000 (12 banks of 64 KiB), which Aura fills into the device tree at boot, so it ends within the part. An entry would be:

#define APPLE_QSPI_JEDEC_GD25UF64E	{ 0xc8, 0x83, 0x17 }
	/* J775D (M5 Ultra): no block protection left set, SR1 0x00 */
	{ APPLE_QSPI_JEDEC_GD25UF64E, 0x800000, 0 },

with { 0xc8, 0x83, 0x17 }, 0x800000 and 0 added to qspi_policy_parts. We have it as one commit on top of this PR, checkpatch --strict clean, if you'd rather we send it separately after this lands. Folding it in here is just as good.

Those status values were validated on the J775D with the old board-table path: with read_only=N, aurora-bless --next --set-boot Aura set the next boot, read back Aura, --clear-next restored the default, the boot volume stayed unchanged and read_only went back to Y. We'll post a J775D row of this PR itself (this PR alone, and this PR plus the GD25UF64E entry) once it has run, including whether the J775D's 12 banks pass the store-header qualification.

Assisted-by: LLM (Claude:Opus 5.5)

@sithglan

Copy link
Copy Markdown
Author

@funkzy thanks, and good to hear the J775D board row can go. I'd rather you send the GD25UF64E entry separately after this lands, for two reasons. Ryan's review and the rows here cover the current four parts. And #2625 adds the same part for the J773g, so the entry should go in once, in whichever of the two lands first, with the other rebasing onto it.

For that commit, besides the apple_qspi_parts[] row:

  • The part also needs adding to the KUnit qspi_policy_parts arrays (known, sizes, bp_ok), as you wrote, and to the known/sizes/tolerated arrays at the top of tools/asahi/qspi-nvram-tests.py's part-table check.
  • A host-test case like the GD25UF16E one would help: the GigaDevice status checks with your SR1 0x00 / SR2 0x02 / SR3 0x20, and BP0 refused, since bp_ok is 0.
  • Your window passes apple_qspi_window_valid() once aura fills it in: 0xc0000 at 0x700000 is 12 whole banks from a 4 KiB boundary, ending within 8 MiB.
  • Before the first write, qualification then checks the SFDP density (8 MiB), and that each of the 12 banks is a v3 store or blank throughout, with at least one store.
  • With no BP bits set, the writable banks are the whole window.

For the J775D row of this PR alone, expect NVRAM denied: reason=part on the first write, because the part isn't in the table yet. With the entry, the probe line should read nvram window [0x700000, 0x7c0000): N stores, writes in [0x700000, 0x7c0000), part c88317. That line is also the answer to whether all 12 banks qualify.

Assisted-by: LLM (Claude:Opus 5.5)

@funkzy

funkzy commented Nov 23, 2026

Copy link
Copy Markdown

J775D (Mac Studio, M5 Ultra) row of this PR, extra evidence for the boards it lists. The J775D isn't admitted until the GD25UF64E entry lands. Read-only one-shot boots through the default 27.0 stub with the published Aura, default command line, in window upsm10@20261122-1511:

  • Kit q2817j, extra evidence: integration/aurora 4a17f73 plus this PR at 44a1bae. Aura filled the nvram partition, and with read_only=N the first write was refused as you expected: NVRAM denied: reason=part opcode=02 addr=0x720000 ... candidate=1. aurora-bless --next --set-boot Aura failed, and the next boot and the partition stayed unchanged.
  • Kit q2817gd2, extra evidence: integration/aurora 6748d83 plus this PR plus the GD25UF64E entry (one commit, held until this lands). The probe line was nvram window [0x700000, 0x7c0000): 12 stores, writes in [0x700000, 0x7c0000), part c88317, so all 12 banks qualify. With read_only=N, aurora-bless --next --set-boot Aura set the next boot and read back Aura, --clear-next restored Aura 27.0, the boot volume stayed Aura 27.0, and read_only went back to Y.

The entry commit adds the part to apple_qspi_parts[], to the KUnit qspi_policy_parts arrays and to the host test's part table, plus a GigaDevice status case with SR1 0x00 / SR2 0x02 / SR3 0x20 that refuses BP0. We'll send it once, after whichever of this PR and #2625 lands first.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

44a1bae merges without conflicts on integration/aurora daa9e2d, and tools/asahi/qspi-nvram-tests.py passes on the merged tree (37 checks). The tip still admits writes through apple_qspi_boards[], so this is still needed. Before it leaves draft: a re-read of the two fixes in 44a1bae (blank banks must be 0xff throughout, banks under block protection are dropped), and write rows on boards that move from the table to the part path besides the J813. #2851 and #2625 each add to the table this removes, so they will need a rebase onto this if it lands first.

@sithglan

Copy link
Copy Markdown
Author

Thanks. Both fixes in 44a1bae are ready for the re-read:

  • A bank only counts as erased when it is 0xff throughout (memchr_inv).
  • apple_qspi_unprotected_banks() drops every bank the BP-protected range touches.

Write rows on the boards that move off the table. I have none of them (J613, J713/J715, J604, J623/J624, J773g, J616s, J700). The only one I can run is the J813, which is posted. The J700 would show the most, because iBoot leaves BP0 set there over the top 64 KiB: it exercises the protected-bank drop and the GD25UF16E alternative together. Could you run that one on your A18 Pro?

The procedure from funkzy's J775D row works as is:

  • Boot read-only and record the probe line (nvram window [...]: N stores, writes in [...], part ...).
  • With read_only=N, run aurora-bless --next --set-boot <volume> and read it back.
  • Run --clear-next and check the boot volume is unchanged.

For the J700, the probe line should show the writes window ending below the protected top 64 KiB.

Noted on #2851 and #2625. If this lands first, both need a rebase from the table onto the part path, and funkzy's GD25UF64E entry already has that form.

Assisted-by: LLM (Claude:Opus 5.5)

@niteria

niteria commented Nov 23, 2026

Copy link
Copy Markdown

J700 (MacBook Neo, apple,j700 / apple,t8140) write-test row at 44a1bae6dd09: ALL PASS.

One-shot trial boot of clean integration/aurora (880a97a3dca2) merged with this PR (44a1bae6dd09, merged head 2052663b1564), kernel 7.3.0-pr-2052663b1564, default kernel command line, Aura 1.0.0b9 / U-Boot 2026.07, stock J700 DTB (nvram at [0x24000, 0x1f4000), syscfg read-only at [0x0, 0x24000)). Built with CONFIG_SPI_APPLE_QSPI=m and CONFIG_MTD_PARTITIONED_MASTER=y so the full 2 MiB NOR (spi0.0) could be read-only hashed without modifying the DTB. Tested with aurora-bless (asahi-bless 0.4.4-neo.2).

  • Part / SFDP (read-only boot, read_only=Y):
    • jedec_id: ef6515 (Winbond W25Q16, 2 MiB; note: this unit has the Winbond variant rather than c88315 GD25UF16E).
    • SFDP basic table header at 0x80, density DWORD 0x00ffffff (2 MiB).
    • Pre-write bank scan of [0x24000, 0x1f4000): all 29 banks hold 3VVN v1 stores (including bank 28 [0x1e4000, 0x1f4000)), and [0x1f4000, 0x200000) is all 0xff.
  • Qualification / probe line (logged once on first write, latched):
    • spi-nor spi0.0: nvram window [0x24000, 0x1f4000): 29 stores, writes in [0x24000, 0x1e4000), part ef6515
    • BP0 over [0x1f0000, 0x200000) dropped the last bank [0x1e4000, 0x1f4000) as expected.
  • aurora-bless round trip:
    • Before: read_only=Y, default boot NixOS Neo, next boot NixOS Neo.
    • --next --set-boot "Macintosh HD" -y: rc 0, read back next boot Macintosh HD, default boot unchanged (NixOS Neo), read_only returned to Y.
    • --clear-next: rc 0, read back next boot NixOS Neo, default boot unchanged (NixOS Neo), read_only returned to Y.
  • NOR integrity (SHA-256 over read-only /dev/mtd3ro):
    • nvram [0x24000, 0x1f4000) changed: ca7affd1…e69a → 14ac9df6…d864 (after set) → eea60866…8cf7 (after clear); only active bank 20 (0x164000) changed.
    • Dropped bank 28 [0x1e4000, 0x1f4000) unchanged: 0708b2c71808dd97c1a9b2f662379a136f8a26be38dc6702b462b1f1690d716e.
    • [0x0, 0x24000) (syscfg) unchanged: d063ecb6b2c1de11b3c8b590ba2e62e1d673e7c11c4595562e9e5ac1f4bb6eaa.
    • [0x1f4000, 0x200000) unchanged: abd8e2a70d51a53287941838446e6ed141005d401faf597fd7c6de0bbc8c329d.
    • Combined NOR outside [0x24000, 0x1f4000) unchanged: adc5a27c0ad84deef4de3d4fdc8ab6b6634e3a1214ee7a7e35980e5860e36b06.
  • Regression checks:
    • 0 NVRAM denied lines, 0 write faults.
    • 0 AVC denials (no SELinux on NixOS), 0 failed systemd units, 0 new kernel errors (the 2 aurora 482600000.gpu RTKit lines also appear on the stock boot).
    • Host tests on the merged tree: tools/asahi/qspi-nvram-tests.py 37/37 PASS; arm64 KUnit apple-qspi-nvram-policy 17/17 PASS.
    • Restored cleanly to the stock kernel afterwards.

Also re-read both fixes in 44a1bae6dd09 (apple_qspi_qualify() full-bank 0xff check via memchr_inv in 4 KiB chunks with latched reason=window refusal and kfree(buf) on every exit; apple_qspi_unprotected_banks() dropping any bank touched by the SR1-decoded range plus the [write_start, write_end) check before WREN and retained per-request SR1 check) — both look solid and match the observed J700 behaviour.

Assisted-by: LLM (Google:Gemini 4 Neon)

@sithglan

Copy link
Copy Markdown
Author

@niteria thank you, that is the row this needed. The J700 is where both fixes show, and the probe line, the dropped bank and the hashes are what the code should give.

@RyanTheTide with that, both conditions you set for leaving draft are met:

  • Re-read of the two fixes in 44a1bae: niteria's above (blank banks must be 0xff throughout; every bank the protected range touches is dropped), and it matches the J700's behaviour.
  • A write row on a board that moves from the table to the part path, besides the J813: the J700, which also covers BP0, the dropped bank and the W25Q16.

So I'm marking it ready. J616s and J713 rows would still be welcome.

One change since your merge check: integration/aurora 7946d189a56f has #2851 now, which describes the J575c's boot NOR. Merged with it, this PR admits the J575c too: [0x700000, +1 MiB) with the W25Q64 (ef6517, as #2851 reports), subject to the same SFDP and bank checks.

  • @7robertodantas could you run the same round trip on your J575c, on integration/aurora plus this PR? The steps are in funkzy's J775D row. Expect nvram window [0x700000, 0x800000): N stores, writes in [0x700000, 0x800000), part ef6517.
  • M3 Air 15 (J615): read NVRAM from the QSPIMC NOR #2593 dropped the T8122 probe gate, so the J615 probes now. Both of its device trees keep nvram read-only, so it stays out.

The merge with 7946d189a56f is clean, and tools/asahi/qspi-nvram-tests.py passes 37/37 on it. I checked the admitted windows on all 138 DTBs of the merge with the driver's partition rule: the table in the description plus the J575c. The description has the J700 row and this note.

Assisted-by: LLM (Claude:Opus 5.5)

@sithglan
sithglan marked this pull request as ready for review November 24, 2026 06:13

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Formal §1–§6 pre-PR review at 44a1bae6dd09a6496924072626581d98d723f16a: APPROVE.

Driver Safety & Write-Protection Audit (§1–§3)

  • §1 No model gating — PASS: Replaces the hardcoded per-board apple_qspi_boards[] table with DT partition parsing plus runtime JEDEC/SFDP/NVRAM-bank/SR1 qualification. Merges cleanly onto integration/aurora (where #2593 already removed the T8122 probe gate).
  • §2 Production-ready, no hacks — PASS: Default kernel command line (read_only=Y default with unchanged root runtime opt-in), zero sleeps/retries over races or lab-only code paths.
  • §3 Boot NOR safety invariants — PASS:
    • Window validation (apple_qspi_window_valid() / apple_qspi_nvram_window()): Requires exactly one available CS0 nvram partition with reg_cells == 2, not marked read-only, 4 KiB-aligned start, non-zero multiple of 64 KiB NVRAM banks, and start + size <= 16 MiB. Correctly keeps read-only partitions (e.g. K114c, J615) and disabled/zero-size partitions out.
    • First-write latched qualification (apple_qspi_qualify()): Serialized under apple_qspi_policy_lock. Confirms JEDEC SFDP basic parameter table density matches part->size (apple_qspi_sfdp_basic_table() / apple_qspi_sfdp_size()), verifies every 64 KiB bank starts with a valid 3VVN v1 header (24 <= size <= 0x10000) or is 0xff across all 64 KiB (memchr_inv in 4 KiB chunks, with kfree(buf) on every exit), and requires stores >= 1. Latches policy denials (sfdp/part-size/window/protected) without latching transient -EIO/-ENOMEM.
    • Block-protection decoding (apple_qspi_protected_range() / apple_qspi_unprotected_banks()): Verified against the Winbond W25Q16JV/JW and GigaDevice GD25UF16E CMP=0 protection tables (GD BP3/BP4 and CMP/SUS stay refused by apple_qspi_gd_status_allows_write()). Dropping any partially overlapped 64 KiB bank whole cleanly closes the J700 BP0 overlap ([0x1e4000, 0x1f4000) excluded so a bank erase cannot stop halfway), while retaining the per-request [write_start, write_end) check, per-request manufacturer status check, per-request SR1 decode, and unchanged opcode/page/erase/readback/fault-latch invariants.

Non-blocking Observations

  • In apple_qspi_nvram_modify(), running apple_qspi_status() + apple_qspi_part_status_allows_write() before apple_qspi_qualify() would avoid emitting dev_info("nvram window ... writes in ...") when CMP/WPS/BP3/BP4 immediately denies the write with reason=status (no safety impact since the status check still rejects before WREN).
  • In apple_qspi_window_valid(), writing start <= (1ULL << 24) && size <= (1ULL << 24) - start would guard direct 64-bit callers against unsigned wraparound (unreachable from u32 reg[2] in apple_qspi_nvram_window()).

Attribution, Evidence, CI & Naming (§4–§6)

  • §4 Clean-room & attribution — PASS: Single commit 44a1bae6dd09 carries human author/committer (Thomas Glanzmann <thomas@glanzmann.de>) and human Signed-off-by: only (zero AI trailers in commit); PR body ends with Assisted-by:.
  • §5 Evidence & CI — PASS:
    • Live CI at exact head 44a1bae6dd09: host-tests SUCCESS (KUnit apple-qspi-nvram-policy 17/17 and tools/asahi/qspi-nvram-tests.py 37/37 with 30 changed-guard controls).
    • Exact-head live HW rows: J813 (ef6517, 16 stores, aurora-bless round-trip, outside-window SHA-256 unchanged, 0 denials/faults/errors), J700 (ef6515, 29 stores, BP0 drops bank 28 [0x1e4000, 0x1f4000), aurora-bless round-trip, bank 28 + syscfg + outside-window SHA-256 unchanged, 0 denials/faults/errors), and J775D negative control (reason=part refusal on unlisted c88317) + positive control with GD25UF64E entry. Follow-up J616s (c22b27 SFDP), J713, and J575c rows remain welcome and fail safe if SFDP disagrees.
  • §6 Naming — PASS.

Assisted-by: LLM (Gemini 4 Neon)

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.

spi: apple-qspi: admit NVRAM writes by DT window and probed part; retire apple_qspi_boards[]

5 participants