Hi again,

the previous patch missed some places to apply the unprotect switch. Here's an 
improved version:

Index: common/env_flash.c
===================================================================
--- common/env_flash.c  (revision 4065)
+++ 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;
 }
@@ -310,7 +313,9 @@
        if (saved_data)
                free(saved_data);
        /* try to re-protect */
+#ifndef CONFIG_ENV_UNPROTECTED
        flash_sect_protect(1, (long)flash_addr, end_addr);
+#endif
        return rc;
 }
 #endif /* CMD_SAVEENV */
@@ -340,7 +345,9 @@
                flash_write(&flag,
                            (ulong)&(flash_addr_new->flags),
                            sizeof(flash_addr_new->flags));
+#ifndef CONFIG_ENV_UNPROTECTED
                flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new);
+#endif
        }
 
        if (flash_addr->flags != ACTIVE_FLAG &&
@@ -352,7 +359,9 @@
                flash_write(&flag,
                            (ulong)&(flash_addr->flags),
                            sizeof(flash_addr->flags));
+#ifndef CONFIG_ENV_UNPROTECTED
                flash_sect_protect(1, (ulong)flash_addr, end_addr);
+#endif
        }
 
        if (gd->env_valid == 2)
Index: drivers/mtd/cfi_flash.c
===================================================================
--- drivers/mtd/cfi_flash.c     (revision 4065)
+++ 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,
@@ -2302,7 +2302,7 @@
 #endif
 
        /* Redundant environment protection ON by default */
-#ifdef CONFIG_ENV_ADDR_REDUND
+#if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_UNPROTECTED)
        flash_protect(FLAG_PROTECT_SET,
                       CONFIG_ENV_ADDR_REDUND,
                       CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,

Regards
Georg



-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im 
Auftrag von Waibel Georg
Gesendet: Dienstag, 26. Februar 2013 12:05
An: '[email protected]'
Betreff: [U-Boot] Flash protection and fw_setenv tool

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

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,


_______________________________________________
U-Boot mailing list
[email protected]
http://lists.denx.de/mailman/listinfo/u-boot
_______________________________________________
U-Boot mailing list
[email protected]
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to