diff mbox series

Unlock flash memory before checking if it is empty

Message ID 72cec4d48b43445d9cf038d6ef688830@NANS01204.it.intra.sercel.com
State Accepted
Headers show
Series Unlock flash memory before checking if it is empty | expand

Commit Message

BRUN Xavier Nov. 14, 2017, 9:54 a.m. UTC
Signed-off-by: Xavier Brun <xavier.brun@sercel.com>
---
 corelib/mtd-interface.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

--
2.11.0

This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.

Comments

Stefano Babic Nov. 14, 2017, 3:08 p.m. UTC | #1
Hi Xavier,

On 14/11/2017 10:54, BRUN Xavier wrote:
> Signed-off-by: Xavier Brun <xavier.brun@sercel.com>
> ---
>  corelib/mtd-interface.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c index 1f8d328..ee7d62a 100644
> --- a/corelib/mtd-interface.c
> +++ b/corelib/mtd-interface.c
> @@ -47,7 +47,6 @@ int flash_erase(int mtdnum)
>  char mtd_device[80];
>  struct mtd_dev_info *mtd;
>  int noskipbad = 0;
> -int unlock = 0;

Agree that it does not currently work, I do not know where it is coming
- unlock is never set.


>  int ret = 0;
>  unsigned int eb, eb_start, eb_cnt, i;
>  uint8_t *buf;
> @@ -96,6 +95,14 @@ int flash_erase(int mtdnum)
>  }
>  }
> 
> +/* Unlock memory if required */
> +if (mtd_is_locked(mtd, fd, eb)) {
> +if (mtd_unlock(mtd, fd, eb) != 0) {
> +TRACE("%s: MTD unlock failure", mtd_device);
> +continue;
> +}
> +}
> +

Why do we need to unlock the sector before reading it ? We need to
unlock it before erasing or writing, but read access are always allowed.
You unlock all sectors even if not necessary.



>  /*
>   * In case of NOR flash, check if the flash
>   * is already empty. This can save
> @@ -123,13 +130,6 @@ int flash_erase(int mtdnum)
>  }
> 
>  /* The sector contains data and it must be erased */
> -if (unlock) {
> -if (mtd_unlock(mtd, fd, eb) != 0) {
> -TRACE("%s: MTD unlock failure", mtd_device);
> -continue;
> -}
> -}
> -
>  if (mtd_erase(flash->libmtd, mtd, fd, eb) != 0) {
>  ERROR("%s: MTD Erase failure", mtd_device);
>  ret  = -EIO;
> --
> 2.11.0
> 

Your patch does not apply - can you check it ?

> This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.

Well, this is an Open Source Mailing List - This footnote should be
dropped when posting to FOSS projects.

Best regards,
Stefano Babic
BRUN Xavier Nov. 14, 2017, 3:32 p.m. UTC | #2
Hi Stefano,

The problem is when the flash was empty AND locked, then the flash was never unlocked before writing.
This is why I've put the unlock method before the empty flash test.

Regards,
Xavier.


-----Message d'origine-----
De : Stefano Babic [mailto:sbabic@denx.de]
Envoyé : mardi 14 novembre 2017 16:08
À : BRUN Xavier <Xavier.BRUN@sercel.com>; swupdate@googlegroups.com
Objet : Re: [swupdate] [PATCH] Unlock flash memory before checking if it is empty

Hi Xavier,

On 14/11/2017 10:54, BRUN Xavier wrote:
> Signed-off-by: Xavier Brun <xavier.brun@sercel.com>
> ---
>  corelib/mtd-interface.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c index
> 1f8d328..ee7d62a 100644
> --- a/corelib/mtd-interface.c
> +++ b/corelib/mtd-interface.c
> @@ -47,7 +47,6 @@ int flash_erase(int mtdnum)  char mtd_device[80];
> struct mtd_dev_info *mtd;  int noskipbad = 0; -int unlock = 0;

Agree that it does not currently work, I do not know where it is coming
- unlock is never set.


>  int ret = 0;
>  unsigned int eb, eb_start, eb_cnt, i;  uint8_t *buf; @@ -96,6 +95,14
> @@ int flash_erase(int mtdnum)  }  }
>
> +/* Unlock memory if required */
> +if (mtd_is_locked(mtd, fd, eb)) {
> +if (mtd_unlock(mtd, fd, eb) != 0) {
> +TRACE("%s: MTD unlock failure", mtd_device); continue; } }
> +

Why do we need to unlock the sector before reading it ? We need to unlock it before erasing or writing, but read access are always allowed.
You unlock all sectors even if not necessary.



>  /*
>   * In case of NOR flash, check if the flash
>   * is already empty. This can save
> @@ -123,13 +130,6 @@ int flash_erase(int mtdnum)  }
>
>  /* The sector contains data and it must be erased */ -if (unlock) {
> -if (mtd_unlock(mtd, fd, eb) != 0) {
> -TRACE("%s: MTD unlock failure", mtd_device); -continue; -} -}
> -
>  if (mtd_erase(flash->libmtd, mtd, fd, eb) != 0) {
>  ERROR("%s: MTD Erase failure", mtd_device);  ret  = -EIO;
> --
> 2.11.0
>

Your patch does not apply - can you check it ?

> This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.

Well, this is an Open Source Mailing List - This footnote should be dropped when posting to FOSS projects.

Best regards,
Stefano Babic


--
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de =====================================================================
This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.
Stefano Babic Nov. 14, 2017, 4:05 p.m. UTC | #3
Hi Xavier,

On 14/11/2017 16:32, BRUN Xavier wrote:
> Hi Stefano,
> 
> The problem is when the flash was empty AND locked, then the flash was never unlocked before writing.

ok, I understand now what happens - thanks !

Anyway, this explanation should be in the commit message, too, to take
track why the patch is required.

Anyway, it looks to me weird to fix this in the erase when no erase
should be done. From your explanation, it fails later in the
flash_handler. Should the unlock better happen before writing else
unconditionally in the erase function ?

> This is why I've put the unlock method before the empty flash test.
> 

Best regards,
Stefano Babic

> Regards,
> Xavier.
> 
> 
> -----Message d'origine-----
> De : Stefano Babic [mailto:sbabic@denx.de]
> Envoyé : mardi 14 novembre 2017 16:08
> À : BRUN Xavier <Xavier.BRUN@sercel.com>; swupdate@googlegroups.com
> Objet : Re: [swupdate] [PATCH] Unlock flash memory before checking if it is empty
> 
> Hi Xavier,
> 
> On 14/11/2017 10:54, BRUN Xavier wrote:
>> Signed-off-by: Xavier Brun <xavier.brun@sercel.com>
>> ---
>>  corelib/mtd-interface.c | 16 ++++++++--------
>>  1 file changed, 8 insertions(+), 8 deletions(-)
>>
>> diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c index
>> 1f8d328..ee7d62a 100644
>> --- a/corelib/mtd-interface.c
>> +++ b/corelib/mtd-interface.c
>> @@ -47,7 +47,6 @@ int flash_erase(int mtdnum)  char mtd_device[80];
>> struct mtd_dev_info *mtd;  int noskipbad = 0; -int unlock = 0;
> 
> Agree that it does not currently work, I do not know where it is coming
> - unlock is never set.
> 
> 
>>  int ret = 0;
>>  unsigned int eb, eb_start, eb_cnt, i;  uint8_t *buf; @@ -96,6 +95,14
>> @@ int flash_erase(int mtdnum)  }  }
>>
>> +/* Unlock memory if required */
>> +if (mtd_is_locked(mtd, fd, eb)) {
>> +if (mtd_unlock(mtd, fd, eb) != 0) {
>> +TRACE("%s: MTD unlock failure", mtd_device); continue; } }
>> +
> 
> Why do we need to unlock the sector before reading it ? We need to unlock it before erasing or writing, but read access are always allowed.
> You unlock all sectors even if not necessary.
> 
> 
> 
>>  /*
>>   * In case of NOR flash, check if the flash
>>   * is already empty. This can save
>> @@ -123,13 +130,6 @@ int flash_erase(int mtdnum)  }
>>
>>  /* The sector contains data and it must be erased */ -if (unlock) {
>> -if (mtd_unlock(mtd, fd, eb) != 0) {
>> -TRACE("%s: MTD unlock failure", mtd_device); -continue; -} -}
>> -
>>  if (mtd_erase(flash->libmtd, mtd, fd, eb) != 0) {
>>  ERROR("%s: MTD Erase failure", mtd_device);  ret  = -EIO;
>> --
>> 2.11.0
>>
> 
> Your patch does not apply - can you check it ?
> 
>> This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.
> 
> Well, this is an Open Source Mailing List - This footnote should be dropped when posting to FOSS projects.
> 
> Best regards,
> Stefano Babic
> 
> 
> --
> =====================================================================
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de =====================================================================
> This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.
>
BRUN Xavier Nov. 14, 2017, 4:44 p.m. UTC | #4
Hi Stefano,

It might be clearer to separate unlock and erase, but it is probably more efficient to leave it here (the loop will always be done anyway).

I'm still searching why my patch doesn't apply. Seems related to whitespaces as it applies with option "--ignore-whitespace"...

Xavier.

-----Message d'origine-----
De : Stefano Babic [mailto:sbabic@denx.de]
Envoyé : mardi 14 novembre 2017 17:05
À : BRUN Xavier <Xavier.BRUN@sercel.com>; Stefano Babic <sbabic@denx.de>; swupdate@googlegroups.com
Objet : Re: [swupdate] [PATCH] Unlock flash memory before checking if it is empty

Hi Xavier,

On 14/11/2017 16:32, BRUN Xavier wrote:
> Hi Stefano,
>
> The problem is when the flash was empty AND locked, then the flash was never unlocked before writing.

ok, I understand now what happens - thanks !

Anyway, this explanation should be in the commit message, too, to take track why the patch is required.

Anyway, it looks to me weird to fix this in the erase when no erase should be done. From your explanation, it fails later in the flash_handler. Should the unlock better happen before writing else unconditionally in the erase function ?

> This is why I've put the unlock method before the empty flash test.
>

Best regards,
Stefano Babic

> Regards,
> Xavier.
>
>
> -----Message d'origine-----
> De : Stefano Babic [mailto:sbabic@denx.de] Envoyé : mardi 14 novembre
> 2017 16:08 À : BRUN Xavier <Xavier.BRUN@sercel.com>;
> swupdate@googlegroups.com Objet : Re: [swupdate] [PATCH] Unlock flash
> memory before checking if it is empty
>
> Hi Xavier,
>
> On 14/11/2017 10:54, BRUN Xavier wrote:
>> Signed-off-by: Xavier Brun <xavier.brun@sercel.com>
>> ---
>>  corelib/mtd-interface.c | 16 ++++++++--------
>>  1 file changed, 8 insertions(+), 8 deletions(-)
>>
>> diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c index
>> 1f8d328..ee7d62a 100644
>> --- a/corelib/mtd-interface.c
>> +++ b/corelib/mtd-interface.c
>> @@ -47,7 +47,6 @@ int flash_erase(int mtdnum)  char mtd_device[80];
>> struct mtd_dev_info *mtd;  int noskipbad = 0; -int unlock = 0;
>
> Agree that it does not currently work, I do not know where it is
> coming
> - unlock is never set.
>
>
>>  int ret = 0;
>>  unsigned int eb, eb_start, eb_cnt, i;  uint8_t *buf; @@ -96,6 +95,14
>> @@ int flash_erase(int mtdnum)  }  }
>>
>> +/* Unlock memory if required */
>> +if (mtd_is_locked(mtd, fd, eb)) {
>> +if (mtd_unlock(mtd, fd, eb) != 0) {
>> +TRACE("%s: MTD unlock failure", mtd_device); continue; } }
>> +
>
> Why do we need to unlock the sector before reading it ? We need to unlock it before erasing or writing, but read access are always allowed.
> You unlock all sectors even if not necessary.
>
>
>
>>  /*
>>   * In case of NOR flash, check if the flash
>>   * is already empty. This can save
>> @@ -123,13 +130,6 @@ int flash_erase(int mtdnum)  }
>>
>>  /* The sector contains data and it must be erased */ -if (unlock) {
>> -if (mtd_unlock(mtd, fd, eb) != 0) {
>> -TRACE("%s: MTD unlock failure", mtd_device); -continue; -} -}
>> -
>>  if (mtd_erase(flash->libmtd, mtd, fd, eb) != 0) {
>>  ERROR("%s: MTD Erase failure", mtd_device);  ret  = -EIO;
>> --
>> 2.11.0
>>
>
> Your patch does not apply - can you check it ?
>
>> This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.
>
> Well, this is an Open Source Mailing List - This footnote should be dropped when posting to FOSS projects.
>
> Best regards,
> Stefano Babic
>
>
> --
> =====================================================================
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de
> =====================================================================
> This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.
>


--
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de =====================================================================
This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.
BRUN Xavier Nov. 15, 2017, 8:48 a.m. UTC | #5
Hi Stefano,

Can you try the attached patch please ?
I successfully applied it on a local repository so it should work.

Thanks,
Xavier.

-----Message d'origine-----
De : Stefano Babic [mailto:sbabic@denx.de]
Envoyé : mardi 14 novembre 2017 17:05
À : BRUN Xavier <Xavier.BRUN@sercel.com>; Stefano Babic <sbabic@denx.de>; swupdate@googlegroups.com
Objet : Re: [swupdate] [PATCH] Unlock flash memory before checking if it is empty

Hi Xavier,

On 14/11/2017 16:32, BRUN Xavier wrote:
> Hi Stefano,
>
> The problem is when the flash was empty AND locked, then the flash was never unlocked before writing.

ok, I understand now what happens - thanks !

Anyway, this explanation should be in the commit message, too, to take track why the patch is required.

Anyway, it looks to me weird to fix this in the erase when no erase should be done. From your explanation, it fails later in the flash_handler. Should the unlock better happen before writing else unconditionally in the erase function ?

> This is why I've put the unlock method before the empty flash test.
>

Best regards,
Stefano Babic

> Regards,
> Xavier.
>
>
> -----Message d'origine-----
> De : Stefano Babic [mailto:sbabic@denx.de] Envoyé : mardi 14 novembre
> 2017 16:08 À : BRUN Xavier <Xavier.BRUN@sercel.com>;
> swupdate@googlegroups.com Objet : Re: [swupdate] [PATCH] Unlock flash
> memory before checking if it is empty
>
> Hi Xavier,
>
> On 14/11/2017 10:54, BRUN Xavier wrote:
>> Signed-off-by: Xavier Brun <xavier.brun@sercel.com>
>> ---
>>  corelib/mtd-interface.c | 16 ++++++++--------
>>  1 file changed, 8 insertions(+), 8 deletions(-)
>>
>> diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c index
>> 1f8d328..ee7d62a 100644
>> --- a/corelib/mtd-interface.c
>> +++ b/corelib/mtd-interface.c
>> @@ -47,7 +47,6 @@ int flash_erase(int mtdnum)  char mtd_device[80];
>> struct mtd_dev_info *mtd;  int noskipbad = 0; -int unlock = 0;
>
> Agree that it does not currently work, I do not know where it is
> coming
> - unlock is never set.
>
>
>>  int ret = 0;
>>  unsigned int eb, eb_start, eb_cnt, i;  uint8_t *buf; @@ -96,6 +95,14
>> @@ int flash_erase(int mtdnum)  }  }
>>
>> +/* Unlock memory if required */
>> +if (mtd_is_locked(mtd, fd, eb)) {
>> +if (mtd_unlock(mtd, fd, eb) != 0) {
>> +TRACE("%s: MTD unlock failure", mtd_device); continue; } }
>> +
>
> Why do we need to unlock the sector before reading it ? We need to unlock it before erasing or writing, but read access are always allowed.
> You unlock all sectors even if not necessary.
>
>
>
>>  /*
>>   * In case of NOR flash, check if the flash
>>   * is already empty. This can save
>> @@ -123,13 +130,6 @@ int flash_erase(int mtdnum)  }
>>
>>  /* The sector contains data and it must be erased */ -if (unlock) {
>> -if (mtd_unlock(mtd, fd, eb) != 0) {
>> -TRACE("%s: MTD unlock failure", mtd_device); -continue; -} -}
>> -
>>  if (mtd_erase(flash->libmtd, mtd, fd, eb) != 0) {
>>  ERROR("%s: MTD Erase failure", mtd_device);  ret  = -EIO;
>> --
>> 2.11.0
>>
>
> Your patch does not apply - can you check it ?
>
>> This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.
>
> Well, this is an Open Source Mailing List - This footnote should be dropped when posting to FOSS projects.
>
> Best regards,
> Stefano Babic
>
>
> --
> =====================================================================
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de
> =====================================================================
> This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.
>


--
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de =====================================================================
This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.
Stefano Babic Nov. 15, 2017, 9:45 a.m. UTC | #6
Hi Xavier,

On 15/11/2017 09:48, BRUN Xavier wrote:
> Hi Stefano,
> 
> Can you try the attached patch please ?
> I successfully applied it on a local repository so it should work.
> 

This can be applied and I'merge it - anyway, this means you have issues
with your mailer. You can switch to "git send-email" for sending patches.

Best regards,
Stefano Babic

> Thanks,
> Xavier.
> 
> -----Message d'origine-----
> De : Stefano Babic [mailto:sbabic@denx.de]
> Envoyé : mardi 14 novembre 2017 17:05
> À : BRUN Xavier <Xavier.BRUN@sercel.com>; Stefano Babic <sbabic@denx.de>; swupdate@googlegroups.com
> Objet : Re: [swupdate] [PATCH] Unlock flash memory before checking if it is empty
> 
> Hi Xavier,
> 
> On 14/11/2017 16:32, BRUN Xavier wrote:
>> Hi Stefano,
>>
>> The problem is when the flash was empty AND locked, then the flash was never unlocked before writing.
> 
> ok, I understand now what happens - thanks !
> 
> Anyway, this explanation should be in the commit message, too, to take track why the patch is required.
> 
> Anyway, it looks to me weird to fix this in the erase when no erase should be done. From your explanation, it fails later in the flash_handler. Should the unlock better happen before writing else unconditionally in the erase function ?
> 
>> This is why I've put the unlock method before the empty flash test.
>>
> 
> Best regards,
> Stefano Babic
> 
>> Regards,
>> Xavier.
>>
>>
>> -----Message d'origine-----
>> De : Stefano Babic [mailto:sbabic@denx.de] Envoyé : mardi 14 novembre
>> 2017 16:08 À : BRUN Xavier <Xavier.BRUN@sercel.com>;
>> swupdate@googlegroups.com Objet : Re: [swupdate] [PATCH] Unlock flash
>> memory before checking if it is empty
>>
>> Hi Xavier,
>>
>> On 14/11/2017 10:54, BRUN Xavier wrote:
>>> Signed-off-by: Xavier Brun <xavier.brun@sercel.com>
>>> ---
>>>  corelib/mtd-interface.c | 16 ++++++++--------
>>>  1 file changed, 8 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c index
>>> 1f8d328..ee7d62a 100644
>>> --- a/corelib/mtd-interface.c
>>> +++ b/corelib/mtd-interface.c
>>> @@ -47,7 +47,6 @@ int flash_erase(int mtdnum)  char mtd_device[80];
>>> struct mtd_dev_info *mtd;  int noskipbad = 0; -int unlock = 0;
>>
>> Agree that it does not currently work, I do not know where it is
>> coming
>> - unlock is never set.
>>
>>
>>>  int ret = 0;
>>>  unsigned int eb, eb_start, eb_cnt, i;  uint8_t *buf; @@ -96,6 +95,14
>>> @@ int flash_erase(int mtdnum)  }  }
>>>
>>> +/* Unlock memory if required */
>>> +if (mtd_is_locked(mtd, fd, eb)) {
>>> +if (mtd_unlock(mtd, fd, eb) != 0) {
>>> +TRACE("%s: MTD unlock failure", mtd_device); continue; } }
>>> +
>>
>> Why do we need to unlock the sector before reading it ? We need to unlock it before erasing or writing, but read access are always allowed.
>> You unlock all sectors even if not necessary.
>>
>>
>>
>>>  /*
>>>   * In case of NOR flash, check if the flash
>>>   * is already empty. This can save
>>> @@ -123,13 +130,6 @@ int flash_erase(int mtdnum)  }
>>>
>>>  /* The sector contains data and it must be erased */ -if (unlock) {
>>> -if (mtd_unlock(mtd, fd, eb) != 0) {
>>> -TRACE("%s: MTD unlock failure", mtd_device); -continue; -} -}
>>> -
>>>  if (mtd_erase(flash->libmtd, mtd, fd, eb) != 0) {
>>>  ERROR("%s: MTD Erase failure", mtd_device);  ret  = -EIO;
>>> --
>>> 2.11.0
>>>
>>
>> Your patch does not apply - can you check it ?
>>
>>> This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.
>>
>> Well, this is an Open Source Mailing List - This footnote should be dropped when posting to FOSS projects.
>>
>> Best regards,
>> Stefano Babic
>>
>>
>> --
>> =====================================================================
>> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
>> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
>> Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de
>> =====================================================================
>> This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.
>>
> 
> 
> --
> =====================================================================
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de =====================================================================
> This e-mail and any accompanying attachments are confidential. If you are not the intended recipient, you must not review, disclose, copy, distribute or use this e-mail; please delete it from your system and notify the sender immediately.
>
diff mbox series

Patch

diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c index 1f8d328..ee7d62a 100644
--- a/corelib/mtd-interface.c
+++ b/corelib/mtd-interface.c
@@ -47,7 +47,6 @@  int flash_erase(int mtdnum)
 char mtd_device[80];
 struct mtd_dev_info *mtd;
 int noskipbad = 0;
-int unlock = 0;
 int ret = 0;
 unsigned int eb, eb_start, eb_cnt, i;
 uint8_t *buf;
@@ -96,6 +95,14 @@  int flash_erase(int mtdnum)
 }
 }

+/* Unlock memory if required */
+if (mtd_is_locked(mtd, fd, eb)) {
+if (mtd_unlock(mtd, fd, eb) != 0) {
+TRACE("%s: MTD unlock failure", mtd_device);
+continue;
+}
+}
+
 /*
  * In case of NOR flash, check if the flash
  * is already empty. This can save
@@ -123,13 +130,6 @@  int flash_erase(int mtdnum)
 }

 /* The sector contains data and it must be erased */
-if (unlock) {
-if (mtd_unlock(mtd, fd, eb) != 0) {
-TRACE("%s: MTD unlock failure", mtd_device);
-continue;
-}
-}
-
 if (mtd_erase(flash->libmtd, mtd, fd, eb) != 0) {
 ERROR("%s: MTD Erase failure", mtd_device);
 ret  = -EIO;