From c150c0f936d68a67f5d8d9b0552d4f256a55c428 Mon Sep 17 00:00:00 2001 From: Piotr Dymacz Date: Thu, 20 Mar 2014 15:48:52 +0100 Subject: [PATCH] Make defenv cmd compatible with env size smaller than env sector size --- u-boot/common/cmd_custom.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/u-boot/common/cmd_custom.c b/u-boot/common/cmd_custom.c index 4db2192..35e6a23 100755 --- a/u-boot/common/cmd_custom.c +++ b/u-boot/common/cmd_custom.c @@ -203,16 +203,35 @@ U_BOOT_CMD(startsc, 1, 0, do_start_sc, "start serial console\n", NULL); * Erase environment sector */ int do_default_env(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]){ - char buf[64]; + int rc, rcode = 0; +#if defined(CFG_ENV_SECT_SIZE) && (CFG_ENV_SECT_SIZE > CFG_ENV_SIZE) + unsigned char env_buffer[CFG_ENV_SECT_SIZE]; +#endif - sprintf(buf, - "erase 0x%lX +0x%lX", - CFG_ENV_ADDR, - CFG_ENV_SIZE); +#if defined(CFG_ENV_SECT_SIZE) && (CFG_ENV_SECT_SIZE > CFG_ENV_SIZE) + /* copy whole env sector to temporary buffer */ + memcpy(env_buffer, (void *)CFG_ENV_ADDR, CFG_ENV_SECT_SIZE); - printf("Executing: %s\n\n", buf); + /* clear env part */ + memset(env_buffer, 0xFF, CFG_ENV_SIZE); +#endif - return(run_command(buf, 0)); + /* erase whole env sector */ + if(flash_sect_erase(CFG_ENV_ADDR, CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1)){ + rcode = 1; + } + +#if defined(CFG_ENV_SECT_SIZE) && (CFG_ENV_SECT_SIZE > CFG_ENV_SIZE) + /* restore data from buffer in FLASH */ + rc = flash_write((char *)env_buffer, CFG_ENV_ADDR, CFG_ENV_SECT_SIZE); + + if(rc != 0){ + flash_perror(rc); + rcode = 1; + } +#endif + + return(rcode); } U_BOOT_CMD(defenv, 1, 1, do_default_env, "reset environment variables to their default values\n", NULL); -- 2.25.1