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>
This commit is contained in:
Simon Glass
2017-08-03 12:22:17 -06:00
committed by Tom Rini
parent 21f639446d
commit c595199194
14 changed files with 83 additions and 42 deletions

14
env/ubi.c vendored
View File

@@ -91,7 +91,7 @@ static int env_ubi_save(void)
#endif /* CONFIG_CMD_SAVEENV */
#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
static void env_ubi_load(void)
static int env_ubi_load(void)
{
ALLOC_CACHE_ALIGN_BUFFER(char, env1_buf, CONFIG_ENV_SIZE);
ALLOC_CACHE_ALIGN_BUFFER(char, env2_buf, CONFIG_ENV_SIZE);
@@ -115,7 +115,7 @@ static void env_ubi_load(void)
printf("\n** Cannot find mtd partition \"%s\"\n",
CONFIG_ENV_UBI_PART);
set_default_env(NULL);
return;
return -EIO;
}
if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)tmp_env1,
@@ -131,9 +131,11 @@ static void env_ubi_load(void)
}
env_import_redund((char *)tmp_env1, (char *)tmp_env2);
return 0;
}
#else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */
static void env_ubi_load(void)
static int env_ubi_load(void)
{
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
@@ -151,17 +153,19 @@ static void env_ubi_load(void)
printf("\n** Cannot find mtd partition \"%s\"\n",
CONFIG_ENV_UBI_PART);
set_default_env(NULL);
return;
return -EIO;
}
if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, CONFIG_ENV_SIZE)) {
printf("\n** Unable to read env from %s:%s **\n",
CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
set_default_env(NULL);
return;
return -EIO;
}
env_import(buf, 1);
return 0;
}
#endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */