X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=env%2Fnand.c;h=d0b95f483d34cc4649c39f53355587f3a277fd0c;hb=a70e2aceeb273c9725c916019c24fecd398d9d97;hp=dea7b00720ef9fbb11309abfda326f11d8568aa5;hpb=5619295995e3262bb5770e8b5e945ffdc5442145;p=oweals%2Fu-boot.git diff --git a/env/nand.c b/env/nand.c index dea7b00720..d0b95f483d 100644 --- a/env/nand.c +++ b/env/nand.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2000-2010 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. @@ -10,8 +11,6 @@ * * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH * Andreas Heppel - * - * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -27,7 +26,7 @@ #if defined(CONFIG_CMD_SAVEENV) && defined(CONFIG_CMD_NAND) && \ !defined(CONFIG_SPL_BUILD) #define CMD_SAVEENV -#elif defined(CONFIG_ENV_OFFSET_REDUND) +#elif defined(CONFIG_ENV_OFFSET_REDUND) && !defined(CONFIG_SPL_BUILD) #error CONFIG_ENV_OFFSET_REDUND must have CONFIG_CMD_SAVEENV & CONFIG_CMD_NAND #endif @@ -41,11 +40,9 @@ #endif #if defined(ENV_IS_EMBEDDED) -env_t *env_ptr = &environment; +static env_t *env_ptr = &environment; #elif defined(CONFIG_NAND_ENV_DST) -env_t *env_ptr = (env_t *)CONFIG_NAND_ENV_DST; -#else /* ! ENV_IS_EMBEDDED */ -env_t *env_ptr; +static env_t *env_ptr = (env_t *)CONFIG_NAND_ENV_DST; #endif /* ENV_IS_EMBEDDED */ DECLARE_GLOBAL_DATA_PTR; @@ -79,7 +76,7 @@ static int env_nand_init(void) if (!crc1_ok && !crc2_ok) { gd->env_addr = 0; - gd->env_valid = 0; + gd->env_valid = ENV_INVALID; return 0; } else if (crc1_ok && !crc2_ok) { @@ -320,7 +317,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; @@ -328,7 +325,7 @@ static int env_nand_load(void) tmp_env2 = (env_t *)malloc(CONFIG_ENV_SIZE); if (tmp_env1 == NULL || tmp_env2 == NULL) { puts("Can't allocate buffers for environment\n"); - set_default_env("!malloc() failed"); + set_default_env("malloc() failed", 0); ret = -EIO; goto done; } @@ -336,24 +333,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); @@ -383,18 +364,18 @@ static int env_nand_load(void) if (mtd && !get_nand_env_oob(mtd, &nand_env_oob_offset)) { printf("Found Environment offset in OOB..\n"); } else { - set_default_env("!no env offset in OOB"); + set_default_env("no env offset in OOB", 0); return; } #endif ret = readenv(CONFIG_ENV_OFFSET, (u_char *)buf); if (ret) { - set_default_env("!readenv() failed"); + set_default_env("readenv() failed", 0); return -EIO; } - env_import(buf, 1); + return env_import(buf, 1); #endif /* ! ENV_IS_EMBEDDED */ return 0;