]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
mtd: spi-nor: disallow further writes to SR if WP# is low
authorBrian Norris <computersforpeace@gmail.com>
Fri, 29 Jan 2016 19:25:33 +0000 (11:25 -0800)
committerBrian Norris <computersforpeace@gmail.com>
Tue, 8 Mar 2016 02:01:55 +0000 (18:01 -0800)
commit47b8edbf0d43dcb9fda83833c05470edf59c31e3
tree49a92a61be05c18d2ee226bdd30fd35240cc5f3b
parentf8860802da84aa2bbc9f316e549a349fb40cda63
mtd: spi-nor: disallow further writes to SR if WP# is low

Locking the flash is most useful if it provides real hardware security.
Otherwise, it's little more than a software permission bit.

A reasonable use case that provides real HW security might be like
follows:

(1) hardware WP# is deasserted
(2) program flash
(3) flash range is protected via status register
(4) hardware WP# is asserted
(5) flash protection range can no longer be changed, until WP# is
    deasserted

In this way, flash protection is co-owned by hardware and software.

Now, one would expect to be able to perform step (3) with
ioctl(MEMLOCK), except that the spi-nor driver does not set the Status
Register Protect bit (a.k.a. Status Register Write Disable (SRWD)), so
even though the range is now locked, it does not satisfy step (5) -- it
can still be changed by a call to ioctl(MEMUNLOCK).

So, let's enable status register protection after the first lock
command, and disable protection only when the flash is fully unlocked.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Tested-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
drivers/mtd/spi-nor/spi-nor.c