From 1bc4944c8f82f75693b15bcd740eced5b0da5cfa Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 27 Nov 2026 22:30:58 +0100 Subject: [PATCH 1/2] arm64: dts: apple: t8152-j873: fix nvram partition size to 13 banks (0xd0000) The J873g (Mac mini, M6) boot NOR is a 1 MiB Winbond W25Q80 (ef6514), not a 2 MiB J700 part. Its ADT /arm-io/qspi/spinor lists ranges 0x100000 and anvram reg <0x24000 0xd0000> (13 x 64 KiB banks, matching /chosen/nvram-bank-count = 13), with syscfg at 0x0..0x24000. With the previous copied J700 length (0x1d0000, ending at 0x1f4000), reads past 0x100000 wrapped back to 0x0 ('iPCB' syscfg header at offset 0xdc000 in mtd0, and banks 0x124000..0x1f4000 byte-identical to 0x24000..0xf4000). Fix the nvram partition to <0x24000 0xd0000>. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi index 538511e3ffc17..e89bd8adb8b1d 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi @@ -51,12 +51,13 @@ #size-cells = <1>; /* - * 64 KiB NVRAM v3 banks ("3VVN") from 0x24000 - * to 0x1f4000, as on T8140 J700. + * 13 x 64 KiB NVRAM v3 banks ("3VVN") from 0x24000 + * to 0xf4000 (ADT /arm-io/qspi/spinor/anvram on the + * 1 MiB W25Q80 boot NOR). */ nvram: partition@24000 { label = "nvram"; - reg = <0x24000 0x1d0000>; + reg = <0x24000 0xd0000>; }; }; }; From 65b4f4a13e57450c71b8a3b2da457ed071d140b0 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 27 Nov 2026 22:30:58 +0100 Subject: [PATCH 2/2] spi: apple-qspi: admit the W25Q80 (ef6514), so the J873g's nvram partition can be written The J873g (Mac mini, M6) boot NOR reads JEDEC ID ef 65 14 (Winbond W25Q80, 8 Mbit / 1 MiB) with no block protection left set: flash_status: jedec=ef6514 sr1=00 sr2=02 sr3=20 Hardware reads confirm the chip physically wraps at 0x100000 (0x100000 aliases 0x000000 'iPCB', and 0x124000..0x1f4000 mirrors 0x024000..0x0f4000), matching ADT /arm-io/qspi/spinor ranges = 0x100000 and anvram [0x24000, 0xf4000) (13 banks of 64 KiB). However, its factory SFDP BFPT encodes 16 Mbit (DWORD 2 = 0x00ffffff -> 0x200000). Add an optional sfdp_size field to struct apple_qspi_part (defaulting to size when 0) and admit W25Q80 with physical size 0x100000, bp_ok 0, and sfdp_size 0x200000. The physical size still bounds window_end (refusing any oversized 2 MiB partition before WREN or SFDP), while apple_qspi_qualify() checks SFDP against the exact 0x00ffffff table the part reports. Cover the W25Q80 status, part table, physical bound, SFDP match, and changed-guard mutations in KUnit and tools/asahi/qspi-nvram-tests.py. Signed-off-by: Thomas Glanzmann --- drivers/spi/spi-apple-qspi-policy-test.c | 22 +++++++++---- drivers/spi/spi-apple-qspi-policy.h | 23 +++++++++++--- drivers/spi/spi-apple-qspi.c | 3 +- tools/asahi/qspi-nvram-tests.py | 40 +++++++++++++++++++----- 4 files changed, 70 insertions(+), 18 deletions(-) diff --git a/drivers/spi/spi-apple-qspi-policy-test.c b/drivers/spi/spi-apple-qspi-policy-test.c index 0383e506b5338..d73a851a81932 100644 --- a/drivers/spi/spi-apple-qspi-policy-test.c +++ b/drivers/spi/spi-apple-qspi-policy-test.c @@ -154,6 +154,9 @@ static void qspi_policy_status(struct kunit *test) KUNIT_EXPECT_TRUE(test, apple_qspi_status_allows_write(0x04, 0x02, 0, 0x1c)); /* The J813 W25Q64: QE and the SR3 drive strength, no block protection. */ KUNIT_EXPECT_TRUE(test, apple_qspi_status_allows_write(0x00, 0x02, 0x60, 0)); + /* The J873g W25Q80: QE and SR3 0x20, no block protection. */ + KUNIT_EXPECT_TRUE(test, apple_qspi_status_allows_write(0x00, 0x02, 0x20, 0)); + KUNIT_EXPECT_FALSE(test, apple_qspi_status_allows_write(0x04, 0x02, 0x20, 0)); /* CMP, SUS and WPS are refused everywhere. */ KUNIT_EXPECT_FALSE(test, apple_qspi_status_allows_write(0, 0x40, 0, 0x1c)); KUNIT_EXPECT_FALSE(test, apple_qspi_status_allows_write(0, 0x80, 0, 0x1c)); @@ -277,15 +280,17 @@ static void qspi_policy_parts(struct kunit *test) static const unsigned char known[][3] = { { 0xef, 0x65, 0x17 }, { 0xc2, 0x2b, 0x27 }, { 0xef, 0x65, 0x15 }, { 0xc8, 0x83, 0x15 }, - { 0xc8, 0x83, 0x17 }, + { 0xc8, 0x83, 0x17 }, { 0xef, 0x65, 0x14 }, }; static const unsigned int sizes[] = { 0x800000, 0x800000, 0x200000, 0x200000, - 0x800000 }; - static const unsigned char bp_ok[] = { 0, 0, 0x1c, 0x1c, 0 }; + 0x800000, 0x100000 }; + static const unsigned int sfdp_sizes[] = { 0x800000, 0x800000, 0x200000, 0x200000, + 0x800000, 0x200000 }; + static const unsigned char bp_ok[] = { 0, 0, 0x1c, 0x1c, 0, 0 }; static const unsigned char unknown[][3] = { - { 0xef, 0x65, 0x16 }, { 0xef, 0x40, 0x17 }, { 0xc2, 0x2b, 0x28 }, - { 0xc8, 0x60, 0x15 }, { 0xc8, 0x83, 0x16 }, { 0xc8, 0x83, 0x18 }, - { 0, 0, 0 }, { 0xff, 0xff, 0xff }, + { 0xef, 0x65, 0x13 }, { 0xef, 0x65, 0x16 }, { 0xef, 0x40, 0x17 }, + { 0xc2, 0x2b, 0x28 }, { 0xc8, 0x60, 0x15 }, { 0xc8, 0x83, 0x16 }, + { 0xc8, 0x83, 0x18 }, { 0, 0, 0 }, { 0xff, 0xff, 0xff }, }; const struct apple_qspi_part *part; unsigned int i; @@ -294,6 +299,7 @@ static void qspi_policy_parts(struct kunit *test) part = apple_qspi_find_part(known[i]); KUNIT_ASSERT_NOT_NULL(test, part); KUNIT_EXPECT_EQ(test, part->size, sizes[i]); + KUNIT_EXPECT_EQ(test, apple_qspi_part_sfdp_size(part), sfdp_sizes[i]); KUNIT_EXPECT_EQ(test, part->bp_ok, bp_ok[i]); } for (i = 0; i < ARRAY_SIZE(unknown); i++) @@ -302,6 +308,10 @@ static void qspi_policy_parts(struct kunit *test) part = apple_qspi_find_part(known[2]); KUNIT_EXPECT_LE(test, 0x1f4000ULL, (unsigned long long)part->size); KUNIT_EXPECT_GT(test, 0x800000ULL, (unsigned long long)part->size); + /* The J873g 13-bank window fits 1 MiB; an oversized 2 MiB J700 window does not. */ + part = apple_qspi_find_part(known[5]); + KUNIT_EXPECT_LE(test, 0xf4000ULL, (unsigned long long)part->size); + KUNIT_EXPECT_GT(test, 0x1f4000ULL, (unsigned long long)part->size); } static void qspi_policy_protected(struct kunit *test) diff --git a/drivers/spi/spi-apple-qspi-policy.h b/drivers/spi/spi-apple-qspi-policy.h index 0a8e502cfcbb4..54a5f6dfd7f8c 100644 --- a/drivers/spi/spi-apple-qspi-policy.h +++ b/drivers/spi/spi-apple-qspi-policy.h @@ -156,19 +156,22 @@ static inline int apple_qspi_nvram_bank_state(const unsigned char h[24]) /* * The boot NOR parts whose nvram partition may be written: the JEDEC ID, the - * size, which bounds the window (a three-byte address past it wraps around) - * and must match the part's SFDP density, and the SR1 block-protect bits the - * part's firmware leaves set. Those stay set; apple_qspi_protected_range() - * says what they protect. + * physical size, which bounds the window (a three-byte address past it wraps + * around), the SR1 block-protect bits the part's firmware leaves set, and + * optionally sfdp_size when a part's factory SFDP density differs from its + * physical size (0 means SFDP density must equal size). Protected bits stay + * set; apple_qspi_protected_range() says what they protect. */ struct apple_qspi_part { unsigned char jedec[3]; unsigned int size; unsigned char bp_ok; + unsigned int sfdp_size; }; #define APPLE_QSPI_JEDEC_W25Q64 { 0xef, 0x65, 0x17 } #define APPLE_QSPI_JEDEC_W25Q16 { 0xef, 0x65, 0x15 } +#define APPLE_QSPI_JEDEC_W25Q80 { 0xef, 0x65, 0x14 } #define APPLE_QSPI_JEDEC_MX_2B27 { 0xc2, 0x2b, 0x27 } #define APPLE_QSPI_JEDEC_GD25UF16E { 0xc8, 0x83, 0x15 } #define APPLE_QSPI_JEDEC_GD25UF64E { 0xc8, 0x83, 0x17 } @@ -184,8 +187,20 @@ static const struct apple_qspi_part apple_qspi_parts[] = { { APPLE_QSPI_JEDEC_GD25UF16E, 0x200000, 0x1c }, /* J775D (M5 Ultra): no block protection left set, SR1 0x00 */ { APPLE_QSPI_JEDEC_GD25UF64E, 0x800000, 0 }, + /* + * J873g (Mac mini, M6): 1 MiB die (wraps at 0x100000, ADT spinor + * ranges 0x100000), no BP bits (SR1 0x00, SR2 0x02, SR3 0x20), + * factory SFDP BFPT reports 16 Mbit (0x00ffffff = 0x200000). + */ + { APPLE_QSPI_JEDEC_W25Q80, 0x100000, 0, 0x200000 }, }; +static inline unsigned int +apple_qspi_part_sfdp_size(const struct apple_qspi_part *part) +{ + return part->sfdp_size ? part->sfdp_size : part->size; +} + static inline const struct apple_qspi_part * apple_qspi_find_part(const unsigned char id[3]) { diff --git a/drivers/spi/spi-apple-qspi.c b/drivers/spi/spi-apple-qspi.c index 9b1e1bcaf8954..aaa76d2375dfd 100644 --- a/drivers/spi/spi-apple-qspi.c +++ b/drivers/spi/spi-apple-qspi.c @@ -716,7 +716,8 @@ static int apple_qspi_qualify(struct spi_mem *mem, struct apple_qspi *qspi, ret = apple_qspi_read_sfdp(mem, table, dword, sizeof(dword)); if (ret) return ret; - if (apple_qspi_sfdp_size(get_unaligned_le32(&dword[4])) != part->size) { + if (apple_qspi_sfdp_size(get_unaligned_le32(&dword[4])) != + apple_qspi_part_sfdp_size(part)) { *denial = "part-size"; ret = -ENODEV; goto latch; diff --git a/tools/asahi/qspi-nvram-tests.py b/tools/asahi/qspi-nvram-tests.py index b34f00178013c..7191853b72c95 100644 --- a/tools/asahi/qspi-nvram-tests.py +++ b/tools/asahi/qspi-nvram-tests.py @@ -167,16 +167,17 @@ def function(source, signature): static bool sent(unsigned int o){for(unsigned int i=0;isize==sizes[i]&&part->bp_ok==tolerated[i]); + assert(part&&part->size==sizes[i]&&apple_qspi_part_sfdp_size(part)==sfdp_sizes[i]&&part->bp_ok==tolerated[i]); } - const u8 unknown[][3]={{0xef,0x65,0x16},{0xef,0x65,0x18},{0xc2,0x2b,0x28},{0xc8,0x60,0x15},{0xef,0x40,0x17},{0,0,0},{0xff,0xff,0xff}}; + const u8 unknown[][3]={{0xef,0x65,0x13},{0xef,0x65,0x16},{0xef,0x65,0x18},{0xc2,0x2b,0x28},{0xc8,0x60,0x15},{0xef,0x40,0x17},{0,0,0},{0xff,0xff,0xff}}; for(unsigned int i=0;iaddr.val < qspi->write_start || op->addr.val + len > qspi->write_end', '0'), ('protected-qualify', '!apple_qspi_unprotected_banks(', '0 && !apple_qspi_unprotected_banks('), - ('sfdp-size', '!= part->size) {', '!= part->size && 0) {'), + ('sfdp-size', 'apple_qspi_part_sfdp_size(part)) {', + 'apple_qspi_part_sfdp_size(part) && 0) {'), ('window-read-only', '!read_only && size &&', 'size &&'), ('window-bank', '!(size % APPLE_QSPI_NVRAM_BANK) &&', ''), ('range', 'addr >= start &&', 'addr >= 1 &&'), @@ -489,6 +511,10 @@ def main(): 'APPLE_QSPI_JEDEC_GD25UF16E\t{ 0xc8, 0x83, 0x16 }'), ('j775d-gd-id', 'APPLE_QSPI_JEDEC_GD25UF64E\t{ 0xc8, 0x83, 0x17 }', 'APPLE_QSPI_JEDEC_GD25UF64E\t{ 0xc8, 0x83, 0x18 }'), + ('j873g-w25q80-id', 'APPLE_QSPI_JEDEC_W25Q80\t\t{ 0xef, 0x65, 0x14 }', + 'APPLE_QSPI_JEDEC_W25Q80\t\t{ 0xef, 0x65, 0x13 }'), + ('j873g-w25q80-size', '{ APPLE_QSPI_JEDEC_W25Q80, 0x100000, 0, 0x200000 }', + '{ APPLE_QSPI_JEDEC_W25Q80, 0x200000, 0, 0x200000 }'), ('read-only', 'read_only || !qspi->nvram_write_candidate || qspi->write_fault', '!qspi->nvram_write_candidate || qspi->write_fault'), ('fault-latch', 'write_fault_latched = true;', 'write_fault_latched = false;'),