From 31f044bd91df58bed6bb8cfadfc187eedac1442e Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Wed, 31 Jan 2018 14:47:11 +0100 Subject: env: move more common code to env_import_redund There is more common code in mmc, nand and ubi env drivers that can be shared by moving to env_import_redund. For this, a status/error value whether the buffers were loaded are passed as additional parameters to env_import_redund. Ideally, these are already returned to the env driver by the storage driver. This is the case for mmc, nand and ubi, so for this change, code deduplicated. Signed-off-by: Simon Goldschmidt Acked-by: Maxime Ripard --- env/nand.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'env/nand.c') diff --git a/env/nand.c b/env/nand.c index 8058b55c50..3e8df39c26 100644 --- a/env/nand.c +++ b/env/nand.c @@ -320,7 +320,7 @@ static int env_nand_load(void) #if defined(ENV_IS_EMBEDDED) return 0; #else - int read1_fail = 0, read2_fail = 0; + int read1_fail, read2_fail; env_t *tmp_env1, *tmp_env2; int ret = 0; @@ -336,24 +336,8 @@ static int env_nand_load(void) read1_fail = readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1); read2_fail = readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2); - if (read1_fail && read2_fail) - puts("*** Error - No Valid Environment Area found\n"); - else if (read1_fail || read2_fail) - puts("*** Warning - some problems detected " - "reading environment; recovered successfully\n"); - - if (read1_fail && read2_fail) { - set_default_env("!bad env area"); - goto done; - } else if (!read1_fail && read2_fail) { - gd->env_valid = ENV_VALID; - env_import((char *)tmp_env1, 1); - } else if (read1_fail && !read2_fail) { - gd->env_valid = ENV_REDUND; - env_import((char *)tmp_env2, 1); - } else { - env_import_redund((char *)tmp_env1, (char *)tmp_env2); - } + ret = env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2, + read2_fail); done: free(tmp_env1); -- cgit v1.2.3