Skip to contentSkip to conversation

mtd: intel-spi: split read/write modes

PATCH In review Mauro Lima 2 participants 8 messages Sep 10, 2021 – Sep 13, 2021

Subsystems (3)
lore
Share & tools
lore

Mauro Lima

author
#0 lore raw

cover mtd: intel-spi: split read/write modes

The purpose of the following patchset is to split read/write functionality from the Intel PCH/PCU SPI flash driver. Being able to use the driver in read-only mode (harmless), the users can get important firmware information from userspace which also includes being able to perform firmware attestation to verify integrity.

Currently fwupd is accessing to firmware information but only with SecureBoot disabled. With this driver the fwupd project could get such information with SecureBoot enabled.

Mauro Lima (4):
mtd: intel-spi: rename intel-spi to intel-spi-base
mtd: intel-spi: move chip internals into a defs.h
mtd: intel-spi: moving write/erase functions
mtd: intel-spi: add read only stubs

 drivers/mtd/spi-nor/controllers/Kconfig       |  50 +-
 drivers/mtd/spi-nor/controllers/Makefile      |   3 +
 .../{intel-spi.c => intel-spi-base.c}         | 442 ++----------------
 .../{intel-spi.h => intel-spi-base.h}         |   1 +
 .../mtd/spi-nor/controllers/intel-spi-defs.h  | 157 +++++++
 .../mtd/spi-nor/controllers/intel-spi-pci.c   |   2 +-
 .../spi-nor/controllers/intel-spi-platform.c  |   2 +-
 .../mtd/spi-nor/controllers/intel-spi-ro.c    |  50 ++
 .../mtd/spi-nor/controllers/intel-spi-rw.h    |  24 +
 drivers/mtd/spi-nor/controllers/intel-spi-w.c | 289 ++++++++++++
 include/linux/platform_data/x86/intel-spi.h   |   2 +
 11 files changed, 595 insertions(+), 427 deletions(-)
 rename drivers/mtd/spi-nor/controllers/{intel-spi.c => intel-spi-base.c} (54%)
 rename drivers/mtd/spi-nor/controllers/{intel-spi.h => intel-spi-base.h} (97%)
 create mode 100644 drivers/mtd/spi-nor/controllers/intel-spi-defs.h
 create mode 100644 drivers/mtd/spi-nor/controllers/intel-spi-ro.c
 create mode 100644 drivers/mtd/spi-nor/controllers/intel-spi-rw.h
 create mode 100644 drivers/mtd/spi-nor/controllers/intel-spi-w.c
Signature · 30 lines
2.31.1


-- 


This e-mail and any attachments may contain information that is 
privileged, confidential,  and/or exempt from disclosure under applicable 
law.  If you are not the intended recipient, you are hereby notified that 
any disclosure, copying, distribution or use of any information contained 
herein is strictly prohibited. If you have received this transmission in 
error, please immediately notify the sender and destroy the original 
transmission and any attachments, whether in electronic or hard copy 
format, without reading or saving.













______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
author
#1 lore raw

PATCH 1/4 mtd: intel-spi: rename intel-spi to intel-spi-base

Rename the files we want to split as base files. Include the new files in intel-spi-{pci|platform}.c. Change the intel-spi obj Makefile to be built with intel-spi-base.

---
 drivers/mtd/spi-nor/controllers/Makefile                        | 1 +
 .../mtd/spi-nor/controllers/{intel-spi.c => intel-spi-base.c}   | 2 +-
 .../mtd/spi-nor/controllers/{intel-spi.h => intel-spi-base.h}   | 0
 drivers/mtd/spi-nor/controllers/intel-spi-pci.c                 | 2 +-
 drivers/mtd/spi-nor/controllers/intel-spi-platform.c            | 2 +-
 5 files changed, 4 insertions(+), 3 deletions(-)
 rename drivers/mtd/spi-nor/controllers/{intel-spi.c => intel-spi-base.c} (99%)
 rename drivers/mtd/spi-nor/controllers/{intel-spi.h => intel-spi-base.h} (100%)
drivers/mtd/spi-nor/controllers/Makefile +1 -0
index e7abba491d98..fa2dc480d2c8 100644
@@ -3,5 +3,6 @@ obj-$(CONFIG_SPI_ASPEED_SMC)	+= aspeed-smc.o
 obj-$(CONFIG_SPI_HISI_SFC)	+= hisi-sfc.o
 obj-$(CONFIG_SPI_NXP_SPIFI)	+= nxp-spifi.o
 obj-$(CONFIG_SPI_INTEL_SPI)	+= intel-spi.o
+intel-spi-y := intel-spi-base.o
 obj-$(CONFIG_SPI_INTEL_SPI_PCI)	+= intel-spi-pci.o
 obj-$(CONFIG_SPI_INTEL_SPI_PLATFORM)	+= intel-spi-platform.o
drivers/mtd/spi-nor/controllers/intel-spi-base.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +1 -1
similarity index 99%
rename from drivers/mtd/spi-nor/controllers/intel-spi.c
rename to drivers/mtd/spi-nor/controllers/intel-spi-base.c
index a413892ff449..362fb41b969e 100644
@@ -16,7 +16,7 @@
 #include <linux/mtd/partitions.h>
 #include <linux/mtd/spi-nor.h>
 
-#include "intel-spi.h"
+#include "intel-spi-base.h"
 
 /* Offsets are from @ispi->base */
 #define BFPREG				0x00
drivers/mtd/spi-nor/controllers/intel-spi-base.h renamed from drivers/mtd/spi-nor/controllers/intel-spi.h +0 -0
similarity index 100%
rename from drivers/mtd/spi-nor/controllers/intel-spi.h
rename to drivers/mtd/spi-nor/controllers/intel-spi-base.h
drivers/mtd/spi-nor/controllers/intel-spi-pci.c +1 -1
index 1bc53b8bb88a..46db2743e244 100644
@@ -11,7 +11,7 @@
 #include <linux/module.h>
 #include <linux/pci.h>
 
-#include "intel-spi.h"
+#include "intel-spi-base.h"
 
 #define BCR		0xdc
 #define BCR_WPD		BIT(0)
drivers/mtd/spi-nor/controllers/intel-spi-platform.c +1 -1
index f80f1086f928..5d6b6125c4b5 100644
@@ -10,7 +10,7 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 
-#include "intel-spi.h"
+#include "intel-spi-base.h"
 
 static int intel_spi_platform_probe(struct platform_device *pdev)
 {
Signature · 30 lines
2.31.1


-- 


This e-mail and any attachments may contain information that is 
privileged, confidential,  and/or exempt from disclosure under applicable 
law.  If you are not the intended recipient, you are hereby notified that 
any disclosure, copying, distribution or use of any information contained 
herein is strictly prohibited. If you have received this transmission in 
error, please immediately notify the sender and destroy the original 
transmission and any attachments, whether in electronic or hard copy 
format, without reading or saving.













______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#2 lore raw

Re: [PATCH 1/4] mtd: intel-spi: rename intel-spi to intel-spi-base

Quoted 4 lines · Mauro Lima

Rename the files we want to split as base files. Include the new files in intel-spi-{pci|platform}.c. Change the intel-spi obj Makefile to be built with intel-spi-base.

I don't think this brings any benefits over the existing name. Furthermore if this needs to be done, -core.c would make more sense. IMHO.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

author
#3 lore raw

PATCH 2/4 mtd: intel-spi: move chip internals into a defs.h

In reply to Mauro Lima

Move definitions about chip and internal spi structure to a defs header file.
Add types.h to .../platform_data/x86/intel-spi.h so it doesn't depends in the order of include files from intel-spi-base. Forward declare struct device to be able to compile.

---
 .../mtd/spi-nor/controllers/intel-spi-base.c  | 151 +----------------
 .../mtd/spi-nor/controllers/intel-spi-base.h  |   1 +
 .../mtd/spi-nor/controllers/intel-spi-defs.h  | 157 ++++++++++++++++++
 include/linux/platform_data/x86/intel-spi.h   |   2 +
 4 files changed, 161 insertions(+), 150 deletions(-)
 create mode 100644 drivers/mtd/spi-nor/controllers/intel-spi-defs.h
drivers/mtd/spi-nor/controllers/intel-spi-base.c +1 -150
index 362fb41b969e..04ff1c381f1d 100644
@@ -6,157 +6,8 @@
  * Author: Mika Westerberg <[email protected]>
  */
 
-#include <linux/err.h>
-#include <linux/io.h>
-#include <linux/iopoll.h>
-#include <linux/module.h>
-#include <linux/sched.h>
-#include <linux/sizes.h>
-#include <linux/mtd/mtd.h>
-#include <linux/mtd/partitions.h>
-#include <linux/mtd/spi-nor.h>
-
 #include "intel-spi-base.h"
-
-/* Offsets are from @ispi->base */
-#define BFPREG				0x00
-
-#define HSFSTS_CTL			0x04
-#define HSFSTS_CTL_FSMIE		BIT(31)
-#define HSFSTS_CTL_FDBC_SHIFT		24
-#define HSFSTS_CTL_FDBC_MASK		(0x3f << HSFSTS_CTL_FDBC_SHIFT)
-
-#define HSFSTS_CTL_FCYCLE_SHIFT		17
-#define HSFSTS_CTL_FCYCLE_MASK		(0x0f << HSFSTS_CTL_FCYCLE_SHIFT)
-/* HW sequencer opcodes */
-#define HSFSTS_CTL_FCYCLE_READ		(0x00 << HSFSTS_CTL_FCYCLE_SHIFT)
-#define HSFSTS_CTL_FCYCLE_WRITE		(0x02 << HSFSTS_CTL_FCYCLE_SHIFT)
-#define HSFSTS_CTL_FCYCLE_ERASE		(0x03 << HSFSTS_CTL_FCYCLE_SHIFT)
-#define HSFSTS_CTL_FCYCLE_ERASE_64K	(0x04 << HSFSTS_CTL_FCYCLE_SHIFT)
-#define HSFSTS_CTL_FCYCLE_RDID		(0x06 << HSFSTS_CTL_FCYCLE_SHIFT)
-#define HSFSTS_CTL_FCYCLE_WRSR		(0x07 << HSFSTS_CTL_FCYCLE_SHIFT)
-#define HSFSTS_CTL_FCYCLE_RDSR		(0x08 << HSFSTS_CTL_FCYCLE_SHIFT)
-
-#define HSFSTS_CTL_FGO			BIT(16)
-#define HSFSTS_CTL_FLOCKDN		BIT(15)
-#define HSFSTS_CTL_FDV			BIT(14)
-#define HSFSTS_CTL_SCIP			BIT(5)
-#define HSFSTS_CTL_AEL			BIT(2)
-#define HSFSTS_CTL_FCERR		BIT(1)
-#define HSFSTS_CTL_FDONE		BIT(0)
-
-#define FADDR				0x08
-#define DLOCK				0x0c
-#define FDATA(n)			(0x10 + ((n) * 4))
-
-#define FRACC				0x50
-
-#define FREG(n)				(0x54 + ((n) * 4))
-#define FREG_BASE_MASK			0x3fff
-#define FREG_LIMIT_SHIFT		16
-#define FREG_LIMIT_MASK			(0x03fff << FREG_LIMIT_SHIFT)
-
-/* Offset is from @ispi->pregs */
-#define PR(n)				((n) * 4)
-#define PR_WPE				BIT(31)
-#define PR_LIMIT_SHIFT			16
-#define PR_LIMIT_MASK			(0x3fff << PR_LIMIT_SHIFT)
-#define PR_RPE				BIT(15)
-#define PR_BASE_MASK			0x3fff
-
-/* Offsets are from @ispi->sregs */
-#define SSFSTS_CTL			0x00
-#define SSFSTS_CTL_FSMIE		BIT(23)
-#define SSFSTS_CTL_DS			BIT(22)
-#define SSFSTS_CTL_DBC_SHIFT		16
-#define SSFSTS_CTL_SPOP			BIT(11)
-#define SSFSTS_CTL_ACS			BIT(10)
-#define SSFSTS_CTL_SCGO			BIT(9)
-#define SSFSTS_CTL_COP_SHIFT		12
-#define SSFSTS_CTL_FRS			BIT(7)
-#define SSFSTS_CTL_DOFRS		BIT(6)
-#define SSFSTS_CTL_AEL			BIT(4)
-#define SSFSTS_CTL_FCERR		BIT(3)
-#define SSFSTS_CTL_FDONE		BIT(2)
-#define SSFSTS_CTL_SCIP			BIT(0)
-
-#define PREOP_OPTYPE			0x04
-#define OPMENU0				0x08
-#define OPMENU1				0x0c
-
-#define OPTYPE_READ_NO_ADDR		0
-#define OPTYPE_WRITE_NO_ADDR		1
-#define OPTYPE_READ_WITH_ADDR		2
-#define OPTYPE_WRITE_WITH_ADDR		3
-
-/* CPU specifics */
-#define BYT_PR				0x74
-#define BYT_SSFSTS_CTL			0x90
-#define BYT_BCR				0xfc
-#define BYT_BCR_WPD			BIT(0)
-#define BYT_FREG_NUM			5
-#define BYT_PR_NUM			5
-
-#define LPT_PR				0x74
-#define LPT_SSFSTS_CTL			0x90
-#define LPT_FREG_NUM			5
-#define LPT_PR_NUM			5
-
-#define BXT_PR				0x84
-#define BXT_SSFSTS_CTL			0xa0
-#define BXT_FREG_NUM			12
-#define BXT_PR_NUM			6
-
-#define CNL_PR				0x84
-#define CNL_FREG_NUM			6
-#define CNL_PR_NUM			5
-
-#define LVSCC				0xc4
-#define UVSCC				0xc8
-#define ERASE_OPCODE_SHIFT		8
-#define ERASE_OPCODE_MASK		(0xff << ERASE_OPCODE_SHIFT)
-#define ERASE_64K_OPCODE_SHIFT		16
-#define ERASE_64K_OPCODE_MASK		(0xff << ERASE_OPCODE_SHIFT)
-
-#define INTEL_SPI_TIMEOUT		5000 /* ms */
-#define INTEL_SPI_FIFO_SZ		64
-
-/**
- * struct intel_spi - Driver private data
- * @dev: Device pointer
- * @info: Pointer to board specific info
- * @nor: SPI NOR layer structure
- * @base: Beginning of MMIO space
- * @pregs: Start of protection registers
- * @sregs: Start of software sequencer registers
- * @nregions: Maximum number of regions
- * @pr_num: Maximum number of protected range registers
- * @writeable: Is the chip writeable
- * @locked: Is SPI setting locked
- * @swseq_reg: Use SW sequencer in register reads/writes
- * @swseq_erase: Use SW sequencer in erase operation
- * @erase_64k: 64k erase supported
- * @atomic_preopcode: Holds preopcode when atomic sequence is requested
- * @opcodes: Opcodes which are supported. This are programmed by BIOS
- *           before it locks down the controller.
- */
-struct intel_spi {
-	struct device *dev;
-	const struct intel_spi_boardinfo *info;
-	struct spi_nor nor;
-	void __iomem *base;
-	void __iomem *pregs;
-	void __iomem *sregs;
-	size_t nregions;
-	size_t pr_num;
-	bool writeable;
-	bool locked;
-	bool swseq_reg;
-	bool swseq_erase;
-	bool erase_64k;
-	u8 atomic_preopcode;
-	u8 opcodes[8];
-};
+#include "intel-spi-defs.h"
 
 static bool writeable;
 module_param(writeable, bool, 0);
drivers/mtd/spi-nor/controllers/intel-spi-base.h +1 -0
index f2871179fd34..ac01c0756888 100644
@@ -11,6 +11,7 @@
 
 #include <linux/platform_data/x86/intel-spi.h>
 
+struct device;
 struct intel_spi;
 struct resource;
 
drivers/mtd/spi-nor/controllers/intel-spi-defs.h new file +157 -0

157 lines not on this page · raw message

include/linux/platform_data/x86/intel-spi.h +2 -0
index 7f53a5c6f35e..4092a104f266 100644
@@ -9,6 +9,8 @@
 #ifndef INTEL_SPI_PDATA_H
 #define INTEL_SPI_PDATA_H
 
+#include <linux/types.h>
+
 enum intel_spi_type {
 	INTEL_SPI_BYT = 1,
 	INTEL_SPI_LPT,
Signature · 30 lines
2.31.1


-- 


This e-mail and any attachments may contain information that is 
privileged, confidential,  and/or exempt from disclosure under applicable 
law.  If you are not the intended recipient, you are hereby notified that 
any disclosure, copying, distribution or use of any information contained 
herein is strictly prohibited. If you have received this transmission in 
error, please immediately notify the sender and destroy the original 
transmission and any attachments, whether in electronic or hard copy 
format, without reading or saving.













______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
author
#4 lore raw

PATCH 3/4 mtd: intel-spi: moving write/erase functions

In reply to Mauro Lima

Split the write/erase behavior. In order to avoid code duplication, we are going to move all the write/erase functionality to a new file 'intel-spi-w.c' and left the base file as a common place for both write and read only ops.
Change the make of intel-spi so we don't have to export all the symbols used between 'intel-spi-w' and 'intel-spi-base'. Add MODULE_LICENSE() to be able to compile as M.
Remove the module param flag, this will be set through menuconfig.

This is the new include diagram:

                    +--------------------+
                    |/include/intel-spi.h|
                    +--------^-----------+
                             |
                             |                  intel-spi-defs.h
                             |                         ^
                             |                         |
{pci|platform} -----> intel-spi-base.h          intel-spi-rw.h
                              ^                 ^       ^
                              |       +---------+       |
                              |       |                 |
                              |       |                 |
                              |       |                 |
                        intel-spi-base.c         intel-spi-w.c
---
 drivers/mtd/spi-nor/controllers/Makefile      |   2 +-
 .../mtd/spi-nor/controllers/intel-spi-base.c  | 291 ++----------------
 .../mtd/spi-nor/controllers/intel-spi-rw.h    |  23 ++
 drivers/mtd/spi-nor/controllers/intel-spi-w.c | 289 +++++++++++++++++
 4 files changed, 345 insertions(+), 260 deletions(-)
 create mode 100644 drivers/mtd/spi-nor/controllers/intel-spi-rw.h
 create mode 100644 drivers/mtd/spi-nor/controllers/intel-spi-w.c
drivers/mtd/spi-nor/controllers/Makefile +1 -1
index fa2dc480d2c8..1933a7c2c30b 100644
@@ -3,6 +3,6 @@ obj-$(CONFIG_SPI_ASPEED_SMC)	+= aspeed-smc.o
 obj-$(CONFIG_SPI_HISI_SFC)	+= hisi-sfc.o
 obj-$(CONFIG_SPI_NXP_SPIFI)	+= nxp-spifi.o
 obj-$(CONFIG_SPI_INTEL_SPI)	+= intel-spi.o
-intel-spi-y := intel-spi-base.o
+intel-spi-y := intel-spi-base.o intel-spi-w.o
 obj-$(CONFIG_SPI_INTEL_SPI_PCI)	+= intel-spi-pci.o
 obj-$(CONFIG_SPI_INTEL_SPI_PLATFORM)	+= intel-spi-platform.o
drivers/mtd/spi-nor/controllers/intel-spi-base.c +32 -259

381 lines not on this page · raw message

drivers/mtd/spi-nor/controllers/intel-spi-rw.h new file +23 -0
new file mode 100644
index 000000000000..46c6461a8a7b
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef INTEL_SPI_RW_H
+#define INTEL_SPI_RW_H
+
+#include "intel-spi-defs.h"
+
+#include <linux/platform_data/x86/intel-spi.h>
+
+int intel_spi_sw_cycle(struct intel_spi *ispi, u8 opcode, size_t len, int optype);
+int intel_spi_wait_hw_busy(struct intel_spi *ispi);
+int intel_spi_hw_cycle(struct intel_spi *ispi, u8 opcode, size_t len);
+
+bool is_write_enabled(void);
+int  __intel_spi_erase(struct spi_nor *nor, loff_t offs);
+ssize_t  __intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, const u_char *write_buf);
+int  __intel_spi_write_reg(struct spi_nor *nor, u8 opcode, const u8 *buf,
+			   size_t len);
+int  __configure_lvscc_uvscc(struct intel_spi *ispi);
+int  __intel_sw_cycle_write(struct intel_spi *ispi, int optype, u8 atomic_preopcode);
+void  __intel_bxt_rw_config(struct intel_spi *ispi);
+void  __intel_byt_rw_config(struct intel_spi *ispi);
+
+#endif /* INTEL_SPI_RW_H */
drivers/mtd/spi-nor/controllers/intel-spi-w.c new file +289 -0

289 lines not on this page · raw message

Signature · 30 lines
2.31.1


-- 


This e-mail and any attachments may contain information that is 
privileged, confidential,  and/or exempt from disclosure under applicable 
law.  If you are not the intended recipient, you are hereby notified that 
any disclosure, copying, distribution or use of any information contained 
herein is strictly prohibited. If you have received this transmission in 
error, please immediately notify the sender and destroy the original 
transmission and any attachments, whether in electronic or hard copy 
format, without reading or saving.













______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
author
#5 lore raw

PATCH 4/4 mtd: intel-spi: add read only stubs

In reply to Mauro Lima

Add read only stub functions (as __weak) in read only mode, so they can be override on read-write mode.
Remove the (DANGEROUS) tag in read only mode.
Add write mode option if pci or platform driver is selected. Change the intel-spi recepie to be able to build read only or read-write mode.

---
 drivers/mtd/spi-nor/controllers/Kconfig       | 50 +++++++++++++------
 drivers/mtd/spi-nor/controllers/Makefile      |  4 +-
 .../mtd/spi-nor/controllers/intel-spi-ro.c    | 50 +++++++++++++++++++
 .../mtd/spi-nor/controllers/intel-spi-rw.h    |  1 +
 4 files changed, 88 insertions(+), 17 deletions(-)
 create mode 100644 drivers/mtd/spi-nor/controllers/intel-spi-ro.c
drivers/mtd/spi-nor/controllers/Kconfig +34 -16
index 5c0e0ec2e6d1..c4f2505c9302 100644
@@ -30,35 +30,53 @@ config SPI_NXP_SPIFI
 config SPI_INTEL_SPI
 	tristate
 
+config SPI_INTEL_SPI_RO
+	bool
+	default y if !SPI_INTEL_SPI_W
+	select SPI_INTEL_SPI
+
 config SPI_INTEL_SPI_PCI
-	tristate "Intel PCH/PCU SPI flash PCI driver (DANGEROUS)"
+	tristate
+
+config SPI_INTEL_SPI_PLATFORM
+	tristate
+
+config SPI_INTEL_SPI_PCI_RO
+	tristate "Intel PCH/PCU SPI flash PCI driver"
 	depends on X86 && PCI
-	select SPI_INTEL_SPI
+	select SPI_INTEL_SPI_RO
+	select SPI_INTEL_SPI_PCI
 	help
 	  This enables PCI support for the Intel PCH/PCU SPI controller in
-	  master mode. This controller is present in modern Intel hardware
-	  and is used to hold BIOS and other persistent settings. Using
-	  this driver it is possible to upgrade BIOS directly from Linux.
-
-	  Say N here unless you know what you are doing. Overwriting the
-	  SPI flash may render the system unbootable.
+	  read only mode. This controller is present in modern Intel
+	  hardware and is used to hold BIOS and other persistent settings.
 
 	  To compile this driver as a module, choose M here: the module
 	  will be called intel-spi-pci.
 
-config SPI_INTEL_SPI_PLATFORM
-	tristate "Intel PCH/PCU SPI flash platform driver (DANGEROUS)"
+config SPI_INTEL_SPI_PLATFORM_RO
+	tristate "Intel PCH/PCU SPI flash platform driver"
 	depends on X86
+	select SPI_INTEL_SPI_RO
+	select SPI_INTEL_SPI_PLATFORM
+	help
+	  This enables PCI support for the Intel PCH/PCU SPI controller in
+	  read only mode. This controller is present in modern Intel
+	  hardware and is used to hold BIOS and other persistent settings.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called intel-spi-pci.
+
+config SPI_INTEL_SPI_W
+	bool "Enable Intel PCH/PCU SPI controller in write mode (DANGEROUS)"
 	select SPI_INTEL_SPI
+	default n if SPI_INTEL_SPI_PCI || SPI_INTEL_SPI_PLATFORM
+	depends on SPI_INTEL_SPI_PCI || SPI_INTEL_SPI_PLATFORM
 	help
-	  This enables platform support for the Intel PCH/PCU SPI
-	  controller in master mode. This controller is present in modern
-	  Intel hardware and is used to hold BIOS and other persistent
-	  settings. Using this driver it is possible to upgrade BIOS
+	  This enables {PCI|PLATFORM} support for the Intel PCH/PCU controller
+	  in master mode. Enabling this mode it is possible to upgrade BIOS
 	  directly from Linux.
 
 	  Say N here unless you know what you are doing. Overwriting the
 	  SPI flash may render the system unbootable.
 
-	  To compile this driver as a module, choose M here: the module
-	  will be called intel-spi-platform.
drivers/mtd/spi-nor/controllers/Makefile +3 -1
index 1933a7c2c30b..a4faeace67fc 100644
@@ -3,6 +3,8 @@ obj-$(CONFIG_SPI_ASPEED_SMC)	+= aspeed-smc.o
 obj-$(CONFIG_SPI_HISI_SFC)	+= hisi-sfc.o
 obj-$(CONFIG_SPI_NXP_SPIFI)	+= nxp-spifi.o
 obj-$(CONFIG_SPI_INTEL_SPI)	+= intel-spi.o
-intel-spi-y := intel-spi-base.o intel-spi-w.o
+intel-spi-y := intel-spi-base.o
+intel-spi-$(CONFIG_SPI_INTEL_SPI_RO) += intel-spi-ro.o
+intel-spi-$(CONFIG_SPI_INTEL_SPI_W) += intel-spi-w.o
 obj-$(CONFIG_SPI_INTEL_SPI_PCI)	+= intel-spi-pci.o
 obj-$(CONFIG_SPI_INTEL_SPI_PLATFORM)	+= intel-spi-platform.o
drivers/mtd/spi-nor/controllers/intel-spi-ro.c new file +50 -0

50 lines not on this page · raw message

drivers/mtd/spi-nor/controllers/intel-spi-rw.h +1 -0
index 46c6461a8a7b..b682db03f17a 100644
@@ -10,6 +10,7 @@ int intel_spi_sw_cycle(struct intel_spi *ispi, u8 opcode, size_t len, int optype
 int intel_spi_wait_hw_busy(struct intel_spi *ispi);
 int intel_spi_hw_cycle(struct intel_spi *ispi, u8 opcode, size_t len);
 
+void check_mode(void);
 bool is_write_enabled(void);
 int  __intel_spi_erase(struct spi_nor *nor, loff_t offs);
 ssize_t  __intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, const u_char *write_buf);
Signature · 30 lines
2.31.1


-- 


This e-mail and any attachments may contain information that is 
privileged, confidential,  and/or exempt from disclosure under applicable 
law.  If you are not the intended recipient, you are hereby notified that 
any disclosure, copying, distribution or use of any information contained 
herein is strictly prohibited. If you have received this transmission in 
error, please immediately notify the sender and destroy the original 
transmission and any attachments, whether in electronic or hard copy 
format, without reading or saving.













______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#6 lore raw

Re: [PATCH 4/4] mtd: intel-spi: add read only stubs

Quoted 6 lines · Mauro Lima

Add read only stub functions (as __weak) in read only mode, so they can be override on read-write mode.
Remove the (DANGEROUS) tag in read only mode.
Add write mode option if pci or platform driver is selected. Change the intel-spi recepie to be able to build read only or read-write mode.

This looks pretty convoluted way to get rid of the "DANGEROUS" in the name ;-)

What is the firmware information fwupd is looking for? Perhaps there are other, better, ways to do this?

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#7 lore raw
In reply to Mauro Lima

Hi,

Quoted 6 lines · Mauro Lima

The purpose of the following patchset is to split read/write functionality from the Intel PCH/PCU SPI flash driver. Being able to use the driver in read-only mode (harmless), the users can get important firmware information from userspace which also includes being able to perform firmware attestation to verify integrity.

The SPI-NOR maintainers wanted that the driver converted first to use "SPI MEM" framework before any new features can be added. I'm currently working on that.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/