From 0cb67690b3f5179c6a37ccafc14c10842cd39275 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Sun, 22 Nov 2026 14:38:08 -0800 Subject: [PATCH] spi: apple-qspi: admit the GD25UF64E, so the J775D's nvram partition can be written The J775D (Mac Studio, M5 Ultra) boot NOR reads JEDEC ID c8 83 17, a GigaDevice GD25UF64E (64 Mbit, 8 MiB), with 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 ends within the part. Add the part with its size and no tolerated BP bits. The part-table checks in KUnit and in tools/asahi/qspi-nvram-tests.py list it, and a host-test case runs the GigaDevice status checks with the J775D's SR1/SR2/SR3 in its partition and refuses BP0. Signed-off-by: Jeff Queisser --- drivers/spi/spi-apple-qspi-policy-test.c | 15 ++++++++---- drivers/spi/spi-apple-qspi-policy.h | 19 +++++++++------- tools/asahi/qspi-nvram-tests.py | 29 ++++++++++++++++++++---- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/drivers/spi/spi-apple-qspi-policy-test.c b/drivers/spi/spi-apple-qspi-policy-test.c index 68b7de086be2f..0383e506b5338 100644 --- a/drivers/spi/spi-apple-qspi-policy-test.c +++ b/drivers/spi/spi-apple-qspi-policy-test.c @@ -183,6 +183,8 @@ static void qspi_policy_gd_status(struct kunit *test) /* The J700 GD25UF16E part: QE is set for good and BP0 by iBoot. */ KUNIT_EXPECT_TRUE(test, apple_qspi_gd_status_allows_write(0x00, 0x02, 0x1c)); KUNIT_EXPECT_TRUE(test, apple_qspi_gd_status_allows_write(0x04, 0x02, 0x1c)); + /* The J775D GD25UF64E part: QE only, no block protection tolerated. */ + KUNIT_EXPECT_TRUE(test, apple_qspi_gd_status_allows_write(0x00, 0x02, 0)); KUNIT_EXPECT_FALSE(test, apple_qspi_gd_status_allows_write(0x04, 0x02, 0)); /* SRP0, SRP1 and LB1 to LB3 stay as found and do not block a write. */ KUNIT_EXPECT_TRUE(test, apple_qspi_gd_status_allows_write(0x80, 0x3b, 0x1c)); @@ -204,8 +206,10 @@ static void qspi_policy_part_status(struct kunit *test) KUNIT_EXPECT_TRUE(test, apple_qspi_part_status_allows_write(0xef, 0x20, 0, 0, 0x1c)); KUNIT_EXPECT_FALSE(test, apple_qspi_part_status_allows_write(0xc8, 0x20, 0, 0, 0x1c)); KUNIT_EXPECT_FALSE(test, apple_qspi_part_status_allows_write(0xef, 0, 0, 0x04, 0x1c)); - /* GigaDevice SR3 bit 2 is LPE, a power setting. */ + /* GigaDevice SR3 bit 2 is LPE, a power setting; J775D leaves SR3 0x20. */ KUNIT_EXPECT_TRUE(test, apple_qspi_part_status_allows_write(0xc8, 0, 0, 0x04, 0x1c)); + KUNIT_EXPECT_TRUE(test, apple_qspi_part_status_allows_write(0xc8, 0x00, 0x02, 0x20, 0)); + KUNIT_EXPECT_FALSE(test, apple_qspi_part_status_allows_write(0xc8, 0x04, 0x02, 0x20, 0)); KUNIT_EXPECT_TRUE(test, apple_qspi_part_status_allows_write(0xef, 0, 0x04, 0, 0x1c)); KUNIT_EXPECT_FALSE(test, apple_qspi_part_status_allows_write(0xc8, 0, 0x04, 0, 0x1c)); KUNIT_EXPECT_FALSE(test, apple_qspi_part_status_allows_write(0xc2, 0x20, 0, 0, 0x1c)); @@ -273,12 +277,15 @@ 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 }, }; - static const unsigned int sizes[] = { 0x800000, 0x800000, 0x200000, 0x200000 }; - static const unsigned char bp_ok[] = { 0, 0, 0x1c, 0x1c }; + static const unsigned int sizes[] = { 0x800000, 0x800000, 0x200000, 0x200000, + 0x800000 }; + static const unsigned char bp_ok[] = { 0, 0, 0x1c, 0x1c, 0 }; static const unsigned char unknown[][3] = { { 0xef, 0x65, 0x16 }, { 0xef, 0x40, 0x17 }, { 0xc2, 0x2b, 0x28 }, - { 0xc8, 0x60, 0x15 }, { 0, 0, 0 }, { 0xff, 0xff, 0xff }, + { 0xc8, 0x60, 0x15 }, { 0xc8, 0x83, 0x16 }, { 0xc8, 0x83, 0x18 }, + { 0, 0, 0 }, { 0xff, 0xff, 0xff }, }; const struct apple_qspi_part *part; unsigned int i; diff --git a/drivers/spi/spi-apple-qspi-policy.h b/drivers/spi/spi-apple-qspi-policy.h index f0ac13bf978b3..0a8e502cfcbb4 100644 --- a/drivers/spi/spi-apple-qspi-policy.h +++ b/drivers/spi/spi-apple-qspi-policy.h @@ -81,14 +81,14 @@ static inline int apple_qspi_mx_status_allows_write(unsigned int sr, #define APPLE_QSPI_MFR_GIGADEVICE 0xc8 /* - * GigaDevice GD25UF16E. SR1 holds WIP, WEL, five block-protect bits BP[4:0] - * at bits 6:2 and SRP0. SR2 holds SRP1, QE, SUS2 at bit 2, LB[3:1], CMP and - * SUS1 at bit 7. SR3 holds output drive, dummy-cycle and low-power settings - * and has no write-protect selection. BUSY and WEL, both suspend bits and - * CMP are always refused. BP[2:0] sit where they do on Winbond parts and - * are tolerated only where bp_ok allows them; BP3 and BP4 move or shrink - * the protected range and are refused unless bp_ok names them. SRP0, SRP1, - * QE and LB stay unchanged. + * GigaDevice GD25UF16E and GD25UF64E. SR1 holds WIP, WEL, five block-protect + * bits BP[4:0] at bits 6:2 and SRP0. SR2 holds SRP1, QE, SUS2 at bit 2, + * LB[3:1], CMP and SUS1 at bit 7. SR3 holds output drive, dummy-cycle and + * low-power settings and has no write-protect selection. BUSY and WEL, both + * suspend bits and CMP are always refused. BP[2:0] sit where they do on + * Winbond parts and are tolerated only where bp_ok allows them; BP3 and BP4 + * move or shrink the protected range and are refused unless bp_ok names them. + * SRP0, SRP1, QE and LB stay unchanged. */ static inline int apple_qspi_gd_status_allows_write(unsigned int sr1, unsigned int sr2, @@ -171,6 +171,7 @@ struct apple_qspi_part { #define APPLE_QSPI_JEDEC_W25Q16 { 0xef, 0x65, 0x15 } #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 } static const struct apple_qspi_part apple_qspi_parts[] = { /* J613, J713, J813; also on the bus of some J616s */ @@ -181,6 +182,8 @@ static const struct apple_qspi_part apple_qspi_parts[] = { { APPLE_QSPI_JEDEC_W25Q16, 0x200000, 0x1c }, /* Some J700s; BP0 covers the same range */ { APPLE_QSPI_JEDEC_GD25UF16E, 0x200000, 0x1c }, + /* J775D (M5 Ultra): no block protection left set, SR1 0x00 */ + { APPLE_QSPI_JEDEC_GD25UF64E, 0x800000, 0 }, }; static inline const struct apple_qspi_part * diff --git a/tools/asahi/qspi-nvram-tests.py b/tools/asahi/qspi-nvram-tests.py index a67a44af65025..b34f00178013c 100644 --- a/tools/asahi/qspi-nvram-tests.py +++ b/tools/asahi/qspi-nvram-tests.py @@ -167,16 +167,16 @@ def function(source, signature): static bool sent(unsigned int o){for(unsigned int i=0;isize==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}}; for(unsigned int i=0;invram_write_candidate || qspi->write_fault', '!qspi->nvram_write_candidate || qspi->write_fault'), ('fault-latch', 'write_fault_latched = true;', 'write_fault_latched = false;'),