From 47cd00fa707af9de76408b69d3e911717dbbfab1 Mon Sep 17 00:00:00 2001 From: wdenk Date: Thu, 6 Mar 2003 13:39:27 +0000 Subject: * Patches by Robert Schwebel, 06 Mar 2003: - fix bug in BOOTP code (must use NetCopyIP) - update of CSB226 port - clear BSS segment on XScale - added support for i2c_init_board() function - update to the Innokom plattform * Extend support for redundand environments for configurations where environment size < sector size --- common/console.c | 2 +- common/env_flash.c | 43 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 8 deletions(-) (limited to 'common') diff --git a/common/console.c b/common/console.c index d888d1ddc7..13ba63b946 100644 --- a/common/console.c +++ b/common/console.c @@ -496,7 +496,7 @@ int console_init_r (void) } #ifndef CFG_CONSOLE_INFO_QUIET - /* Print informations */ + /* Print information */ printf ("In: "); if (stdio_devices[stdin] == NULL) { printf ("No input devices available!\n"); diff --git a/common/env_flash.c b/common/env_flash.c index 69fa2ae21f..19e2282643 100644 --- a/common/env_flash.c +++ b/common/env_flash.c @@ -34,6 +34,7 @@ #include #include #include +#include #if ((CONFIG_COMMANDS&(CFG_CMD_ENV|CFG_CMD_FLASH)) == (CFG_CMD_ENV|CFG_CMD_FLASH)) #define CMD_SAVEENV @@ -41,11 +42,6 @@ #error Cannot use CFG_ENV_ADDR_REDUND without CFG_CMD_ENV & CFG_CMD_FLASH #endif -#if defined(CFG_ENV_SECT_SIZE) && (CFG_ENV_SECT_SIZE > CFG_ENV_SIZE) && \ - defined(CFG_ENV_ADDR_REDUND) -#error CFG_ENV_ADDR_REDUND should not be used when CFG_ENV_SECT_SIZE > CFG_ENV_SIZE -#endif - #if defined(CFG_ENV_SIZE_REDUND) && (CFG_ENV_SIZE_REDUND < CFG_ENV_SIZE) #error CFG_ENV_SIZE_REDUND should not be less then CFG_ENV_SIZE #endif @@ -80,8 +76,9 @@ static env_t *flash_addr = (env_t *)CFG_ENV_ADDR; #ifdef CFG_ENV_ADDR_REDUND static env_t *flash_addr_new = (env_t *)CFG_ENV_ADDR_REDUND; -static ulong end_addr = CFG_ENV_ADDR + CFG_ENV_SIZE - 1; -static ulong end_addr_new = CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1; +/* CFG_ENV_ADDR is supposed to be on sector boundary */ +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; @@ -164,6 +161,8 @@ int env_init(void) int saveenv(void) { int rc = 1; + ulong up_data = 0; + char *saved_data = NULL; debug ("Protect off %08lX ... %08lX\n", (ulong)flash_addr, end_addr); @@ -179,6 +178,22 @@ int saveenv(void) goto Done; } +#if CFG_ENV_SECT_SIZE > CFG_ENV_SIZE + up_data = (end_addr_new + 1 - ((long)flash_addr_new + CFG_ENV_SIZE)); + debug ("Data to save 0x%x\n", up_data); + if (up_data) { + if ((saved_data = malloc(up_data)) == NULL) { + printf("Unable to save the rest of sector (%ld)\n", + up_data); + goto Done; + } + memcpy(saved_data, + (void *)((long)flash_addr_new + CFG_ENV_SIZE), up_data); + debug ("Data (start 0x%x, len 0x%x) saved at 0x%x\n", + (long)flash_addr_new + CFG_ENV_SIZE, + up_data, saved_data); + } +#endif puts ("Erasing Flash..."); debug (" %08lX ... %08lX ...", (ulong)flash_addr_new, end_addr_new); @@ -212,6 +227,18 @@ int saveenv(void) } puts ("done\n"); +#if CFG_ENV_SECT_SIZE > CFG_ENV_SIZE + if (up_data) { /* restore the rest of sector */ + debug ("Restoring the rest of data to 0x%x len 0x%x\n", + (long)flash_addr_new + CFG_ENV_SIZE, up_data); + if (flash_write(saved_data, + (long)flash_addr_new + CFG_ENV_SIZE, + up_data)) { + flash_perror(rc); + goto Done; + } + } +#endif { env_t * etmp = flash_addr; ulong ltmp = end_addr; @@ -226,6 +253,8 @@ int saveenv(void) rc = 0; Done: + if (saved_data) + free (saved_data); /* try to re-protect */ (void) flash_sect_protect (1, (ulong)flash_addr, end_addr); (void) flash_sect_protect (1, (ulong)flash_addr_new, end_addr_new); -- cgit v1.2.1