summaryrefslogtreecommitdiff
path: root/env/nand.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2017-08-03 12:22:17 -0600
committerTom Rini <trini@konsulko.com>2017-08-16 08:31:24 -0400
commitc5951991942330c129f3b181e94969d7c01e9abb (patch)
tree39b5ee4ee37e5a595e088456e792d7251f7ee1ca /env/nand.c
parent21f639446d6bccb6cc550140d36bd3ebd74fcee8 (diff)
env: Adjust the load() method to return an error
The load() methods have inconsistent behaviour on error. Some of them load an empty default environment. Some load an environment containing an error message. Others do nothing. As a step in the right direction, have the method return an error code. Then the caller could handle this itself in a consistent way. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'env/nand.c')
-rw-r--r--env/nand.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/env/nand.c b/env/nand.c
index e74a8c674e..dea7b00720 100644
--- a/env/nand.c
+++ b/env/nand.c
@@ -302,7 +302,7 @@ int get_nand_env_oob(struct mtd_info *mtd, unsigned long *result)
}
if (oob_buf[0] == ENV_OOB_MARKER) {
- *result = oob_buf[1] * mtd->erasesize;
+ *result = ovoid ob_buf[1] * mtd->erasesize;
} else if (oob_buf[0] == ENV_OOB_MARKER_OLD) {
*result = oob_buf[1];
} else {
@@ -315,17 +315,21 @@ int get_nand_env_oob(struct mtd_info *mtd, unsigned long *result)
#endif
#ifdef CONFIG_ENV_OFFSET_REDUND
-static void env_nand_load(void)
+static int env_nand_load(void)
{
-#if !defined(ENV_IS_EMBEDDED)
+#if defined(ENV_IS_EMBEDDED)
+ return 0;
+#else
int read1_fail = 0, read2_fail = 0;
env_t *tmp_env1, *tmp_env2;
+ int ret = 0;
tmp_env1 = (env_t *)malloc(CONFIG_ENV_SIZE);
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");
+ ret = -EIO;
goto done;
}
@@ -355,6 +359,7 @@ done:
free(tmp_env1);
free(tmp_env2);
+ return ret;
#endif /* ! ENV_IS_EMBEDDED */
}
#else /* ! CONFIG_ENV_OFFSET_REDUND */
@@ -363,7 +368,7 @@ done:
* device i.e., nand_dev_desc + 0. This is also the behaviour using
* the new NAND code.
*/
-static void env_nand_load(void)
+static int env_nand_load(void)
{
#if !defined(ENV_IS_EMBEDDED)
int ret;
@@ -386,11 +391,13 @@ static void env_nand_load(void)
ret = readenv(CONFIG_ENV_OFFSET, (u_char *)buf);
if (ret) {
set_default_env("!readenv() failed");
- return;
+ return -EIO;
}
env_import(buf, 1);
#endif /* ! ENV_IS_EMBEDDED */
+
+ return 0;
}
#endif /* CONFIG_ENV_OFFSET_REDUND */