flash/nor/nrf5: check protection before flash erase/write on nRF51
authorTomas Vanek <vanekt@fbl.cz>
Mon, 16 Mar 2020 14:49:54 +0000 (15:49 +0100)
committerTomas Vanek <vanekt@fbl.cz>
Wed, 28 Oct 2020 10:51:29 +0000 (10:51 +0000)
commit491636c8b8328a54bef41b68771c2965dd468e05
tree67b892726af225b89ecedbd2980d822962935c50
parentc97ccc8971b44fbce28438cb926990a6e5a63450
flash/nor/nrf5: check protection before flash erase/write on nRF51

nRF51 devices have a clumsy flash protection based on UICR CLENR0.
A code running in RAM can write to a protected flash region without
any hint the protection gets violated.
NVMC flash page erase obeys protection setting but fails absolutely
silently.

Before this change the first problem was not addressed in the code.
To justify the second one, protection was loaded during probe,
after protection setting and after a mass erase.

Move protection updates to the beginning of erase/write operation
and limit them to nRF51 series only. Check for protected sectors
before write.

The change also fixes the problem of 'nrf5 mass_erase' on
nRF52833/840 devices. They use ACL flash protection, which is not
supported in nrf5 driver. mass_erase then looked like it failed.

Change-Id: Ie58cda68eb104d410b02777c3df5b343408e2666
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/5522
Tested-by: jenkins
src/flash/nor/nrf5.c