[U-Boot-Users] Patch: Changes to support GCC 3.3.x

Yuli Barcohen yuli at arabellasw.com
Thu Mar 4 15:00:05 CET 2004


GCC 3.3.x changed handling of global variables explicitly initialised to
zero. It puts them to .bss section and not .data as it was in older GCC
versions. This change breaks environment redundancy feature. Attached
patch fixes the problem.

-- 
========================================================================
 Yuli Barcohen       | Phone +972-9-765-1788 |  Software Project Leader
 yuli at arabellasw.com | Fax   +972-9-765-7494 | Arabella Software, Israel
========================================================================
-------------- next part --------------
Index: common/env_flash.c
===================================================================
RCS file: /home/CVS/u-boot/u-boot/common/env_flash.c,v
retrieving revision 1.1.1.3
diff -p -u -r1.1.1.3 env_flash.c
--- common/env_flash.c	16 Jul 2003 11:23:42 -0000	1.1.1.3
+++ common/env_flash.c	4 Mar 2004 13:50:24 -0000
@@ -79,9 +79,9 @@ static env_t *flash_addr_new = (env_t *)
 static ulong end_addr = CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1;
 static ulong end_addr_new = CFG_ENV_ADDR_REDUND + CFG_ENV_SECT_SIZE - 1;
 
-static uchar active_flag = 1;
-static uchar obsolete_flag = 0;
-#endif
+#define ACTIVE_FLAG   1
+#define OBSOLETE_FLAG 0
+#endif /* CFG_ENV_ADDR_REDUND */
 
 extern uchar default_environment[];
 extern int default_environment_size;
@@ -127,12 +127,12 @@ int  env_init(void)
 		gd->env_addr  = addr_default;
 		gd->env_valid = 0;
 	}
-	else if (flag1 == active_flag && flag2 == obsolete_flag)
+	else if (flag1 == ACTIVE_FLAG && flag2 == OBSOLETE_FLAG)
 	{
 		gd->env_addr  = addr1;
 		gd->env_valid = 1;
 	}
-	else if (flag1 == obsolete_flag && flag2 == active_flag)
+	else if (flag1 == OBSOLETE_FLAG && flag2 == ACTIVE_FLAG)
 	{
 		gd->env_addr  = addr2;
 		gd->env_valid = 1;
@@ -161,6 +161,7 @@ int saveenv(void)
 {
 	char *saved_data = NULL;
 	int rc = 1;
+	char flag = OBSOLETE_FLAG, new_flag = ACTIVE_FLAG;
 #if CFG_ENV_SECT_SIZE > CFG_ENV_SIZE
 	ulong up_data = 0;
 #endif
@@ -215,11 +216,11 @@ int saveenv(void)
 			(ulong)&(flash_addr_new->crc),
 			sizeof(env_ptr->crc)) ||
 
-	    flash_write((char *)&obsolete_flag,
+	    flash_write(&flag,
 			(ulong)&(flash_addr->flags),
 			sizeof(flash_addr->flags)) ||
 
-	    flash_write((char *)&active_flag,
+	    flash_write(&new_flag,
 			(ulong)&(flash_addr_new->flags),
 			sizeof(flash_addr_new->flags)))
 	{
@@ -373,24 +374,28 @@ void env_relocate_spec (void)
 		end_addr_new = ltmp;
 	}
 
-	if (flash_addr_new->flags != obsolete_flag &&
+	if (flash_addr_new->flags != OBSOLETE_FLAG &&
 	    crc32(0, flash_addr_new->data, ENV_SIZE) ==
 	    flash_addr_new->crc)
 	{
+		char flag = OBSOLETE_FLAG;
+
 		gd->env_valid = 2;
 		flash_sect_protect (0, (ulong)flash_addr_new, end_addr_new);
-		flash_write((char *)&obsolete_flag,
+		flash_write(&flag,
 			    (ulong)&(flash_addr_new->flags),
 			    sizeof(flash_addr_new->flags));
 		flash_sect_protect (1, (ulong)flash_addr_new, end_addr_new);
 	}
 
-	if (flash_addr->flags != active_flag &&
-	    (flash_addr->flags & active_flag) == active_flag)
+	if (flash_addr->flags != ACTIVE_FLAG &&
+	    (flash_addr->flags & ACTIVE_FLAG) == ACTIVE_FLAG)
 	{
+		char flag = ACTIVE_FLAG;
+
 		gd->env_valid = 2;
 		flash_sect_protect (0, (ulong)flash_addr, end_addr);
-		flash_write((char *)&active_flag,
+		flash_write(&flag,
 			    (ulong)&(flash_addr->flags),
 			    sizeof(flash_addr->flags));
 		flash_sect_protect (1, (ulong)flash_addr, end_addr);


More information about the U-Boot mailing list