Skip to contentSkip to conversation

mtd: cfi_cmdset_0002: Support Persistent Protection Bits (PPB) locking

PATCH In review Stefan Roese 4 participants 4 messages Dec 13, 2012 – Jan 17, 2013 1 message not in the archive

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

PATCH v2 1/1 mtd: cfi_cmdset_0002: Support Persistent Protection Bits (PPB) locking

Currently cfi_cmdset_0002.c does not support PPB locking of sectors. This patch adds support for this locking/unlocking mechanism. It is needed on some platforms, since newer U-Boot versions do support this PPB locking and protect for example their environment sector(s) this way.

This PPB locking/unlocking will be enabled for all devices supported by cfi_cmdset_0002 reporting 8 in the CFI word 0x49 (Sector Protect/Unprotect scheme).

Please note that PPB locking does support sector-by-sector locking. But the whole chip can only be unlocked together. So unlocking one sector will automatically unlock all sectors of this device. Because of this chip limitation, the PPB unlocking function saves the current locking status of all sectors before unlocking the whole device. After unlocking the saved locking status is re-configured. This way only the addressed sectors will be unlocked.

To selectively enable this advanced sector protection mechanism, the device-tree property "use-advanced-sector-protection" has been created. To enable support for this locking this property needs to be present in the flash DT node. E.g.:

nor_flash@0,0 {
	compatible = "amd,s29gl256n", "cfi-flash";
	bank-width = <2>;
	use-advanced-sector-protection;
	...

Tested with Spanion S29GL512S10THI and Micron JS28F512M29EWx flash devices.

---
v2:
- Use msecs_to_jiffies
- Use UDELAY macro

 .../devicetree/bindings/mtd/mtd-physmap.txt        |   3 +
 drivers/mtd/chips/cfi_cmdset_0002.c                | 210 +++++++++++++++++++++
 drivers/mtd/maps/physmap_of.c                      |   1 +
 include/linux/mtd/map.h                            |   1 +
 4 files changed, 215 insertions(+)
Documentation/devicetree/bindings/mtd/mtd-physmap.txt +3 -0
index 94de19b..15902b8 100644
@@ -23,6 +23,9 @@ file systems on embedded devices.
    unaligned accesses as implemented in the JFFS2 code via memcpy().
    By defining "no-unaligned-direct-access", the flash will not be
    exposed directly to the MTD users (e.g. JFFS2) any more.
+ - use-advanced-sector-protection: boolean to enable support for the
+   advanced sector protection (Spansion: PPB - Persistent Protection
+   Bits) locking.
 
 For JEDEC compatible devices, the following additional properties
 are defined:
drivers/mtd/chips/cfi_cmdset_0002.c +210 -0

240 lines not on this page · raw message

drivers/mtd/maps/physmap_of.c +1 -0
index 6f19aca..d2999fc 100644
@@ -238,6 +238,7 @@ static int __devinit of_flash_probe(struct platform_device *dev)
 		info->list[i].map.phys = res.start;
 		info->list[i].map.size = res_size;
 		info->list[i].map.bankwidth = be32_to_cpup(width);
+		info->list[i].map.device_node = dp;
 
 		err = -ENOMEM;
 		info->list[i].map.virt = ioremap(info->list[i].map.phys,
include/linux/mtd/map.h +1 -0
index 3595a02..41db531 100644
@@ -245,6 +245,7 @@ struct map_info {
 	unsigned long pfow_base;
 	unsigned long map_priv_1;
 	unsigned long map_priv_2;
+	struct device_node *device_node;
 	void *fldrv_priv;
 	struct mtd_chip_driver *fldrv;
 };
Signature · 1 line
1.8.0.2
#2 lore raw
In reply to a message not in the archive
Quoted 4 lines · Stefan Roese

Currently cfi_cmdset_0002.c does not support PPB locking of sectors. This patch adds support for this locking/unlocking mechanism. It is needed on some platforms, since newer U-Boot versions do support this PPB locking and protect for example their environment sector(s) this way.

Some "#ifdef CONFIG_OF"s are missing:

drivers/mtd/chips/cfi_cmdset_0002.c: In function ‘cfi_cmdset_0002’:
drivers/mtd/chips/cfi_cmdset_0002.c:579:4: error: implicit declaration of function ‘of_property_read_bool’ [-Werror=implicit-function-declaration] drivers/mtd/chips/cfi_cmdset_0002.c: In function ‘do_read_secsi_onechip’:
drivers/mtd/chips/cfi_cmdset_0002.c:1146:16: warning: variable ‘timeo’ set but not used [-Wunused-but-set-variable]
cc1: some warnings being treated as errors
make[4]: *** [drivers/mtd/chips/cfi_cmdset_0002.o] Error 1

Please, check allso the timeo warning.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#3 lore raw
Quoted 10 lines · Artem Bityutskiy
Quoted 4 lines · Stefan Roese

Currently cfi_cmdset_0002.c does not support PPB locking of sectors. This patch adds support for this locking/unlocking mechanism. It is needed on some platforms, since newer U-Boot versions do support this PPB locking and protect for example their environment sector(s) this way.

Some "#ifdef CONFIG_OF"s are missing:

drivers/mtd/chips/cfi_cmdset_0002.c: In function ‘cfi_cmdset_0002’:
drivers/mtd/chips/cfi_cmdset_0002.c:579:4: error: implicit declaration of function ‘of_property_read_bool’ [-Werror=implicit-function-declaration]

Okay. Will add in next version.

Quoted 6 lines

drivers/mtd/chips/cfi_cmdset_0002.c: In function ‘do_read_secsi_onechip’:
drivers/mtd/chips/cfi_cmdset_0002.c:1146:16: warning: variable ‘timeo’ set but not used [-Wunused-but-set-variable]
cc1: some warnings being treated as errors
make[4]: *** [drivers/mtd/chips/cfi_cmdset_0002.o] Error 1

Please, check allso the timeo warning.

Hmmm. I didn't touch do_read_secsi_onechip() with this patch. And I'm not able to reproduce this warning. Are you sure this warning is introduced by this PPB locking patch?

Thanks,
Stefan

#4 lore raw
Quoted 6 lines · Stefan Roese
Quoted 2 lines

Please, check allso the timeo warning.

Hmmm. I didn't touch do_read_secsi_onechip() with this patch. And I'm not able to reproduce this warning. Are you sure this warning is introduced by this PPB locking patch?

Dunno, my tools sayse it is you. It may be mistaken. I compile with W=1, this is why I see more warnings, I guess?

Signature · 2 lines
Best Regards,
Artem Bityutskiy