mtd: spi-nor: add unlock all config option
authorMichael Walle <michael@walle.cc>
Wed, 9 Dec 2020 09:53:25 +0000 (10:53 +0100)
committerPriyanka Jain <priyanka.jain@nxp.com>
Mon, 8 Feb 2021 08:31:13 +0000 (14:01 +0530)
Provide an explicit configuration option to disable default "unlock all"
of any flash chip which supports locking. It doesn't make sense to
automatically unprotect the entire flash on each u-boot startup if the
block protection bits are actually used.

Traditionally, the unlock was there to be able to write to flash devices
which powered-up with the block protection bits set. Over time this
feature creeped into all flash devices which support locking.

For a more detailed description and discussion see:
https://lore.kernel.org/linux-mtd/20201203162959.29589-8-michael@walle.cc/

Keep things simple in u-boot and just provide a configration option to
disable this behavior which can be set per board.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Priyanka Jain <priyanka.jain@nxp.com>
drivers/mtd/spi/Kconfig
drivers/mtd/spi/spi-nor-core.c

index ea44443..f8db8e5 100644 (file)
@@ -95,6 +95,16 @@ config SPI_FLASH_BAR
          Bank/Extended address registers are used to access the flash
          which has size > 16MiB in 3-byte addressing.
 
+config SPI_FLASH_UNLOCK_ALL
+       bool "Unlock the entire SPI flash on u-boot startup"
+       default y
+       help
+        Some flashes tend to power up with the software write protection
+        bits set. If this option is set, the whole flash will be unlocked.
+
+        For legacy reasons, this option default to y. But if you intend to
+        actually use the software protection bits you should say n here.
+
 config SF_DUAL_FLASH
        bool "SPI DUAL flash memory support"
        help
index e16b0e1..ef426da 100644 (file)
@@ -2443,10 +2443,11 @@ static int spi_nor_init(struct spi_nor *nor)
         * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up
         * with the software protection bits set
         */
-       if (JEDEC_MFR(nor->info) == SNOR_MFR_ATMEL ||
-           JEDEC_MFR(nor->info) == SNOR_MFR_INTEL ||
-           JEDEC_MFR(nor->info) == SNOR_MFR_SST ||
-           nor->info->flags & SPI_NOR_HAS_LOCK) {
+       if (IS_ENABLED(CONFIG_SPI_FLASH_UNLOCK_ALL) &&
+           (JEDEC_MFR(nor->info) == SNOR_MFR_ATMEL ||
+            JEDEC_MFR(nor->info) == SNOR_MFR_INTEL ||
+            JEDEC_MFR(nor->info) == SNOR_MFR_SST ||
+            nor->info->flags & SPI_NOR_HAS_LOCK)) {
                write_enable(nor);
                write_sr(nor, 0);
                spi_nor_wait_till_ready(nor);