Skip to content

Commit 188c803

Browse files
Venkatesh Yadav Abbarapumichalsimek
Venkatesh Yadav Abbarapu
authored andcommitted
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. By disabling the lock config will save some amount of memory and also don't expose the lock functionality to the users i.e., via sf protect command. Signed-off-by: Venkatesh Yadav Abbarapu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michal Simek <[email protected]>
1 parent bd9ff68 commit 188c803

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

cmd/sf.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ static int do_spi_flash(struct cmd_tbl *cmdtp, int flag, int argc,
604604
ret = do_spi_flash_read_write(argc, argv);
605605
else if (strcmp(cmd, "erase") == 0)
606606
ret = do_spi_flash_erase(argc, argv);
607-
else if (strcmp(cmd, "protect") == 0)
607+
else if (IS_ENABLED(CONFIG_SPI_FLASH_LOCK) && strcmp(cmd, "protect") == 0)
608608
ret = do_spi_protect(argc, argv);
609609
else if (IS_ENABLED(CONFIG_CMD_SF_TEST) && !strcmp(cmd, "test"))
610610
ret = do_spi_flash_test(argc, argv);
@@ -629,8 +629,10 @@ U_BOOT_LONGHELP(sf,
629629
"sf update addr offset|partition len - erase and write `len' bytes from memory\n"
630630
" at `addr' to flash at `offset'\n"
631631
" or to start of mtd `partition'\n"
632+
#ifdef CONFIG_SPI_FLASH_LOCK
632633
"sf protect lock/unlock sector len - protect/unprotect 'len' bytes starting\n"
633634
" at address 'sector'"
635+
#endif
634636
#ifdef CONFIG_CMD_SF_TEST
635637
"\nsf test offset len - run a very basic destructive test"
636638
#endif

drivers/mtd/spi/Kconfig

+7
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ config SPI_FLASH_BAR
134134
Bank/Extended address registers are used to access the flash
135135
which has size > 16MiB in 3-byte addressing.
136136

137+
config SPI_FLASH_LOCK
138+
bool "Enable the Locking feature"
139+
default y
140+
help
141+
Enable the SPI flash lock support. By default this is set to y.
142+
If you intend not to use the lock support you should say n here.
143+
137144
config SPI_FLASH_UNLOCK_ALL
138145
bool "Unlock the entire SPI flash on u-boot startup"
139146
default y

drivers/mtd/spi/spi-nor-core.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,7 @@ static int spansion_erase_non_uniform(struct spi_nor *nor, u32 addr,
11001100
}
11011101
#endif
11021102

1103+
#if defined(CONFIG_SPI_FLASH_LOCK)
11031104
#if defined(CONFIG_SPI_FLASH_STMICRO) || defined(CONFIG_SPI_FLASH_SST)
11041105
/* Write status register and ensure bits in mask match written values */
11051106
static int write_sr_and_check(struct spi_nor *nor, u8 status_new, u8 mask)
@@ -1387,6 +1388,7 @@ static int stm_is_unlocked(struct spi_nor *nor, loff_t ofs, uint64_t len)
13871388
return stm_is_unlocked_sr(nor, ofs, len, status);
13881389
}
13891390
#endif /* CONFIG_SPI_FLASH_STMICRO */
1391+
#endif
13901392

13911393
static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
13921394
{
@@ -1462,6 +1464,7 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
14621464
return ret;
14631465
}
14641466

1467+
#if defined(CONFIG_SPI_FLASH_LOCK)
14651468
#ifdef CONFIG_SPI_FLASH_SST
14661469
/*
14671470
* sst26 flash series has its own block protection implementation:
@@ -1730,6 +1733,8 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
17301733
return ret;
17311734
}
17321735
#endif
1736+
#endif
1737+
17331738
/*
17341739
* Write an address range to the nor chip. Data must be written in
17351740
* FLASH_PAGESIZE chunks. The address range may be any size provided
@@ -4104,6 +4109,7 @@ int spi_nor_scan(struct spi_nor *nor)
41044109
mtd->_read = spi_nor_read;
41054110
mtd->_write = spi_nor_write;
41064111

4112+
#if defined(CONFIG_SPI_FLASH_LOCK)
41074113
#if defined(CONFIG_SPI_FLASH_STMICRO) || defined(CONFIG_SPI_FLASH_SST)
41084114
/* NOR protection support for STmicro/Micron chips and similar */
41094115
if (JEDEC_MFR(info) == SNOR_MFR_ST ||
@@ -4127,7 +4133,7 @@ int spi_nor_scan(struct spi_nor *nor)
41274133
nor->flash_is_unlocked = sst26_is_unlocked;
41284134
}
41294135
#endif
4130-
4136+
#endif
41314137
if (info->flags & USE_FSR)
41324138
nor->flags |= SNOR_F_USE_FSR;
41334139
if (info->flags & SPI_NOR_HAS_TB)

0 commit comments

Comments
 (0)