From: Piotr Dymacz Date: Sun, 9 Jul 2017 20:08:15 +0000 (+0200) Subject: In case of missing recovery script in env, copy it from default one X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=bf3269ac6e7743bef6a282be7c96ffde325c1726;p=oweals%2Fu-boot_mod.git In case of missing recovery script in env, copy it from default one In case of update from some old version on device with correct env in FLASH, recovery script (moved to env variable 'recovery' in 4f11127) isn't available which results in missing 'button recovery mode'. This fixes backward compatibility and ensures that the 'recovery' variable is available in env - in case if it's not available in saved env, value is copied from default env (the one embedded with image). This fixes #154 and closes #131 --- diff --git a/u-boot/common/cmd_nvedit.c b/u-boot/common/cmd_nvedit.c index 55b6180..88499df 100644 --- a/u-boot/common/cmd_nvedit.c +++ b/u-boot/common/cmd_nvedit.c @@ -390,9 +390,9 @@ int _do_setenv(int flag, int argc, char *argv[]){ return(0); } -void setenv(char *varname, char *varvalue){ +int setenv(char *varname, char *varvalue){ char *argv[4] = { "setenv", varname, varvalue, NULL }; - _do_setenv(0, 3, argv); + return _do_setenv(0, 3, argv); } int do_setenv(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){ diff --git a/u-boot/common/main.c b/u-boot/common/main.c index 888a9f3..158e7e3 100644 --- a/u-boot/common/main.c +++ b/u-boot/common/main.c @@ -202,12 +202,28 @@ void main_loop(void) gd->flags &= ~(GD_FLG_SILENT); #endif - /* Do we have recovery script in env var at all? */ c = getenv("recovery"); - if (c == NULL) { - printf_wrn("recovery script is missing\n" - " in env, use 'defenv' to reset env\n\n"); - } else { + + /* + * If recovery script is missing in saved env, try default one, + * copy 'recovery' var (if available) from it and save changes + */ + #if defined(CONFIG_CMD_ENV) && defined(CONFIG_CMD_FLASH) + if (c == NULL && gd->env_valid) { + gd->env_valid = 0; + c = getenv("recovery"); + gd->env_valid = 1; + + if (c) { + if (setenv("recovery", c) == 0) + saveenv(); + else + c = NULL; + } + } + #endif + + if (c) { /* * Always clear values of variables used in recovery * script as they could be accidentally saved before @@ -227,6 +243,13 @@ void main_loop(void) } setenv("cnt", NULL); + } else { + /* + * We should have recovery script at least in def env + * as 'CONFIG_BTN_RECOVERY_SCRIPT' is defined here, + * but show the error anyway, just in case... + */ + printf_err("recovery script is missing in env!\n\n"); } } #endif /* CONFIG_RECOVERY_MODE */ diff --git a/u-boot/include/common.h b/u-boot/include/common.h index cc32b91..caf6dfa 100644 --- a/u-boot/include/common.h +++ b/u-boot/include/common.h @@ -211,7 +211,7 @@ void env_relocate (void); char *getenv (char *); int getenv_r (char *name, char *buf, unsigned len); int saveenv (void); -void setenv (char *, char *); +int setenv (char *, char *); #ifdef CONFIG_ARM