aboutsummaryrefslogtreecommitdiffstats
path: root/env
diff options
context:
space:
mode:
authorSimon Goldschmidt2018-01-31 07:47:13 -0600
committerTom Rini2018-02-01 07:05:53 -0600
commit80719938c9f901cc6b90b85d8065d084a03c06ae (patch)
treea3ea173d81744cd8dc118e1de90520bf6ae1c6af /env
parent2166ebf7831674508425daf50c78e481083c6462 (diff)
downloadu-boot-80719938c9f901cc6b90b85d8065d084a03c06ae.tar.gz
u-boot-80719938c9f901cc6b90b85d8065d084a03c06ae.tar.xz
u-boot-80719938c9f901cc6b90b85d8065d084a03c06ae.zip
env: sf: use env_import_redund to simplify env_sf_load
For the redundant environment configuration, env_sf_load still contained duplicate code instead of using env_import_redund(). Simplify the code by only executing the load twice and delegating everything else to env_import_redund. Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Diffstat (limited to 'env')
-rw-r--r--env/sf.c67
1 files changed, 8 insertions, 59 deletions
diff --git a/env/sf.c b/env/sf.c
index 3dc54410df..6326b37e46 100644
--- a/env/sf.c
+++ b/env/sf.c
@@ -166,10 +166,8 @@ static int env_sf_save(void)
166static int env_sf_load(void) 166static int env_sf_load(void)
167{ 167{
168 int ret; 168 int ret;
169 int crc1_ok = 0, crc2_ok = 0; 169 int read1_fail, read2_fail;
170 env_t *tmp_env1 = NULL; 170 env_t *tmp_env1, *tmp_env2;
171 env_t *tmp_env2 = NULL;
172 env_t *ep = NULL;
173 171
174 tmp_env1 = (env_t *)memalign(ARCH_DMA_MINALIGN, 172 tmp_env1 = (env_t *)memalign(ARCH_DMA_MINALIGN,
175 CONFIG_ENV_SIZE); 173 CONFIG_ENV_SIZE);
@@ -185,63 +183,14 @@ static int env_sf_load(void)
185 if (ret) 183 if (ret)
186 goto out; 184 goto out;
187 185
188 ret = spi_flash_read(env_flash, CONFIG_ENV_OFFSET, 186 read1_fail = spi_flash_read(env_flash, CONFIG_ENV_OFFSET,
189 CONFIG_ENV_SIZE, tmp_env1); 187 CONFIG_ENV_SIZE, tmp_env1);
190 if (ret) { 188 read2_fail = spi_flash_read(env_flash, CONFIG_ENV_OFFSET_REDUND,
191 set_default_env("!spi_flash_read() failed"); 189 CONFIG_ENV_SIZE, tmp_env2);
192 goto err_read;
193 }
194
195 if (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc)
196 crc1_ok = 1;
197 190
198 ret = spi_flash_read(env_flash, CONFIG_ENV_OFFSET_REDUND, 191 ret = env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2,
199 CONFIG_ENV_SIZE, tmp_env2); 192 read2_fail);
200 if (!ret) {
201 if (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc)
202 crc2_ok = 1;
203 }
204 193
205 if (!crc1_ok && !crc2_ok) {
206 set_default_env("!bad CRC");
207 ret = -EIO;
208 goto err_read;
209 } else if (crc1_ok && !crc2_ok) {
210 gd->env_valid = ENV_VALID;
211 } else if (!crc1_ok && crc2_ok) {
212 gd->env_valid = ENV_REDUND;
213 } else if (tmp_env1->flags == ACTIVE_FLAG &&
214 tmp_env2->flags == OBSOLETE_FLAG) {
215 gd->env_valid = ENV_VALID;
216 } else if (tmp_env1->flags == OBSOLETE_FLAG &&
217 tmp_env2->flags == ACTIVE_FLAG) {
218 gd->env_valid = ENV_REDUND;
219 } else if (tmp_env1->flags == tmp_env2->flags) {
220 gd->env_valid = ENV_VALID;
221 } else if (tmp_env1->flags == 0xFF) {
222 gd->env_valid = ENV_VALID;
223 } else if (tmp_env2->flags == 0xFF) {
224 gd->env_valid = ENV_REDUND;
225 } else {
226 /*
227 * this differs from code in env_flash.c, but I think a sane
228 * default path is desirable.
229 */
230 gd->env_valid = ENV_VALID;
231 }
232
233 if (gd->env_valid == ENV_VALID)
234 ep = tmp_env1;
235 else
236 ep = tmp_env2;
237
238 ret = env_import((char *)ep, 0);
239 if (ret) {
240 pr_err("Cannot import environment: errno = %d\n", errno);
241 set_default_env("!env_import failed");
242 }
243
244err_read:
245 spi_flash_free(env_flash); 194 spi_flash_free(env_flash);
246 env_flash = NULL; 195 env_flash = NULL;
247out: 196out: