mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 13:55:32 +00:00
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 <michael@walle.cc> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Reviewed-by: Jungseung Lee <js07.lee@samsung.com> Reviewed-by: Michael Walle <michael@walle.cc>
This commit is contained in:
parent
5bb783cc92
commit
b0e2d252f9
1 changed files with 13 additions and 7 deletions
|
@ -1682,13 +1682,19 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
|
|||
*
|
||||
* pow = ceil(log2(size / len)) = log2(size) - floor(log2(len))
|
||||
*/
|
||||
pow = ilog2(mtd->size) - ilog2(lock_len);
|
||||
val = mask - (pow << SR_BP_SHIFT);
|
||||
if (val & ~mask)
|
||||
return -EINVAL;
|
||||
/* Don't "lock" with no region! */
|
||||
if (!(val & mask))
|
||||
return -EINVAL;
|
||||
if (lock_len == mtd->size) {
|
||||
val = mask;
|
||||
} else {
|
||||
pow = ilog2(mtd->size) - ilog2(lock_len);
|
||||
val = mask - (pow << SR_BP_SHIFT);
|
||||
|
||||
if (val & ~mask)
|
||||
return -EINVAL;
|
||||
|
||||
/* Don't "lock" with no region! */
|
||||
if (!(val & mask))
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
status_new = (status_old & ~mask & ~tb_mask) | val;
|
||||
|
||||
|
|
Loading…
Reference in a new issue