Skip to content

Commit b0e2d25

Browse files
committed
mtd: spi-nor: Set all BP bits to one when lock_len == mtd->size
When there are more BP settings than needed for defining the protected areas of the flash memory, most flashes will define the remaining settings as "protect all", i.e. the equivalent of having all the BP bits set to one. But there are flashes where the in-between BP values are undefined (not mentioned), and only the "all bits set" is protecting the entire memory. One such example is w25q80, where BP[2:0]=0b101 and 0b110 are not defined. Set all the BP bits to one when lock_len == mtd->size, to treat this special case. Suggested-by: Michael Walle <[email protected]> Signed-off-by: Tudor Ambarus <[email protected]> Reviewed-by: Jungseung Lee <[email protected]> Reviewed-by: Michael Walle <[email protected]>
1 parent 5bb783c commit b0e2d25

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

drivers/mtd/spi-nor/core.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,13 +1682,19 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
16821682
*
16831683
* pow = ceil(log2(size / len)) = log2(size) - floor(log2(len))
16841684
*/
1685-
pow = ilog2(mtd->size) - ilog2(lock_len);
1686-
val = mask - (pow << SR_BP_SHIFT);
1687-
if (val & ~mask)
1688-
return -EINVAL;
1689-
/* Don't "lock" with no region! */
1690-
if (!(val & mask))
1691-
return -EINVAL;
1685+
if (lock_len == mtd->size) {
1686+
val = mask;
1687+
} else {
1688+
pow = ilog2(mtd->size) - ilog2(lock_len);
1689+
val = mask - (pow << SR_BP_SHIFT);
1690+
1691+
if (val & ~mask)
1692+
return -EINVAL;
1693+
1694+
/* Don't "lock" with no region! */
1695+
if (!(val & mask))
1696+
return -EINVAL;
1697+
}
16921698

16931699
status_new = (status_old & ~mask & ~tb_mask) | val;
16941700

0 commit comments

Comments
 (0)