mtd: spi-nor: Avoid setting SRWD bit in SR
Subsystems (3)
v3 cover mtd: spi-nor: Avoid setting SRWD bit in SR
Setting the status register write disable (SRWD) bit in the status register (SR) with WP# signal of the flash not connected or wrongly tied to GND (that includes internal pull-downs), will configure the SR permanently as read-only. To avoid this a boolean type DT property "no-wp" is introduced. If this property is defined, the spi-nor doesn't set the SRWD bit in SR while performing flash protection operation.
---
BRANCH: for-next
Changes in v3:
- Updated DT property name to "no-wp".
- Removed Reviewed-by tag from 1/2 as the DT property name has changed.
- Updated spi-nor flag name to SNOR_F_NO_WP.
- Updated DT property description.
- Updated patch description.
- Updated comments in swp.c file.
- Replaced WP with WP# in patch descriptions, comments & DT property description.
Changes in v2:
- Modified DT property description to add information about a valid use case.
- Added Reviewed-by tag in 1/2.
- Updated comment description in 2/2.
---
Amit Kumar Mahapatra (2):
dt-bindings: mtd: jedec, spi-nor: Add DT property to avoid setting
SRWD bit in status register
mtd: spi-nor: Avoid setting SRWD bit in SR if WP# signal not connected
.../devicetree/bindings/mtd/jedec,spi-nor.yaml | 15 +++++++++++++++ drivers/mtd/spi-nor/core.c | 3 +++ drivers/mtd/spi-nor/core.h | 1 + drivers/mtd/spi-nor/swp.c | 9 +++++++-- 4 files changed, 26 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 1/2 dt-bindings: mtd: jedec, spi-nor: Add DT property to avoid setting SRWD bit in status register
If the WP# signal of the flash device is either not connected or is wrongly tied to GND (that includes internal pull-downs), and the software sets the status register write disable (SRWD) bit in the status register then the status register permanently becomes read-only. To avoid this added a new boolean DT property "no-wp". If this property is set in the DT then the software avoids setting the SRWD during status register write operation.
---
As the DT property name has changed so, removed Reviewed-by tag. @Cornor if possible, could you please review this updated patch.
--- .../devicetree/bindings/mtd/jedec,spi-nor.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml +15 -0
@@ -70,6 +70,21 @@ properties: be used on such systems, to denote the absence of a reliable reset mechanism. + no-wp: + type: boolean + description: + The status register write disable (SRWD) bit in status register, combined + with the WP# signal, provides hardware data protection for the device. When + the SRWD bit is set to 1, and the WP# signal is either driven LOW or hard + strapped to LOW, the status register nonvolatile bits become read-only and + the WRITE STATUS REGISTER operation will not execute. The only way to exit + this hardware-protected mode is to drive WP# HIGH. If the WP# signal of the + flash device is not connected or is wrongly tied to GND (that includes internal + pull-downs) then status register permanently becomes read-only as the SRWD bit + cannot be reset. This boolean flag can be used on such systems to avoid setting + the SRWD bit while writing the status register. WP# signal hard strapped to GND + can be a valid use case. + reset-gpios: description: A GPIO line connected to the RESET (active low) signal of the device.
Signature · 1 line
2.17.1
Re: [PATCH v3 1/2] dt-bindings: mtd: jedec, spi-nor: Add DT property to avoid setting SRWD bit in status register
Quoted 11 lines · Amit Kumar Mahapatra
If the WP# signal of the flash device is either not connected or is wrongly tied to GND (that includes internal pull-downs), and the software sets the status register write disable (SRWD) bit in the status register then the status register permanently becomes read-only. To avoid this added a new boolean DT property "no-wp". If this property is set in the DT then the software avoids setting the SRWD during status register write operation.
Signed-off-by Amit Kumar Mahapatra <[email protected]>---
As the DT property name has changed so, removed Reviewed-by tag. @Cornor if possible, could you please review this updated patch.
Rob was the one who objected to the property name.
Old & new names are fine by me, it was the text I think I cared about.
Thanks for actually explaining why you dropped the tag, Conor.
Quoted 33 lines
--- .../devicetree/bindings/mtd/jedec,spi-nor.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+)Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml +15
-0@@ -70,6 +70,21 @@ properties: be used on such systems, to denote the absence of a reliable reset mechanism. + no-wp: + type: boolean + description: + The status register write disable (SRWD) bit in status register, combined + with the WP# signal, provides hardware data protection for the device. When + the SRWD bit is set to 1, and the WP# signal is either driven LOW or hard + strapped to LOW, the status register nonvolatile bits become read-only and + the WRITE STATUS REGISTER operation will not execute. The only way to exit + this hardware-protected mode is to drive WP# HIGH. If the WP# signal of the + flash device is not connected or is wrongly tied to GND (that includes internal + pull-downs) then status register permanently becomes read-only as the SRWD bit + cannot be reset. This boolean flag can be used on such systems to avoid setting + the SRWD bit while writing the status register. WP# signal hard strapped to GND + can be a valid use case. + reset-gpios: description: A GPIO line connected to the RESET (active low) signal of the device.Signature · 1 line
2.17.1
Re: [PATCH v3 1/2] dt-bindings: mtd: jedec, spi-nor: Add DT property to avoid setting SRWD bit in status register
In reply to Amit Kumar MahapatraQuoted 7 lines · Amit Kumar Mahapatra
If the WP# signal of the flash device is either not connected or is wrongly tied to GND (that includes internal pull-downs), and the software sets the status register write disable (SRWD) bit in the status register then the status register permanently becomes read-only. To avoid this added a new boolean DT property "no-wp". If this property is set in the DT then the software avoids setting the SRWD during status register write operation.
Quoted 8 lines
Signed-off-by Amit Kumar Mahapatra <[email protected]>---
As the DT property name has changed so, removed Reviewed-by tag. @Cornor if possible, could you please review this updated patch.--- .../devicetree/bindings/mtd/jedec,spi-nor.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v3 1/2] dt-bindings: mtd: jedec, spi-nor: Add DT property to avoid setting SRWD bit in status register
In reply to Amit Kumar MahapatraAm 2023-06-25 12:02, schrieb Amit Kumar Mahapatra:
Quoted 47 lines
If the WP# signal of the flash device is either not connected or is wrongly tied to GND (that includes internal pull-downs), and the software sets the status register write disable (SRWD) bit in the status register then the status register permanently becomes read-only. To avoid this added a new boolean DT property "no-wp". If this property is set in the DT then the software avoids setting the SRWD during status register write operation.
Signed-off-by Amit Kumar Mahapatra <[email protected]>---
As the DT property name has changed so, removed Reviewed-by tag. @Cornor if possible, could you please review this updated patch.--- .../devicetree/bindings/mtd/jedec,spi-nor.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+)Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml +0
-0@@ -70,6 +70,21 @@ properties: be used on such systems, to denote the absence of a reliablereset
mechanism.Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml +4
-0+ no-wp: + type: boolean + description: + The status register write disable (SRWD) bit in status register,combined
+ with the WP# signal, provides hardware data protection for the
device. When
+ the SRWD bit is set to 1, and the WP# signal is either driven
LOW or hard
+ strapped to LOW, the status register nonvolatile bits become
read-only and
+ the WRITE STATUS REGISTER operation will not execute. The only
way to exit
+ this hardware-protected mode is to drive WP# HIGH. If the WP#
signal of the
+ flash device is not connected or is wrongly tied to GND (that
includes internal
+ pull-downs) then status register permanently becomes read-only
as the SRWD bit
+ cannot be reset. This boolean flag can be used on such systems
to avoid setting
+ the SRWD bit while writing the status register. WP# signal hard
strapped to GND
Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml properties: · line 87
Quoted 2 lines
Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml +2
-0+ can be a valid use case. +
Sounds good! Thank you.
-michael
PATCH v3 2/2 mtd: spi-nor: Avoid setting SRWD bit in SR if WP# signal not connected
In reply to Amit Kumar MahapatraSetting the status register write disable (SRWD) bit in the status register (SR) with WP# signal of the flash left floating or wrongly tied to GND (that includes internal pull-downs), will configure the SR permanently as read-only. If WP# signal is left floating or wrongly tied to GND, avoid setting SRWD bit while writing the SR during flash protection.
--- drivers/mtd/spi-nor/core.c | 3 +++ drivers/mtd/spi-nor/core.h | 1 + drivers/mtd/spi-nor/swp.c | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-)
drivers/mtd/spi-nor/core.c +3 -0
@@ -2864,6 +2864,9 @@ static void spi_nor_init_flags(struct spi_nor *nor)if (flags &NO_CHIP_ERASE ) nor->flags |=SNOR_F_NO_OP_CHIP_ERASE ; +if (of_property_read_bool (np,"no-wp" )) + nor->flags |=SNOR_F_NO_WP ; +if (flags &SPI_NOR_RWW && nor->info->n_banks >1 && !nor->controller_ops) nor->flags |=SNOR_F_RWW ;
drivers/mtd/spi-nor/core.h +1 -0
@@ -132,6 +132,7 @@ enum spi_nor_option_flags {SNOR_F_SWP_IS_VOLATILE =BIT (13 ),SNOR_F_RWW =BIT (14 ),SNOR_F_ECC =BIT (15 ), + SNOR_F_NO_WP = BIT(16), }; struct spi_nor_read_command {
drivers/mtd/spi-nor/swp.c +7 -2
@@ -214,8 +214,13 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) status_new = (status_old & ~mask & ~tb_mask) | val; -/* Disallow further writes if WP pin is asserted */ - status_new |=SR_SRWD ; +/* +* Disallow further writes if WP# pin is neither left floating nor +* wrongly tied to GND(that includes internal pull-downs). +* WP# pin hard strapped to GND can be a valid use case. +*/ +if (!(nor->flags &SNOR_F_NO_WP )) + status_new |=SR_SRWD ;if (!use_top) status_new |= tb_mask;
Signature · 1 line
2.17.1
Re: [PATCH v3 2/2] mtd: spi-nor: Avoid setting SRWD bit in SR if WP# signal not connected
Am 2023-06-25 12:02, schrieb Amit Kumar Mahapatra:
Quoted 18 lines
Setting the status register write disable (SRWD) bit in the status register (SR) with WP# signal of the flash left floating or wrongly tied to GND (that includes internal pull-downs), will configure the SR permanently as read-only. If WP# signal is left floating or wrongly tied to GND, avoid setting SRWD bit while writing the SR during flash protection.
Signed-off-by Amit Kumar Mahapatra <[email protected]>--- drivers/mtd/spi-nor/core.c | 3 +++ drivers/mtd/spi-nor/core.h | 1 + drivers/mtd/spi-nor/swp.c | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-)drivers/mtd/spi-nor/core.c +0
-0
drivers/mtd/spi-nor/core.c static void spi_nor_init_flags(struct spi_nor · line 2870
Quoted 7 lines
drivers/mtd/spi-nor/core.c +3
-0@@ -2864,6 +2864,9 @@ static void spi_nor_init_flags(struct spi_nor *nor)if (flags &NO_CHIP_ERASE ) nor->flags |=SNOR_F_NO_OP_CHIP_ERASE ; +if (of_property_read_bool (np,"no-wp" )) + nor->flags |=SNOR_F_NO_WP ; +
Please put it below the of_property_read_bool() which is already there, just to keep things sorted.
drivers/mtd/spi-nor/core.h enum spi_nor_option_flags { · line 135
Quoted 12 lines
drivers/mtd/spi-nor/core.c +0
-0if (flags &SPI_NOR_RWW && nor->info->n_banks >1 && !nor->controller_ops)drivers/mtd/spi-nor/core.c +0
-0nor->flags |=SNOR_F_RWW ;drivers/mtd/spi-nor/core.h +1
-0@@ -132,6 +132,7 @@ enum spi_nor_option_flags {SNOR_F_SWP_IS_VOLATILE =BIT (13 ),SNOR_F_RWW =BIT (14 ),SNOR_F_ECC =BIT (15 ), + SNOR_F_NO_WP = BIT(16),
See the comment right above this enum :/
Quoted 8 lines
drivers/mtd/spi-nor/core.h +0
-0};struct spi_nor_read_command {drivers/mtd/spi-nor/swp.c +0
-0
drivers/mtd/spi-nor/swp.c static int spi_nor_sr_lock(struct spi_nor *nor, · line 220
Quoted 9 lines
drivers/mtd/spi-nor/swp.c +3
-2@@ -214,8 +214,13 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) status_new = (status_old & ~mask & ~tb_mask) | val; -/* Disallow further writes if WP pin is asserted */ - status_new |=SR_SRWD ; +/* +* Disallow further writes if WP# pin is neither left floating nor +* wrongly tied to GND(that includes internal pull-downs).
nit: space missing
Otherwise looks good.
Thanks,
-michael
Quoted 7 lines
drivers/mtd/spi-nor/swp.c +4
-0+* WP# pin hard strapped to GND can be a valid use case. +*/ +if (!(nor->flags &SNOR_F_NO_WP )) + status_new |=SR_SRWD ;if (!use_top)
status_new|=tb_mask;
Re: [PATCH v3 2/2] mtd: spi-nor: Avoid setting SRWD bit in SR if WP# signal not connected
Quoted 63 lines · Michael Walle
Am 2023-06-25 12:02, schrieb Amit Kumar Mahapatra:
Quoted 18 lines
Setting the status register write disable (SRWD) bit in the status register (SR) with WP# signal of the flash left floating or wrongly tied to GND (that includes internal pull-downs), will configure the SR permanently as read-only. If WP# signal is left floating or wrongly tied to GND, avoid setting SRWD bit while writing the SR during flash protection.
Signed-off-by Amit Kumar Mahapatra <[email protected]>---
drivers/mtd/spi-nor/core.c | 3 +++
drivers/mtd/spi-nor/core.h | 1 +
drivers/mtd/spi-nor/swp.c | 9 +++++++--3 files changed, 11 insertions(+), 2 deletions(-)drivers/mtd/spi-nor/core.c +0
-0drivers/mtd/spi-nor/core.c static void spi_nor_init_flags(struct spi_nor *nor) · line 2869
Quoted 6 lines
drivers/mtd/spi-nor/core.c +3
-0@@ -2864,6 +2864,9 @@ static void spi_nor_init_flags(struct spi_nor *nor) if (flags & NO_CHIP_ERASE) nor->flags |= SNOR_F_NO_OP_CHIP_ERASE; + if (of_property_read_bool(np, "no-wp")) + nor->flags |= SNOR_F_NO_WP; +Please put it below the
of_property_read_bool()which is already there, just to keep things sorted.drivers/mtd/spi-nor/core.h enum spi_nor_option_flags { · line 135
Quoted 12 lines
if (flags &
SPI_NOR_RWW&&nor->info->n_banks> 1 && !nor->controller_ops)
nor->flags|=SNOR_F_RWW;drivers/mtd/spi-nor/core.h +1
-0@@ -132,6 +132,7 @@ enum spi_nor_option_flags { SNOR_F_SWP_IS_VOLATILE = BIT(13), SNOR_F_RWW = BIT(14), SNOR_F_ECC = BIT(15), + SNOR_F_NO_WP = BIT(16),See the comment right above this enum :/
Quoted 8 lines
drivers/mtd/spi-nor/core.h +0
-0}; struct spi_nor_read_command {drivers/mtd/spi-nor/swp.c +0
-0drivers/mtd/spi-nor/swp.c static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) · line 219
Quoted 8 lines
drivers/mtd/spi-nor/swp.c +3
-2@@ -214,8 +214,13 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) status_new = (status_old & ~mask & ~tb_mask) | val; - /* Disallow further writes if WP pin is asserted */ - status_new |= SR_SRWD; + /* +* Disallow further writes if WP# pin is neither left floating nor +* wrongly tied to GND(that includes internal pull-downs). nit: space missing
Quoted 2 lines
Otherwise looks good.
Thanks, Michael.
Amit, would be good if you can address Michael's comments and resubmit. If not, I'll amend the patch by myself when applying.
Cheers,
ta
RE: [PATCH v3 2/2] mtd: spi-nor: Avoid setting SRWD bit in SR if WP# signal not connected
Hello Tudor,
Quoted 84 lines
-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Friday, June 30, 2023 2:18 PM
To: Michael Walle <[email protected]>; Mahapatra, Amit Kumar <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; git (AMD-Xilinx) <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v3 2/2] mtd: spi-nor: Avoid setting SRWD bit in SR if WP# signal not connectedQuoted 6 lines · Michael Walle
Am 2023-06-25 12:02, schrieb Amit Kumar Mahapatra:
Quoted 5 lines
Setting the status register write disable (SRWD) bit in the status register (SR) with WP# signal of the flash left floating or wrongly tied to GND (that includes internal pull-downs), will configure the SR permanently as read-only. If WP# signal is left floating or wrongly tied to GND, avoid setting SRWD bit while writing the SR during
flash protection.
Quoted 2 lines
Quoted 2 lines
Signed-off-by Amit Kumar Mahapatra <amit.kumar-Quoted 58 lines
Quoted 11 lines
---
drivers/mtd/spi-nor/core.c | 3 +++
drivers/mtd/spi-nor/core.h | 1 +
drivers/mtd/spi-nor/swp.c | 9 +++++++--3 files changed, 11 insertions(+), 2 deletions(-)drivers/mtd/spi-nor/core.c +0
-0drivers/mtd/spi-nor/core.c static void spi_nor_init_flags(struct spi_nor · line 2870
Quoted 7 lines
drivers/mtd/spi-nor/core.c +3
-0@@ -2864,6 +2864,9 @@ static void spi_nor_init_flags(struct spi_nor *nor) if (flags & NO_CHIP_ERASE) nor->flags |= SNOR_F_NO_OP_CHIP_ERASE; + if (of_property_read_bool(np, "no-wp")) + nor->flags |= SNOR_F_NO_WP; +Please put it below the
of_property_read_bool()which is already there, just to keep things sorted.drivers/mtd/spi-nor/core.h enum spi_nor_option_flags { · line 135
Quoted 12 lines
if (flags &
SPI_NOR_RWW&&nor->info->n_banks> 1 && !nor->controller_ops)
nor->flags|=SNOR_F_RWW;drivers/mtd/spi-nor/core.h +1
-0@@ -132,6 +132,7 @@ enum spi_nor_option_flags { SNOR_F_SWP_IS_VOLATILE = BIT(13), SNOR_F_RWW = BIT(14), SNOR_F_ECC = BIT(15), + SNOR_F_NO_WP = BIT(16),See the comment right above this enum :/
Quoted 8 lines
drivers/mtd/spi-nor/core.h +0
-0}; struct spi_nor_read_command {drivers/mtd/spi-nor/swp.c +0
-0drivers/mtd/spi-nor/swp.c static int spi_nor_sr_lock(struct spi_nor *nor, · line 221
Quoted 10 lines
drivers/mtd/spi-nor/swp.c +4
-2@@ -214,8 +214,13 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) status_new = (status_old & ~mask & ~tb_mask) | val; - /* Disallow further writes if WP pin is asserted */ - status_new |= SR_SRWD; + /* +* Disallow further writes if WP# pin is neither left floating +nor +* wrongly tied to GND(that includes internal pull-downs). nit: space missing
Quoted 7 lines
Quoted 2 lines
Otherwise looks good.
Thanks, Michael.
Amit, would be good if you can address Michael's comments and resubmit. If not, I'll amend the patch by myself when applying.
I will address Michael's comments and send the next series.
Regards,
Amit
Quoted 3 lines
Cheers,
ta
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/