[U-Boot] erase and saveenv stop working after using fw_setenv

Hi!
I'm using U-Boot 1.3.4 and Linux 2.6.26.5 on MPC8323E-RDB. After using fw_printenv in Linux, erase and saveenv stop working in U-Boot. In Linux, fw_* still work.
When using erase, this is the result:
=> protect off fe040000 fe05ffff Un-Protected 1 sectors => erase fe040000 fe05ffff
Flash erase error at address fe040000 Block Erase Error. Block locked. done Erased 1 sectors => md fe040000 fe040000: c7be9eae 626f6f74 636d643d 73657465 ....bootcmd=sete fe040010: 6e762062 6f6f7461 72677320 726f6f74 nv bootargs root ...
So the sector doesn't get erased.
Errors are similar when using saveenv:
=> saveenv Saving Environment to Flash... Un-Protected 1 sectors Erasing Flash... Flash erase error at address fe040000 Block Erase Error. Block locked. done Erased 1 sectors
I tracked the error message down to cfi_flash.c, where this function call fails:
flash_isequal (info, sector, 0, FLASH_STATUS_DONE)
However, I have no clue on how CFI works, so my ability to debug it further stops here. A possible reason I can think of is that the ioctl calls in fw_setenv are somehow messing up the Flash status.
Any ideas?

Dear Petri Lehtinen,
In message 48CF6452.40603@inoi.fi you wrote:
I'm using U-Boot 1.3.4 and Linux 2.6.26.5 on MPC8323E-RDB. After using fw_printenv in Linux, erase and saveenv stop working in U-Boot. In
--^^^^^^^^^^^--
I think this must be a typo. fw_printenv should have no effect. I guess you mean fw_setenv (as in the Subject) ?
Linux, fw_* still work.
Obviously the flash locking is the important thing here. Probably your flashes weren't locked before, but are locked after running fw_setenv.
When using erase, this is the result:
=> protect off fe040000 fe05ffff Un-Protected 1 sectors => erase fe040000 fe05ffff
Flash erase error at address fe040000 Block Erase Error. Block locked.
^^^^^^^^^^^^^^^
That's a pretty clear error message here.
Errors are similar when using saveenv:
=> saveenv Saving Environment to Flash... Un-Protected 1 sectors Erasing Flash... Flash erase error at address fe040000 Block Erase Error. Block locked.
^^^^^^^^^^^^^^^
Again, a clear error message.
However, I have no clue on how CFI works, so my ability to debug it further stops here. A possible reason I can think of is that the ioctl calls in fw_setenv are somehow messing up the Flash status.
The problem is that the MPC8323ERDB board has flash chips that support hardware flash protection (locking), but the board config file does not select the CFG_FLASH_PROTECTION option. Therefore U-Boot will not make any attempts to lock or unlock any flash sectors.
I think two things should be done:
a) Kim, I think it would make sense to add CFG_FLASH_PROTECTION to all board configurations that use lockable flash chips. I would even consider this a bug fix and pull it into the upcoming 2008-10 release, if you want.
b) Guennadi, I think it would be nice, user-friendly behaviour if fw_setenv did not unconditional locking, but would instead leave the flash in the same state it found it. Do you think it would be possible to test the state first, and then perform the unlock / lock operations only when the flash sectors were already locked when fw_setenv was called?
Best regards,
Wolfgang Denk

On Tue, 16 Sep 2008, Wolfgang Denk wrote:
b) Guennadi, I think it would be nice, user-friendly behaviour if fw_setenv did not unconditional locking, but would instead leave the flash in the same state it found it. Do you think it would be possible to test the state first, and then perform the unlock / lock operations only when the flash sectors were already locked when fw_setenv was called?
I am not sure if this is possible with the current MTD ABI, it looks like it is not. There is a flags member in struct mtd_info_user, which can take value MTD_WRITEABLE, but I think it means something different - whether this mtd-device is writable in principle. So, it looks like the only way to find out whether the specific sector is locked is to try to write / erase it:-(
Thanks Guennadi --- Guennadi Liakhovetski, Ph.D.
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office@denx.de

fw_printenv in Linux, erase and saveenv stop working in U-Boot. In
--^^^^^^^^^^^--
I think this must be a typo. fw_printenv should have no effect. I guess you mean fw_setenv (as in the Subject) ?
Ahh, yes. I meant fw_setenv of course.
The problem is that the MPC8323ERDB board has flash chips that support hardware flash protection (locking), but the board config file does not select the CFG_FLASH_PROTECTION option. Therefore U-Boot will not make any attempts to lock or unlock any flash sectors.
I enabled CFG_FLASH_PROTECTION, and now it works. Thanks a lot.

On Tue, 16 Sep 2008 11:04:50 +0200 Wolfgang Denk wd@denx.de wrote:
The problem is that the MPC8323ERDB board has flash chips that support hardware flash protection (locking), but the board config file does not select the CFG_FLASH_PROTECTION option. Therefore U-Boot will not make any attempts to lock or unlock any flash sectors.
I think two things should be done:
a) Kim, I think it would make sense to add CFG_FLASH_PROTECTION to all board configurations that use lockable flash chips. I would even consider this a bug fix and pull it into the upcoming 2008-10 release, if you want.
ok, I'll leave non-fsl boards up to their maintainers though:
From 6074f0f040f2870135af498c16141f6432fb92f9 Mon Sep 17 00:00:00 2001
From: Kim Phillips kim.phillips@freescale.com Date: Tue, 23 Sep 2008 09:38:49 -0500 Subject: [PATCH] mpc83xx: add h/w flash protection to board configs
the operating system may leave flash in a h/w locked state after writing. This allows u-boot to continue to write flash by enabling h/w unlocking by default.
Signed-off-by: Kim Phillips kim.phillips@freescale.com --- include/configs/MPC8313ERDB.h | 1 + include/configs/MPC8315ERDB.h | 1 + include/configs/MPC8323ERDB.h | 1 + include/configs/MPC832XEMDS.h | 1 + include/configs/MPC8349EMDS.h | 1 + include/configs/MPC8349ITX.h | 1 + include/configs/MPC8360EMDS.h | 1 + include/configs/MPC837XEMDS.h | 1 + include/configs/MPC837XERDB.h | 1 + 9 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/include/configs/MPC8313ERDB.h b/include/configs/MPC8313ERDB.h index 55d7852..b361217 100644 --- a/include/configs/MPC8313ERDB.h +++ b/include/configs/MPC8313ERDB.h @@ -174,6 +174,7 @@ #define CONFIG_FLASH_CFI_DRIVER /* use the CFI driver */ #define CFG_FLASH_BASE 0xFE000000 /* start of FLASH */ #define CFG_FLASH_SIZE 8 /* flash size in MB */ +#define CFG_FLASH_PROTECTION 1 /* Use h/w Flash protection. */ #define CFG_FLASH_EMPTY_INFO /* display empty sectors */ #define CFG_FLASH_USE_BUFFER_WRITE /* buffer up multiple bytes */
diff --git a/include/configs/MPC8315ERDB.h b/include/configs/MPC8315ERDB.h index 5879a82..83f64c6 100644 --- a/include/configs/MPC8315ERDB.h +++ b/include/configs/MPC8315ERDB.h @@ -193,6 +193,7 @@
#define CFG_FLASH_BASE 0xFE000000 /* FLASH base address */ #define CFG_FLASH_SIZE 8 /* FLASH size is 8M */ +#define CFG_FLASH_PROTECTION 1 /* Use h/w Flash protection. */
#define CFG_LBLAWBAR0_PRELIM CFG_FLASH_BASE /* Window base at flash base */ #define CFG_LBLAWAR0_PRELIM 0x80000016 /* 8MB window size */ diff --git a/include/configs/MPC8323ERDB.h b/include/configs/MPC8323ERDB.h index 977142b..697c5ad 100644 --- a/include/configs/MPC8323ERDB.h +++ b/include/configs/MPC8323ERDB.h @@ -181,6 +181,7 @@ #define CONFIG_FLASH_CFI_DRIVER /* use the CFI driver */ #define CFG_FLASH_BASE 0xFE000000 /* FLASH base address */ #define CFG_FLASH_SIZE 16 /* FLASH size is 16M */ +#define CFG_FLASH_PROTECTION 1 /* Use h/w Flash protection. */
#define CFG_LBLAWBAR0_PRELIM CFG_FLASH_BASE /* Window base at flash base */ #define CFG_LBLAWAR0_PRELIM 0x80000018 /* 32MB window size */ diff --git a/include/configs/MPC832XEMDS.h b/include/configs/MPC832XEMDS.h index 01cf557..9a9b500 100644 --- a/include/configs/MPC832XEMDS.h +++ b/include/configs/MPC832XEMDS.h @@ -169,6 +169,7 @@ #define CONFIG_FLASH_CFI_DRIVER /* use the CFI driver */ #define CFG_FLASH_BASE 0xFE000000 /* FLASH base address */ #define CFG_FLASH_SIZE 16 /* FLASH size is 16M */ +#define CFG_FLASH_PROTECTION 1 /* Use h/w Flash protection. */
#define CFG_LBLAWBAR0_PRELIM CFG_FLASH_BASE /* Window base at flash base */ #define CFG_LBLAWAR0_PRELIM 0x80000018 /* 32MB window size */ diff --git a/include/configs/MPC8349EMDS.h b/include/configs/MPC8349EMDS.h index 87f1672..8135254 100644 --- a/include/configs/MPC8349EMDS.h +++ b/include/configs/MPC8349EMDS.h @@ -156,6 +156,7 @@ #define CONFIG_FLASH_CFI_DRIVER /* use the CFI driver */ #define CFG_FLASH_BASE 0xFE000000 /* start of FLASH */ #define CFG_FLASH_SIZE 32 /* max flash size in MB */ +#define CFG_FLASH_PROTECTION 1 /* Use h/w Flash protection. */ /* #define CFG_FLASH_USE_BUFFER_WRITE */
#define CFG_BR0_PRELIM (CFG_FLASH_BASE | /* flash Base address */ \ diff --git a/include/configs/MPC8349ITX.h b/include/configs/MPC8349ITX.h index fa0c0a7..81ea9f8 100644 --- a/include/configs/MPC8349ITX.h +++ b/include/configs/MPC8349ITX.h @@ -190,6 +190,7 @@ boards, we say we have two, but don't display a message if we find only one. */ #define CFG_FLASH_BANKS_LIST {CFG_FLASH_BASE, CFG_FLASH_BASE + 0x800000} #define CFG_FLASH_SIZE 16 /* FLASH size in MB */ #define CFG_FLASH_SIZE_SHIFT 4 /* log2 of the above value */ +#define CFG_FLASH_PROTECTION 1 /* Use h/w Flash protection. */
/* Vitesse 7385 */
diff --git a/include/configs/MPC8360EMDS.h b/include/configs/MPC8360EMDS.h index f60d7a7..baff03e 100644 --- a/include/configs/MPC8360EMDS.h +++ b/include/configs/MPC8360EMDS.h @@ -194,6 +194,7 @@ #define CONFIG_FLASH_CFI_DRIVER /* use the CFI driver */ #define CFG_FLASH_BASE 0xFE000000 /* FLASH base address */ #define CFG_FLASH_SIZE 32 /* max FLASH size is 32M */ +#define CFG_FLASH_PROTECTION 1 /* Use h/w Flash protection. */ #define CONFIG_FLASH_SHOW_PROGRESS 45 /* count down from 45/5: 9..1 */
#define CFG_LBLAWBAR0_PRELIM CFG_FLASH_BASE /* Window base at flash base */ diff --git a/include/configs/MPC837XEMDS.h b/include/configs/MPC837XEMDS.h index 7c87388..256f156 100644 --- a/include/configs/MPC837XEMDS.h +++ b/include/configs/MPC837XEMDS.h @@ -229,6 +229,7 @@ #define CONFIG_FLASH_CFI_DRIVER /* use the CFI driver */ #define CFG_FLASH_BASE 0xFE000000 /* FLASH base address */ #define CFG_FLASH_SIZE 32 /* max FLASH size is 32M */ +#define CFG_FLASH_PROTECTION 1 /* Use h/w Flash protection. */
#define CFG_LBLAWBAR0_PRELIM CFG_FLASH_BASE /* Window base at flash base */ #define CFG_LBLAWAR0_PRELIM 0x80000018 /* 32MB window size */ diff --git a/include/configs/MPC837XERDB.h b/include/configs/MPC837XERDB.h index 2ac4ad0..da77121 100644 --- a/include/configs/MPC837XERDB.h +++ b/include/configs/MPC837XERDB.h @@ -253,6 +253,7 @@ #define CFG_FLASH_BASE 0xFE000000 /* FLASH base address */ #define CFG_FLASH_SIZE 8 /* max FLASH size is 32M */
+#define CFG_FLASH_PROTECTION 1 /* Use h/w Flash protection. */ #define CFG_FLASH_EMPTY_INFO /* display empty sectors */ #define CFG_FLASH_USE_BUFFER_WRITE /* buffer up multiple bytes */
participants (4)
-
Guennadi Liakhovetski
-
Kim Phillips
-
Petri Lehtinen
-
Wolfgang Denk