]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
spi: intel: Allow writeable MTD partition with module param
authorJakub Czapiga <czapiga@google.com>
Fri, 25 Jul 2025 12:25:42 +0000 (12:25 +0000)
committerMark Brown <broonie@kernel.org>
Fri, 25 Jul 2025 12:44:36 +0000 (13:44 +0100)
The MTD device is blocked from writing to the SPI-NOR chip if any region
of it is write-protected, even if "writeable=1" module parameter is set.

Add ability to bypass this behaviour by introducing new module parameter
"ignore_protestion_status" which allows to rely on the write protection
mechanism of SPI-NOR chip itself, which most modern chips (since
the 1990'+) have already implemented.

Any erase/write operations performed on the write-protected section will
be rejected by the chip.

Signed-off-by: Jakub Czapiga <czapiga@google.com>
Link: https://patch.msgid.link/20250725122542.2633334-1-czapiga@google.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-intel.c

index 5d5a546c62ea7ffeac37e7e34b761607e7c2b6aa..13bbb2133507d801b06e3c7e3b56090dbfd02178 100644 (file)
@@ -189,6 +189,11 @@ struct intel_spi_mem_op {
 static bool writeable;
 module_param(writeable, bool, 0);
 MODULE_PARM_DESC(writeable, "Enable write access to SPI flash chip (default=0)");
+static bool ignore_protection_status;
+module_param(ignore_protection_status, bool, 0);
+MODULE_PARM_DESC(
+       ignore_protection_status,
+       "Do not block SPI flash chip write access even if it is write-protected (default=0)");
 
 static void intel_spi_dump_regs(struct intel_spi *ispi)
 {
@@ -1248,13 +1253,15 @@ static void intel_spi_fill_partition(struct intel_spi *ispi,
                        continue;
 
                /*
-                * If any of the regions have protection bits set, make the
-                * whole partition read-only to be on the safe side.
+                * If any of the regions have protection bits set and
+                * the ignore protection status parameter is not set,
+                * make the whole partition read-only to be on the safe side.
                 *
                 * Also if the user did not ask the chip to be writeable
                 * mask the bit too.
                 */
-               if (!writeable || intel_spi_is_protected(ispi, base, limit)) {
+               if (!writeable || (!ignore_protection_status &&
+                                  intel_spi_is_protected(ispi, base, limit))) {
                        part->mask_flags |= MTD_WRITEABLE;
                        ispi->protected = true;
                }