[BUG]: spi-nor: spi_nor_init() fails when SR locked

David Clear dac2 at pensando.io
Mon Jul 20 14:13:26 EDT 2020


Hi Tudor,

I'm seeing a change of behavior in spi-nor/next vs. my older 4.14
kernel w.r.t. how SR lock is working.

In my system with a Micron mt25qu02g, I'm using the hardware WP# to
lock the SR.  When hardware write-protect is on, at the next reboot
the kernel rejects the flash as it cannot unlock the whole device.

I traced the problem to spi_nor_write_sr1_and_check(), which is
writing to the SR and reading back a different value (as the locked SR
bits are immutable).

Call trace:
 spi_nor_write_sr1_and_check+0x68/0x70
 spi_nor_write_sr_and_check+0x34/0xd0
 spi_nor_sr_unlock+0x108/0x230
 spi_nor_unlock+0x54/0x80  (via spi_nor_unlock_all())
 spi_nor_init+0x94/0x100

spi_nor_write_sr1_and_check() is returning -EIO here:
        if (nor->bouncebuf[0] != sr1) {
                dev_dbg(nor->dev, "SR1: read back test failed\n");
                BUG();
                return -EIO;
        }

In my specific case Linux doesn't have (and cannot be given, for
product security reasons) control over the WP#.  In any case, I don't
think a write-protected flash should be rejected here.

Can you suggest how we might proceed?  The way WP# is used is
board-specific so perhaps a device-tree property of some sort in the
flash device node can inform the code to do or not do the
spi_nor_unlock_all()?

I can take a look at putting a patch together if you suggest an
acceptable mechanism.

Regards,
David.



More information about the linux-mtd mailing list