[PATCH 11/30] mtd: spi-nor: winbond: W25Q32JV-Q/N: Fill locking information
Michael Walle
mwalle at kernel.org
Mon Jul 6 07:21:54 PDT 2026
On Fri May 29, 2026 at 5:22 PM CEST, Miquel Raynal wrote:
> The SFDP table does not advertize the locking capabilities of the
> device, flag these capabilities.
>
> Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
> ---
> $ alias show_sectors='grep -A4 "locked sectors" /sys/kernel/debug/spi-nor/spi0.0
> /params'
> $ flash_lock -u /dev/mtd0
> $ flash_lock -i /dev/mtd0
> Device: /dev/mtd0
> Start: 0
> Len: 0x400000
> Lock status: unlocked
> Return code: 0
> $ mtd_debug erase /dev/mtd0 0 2097152
> Erased 2097152 bytes from address 0x00000000 in flash
> $ mtd_debug write /dev/mtd0 0 2097152 spi_test
> Copied 2097152 bytes from spi_test to address 0x00000000 in flash
> $ mtd_debug read /dev/mtd0 0 2097152 spi_read
> Copied 2097152 bytes from address 0x00000000 in flash to spi_read
> $ sha256sum spi*
> 6d7c114421890dfa12e1824aa351d4490815a9c0ceb9c2e7981073106a11fc71 spi_read
> 6d7c114421890dfa12e1824aa351d4490815a9c0ceb9c2e7981073106a11fc71 spi_test
> $ show_sectors
> locked sectors
> region (in hex) | status | #sectors
> ------------------+----------+---------
> 00000000-003fffff | unlocked | 64
> $ flash_lock -l /dev/mtd0
> $ flash_lock -i /dev/mtd0
> Device: /dev/mtd0
> Start: 0
> Len: 0x400000
> Lock status: locked
> Return code: 1
> $ mtd_debug erase /dev/mtd0 0 2097152
> Erased 2097152 bytes from address 0x00000000 in flash
> $ mtd_debug read /dev/mtd0 0 2097152 spi_read
> Copied 2097152 bytes from address 0x00000000 in flash to spi_read
> $ sha256sum spi*
> 6d7c114421890dfa12e1824aa351d4490815a9c0ceb9c2e7981073106a11fc71 spi_read
> 6d7c114421890dfa12e1824aa351d4490815a9c0ceb9c2e7981073106a11fc71 spi_test
> $ dd if=/dev/urandom of=./spi_test2 bs=1M count=2
> 2+0 records in
> 2+0 records out
> $ mtd_debug write /dev/mtd0 0 2097152 spi_test2
> Copied 2097152 bytes from spi_test2 to address 0x00000000 in flash
> $ mtd_debug read /dev/mtd0 0 2097152 spi_read2
> Copied 2097152 bytes from address 0x00000000 in flash to spi_read2
> $ sha256sum spi*
> 6d7c114421890dfa12e1824aa351d4490815a9c0ceb9c2e7981073106a11fc71 spi_read
> 6d7c114421890dfa12e1824aa351d4490815a9c0ceb9c2e7981073106a11fc71 spi_read2
> 6d7c114421890dfa12e1824aa351d4490815a9c0ceb9c2e7981073106a11fc71 spi_test
> 5b69b16c88c3ae48213c359d2f9fd7f0583e513dabb224b3404bc93a5e173253 spi_test2
> $ show_sectors
> locked sectors
> region (in hex) | status | #sectors
> ------------------+----------+---------
> 00000000-003fffff | locked | 64
> $ flash_lock -u /dev/mtd0
> $ size=$(cat /sys/class/mtd/mtd0/size)
> $ nblocks=$(grep unlocked /sys/kernel/debug/spi-nor/spi0.0/params | sed -e 's/.*
> unlocked | //')
> $
> $ bs=$(($size / $nblocks))
> $ flash_lock -u /dev/mtd0
> $ flash_lock -l /dev/mtd0 $(($size - (2 * $bs))) 2 # last two
> $ show_sectors
> locked sectors
> region (in hex) | status | #sectors
> ------------------+----------+---------
> 00000000-003dffff | unlocked | 62
> 003e0000-003fffff | locked | 2
> $ flash_lock -u /dev/mtd0 $(($size - (2 * $bs))) 1 # last one
> $ show_sectors
> locked sectors
> region (in hex) | status | #sectors
> ------------------+----------+---------
> 00000000-003effff | unlocked | 63
> 003f0000-003fffff | locked | 1
> $ flash_lock -u /dev/mtd0
> $ all_but_one=$((($size / $bs) - 1))
> $ flash_lock -l /dev/mtd0 $bs $all_but_one # all but the first
> $ show_sectors
> locked sectors
> region (in hex) | status | #sectors
> ------------------+----------+---------
> 00000000-0000ffff | unlocked | 1
> 00010000-003fffff | locked | 63
> $ flash_lock -u /dev/mtd0 $bs 1 # all but the two first
> $ show_sectors
> locked sectors
> region (in hex) | status | #sectors
> ------------------+----------+---------
> 00000000-0001ffff | unlocked | 2
> 00020000-003fffff | locked | 62
> $ flash_lock -u /dev/mtd0
> $ flash_lock -l /dev/mtd0 0 $all_but_one # same from the other side
> $ show_sectors
> locked sectors
> region (in hex) | status | #sectors
> ------------------+----------+---------
> 00000000-003effff | locked | 63
> 003f0000-003fffff | unlocked | 1
> $ flash_lock -u /dev/mtd0 $(($size - (2 * $bs))) 1 # all but two
> $ show_sectors
> locked sectors
> region (in hex) | status | #sectors
> ------------------+----------+---------
> 00000000-003dffff | locked | 62
> 003e0000-003fffff | unlocked | 2
> ---
> drivers/mtd/spi-nor/winbond.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/spi-nor/winbond.c b/drivers/mtd/spi-nor/winbond.c
> index 07ab66a9e6c0..e6dca2493357 100644
> --- a/drivers/mtd/spi-nor/winbond.c
> +++ b/drivers/mtd/spi-nor/winbond.c
> @@ -200,7 +200,7 @@ static const struct flash_info winbond_nor_parts[] = {
> }, {
> /* W25Q32JV-Q/N */
> .id = SNOR_ID(0xef, 0x40, 0x16),
> - .flags = SPI_NOR_QUAD_PP,
> + .flags = SPI_NOR_QUAD_PP | SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB | SPI_NOR_HAS_CMP,
The original W25Q32 doesn't have the CMP bit.
-michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 297 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-mtd/attachments/20260706/dc75f091/attachment.sig>
More information about the linux-mtd
mailing list