diff options
author | Simon Glass <sjg@chromium.org> | 2017-08-03 12:22:17 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2017-08-16 08:31:24 -0400 |
commit | c5951991942330c129f3b181e94969d7c01e9abb (patch) | |
tree | 39b5ee4ee37e5a595e088456e792d7251f7ee1ca /env/mmc.c | |
parent | 21f639446d6bccb6cc550140d36bd3ebd74fcee8 (diff) | |
download | u-boot-c5951991942330c129f3b181e94969d7c01e9abb.zip u-boot-c5951991942330c129f3b181e94969d7c01e9abb.tar.gz u-boot-c5951991942330c129f3b181e94969d7c01e9abb.tar.bz2 |
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/mmc.c')
-rw-r--r-- | env/mmc.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -207,7 +207,7 @@ static inline int read_env(struct mmc *mmc, unsigned long size, } #ifdef CONFIG_ENV_OFFSET_REDUND -static void env_mmc_load(void) +static int env_mmc_load(void) { #if !defined(ENV_IS_EMBEDDED) struct mmc *mmc; @@ -224,13 +224,13 @@ static void env_mmc_load(void) errmsg = init_mmc_for_env(mmc); if (errmsg) { - ret = 1; + ret = -EIO; goto err; } if (mmc_get_env_addr(mmc, 0, &offset1) || mmc_get_env_addr(mmc, 1, &offset2)) { - ret = 1; + ret = -EIO; goto fini; } @@ -245,7 +245,7 @@ static void env_mmc_load(void) if (read1_fail && read2_fail) { errmsg = "!bad CRC"; - ret = 1; + ret = -EIO; goto fini; } else if (!read1_fail && read2_fail) { gd->env_valid = ENV_VALID; @@ -264,10 +264,12 @@ fini: err: if (ret) set_default_env(errmsg); + #endif + return ret; } #else /* ! CONFIG_ENV_OFFSET_REDUND */ -static void env_mmc_load(void) +static int env_mmc_load(void) { #if !defined(ENV_IS_EMBEDDED) ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); @@ -281,18 +283,18 @@ static void env_mmc_load(void) errmsg = init_mmc_for_env(mmc); if (errmsg) { - ret = 1; + ret = -EIO; goto err; } if (mmc_get_env_addr(mmc, 0, &offset)) { - ret = 1; + ret = -EIO; goto fini; } if (read_env(mmc, CONFIG_ENV_SIZE, offset, buf)) { errmsg = "!read failed"; - ret = 1; + ret = -EIO; goto fini; } @@ -305,6 +307,7 @@ err: if (ret) set_default_env(errmsg); #endif + return ret; } #endif /* CONFIG_ENV_OFFSET_REDUND */ |