Patchwork [U-Boot] Flash protection and fw_setenv tool

login
register
mail settings
Submitter Waibel Georg
Date Feb. 26, 2013, 11:04 a.m.
Message ID <E1C9442006A9AE48A7A4B85E0D01C4D45B47C0@stwexdb.stww2k.local>
Download mbox | patch
Permalink /patch/223201/
State Not Applicable
Headers show

Comments

Waibel Georg - Feb. 26, 2013, 11:04 a.m.
Hi,

I activated flash sector protection for our CFI NOR flash chip (CONFIG_SYS_FLASH_PROTECTION). Protection bits for U-Boot code sectors and environment sector are set by default during U-Boot startup. Thus from Linux, I cannot write to this sectors, which is generally a correct behavior. BUT, with this, changing the environment from user space with the fw_setenv tool does not work anymore. 
And here's the question: How to deal with this issue correctly? Two approaches came in my mind:
a) 
Unprotecting the flash sectors by the Linux kernel (in CFI driver). This seems not to be implemented yet, at least for AMD CFI command set (0x0002). 
However, when unprotecting flash sectors from Linux side, does a sector protection actually makes sense?
b)
Introduce a config option in U-Boot which allows to leave the environment unprotected. See patch below. I called this option CONFIG_ENV_UNPROTECTED
When defined, U-Boot does not protect the environment. For compatibility with boards in which the environment sector is already protected, I left the unprotect part in the saveenv function untouched.

Any comments about this issue?
Thanks and regards
Georg

Patch

Index: common/env_flash.c
===================================================================
--- common/env_flash.c	(revision 3966)
+++ common/env_flash.c	(working copy)
@@ -218,9 +218,12 @@ 
 done:
 	if (saved_data)
 		free(saved_data);
+
+#ifndef CONFIG_ENV_UNPROTECTED
 	/* try to re-protect */
 	flash_sect_protect(1, (ulong)flash_addr, end_addr);
 	flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new);
+#endif
 
 	return rc;
 }
Index: drivers/mtd/cfi_flash.c
===================================================================
--- drivers/mtd/cfi_flash.c	(revision 3966)
+++ drivers/mtd/cfi_flash.c	(working copy)
@@ -2294,7 +2294,7 @@ 
 #endif
 
 	/* Environment protection ON by default */
-#ifdef CONFIG_ENV_IS_IN_FLASH
+#if defined(CONFIG_ENV_IS_IN_FLASH) && !defined(CONFIG_ENV_UNPROTECTED)
 	flash_protect(FLAG_PROTECT_SET,
 		       CONFIG_ENV_ADDR,
 		       CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,