mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mtd: nand: fix nand_lock/unlock() function
@ 2018-11-14 11:04 Marc Kleine-Budde
  2018-11-15  8:02 ` Sascha Hauer
  2018-11-16  7:33 ` Sascha Hauer
  0 siblings, 2 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2018-11-14 11:04 UTC (permalink / raw)
  To: barebox; +Cc: sha

From: White Ding <bpqw@micron.com>

Do nand reset before write protect check.

If we want to check the WP# low or high through STATUS READ and check bit 7,
we must reset the device, other operation (eg.erase/program a locked block) can
also clear the bit 7 of status register.

As we know the status register can be refreshed, if we do some operation to trigger it,
for example if we do erase/program operation to one block that is locked, then READ STATUS,
the bit 7 of READ STATUS will be 0 indicate the device in write protect, then if we do
erase/program operation to another block that is unlocked, the bit 7 of READ STATUS will
be 1 indicate the device is not write protect.
Suppose we checked the bit 7 of READ STATUS is 0 then judge the WP# is low (write protect),
but in this case the WP# maybe high if we do erase/program operation to a locked block,
so we must reset the device if we want to check the WP# low or high through STATUS READ and
check bit 7.

Signed-off-by: White Ding <bpqw@micron.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
[Cherry-picked from linux: 57d3a9a89a06 mtd: nand: fix nand_lock/unlock() function]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/mtd/nand/nand_base.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index ccf96150429a..128802fa5c20 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -852,6 +852,15 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 
 	chip->select_chip(mtd, chipnr);
 
+	/*
+	 * Reset the chip.
+	 * If we want to check the WP through READ STATUS and check the bit 7
+	 * we must reset the chip
+	 * some operation can also clear the bit 7 of status register
+	 * eg. erase/program a locked block
+	 */
+	chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
+
 	/* Check, if it is write protected */
 	if (nand_check_wp(mtd)) {
 		pr_debug("%s: device is write protected!\n",
@@ -902,6 +911,15 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 
 	chip->select_chip(mtd, chipnr);
 
+	/*
+	 * Reset the chip.
+	 * If we want to check the WP through READ STATUS and check the bit 7
+	 * we must reset the chip
+	 * some operation can also clear the bit 7 of status register
+	 * eg. erase/program a locked block
+	 */
+	chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
+
 	/* Check, if it is write protected */
 	if (nand_check_wp(mtd)) {
 		pr_debug("%s: device is write protected!\n",
-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mtd: nand: fix nand_lock/unlock() function
  2018-11-14 11:04 [PATCH] mtd: nand: fix nand_lock/unlock() function Marc Kleine-Budde
@ 2018-11-15  8:02 ` Sascha Hauer
  2018-11-15  8:32   ` Marc Kleine-Budde
  2018-11-16  7:33 ` Sascha Hauer
  1 sibling, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2018-11-15  8:02 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: barebox

On Wed, Nov 14, 2018 at 12:04:27PM +0100, Marc Kleine-Budde wrote:
> From: White Ding <bpqw@micron.com>
> 
> Do nand reset before write protect check.
> 
> If we want to check the WP# low or high through STATUS READ and check bit 7,
> we must reset the device, other operation (eg.erase/program a locked block) can
> also clear the bit 7 of status register.
> 
> As we know the status register can be refreshed, if we do some operation to trigger it,
> for example if we do erase/program operation to one block that is locked, then READ STATUS,
> the bit 7 of READ STATUS will be 0 indicate the device in write protect, then if we do
> erase/program operation to another block that is unlocked, the bit 7 of READ STATUS will
> be 1 indicate the device is not write protect.
> Suppose we checked the bit 7 of READ STATUS is 0 then judge the WP# is low (write protect),
> but in this case the WP# maybe high if we do erase/program operation to a locked block,
> so we must reset the device if we want to check the WP# low or high through STATUS READ and
> check bit 7.

Have you observed a failure this patch fixes or what is your motivation
to send this patch?

Sascha

> 
> Signed-off-by: White Ding <bpqw@micron.com>
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
> [Cherry-picked from linux: 57d3a9a89a06 mtd: nand: fix nand_lock/unlock() function]
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
>  drivers/mtd/nand/nand_base.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index ccf96150429a..128802fa5c20 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -852,6 +852,15 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
>  
>  	chip->select_chip(mtd, chipnr);
>  
> +	/*
> +	 * Reset the chip.
> +	 * If we want to check the WP through READ STATUS and check the bit 7
> +	 * we must reset the chip
> +	 * some operation can also clear the bit 7 of status register
> +	 * eg. erase/program a locked block
> +	 */
> +	chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
> +
>  	/* Check, if it is write protected */
>  	if (nand_check_wp(mtd)) {
>  		pr_debug("%s: device is write protected!\n",
> @@ -902,6 +911,15 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
>  
>  	chip->select_chip(mtd, chipnr);
>  
> +	/*
> +	 * Reset the chip.
> +	 * If we want to check the WP through READ STATUS and check the bit 7
> +	 * we must reset the chip
> +	 * some operation can also clear the bit 7 of status register
> +	 * eg. erase/program a locked block
> +	 */
> +	chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
> +
>  	/* Check, if it is write protected */
>  	if (nand_check_wp(mtd)) {
>  		pr_debug("%s: device is write protected!\n",
> -- 
> 2.19.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mtd: nand: fix nand_lock/unlock() function
  2018-11-15  8:02 ` Sascha Hauer
@ 2018-11-15  8:32   ` Marc Kleine-Budde
  0 siblings, 0 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2018-11-15  8:32 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox


[-- Attachment #1.1.1: Type: text/plain, Size: 1756 bytes --]

On 11/15/18 9:02 AM, Sascha Hauer wrote:
> On Wed, Nov 14, 2018 at 12:04:27PM +0100, Marc Kleine-Budde wrote:
>> From: White Ding <bpqw@micron.com>
>>
>> Do nand reset before write protect check.
>>
>> If we want to check the WP# low or high through STATUS READ and check bit 7,
>> we must reset the device, other operation (eg.erase/program a locked block) can
>> also clear the bit 7 of status register.
>>
>> As we know the status register can be refreshed, if we do some operation to trigger it,
>> for example if we do erase/program operation to one block that is locked, then READ STATUS,
>> the bit 7 of READ STATUS will be 0 indicate the device in write protect, then if we do
>> erase/program operation to another block that is unlocked, the bit 7 of READ STATUS will
>> be 1 indicate the device is not write protect.
>> Suppose we checked the bit 7 of READ STATUS is 0 then judge the WP# is low (write protect),
>> but in this case the WP# maybe high if we do erase/program operation to a locked block,
>> so we must reset the device if we want to check the WP# low or high through STATUS READ and
>> check bit 7.
> 
> Have you observed a failure this patch fixes or what is your motivation
> to send this patch?

A $CUSTOMER send me in private a fix needed for the micron NAND chip
found his Phytec board or a board they derived from it. I noticed that
the fix is in mainline Linux, too and I decided to cherry pick it into
barebox.

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mtd: nand: fix nand_lock/unlock() function
  2018-11-14 11:04 [PATCH] mtd: nand: fix nand_lock/unlock() function Marc Kleine-Budde
  2018-11-15  8:02 ` Sascha Hauer
@ 2018-11-16  7:33 ` Sascha Hauer
  1 sibling, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2018-11-16  7:33 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: barebox

On Wed, Nov 14, 2018 at 12:04:27PM +0100, Marc Kleine-Budde wrote:
> From: White Ding <bpqw@micron.com>
> 
> Do nand reset before write protect check.
> 
> If we want to check the WP# low or high through STATUS READ and check bit 7,
> we must reset the device, other operation (eg.erase/program a locked block) can
> also clear the bit 7 of status register.
> 
> As we know the status register can be refreshed, if we do some operation to trigger it,
> for example if we do erase/program operation to one block that is locked, then READ STATUS,
> the bit 7 of READ STATUS will be 0 indicate the device in write protect, then if we do
> erase/program operation to another block that is unlocked, the bit 7 of READ STATUS will
> be 1 indicate the device is not write protect.
> Suppose we checked the bit 7 of READ STATUS is 0 then judge the WP# is low (write protect),
> but in this case the WP# maybe high if we do erase/program operation to a locked block,
> so we must reset the device if we want to check the WP# low or high through STATUS READ and
> check bit 7.
> 
> Signed-off-by: White Ding <bpqw@micron.com>
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
> [Cherry-picked from linux: 57d3a9a89a06 mtd: nand: fix nand_lock/unlock() function]
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
>  drivers/mtd/nand/nand_base.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index ccf96150429a..128802fa5c20 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -852,6 +852,15 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
>  
>  	chip->select_chip(mtd, chipnr);
>  
> +	/*
> +	 * Reset the chip.
> +	 * If we want to check the WP through READ STATUS and check the bit 7
> +	 * we must reset the chip
> +	 * some operation can also clear the bit 7 of status register
> +	 * eg. erase/program a locked block
> +	 */
> +	chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
> +
>  	/* Check, if it is write protected */
>  	if (nand_check_wp(mtd)) {
>  		pr_debug("%s: device is write protected!\n",
> @@ -902,6 +911,15 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
>  
>  	chip->select_chip(mtd, chipnr);
>  
> +	/*
> +	 * Reset the chip.
> +	 * If we want to check the WP through READ STATUS and check the bit 7
> +	 * we must reset the chip
> +	 * some operation can also clear the bit 7 of status register
> +	 * eg. erase/program a locked block
> +	 */
> +	chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
> +
>  	/* Check, if it is write protected */
>  	if (nand_check_wp(mtd)) {
>  		pr_debug("%s: device is write protected!\n",
> -- 
> 2.19.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-11-16  7:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-14 11:04 [PATCH] mtd: nand: fix nand_lock/unlock() function Marc Kleine-Budde
2018-11-15  8:02 ` Sascha Hauer
2018-11-15  8:32   ` Marc Kleine-Budde
2018-11-16  7:33 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox