diff options
author | Simon Glass <sjg@chromium.org> | 2017-08-03 18:21:56 (GMT) |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2017-08-15 12:18:51 (GMT) |
commit | 203e94f6c9ca03e260175ce240f5856507395585 (patch) | |
tree | 1b13b0ff87c4117e18e6ee7db97e09c541724b69 /env/nand.c | |
parent | 75de597d2d91b1102584d4b641daf592d894207e (diff) | |
download | u-boot-203e94f6c9ca03e260175ce240f5856507395585.tar.xz |
env: Add an enum for environment state
At present we have three states for the environment, numbered 0, 1 and 2.
Add an enum to record this to avoid open-coded values.
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'env/nand.c')
-rw-r--r-- | env/nand.c | 29 |
1 files changed, 15 insertions, 14 deletions
@@ -84,37 +84,37 @@ int env_init(void) return 0; } else if (crc1_ok && !crc2_ok) { - gd->env_valid = 1; + gd->env_valid = ENV_VALID; } #ifdef CONFIG_ENV_OFFSET_REDUND else if (!crc1_ok && crc2_ok) { - gd->env_valid = 2; + gd->env_valid = ENV_REDUND; } else { /* both ok - check serial */ if (tmp_env1->flags == 255 && tmp_env2->flags == 0) - gd->env_valid = 2; + gd->env_valid = ENV_REDUND; else if (tmp_env2->flags == 255 && tmp_env1->flags == 0) - gd->env_valid = 1; + gd->env_valid = ENV_VALID; else if (tmp_env1->flags > tmp_env2->flags) - gd->env_valid = 1; + gd->env_valid = ENV_VALID; else if (tmp_env2->flags > tmp_env1->flags) - gd->env_valid = 2; + gd->env_valid = ENV_REDUND; else /* flags are equal - almost impossible */ - gd->env_valid = 1; + gd->env_valid = ENV_VALID; } - if (gd->env_valid == 2) + if (gd->env_valid == ENV_REDUND) env_ptr = tmp_env2; else #endif - if (gd->env_valid == 1) + if (gd->env_valid == ENV_VALID) env_ptr = tmp_env1; gd->env_addr = (ulong)env_ptr->data; #else /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */ gd->env_addr = (ulong)&default_environment[0]; - gd->env_valid = 1; + gd->env_valid = ENV_VALID; #endif /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */ return 0; @@ -217,14 +217,15 @@ int saveenv(void) return ret; #ifdef CONFIG_ENV_OFFSET_REDUND - env_idx = (gd->env_valid == 1); + env_idx = (gd->env_valid == ENV_VALID); #endif ret = erase_and_write_env(&location[env_idx], (u_char *)env_new); #ifdef CONFIG_ENV_OFFSET_REDUND if (!ret) { /* preset other copy for next write */ - gd->env_valid = gd->env_valid == 2 ? 1 : 2; + gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID : + ENV_REDUND; return ret; } @@ -342,10 +343,10 @@ void env_relocate_spec(void) set_default_env("!bad env area"); goto done; } else if (!read1_fail && read2_fail) { - gd->env_valid = 1; + gd->env_valid = ENV_VALID; env_import((char *)tmp_env1, 1); } else if (read1_fail && !read2_fail) { - gd->env_valid = 2; + gd->env_valid = ENV_REDUND; env_import((char *)tmp_env2, 1); } else { env_import_redund((char *)tmp_env1, (char *)tmp_env2); |