Skip to contentSkip to conversation

Add spi flash lock option

PATCH Superseded Venkatesh Yadav Abbarapu 2 participants 6 messages Sep 28, 2023 – Sep 29, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add spi flash lock option

Disabling the flash lock option for versal and versal-net mini ospi and qspi defconfigs.

Venkatesh Yadav Abbarapu (3):
mtd: spi-nor: Add spi flash lock config option
arm64: versal: Disable the lock option for mini ospi and qspi
arm64: versal_net: Disable the lock option for mini ospi and qspi

 configs/xilinx_versal_mini_ospi_defconfig     | 3 ++-
 configs/xilinx_versal_mini_qspi_defconfig     | 3 ++-
 configs/xilinx_versal_net_mini_ospi_defconfig | 3 ++-
 configs/xilinx_versal_net_mini_qspi_defconfig | 3 ++-
 drivers/mtd/spi/Kconfig                       | 7 +++++++
 drivers/mtd/spi/spi-nor-core.c                | 8 +++++++-
 6 files changed, 22 insertions(+), 5 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/3 mtd: spi-nor: Add spi flash lock config option

Provide an explicit configuration option to disable default "lock" of any flash chip which supports locking.

---
 drivers/mtd/spi/Kconfig        | 7 +++++++
 drivers/mtd/spi/spi-nor-core.c | 8 +++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)
drivers/mtd/spi/Kconfig +7 -0
index a9617c6c58..476d848321 100644
@@ -134,6 +134,13 @@ 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_LOCK
+	bool "Enable the Locking feature"
+	default y
+	help
+	 Enable the SPI flash lock support. By default this is set to y.
+	 If you intend not to use the lock support you should say n here.
+
 config SPI_FLASH_UNLOCK_ALL
 	bool "Unlock the entire SPI flash on u-boot startup"
 	default y
drivers/mtd/spi/spi-nor-core.c +7 -1
index 6093277f17..9c51f2b1b0 100644
@@ -1099,6 +1099,7 @@ static int spansion_erase_non_uniform(struct spi_nor *nor, u32 addr,
 }
 #endif
 
+#if defined(CONFIG_SPI_FLASH_LOCK)
 #if defined(CONFIG_SPI_FLASH_STMICRO) || defined(CONFIG_SPI_FLASH_SST)
 /* Write status register and ensure bits in mask match written values */
 static int write_sr_and_check(struct spi_nor *nor, u8 status_new, u8 mask)
@@ -1386,6 +1387,7 @@ static int stm_is_unlocked(struct spi_nor *nor, loff_t ofs, uint64_t len)
 	return stm_is_unlocked_sr(nor, ofs, len, status);
 }
 #endif /* CONFIG_SPI_FLASH_STMICRO */
+#endif
 
 static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
 {
@@ -1461,6 +1463,7 @@ read_err:
 	return ret;
 }
 
+#if defined(CONFIG_SPI_FLASH_LOCK)
 #ifdef CONFIG_SPI_FLASH_SST
 /*
  * sst26 flash series has its own block protection implementation:
@@ -1729,6 +1732,8 @@ sst_write_err:
 	return ret;
 }
 #endif
+#endif
+
 /*
  * Write an address range to the nor chip.  Data must be written in
  * FLASH_PAGESIZE chunks.  The address range may be any size provided
@@ -4103,6 +4108,7 @@ int spi_nor_scan(struct spi_nor *nor)
 	mtd->_read = spi_nor_read;
 	mtd->_write = spi_nor_write;
 
+#if defined(CONFIG_SPI_FLASH_LOCK)
 #if defined(CONFIG_SPI_FLASH_STMICRO) || defined(CONFIG_SPI_FLASH_SST)
 	/* NOR protection support for STmicro/Micron chips and similar */
 	if (JEDEC_MFR(info) == SNOR_MFR_ST ||
@@ -4126,7 +4132,7 @@ int spi_nor_scan(struct spi_nor *nor)
 		nor->flash_is_unlocked = sst26_is_unlocked;
 	}
 #endif
-
+#endif
 	if (info->flags & USE_FSR)
 		nor->flags |= SNOR_F_USE_FSR;
 	if (info->flags & SPI_NOR_HAS_TB)
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH 1/3] mtd: spi-nor: Add spi flash lock config option

Quoted 2 lines · Venkatesh Yadav Abbarapu

Provide an explicit configuration option to disable default "lock" of any flash chip which supports locking.

Please also write reason for it. Based on 2/3 and 3/3 I expect you want to save some memory. Another reason could be not expose that functionality to be exposed to users. Should we also guard sf protect command itself? It could give us additional space.

Quoted 71 lines
---
  drivers/mtd/spi/Kconfig        | 7 +++++++
  drivers/mtd/spi/spi-nor-core.c | 8 +++++++-
  2 files changed, 14 insertions(+), 1 deletion(-)
drivers/mtd/spi/Kconfig +7 -0
index a9617c6c58..476d848321 100644
@@ -134,6 +134,13 @@ 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_LOCK
+	bool "Enable the Locking feature"
+	default y
+	help
+	 Enable the SPI flash lock support. By default this is set to y.
+	 If you intend not to use the lock support you should say n here.
+
  config SPI_FLASH_UNLOCK_ALL
  	bool "Unlock the entire SPI flash on u-boot startup"
  	default y
drivers/mtd/spi/spi-nor-core.c +6 -0
index 6093277f17..9c51f2b1b0 100644
@@ -1099,6 +1099,7 @@ static int spansion_erase_non_uniform(struct spi_nor *nor, u32 addr,
  }
  #endif
 
+#if defined(CONFIG_SPI_FLASH_LOCK)
  #if defined(CONFIG_SPI_FLASH_STMICRO) || defined(CONFIG_SPI_FLASH_SST)
  /* Write status register and ensure bits in mask match written values */
  static int write_sr_and_check(struct spi_nor *nor, u8 status_new, u8 mask)
@@ -1386,6 +1387,7 @@ static int stm_is_unlocked(struct spi_nor *nor, loff_t ofs, uint64_t len)
  	return stm_is_unlocked_sr(nor, ofs, len, status);
  }
  #endif /* CONFIG_SPI_FLASH_STMICRO */
+#endif
 
  static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
  {
@@ -1461,6 +1463,7 @@ read_err:
  	return ret;
  }
 
+#if defined(CONFIG_SPI_FLASH_LOCK)
  #ifdef CONFIG_SPI_FLASH_SST
  /*
   * sst26 flash series has its own block protection implementation:
@@ -1729,6 +1732,8 @@ sst_write_err:
  	return ret;
  }
  #endif
+#endif
+
  /*
   * Write an address range to the nor chip.  Data must be written in
   * FLASH_PAGESIZE chunks.  The address range may be any size provided
@@ -4103,6 +4108,7 @@ int spi_nor_scan(struct spi_nor *nor)
  	mtd->_read = spi_nor_read;
  	mtd->_write = spi_nor_write;
 
+#if defined(CONFIG_SPI_FLASH_LOCK)
  #if defined(CONFIG_SPI_FLASH_STMICRO) || defined(CONFIG_SPI_FLASH_SST)
  	/* NOR protection support for STmicro/Micron chips and similar */
  	if (JEDEC_MFR(info) == SNOR_MFR_ST ||

drivers/mtd/spi/spi-nor-core.c int spi_nor_scan(struct spi_nor *nor) · line 4138

Quoted 8 lines
drivers/mtd/spi/spi-nor-core.c +1 -1
@@ -4126,7 +4132,7 @@ int spi_nor_scan(struct spi_nor *nor)
  		nor->flash_is_unlocked = sst26_is_unlocked;
  	}
  #endif
-
+#endif
  	if (info->flags & USE_FSR)
  		nor->flags |= SNOR_F_USE_FSR;
  	if (info->flags & SPI_NOR_HAS_TB)

M

#3 lore raw

PATCH 2/3 arm64: versal: Disable the lock option for mini ospi and qspi

In reply to Venkatesh Yadav Abbarapu

As mini configs are required only for flashing the images, so disabling the lock config which will save nearly 6KB of memory.

---
 configs/xilinx_versal_mini_ospi_defconfig | 3 ++-
 configs/xilinx_versal_mini_qspi_defconfig | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
configs/xilinx_versal_mini_ospi_defconfig +2 -1
index 27b59f899a..539ce2d3c0 100644
@@ -12,7 +12,6 @@ CONFIG_SF_DEFAULT_SPEED=30000000
 CONFIG_ENV_SIZE=0x80
 # CONFIG_DM_GPIO is not set
 CONFIG_DEFAULT_DEVICE_TREE="versal-mini-ospi-single"
-CONFIG_SYS_PROMPT="Versal> "
 CONFIG_SYS_MEM_RSVD_FOR_MMU=y
 CONFIG_VERSAL_NO_DDR=y
 # CONFIG_PSCI_RESET is not set
@@ -27,6 +26,7 @@ CONFIG_BOARD_EARLY_INIT_R=y
 # CONFIG_CMDLINE_EDITING is not set
 # CONFIG_AUTO_COMPLETE is not set
 # CONFIG_SYS_LONGHELP is not set
+CONFIG_SYS_PROMPT="Versal> "
 # CONFIG_CMD_BDI is not set
 # CONFIG_CMD_CONSOLE is not set
 # CONFIG_CMD_BOOTD is not set
@@ -57,6 +57,7 @@ CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_DM_SPI_FLASH=y
 CONFIG_SPI_FLASH_SOFT_RESET=y
 CONFIG_SPI_FLASH_SOFT_RESET_ON_BOOT=y
+# CONFIG_SPI_FLASH_LOCK is not set
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
configs/xilinx_versal_mini_qspi_defconfig +2 -1
index 4b0793411c..93365e7d30 100644
@@ -10,7 +10,6 @@ CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0xFFFE0000
 CONFIG_SF_DEFAULT_SPEED=30000000
 CONFIG_ENV_SIZE=0x80
 CONFIG_DEFAULT_DEVICE_TREE="versal-mini-qspi-single"
-CONFIG_SYS_PROMPT="Versal> "
 CONFIG_SYS_MEM_RSVD_FOR_MMU=y
 CONFIG_VERSAL_NO_DDR=y
 # CONFIG_PSCI_RESET is not set
@@ -27,6 +26,7 @@ CONFIG_BOARD_EARLY_INIT_R=y
 # CONFIG_CMDLINE_EDITING is not set
 # CONFIG_AUTO_COMPLETE is not set
 # CONFIG_SYS_LONGHELP is not set
+CONFIG_SYS_PROMPT="Versal> "
 # CONFIG_SYS_XTRACE is not set
 # CONFIG_CMD_BDI is not set
 # CONFIG_CMD_CONSOLE is not set
@@ -61,6 +61,7 @@ CONFIG_BOARD_EARLY_INIT_R=y
 # CONFIG_MMC is not set
 CONFIG_DM_SPI_FLASH=y
 # CONFIG_SPI_FLASH_SMART_HWCAPS is not set
+# CONFIG_SPI_FLASH_LOCK is not set
 # CONFIG_SPI_FLASH_UNLOCK_ALL is not set
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
Signature · 1 line
2.17.1
maintainer
#4 lore raw

Re: [PATCH 2/3] arm64: versal: Disable the lock option for mini ospi and qspi

Quoted 22 lines · Venkatesh Yadav Abbarapu

As mini configs are required only for flashing the images, so disabling the lock config which will save nearly 6KB of memory.

---
  configs/xilinx_versal_mini_ospi_defconfig | 3 ++-
  configs/xilinx_versal_mini_qspi_defconfig | 3 ++-
  2 files changed, 4 insertions(+), 2 deletions(-)
configs/xilinx_versal_mini_ospi_defconfig +0 -1
index 27b59f899a..539ce2d3c0 100644
@@ -12,7 +12,6 @@ CONFIG_SF_DEFAULT_SPEED=30000000
  CONFIG_ENV_SIZE=0x80
  # CONFIG_DM_GPIO is not set
  CONFIG_DEFAULT_DEVICE_TREE="versal-mini-ospi-single"
-CONFIG_SYS_PROMPT="Versal> "
  CONFIG_SYS_MEM_RSVD_FOR_MMU=y
  CONFIG_VERSAL_NO_DDR=y
  # CONFIG_PSCI_RESET is not set

configs/xilinx_versal_mini_ospi_defconfig CONFIG_BOARD_EARLY_INIT_R=y · line 29

Quoted 4 lines
configs/xilinx_versal_mini_ospi_defconfig +1 -0
@@ -27,6 +26,7 @@ CONFIG_BOARD_EARLY_INIT_R=y
  # CONFIG_CMDLINE_EDITING is not set
  # CONFIG_AUTO_COMPLETE is not set
  # CONFIG_SYS_LONGHELP is not set
+CONFIG_SYS_PROMPT="Versal> "

Ignore this change. It will be handled by different patch.

The same for ther est of file and 3/3.

M

#5 lore raw

PATCH 3/3 arm64: versal_net: Disable the lock option for mini ospi and qspi

In reply to Venkatesh Yadav Abbarapu

As mini configs are required only for flashing the images, so disabling the lock config which will save nearly 6KB of memory.

---
 configs/xilinx_versal_net_mini_ospi_defconfig | 3 ++-
 configs/xilinx_versal_net_mini_qspi_defconfig | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
configs/xilinx_versal_net_mini_ospi_defconfig +2 -1
index d11e180780..db3e7c80b2 100644
@@ -12,7 +12,6 @@ CONFIG_SF_DEFAULT_SPEED=30000000
 CONFIG_ENV_SIZE=0x80
 # CONFIG_DM_GPIO is not set
 CONFIG_DEFAULT_DEVICE_TREE="versal-net-mini-ospi-single"
-CONFIG_SYS_PROMPT="Versal NET> "
 CONFIG_SYS_MEM_RSVD_FOR_MMU=y
 # CONFIG_PSCI_RESET is not set
 CONFIG_SYS_LOAD_ADDR=0xBBF80000
@@ -26,6 +25,7 @@ CONFIG_BOARD_EARLY_INIT_R=y
 # CONFIG_CMDLINE_EDITING is not set
 # CONFIG_AUTO_COMPLETE is not set
 # CONFIG_SYS_LONGHELP is not set
+CONFIG_SYS_PROMPT="Versal NET> "
 # CONFIG_CMD_BDI is not set
 # CONFIG_CMD_CONSOLE is not set
 # CONFIG_CMD_BOOTD is not set
@@ -56,6 +56,7 @@ CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_DM_SPI_FLASH=y
 CONFIG_SPI_FLASH_SOFT_RESET=y
 CONFIG_SPI_FLASH_SOFT_RESET_ON_BOOT=y
+# CONFIG_SPI_FLASH_LOCK is not set
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
configs/xilinx_versal_net_mini_qspi_defconfig +2 -1
index a7ebc38cda..c0ff42aa91 100644
@@ -10,7 +10,6 @@ CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0xBBF20000
 CONFIG_SF_DEFAULT_SPEED=30000000
 CONFIG_ENV_SIZE=0x80
 CONFIG_DEFAULT_DEVICE_TREE="versal-net-mini-qspi-single"
-CONFIG_SYS_PROMPT="Versal NET> "
 CONFIG_SYS_MEM_RSVD_FOR_MMU=y
 # CONFIG_PSCI_RESET is not set
 CONFIG_SYS_LOAD_ADDR=0xBBF80000
@@ -26,6 +25,7 @@ CONFIG_BOARD_EARLY_INIT_R=y
 # CONFIG_CMDLINE_EDITING is not set
 # CONFIG_AUTO_COMPLETE is not set
 # CONFIG_SYS_LONGHELP is not set
+CONFIG_SYS_PROMPT="Versal NET> "
 # CONFIG_SYS_XTRACE is not set
 # CONFIG_CMD_BDI is not set
 # CONFIG_CMD_CONSOLE is not set
@@ -60,6 +60,7 @@ CONFIG_BOARD_EARLY_INIT_R=y
 # CONFIG_MMC is not set
 CONFIG_DM_SPI_FLASH=y
 # CONFIG_SPI_FLASH_SMART_HWCAPS is not set
+# CONFIG_SPI_FLASH_LOCK is not set
 # CONFIG_SPI_FLASH_UNLOCK_ALL is not set
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
Signature · 1 line
2.17.1