[PATCH v2] spi: intel: Allow writeable MTD partition with module param

Jakub Czapiga posted 1 patch 2 months, 3 weeks ago
There is a newer version of this series
drivers/spi/spi-intel.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
[PATCH v2] spi: intel: Allow writeable MTD partition with module param
Posted by Jakub Czapiga 2 months, 3 weeks ago
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>
---
v1 -> v2:
- Fix typo in the macro name.

 drivers/spi/spi-intel.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-intel.c b/drivers/spi/spi-intel.c
index 5d5a546c62ea..6428e7de1aec 100644
--- a/drivers/spi/spi-intel.c
+++ b/drivers/spi/spi-intel.c
@@ -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_PRAM_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;
 		}
-- 
2.50.0.727.gbf7dc18ff4-goog
Re: [PATCH v2] spi: intel: Allow writeable MTD partition with module param
Posted by Mark Brown 2 months, 1 week ago
On Thu, 17 Jul 2025 15:28:51 +0000, Jakub Czapiga wrote:
> 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.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: intel: Allow writeable MTD partition with module param
      commit: 87aa3c8d8c4aa2e2567fe04126d14eb9fde815e5

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
Re: [PATCH v2] spi: intel: Allow writeable MTD partition with module param
Posted by Mark Brown 2 months, 2 weeks ago
On Thu, Jul 17, 2025 at 03:28:51PM +0000, Jakub Czapiga wrote:
> 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.

This doesn't compile:

/build/stage/linux/drivers/spi/spi-intel.c:196:2: error: expected identifier
  196 |         "Do not block SPI flash chip write access even if it is write-protected (default=0)");
      |         ^
/build/stage/linux/drivers/spi/spi-intel.c:194:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
  194 | MODULE_PRAM_DESC(
      | ^
      | int
/build/stage/linux/drivers/spi/spi-intel.c:194:17: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
  194 | MODULE_PRAM_DESC(
      |                 ^
  195 |         ignore_protection_status,
  196 |         "Do not block SPI flash chip write access even if it is write-protected (default=0)");
      |                                                                                             
      |                                                                                             void