Skip to contentSkip to conversation

Versatile flash protection in DT

PATCH New Linus Walleij 3 participants 14 messages Jan 26, 2016 – Mar 31, 2016

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover Versatile flash protection in DT

This patch set augments the physmap driver to react to the "arm,versatile-flash" compatible string by installing special VPP/writeprotect handling so that the corresponding boardfile code can be removed from the ARM boardfiles.

The patches pretty much speak for themselves, I would eventually like to have the two mtd patches merged into the MTD tree by themselves, and the rest of the patches merged into the ARM SoC tree, as there is no compile-time dependency between them and we can do a smooth transition along with other cleanup patches in the ARM SoC tree.

Linus Walleij (6):
mtd: augment the "arm,versatile-flash" bindings
mtd: physmap_of: add a hook for Versatile write protection
ARM: versatile: move flash registration to the device tree
ARM: integrator: move flash registration to device tree
ARM: realview: add flash devices to the PB1176 DTS
ARM: realview: fix up PB11MP flash compat strings

 .../devicetree/bindings/mtd/arm-versatile.txt      |  20 +-
 arch/arm/boot/dts/arm-realview-pb1176.dts          |  32 +++
 arch/arm/boot/dts/arm-realview-pb11mp.dts          |   4 +-
 arch/arm/boot/dts/integrator.dtsi                  |   3 +-
 arch/arm/boot/dts/versatile-ab.dts                 |   5 +-
 arch/arm/mach-integrator/integrator_ap.c           |  62 -----
 arch/arm/mach-integrator/integrator_cp.c           |  51 -----
 arch/arm/mach-versatile/versatile_dt.c             |  47 ----
 drivers/mtd/maps/Kconfig                           |  10 +
 drivers/mtd/maps/Makefile                          |   1 +
 drivers/mtd/maps/physmap_of.c                      |   6 +
 drivers/mtd/maps/physmap_of_versatile.c            | 253 +++++++++++++++++++++
 drivers/mtd/maps/physmap_of_versatile.h            |  16 ++
 13 files changed, 344 insertions(+), 166 deletions(-)
 create mode 100644 drivers/mtd/maps/physmap_of_versatile.c
 create mode 100644 drivers/mtd/maps/physmap_of_versatile.h
Signature · 1 line
2.4.3
#1 lore raw

PATCH 1/6 mtd: augment the "arm,versatile-flash" bindings

The bindings for the "arm,versatile-flash" device was merged in commit 3ba7222ac992d24d09ccd0b55940b54849eef752 "arm/versatile: Add device tree support" but was never used for anything.

Versatile flash chips are actually just standard CFI chips, but they have one or two bits in a system controller to control VPP and write protection. Let's use this compatible string in conjunction with "cfi-flash" to indicate that we have a normal CFI flash with some extra Versatile-specific protection.

Cc devicetree at vger.kernel.org
Cc Grant Likely <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Mark Rutland <[email protected]>
---
 .../devicetree/bindings/mtd/arm-versatile.txt        | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/mtd/arm-versatile.txt +19 -1
index beace4b89daa..4ec28796a3c0 100644
@@ -1,8 +1,26 @@
 Flash device on ARM Versatile board
 
+These flash chips are found in the ARM reference designs like Integrator,
+Versatile, RealView, Versatile Express etc.
+
+They are regular CFI compatible (Intel or AMD extended) flash chips with
+some special write protect/VPP bits that can be controlled by the machine's
+system controller.
+
 Required properties:
-- compatible : must be "arm,versatile-flash";
+- compatible : must be "arm,versatile-flash", "cfi-flash";
+- reg : memory address for the flash chip
 - bank-width : width in bytes of flash interface.
 
+For the rest of the properties, see mtd-physmap.txt.
+
 The device tree may optionally contain sub-nodes describing partitions of the
 address space. See partition.txt for more detail.
+
+Example:
+
+flash at 34000000 {
+	compatible = "arm,versatile-flash", "cfi-flash";
+	reg = <0x34000000 0x4000000>;
+	bank-width = <4>;
+};
Signature · 1 line
2.4.3
maintainer
#2 lore raw

PATCH 1/6 mtd: augment the "arm,versatile-flash" bindings

Quoted 17 lines · Linus Walleij

The bindings for the "arm,versatile-flash" device was merged in commit 3ba7222ac992d24d09ccd0b55940b54849eef752 "arm/versatile: Add device tree support" but was never used for anything.

Versatile flash chips are actually just standard CFI chips, but they have one or two bits in a system controller to control VPP and write protection. Let's use this compatible string in conjunction with "cfi-flash" to indicate that we have a normal CFI flash with some extra Versatile-specific protection.

Cc devicetree at vger.kernel.org
Cc Grant Likely <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Mark Rutland <[email protected]>
Quoted 3 lines
---
 .../devicetree/bindings/mtd/arm-versatile.txt        | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
#3 lore raw

PATCH 2/6 mtd: physmap_of: add a hook for Versatile write protection

In reply to Linus Walleij

In order to support device tree probing of Versatile NOR flash chips, there must be a way to add the VPP (write protection) enable/disable callback. The register in question is in the system controllers of these machines. Apart from this quirk, the ARM flash chips are standard CFI flash chips from various vendors.

Additionally, the Integrator/AP require you to set up the external bus interface (EBI) to allow writes to the chip select where the flash memory is connected.

Solve this by looking for the arm,versatile-flash compatible string in the flash device tree node. In the driver, add a special hook to check for the various Versatile syscons and register a callback for .set_vpp() if this compatible is present.

Provide a special Kconfig entry for the addon hook so it will not be compiled in if the Versatile boards are not supported. Stubs in the header file make sure the impact will be zero on other platforms. (Compilers optimze this out.)

With this patch, a large slew of ARM board file code can be removed.

Cc Grant Likely <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>
---
 drivers/mtd/maps/Kconfig                |  10 ++
 drivers/mtd/maps/Makefile               |   1 +
 drivers/mtd/maps/physmap_of.c           |   6 +
 drivers/mtd/maps/physmap_of_versatile.c | 253 ++++++++++++++++++++++++++++++++
 drivers/mtd/maps/physmap_of_versatile.h |  16 ++
 5 files changed, 286 insertions(+)
 create mode 100644 drivers/mtd/maps/physmap_of_versatile.c
 create mode 100644 drivers/mtd/maps/physmap_of_versatile.h
drivers/mtd/maps/Kconfig +10 -0
index 7c95a656f9e4..392f9eff5fb7 100644
@@ -74,6 +74,16 @@ config MTD_PHYSMAP_OF
 	  physically into the CPU's memory. The mapping description here is
 	  taken from OF device tree.
 
+config MTD_PHYSMAP_OF_VERSATILE
+	bool "Support ARM Versatile physmap OF"
+	depends on MTD_PHYSMAP_OF
+	depends on MFD_SYSCON
+	default y if (ARCH_INTEGRATOR || ARCH_VERSATILE || REALVIEW_DT)
+	help
+	  This provides some extra DT physmap parsing for the ARM Versatile
+	  platforms, basically to add a VPP (write protection) callback so
+	  the flash can be taken out of write protection.
+
 config MTD_PMC_MSP_EVM
 	tristate "CFI Flash device mapped on PMC-Sierra MSP"
 	depends on PMC_MSP && MTD_CFI
drivers/mtd/maps/Makefile +1 -0
index 141c91a5b24c..188873a72f1d 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_MTD_TSUNAMI)	+= tsunami_flash.o
 obj-$(CONFIG_MTD_PXA2XX)	+= pxa2xx-flash.o
 obj-$(CONFIG_MTD_PHYSMAP)	+= physmap.o
 obj-$(CONFIG_MTD_PHYSMAP_OF)	+= physmap_of.o
+obj-$(CONFIG_MTD_PHYSMAP_OF_VERSATILE) += physmap_of_versatile.o
 obj-$(CONFIG_MTD_PISMO)		+= pismo.o
 obj-$(CONFIG_MTD_PMC_MSP_EVM)   += pmcmsp-flash.o
 obj-$(CONFIG_MTD_PCMCIA)	+= pcmciamtd.o
drivers/mtd/maps/physmap_of.c +6 -0
index 70c453144f00..22f3858c0364 100644
@@ -24,6 +24,7 @@
 #include <linux/of_address.h>
 #include <linux/of_platform.h>
 #include <linux/slab.h>
+#include "physmap_of_versatile.h"
 
 struct of_flash_list {
 	struct mtd_info *mtd;
@@ -240,6 +241,11 @@ static int of_flash_probe(struct platform_device *dev)
 		info->list[i].map.size = res_size;
 		info->list[i].map.bankwidth = be32_to_cpup(width);
 		info->list[i].map.device_node = dp;
+		err = of_flash_probe_versatile(dev, dp, &info->list[i].map);
+		if (err) {
+			dev_err(&dev->dev, "Can't probe Versatile VPP\n");
+			return err;
+		}
 
 		err = -ENOMEM;
 		info->list[i].map.virt = ioremap(info->list[i].map.phys,
drivers/mtd/maps/physmap_of_versatile.c new file +253 -0

253 lines not on this page · raw message

drivers/mtd/maps/physmap_of_versatile.h new file +16 -0
new file mode 100644
index 000000000000..5b86f6dc6b3d
@@ -0,0 +1,16 @@
+#include <linux/of.h>
+#include <linux/mtd/map.h>
+
+#ifdef CONFIG_MTD_PHYSMAP_OF_VERSATILE
+int of_flash_probe_versatile(struct platform_device *pdev,
+			     struct device_node *np,
+			     struct map_info *map);
+#else
+static inline
+int of_flash_probe_versatile(struct platform_device *pdev,
+			     struct device_node *np,
+			     struct map_info *map)
+{
+	return 0;
+}
+#endif
Signature · 1 line
2.4.3
#4 lore raw

PATCH 2/6 mtd: physmap_of: add a hook for Versatile write protection

Quoted 4 lines · Linus Walleij

Solve this by looking for the arm,versatile-flash compatible string in the flash device tree node. In the driver, add a special hook to check for the various Versatile syscons and register a callback for .set_vpp() if this compatible is present.

You are aware that the "write enable" applies to all flash devices on the board, and not just NOR flash. What that means is if you have drivers for the other flash devices, you need to have a way to enable writes when _any_ driver wants write access.

So, it shouldn't be part of the flash driver at all.

Signature · 3 lines
RMK's Patch system: http://www.arm.linux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#5 lore raw

PATCH 2/6 mtd: physmap_of: add a hook for Versatile write protection

Quoted 6 lines · Russell King - ARM Linux
Quoted 4 lines · Linus Walleij

Solve this by looking for the arm,versatile-flash compatible string in the flash device tree node. In the driver, add a special hook to check for the various Versatile syscons and register a callback for .set_vpp() if this compatible is present.

Quoted 6 lines

You are aware that the "write enable" applies to all flash devices on the board, and not just NOR flash. What that means is if you have drivers for the other flash devices, you need to have a way to enable writes when _any_ driver wants write access.

So, it shouldn't be part of the flash driver at all.

Yes this is correct ... I put in the current code to be able to test writes on the hardware. As to actually write to flash on the Integrator both flags must be set to 1.

I don't see why it would just be a problem just for write enable though, as I guess the VPP bit is *also* shared by all devices?

After
commit 876fe76d793d03077
"mtd: maps: physmap: Add reference counter to set_vpp()"

As long as the flash devices are all physmap this reference counter should hold VPP+WP enabled with this code as long as any flash device has called .set_vpp().

It is a bit unintuitive that .set_vpp() is named like that though. .enable_write() or something would be better I guess. (The reference count also makes it start to reimplement the regulator infrastructure.)

Yours,
Linus Walleij

#6 lore raw

PATCH 2/6 mtd: physmap_of: add a hook for Versatile write protection

In reply to Linus Walleij

Hey MTD folks,

Quoted 21 lines · Linus Walleij

In order to support device tree probing of Versatile NOR flash chips, there must be a way to add the VPP (write protection) enable/disable callback. The register in question is in the system controllers of these machines. Apart from this quirk, the ARM flash chips are standard CFI flash chips from various vendors.

Additionally, the Integrator/AP require you to set up the external bus interface (EBI) to allow writes to the chip select where the flash memory is connected.

Solve this by looking for the arm,versatile-flash compatible string in the flash device tree node. In the driver, add a special hook to check for the various Versatile syscons and register a callback for .set_vpp() if this compatible is present.

Provide a special Kconfig entry for the addon hook so it will not be compiled in if the Versatile boards are not supported. Stubs in the header file make sure the impact will be zero on other platforms. (Compilers optimze this out.)

Quoted 7 lines

With this patch, a large slew of ARM board file code can be removed.

Cc Grant Likely <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>

Do you think my reply to this about reference counting and subsequent (accepted) patch to update the documentation to reflect 876fe76d793d03077
"mtd: maps: physmap: Add reference counter to set_vpp()" is enough to warrant merging of this?

If you want the code developed in any special direction just tell me.

Yours,
Linus Walleij

#7 lore raw

PATCH 2/6 mtd: physmap_of: add a hook for Versatile write protection

Quoted 32 lines · Linus Walleij
Quoted 21 lines · Linus Walleij

In order to support device tree probing of Versatile NOR flash chips, there must be a way to add the VPP (write protection) enable/disable callback. The register in question is in the system controllers of these machines. Apart from this quirk, the ARM flash chips are standard CFI flash chips from various vendors.

Additionally, the Integrator/AP require you to set up the external bus interface (EBI) to allow writes to the chip select where the flash memory is connected.

Solve this by looking for the arm,versatile-flash compatible string in the flash device tree node. In the driver, add a special hook to check for the various Versatile syscons and register a callback for .set_vpp() if this compatible is present.

Provide a special Kconfig entry for the addon hook so it will not be compiled in if the Versatile boards are not supported. Stubs in the header file make sure the impact will be zero on other platforms. (Compilers optimze this out.)

Quoted 7 lines

With this patch, a large slew of ARM board file code can be removed.

Cc Grant Likely <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>
Quoted 8 lines

Do you think my reply to this about reference counting and subsequent (accepted) patch to update the documentation to reflect 876fe76d793d03077
"mtd: maps: physmap: Add reference counter to set_vpp()" is enough to warrant merging of this?

If you want the code developed in any special direction just tell me.

Ping.

Yours,
Linus Walleij

#8 lore raw

PATCH 2/6 mtd: physmap_of: add a hook for Versatile write protection

Quoted 39 lines · Linus Walleij
Quoted 38 lines · Linus Walleij
Quoted 21 lines · Linus Walleij

In order to support device tree probing of Versatile NOR flash chips, there must be a way to add the VPP (write protection) enable/disable callback. The register in question is in the system controllers of these machines. Apart from this quirk, the ARM flash chips are standard CFI flash chips from various vendors.

Additionally, the Integrator/AP require you to set up the external bus interface (EBI) to allow writes to the chip select where the flash memory is connected.

Solve this by looking for the arm,versatile-flash compatible string in the flash device tree node. In the driver, add a special hook to check for the various Versatile syscons and register a callback for .set_vpp() if this compatible is present.

Provide a special Kconfig entry for the addon hook so it will not be compiled in if the Versatile boards are not supported. Stubs in the header file make sure the impact will be zero on other platforms. (Compilers optimze this out.)

Quoted 7 lines

With this patch, a large slew of ARM board file code can be removed.

Cc Grant Likely <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>

Do you think my reply to this about reference counting and subsequent (accepted) patch to update the documentation to reflect 876fe76d793d03077
"mtd: maps: physmap: Add reference counter to set_vpp()" is enough to warrant merging of this?

Quoted 4 lines
Quoted 2 lines

If you want the code developed in any special direction just tell me.

Ping.

Ping.

Yours,
Linus Walleij

#9 lore raw

PATCH 2/6 mtd: physmap_of: add a hook for Versatile write protection

Quoted 40 lines · Linus Walleij
Quoted 39 lines · Linus Walleij
Quoted 38 lines · Linus Walleij
Quoted 21 lines · Linus Walleij

In order to support device tree probing of Versatile NOR flash chips, there must be a way to add the VPP (write protection) enable/disable callback. The register in question is in the system controllers of these machines. Apart from this quirk, the ARM flash chips are standard CFI flash chips from various vendors.

Additionally, the Integrator/AP require you to set up the external bus interface (EBI) to allow writes to the chip select where the flash memory is connected.

Solve this by looking for the arm,versatile-flash compatible string in the flash device tree node. In the driver, add a special hook to check for the various Versatile syscons and register a callback for .set_vpp() if this compatible is present.

Provide a special Kconfig entry for the addon hook so it will not be compiled in if the Versatile boards are not supported. Stubs in the header file make sure the impact will be zero on other platforms. (Compilers optimze this out.)

Quoted 7 lines

With this patch, a large slew of ARM board file code can be removed.

Cc Grant Likely <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>

Do you think my reply to this about reference counting and subsequent (accepted) patch to update the documentation to reflect 876fe76d793d03077
"mtd: maps: physmap: Add reference counter to set_vpp()" is enough to warrant merging of this?

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

If you want the code developed in any special direction just tell me.

Ping.

Ping.

Ping.

Yours,
Linus Walleij

#10 lore raw

PATCH 3/6 ARM: versatile: move flash registration to the device tree

In reply to Linus Walleij

This moves the boardfile definition of the flash memory in the Versatile board into the device tree. The flash was already defined with the property "arm,versatile-flash" which was not handled by the kernel: instead define it as compatible also with "cfi-flash" so it detects properly, and delete the corresponding boardfile code so we get a smooth transition.

The old compatible string "arm,versatile-flash" is reused to indicate to the MTD physmap subsystem that this flash requires special VPP handling. (See separate patch.)

Cc Grant Likely <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>
---
 arch/arm/boot/dts/versatile-ab.dts     |  5 ++--
 arch/arm/mach-versatile/versatile_dt.c | 47 ----------------------------------
 2 files changed, 3 insertions(+), 49 deletions(-)
arch/arm/boot/dts/versatile-ab.dts +3 -2
index 6fd7efbead34..28253ee84404 100644
@@ -119,8 +119,9 @@
 	};
 
 	flash at 34000000 {
-		compatible = "arm,versatile-flash";
-		reg = <0x34000000 0x4000000>;
+		/* 64 MiB NOR flash in non-interleaved chips */
+		compatible = "arm,versatile-flash", "cfi-flash";
+		reg = <0x34000000 0x04000000>;
 		bank-width = <4>;
 	};
 
arch/arm/mach-versatile/versatile_dt.c +0 -47

80 lines not on this page · raw message

Signature · 1 line
2.4.3
#11 lore raw

PATCH 4/6 ARM: integrator: move flash registration to device tree

In reply to Linus Walleij

The flash on the Integrator was already defined by the device tree, but VPP control and flash protection was in the boardfiles. Simply add the compatible string "arm,versatile-flash" and the special add-on code for flash programming voltage and protection kicks in in the MTD layer.

Remove the board file code and augment the device tree in one go for seamless transition.

Cc Grant Likely <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>
---
 arch/arm/boot/dts/integrator.dtsi        |  3 +-
 arch/arm/mach-integrator/integrator_ap.c | 62 --------------------------------
 arch/arm/mach-integrator/integrator_cp.c | 51 --------------------------
 3 files changed, 2 insertions(+), 114 deletions(-)
arch/arm/boot/dts/integrator.dtsi +2 -1
index 3807d4f46ef7..adc4befea46d 100644
@@ -52,8 +52,9 @@
 	};
 
 	flash at 24000000 {
-		compatible = "cfi-flash";
+		compatible = "arm,versatile-flash", "cfi-flash";
 		reg = <0x24000000 0x02000000>;
+		bank-width = <4>;
 	};
 
 	fpga {
arch/arm/mach-integrator/integrator_ap.c +0 -62

80 lines not on this page · raw message

arch/arm/mach-integrator/integrator_cp.c +0 -51

77 lines not on this page · raw message

Signature · 1 line
2.4.3
#12 lore raw

PATCH 5/6 ARM: realview: add flash devices to the PB1176 DTS

In reply to Linus Walleij

This adds the flash memories and ROM to the PB1175 DTS file. The secure flash is marked as "disabled" by default so as to protect the user from overwriting the boot monitor.

---
 arch/arm/boot/dts/arm-realview-pb1176.dts | 32 +++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
arch/arm/boot/dts/arm-realview-pb1176.dts +32 -0
index 1bc64cda819e..b7d727ef1868 100644
@@ -106,6 +106,31 @@
 		clock-frequency = <0>;
 	};
 
+	flash at 30000000 {
+		compatible = "arm,versatile-flash", "cfi-flash";
+		reg = <0x30000000 0x4000000>;
+		bank-width = <4>;
+	};
+
+	fpga_flash at 38000000 {
+		compatible = "arm,versatile-flash", "cfi-flash";
+		reg = <0x38000000 0x800000>;
+		bank-width = <4>;
+	};
+
+	/*
+	 * The "secure flash" contains things like the boot
+	 * monitor so we don't want people to accidentally
+	 * screw this up. Mark the device tree node disabled
+	 * by default.
+	 */
+	secflash at 3c000000 {
+		compatible = "arm,versatile-flash", "cfi-flash";
+		reg = <0x3c000000 0x4000000>;
+		bank-width = <4>;
+		status = "disabled";
+	};
+
 	soc {
 		#address-cells = <1>;
 		#size-cells = <1>;
@@ -297,6 +322,13 @@
 			clocks = <&uartclk>, <&pclk>;
 			clock-names = "uartclk", "apb_pclk";
 		};
+
+		/* Direct-mapped development chip ROM */
+		pb1176_rom at 10200000 {
+			compatible = "direct-mapped";
+			reg = <0x10200000 0x4000>;
+			bank-width = <1>;
+		};
 	};
 
 	/* These peripherals are inside the FPGA rather than the DevChip */
Signature · 1 line
2.4.3
#13 lore raw

PATCH 6/6 ARM: realview: fix up PB11MP flash compat strings

In reply to Linus Walleij

The two flash memories in the PB11MPCore have their VPP/WP lines controlled from the system controller add-on in the MTD subsystem. "arm,versatile-flash" is the first compatible string to use to get the right support.

---
 arch/arm/boot/dts/arm-realview-pb11mp.dts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/boot/dts/arm-realview-pb11mp.dts +2 -2
index da755c9851a7..63d6a051839f 100644
@@ -230,14 +230,14 @@
 
 	flash0 at 40000000 {
 		/* 2 * 32MiB NOR Flash memory */
-		compatible = "arm,vexpress-flash", "cfi-flash";
+		compatible = "arm,versatile-flash", "cfi-flash";
 		reg = <0x40000000 0x04000000>;
 		bank-width = <4>;
 	};
 
 	flash1 at 44000000 {
 		// 2 * 32MiB NOR Flash memory
-		compatible = "arm,vexpress-flash", "cfi-flash";
+		compatible = "arm,versatile-flash", "cfi-flash";
 		reg = <0x44000000 0x04000000>;
 		bank-width = <4>;
 	};
Signature · 1 line
2.4.3