Commit 9d364af23ea26414afd09152e85d62a0d950a50d
Committed by
Tom Rini
1 parent
76768f5f08
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
env: Switch env_nand, env_mmc and env_ubi to env_import_redund
The env_nand, env_mmc and env_ubi implementations all implement redundancy using an identical serial-number scheme. This commit migrates them to use the implementation in env_common, which is functionally identical. Signed-off-by: Fiach Antaw <fiach.antaw@uqconnect.edu.au> Reviewed-by: Tom Rini <trini@konsulko.com>
Showing 3 changed files with 16 additions and 110 deletions Side-by-side Diff
common/env_mmc.c
... | ... | @@ -160,10 +160,6 @@ |
160 | 160 | return (n == blk_cnt) ? 0 : -1; |
161 | 161 | } |
162 | 162 | |
163 | -#ifdef CONFIG_ENV_OFFSET_REDUND | |
164 | -static unsigned char env_flags; | |
165 | -#endif | |
166 | - | |
167 | 163 | int saveenv(void) |
168 | 164 | { |
169 | 165 | ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); |
... | ... | @@ -184,8 +180,6 @@ |
184 | 180 | goto fini; |
185 | 181 | |
186 | 182 | #ifdef CONFIG_ENV_OFFSET_REDUND |
187 | - env_new->flags = ++env_flags; /* increase the serial */ | |
188 | - | |
189 | 183 | if (gd->env_valid == 1) |
190 | 184 | copy = 1; |
191 | 185 | #endif |
... | ... | @@ -236,8 +230,6 @@ |
236 | 230 | struct mmc *mmc; |
237 | 231 | u32 offset1, offset2; |
238 | 232 | int read1_fail = 0, read2_fail = 0; |
239 | - int crc1_ok = 0, crc2_ok = 0; | |
240 | - env_t *ep; | |
241 | 233 | int ret; |
242 | 234 | int dev = mmc_get_env_dev(); |
243 | 235 | const char *errmsg = NULL; |
244 | 236 | |
245 | 237 | |
246 | 238 | |
247 | 239 | |
248 | 240 | |
... | ... | @@ -268,42 +260,20 @@ |
268 | 260 | puts("*** Warning - some problems detected " |
269 | 261 | "reading environment; recovered successfully\n"); |
270 | 262 | |
271 | - crc1_ok = !read1_fail && | |
272 | - (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc); | |
273 | - crc2_ok = !read2_fail && | |
274 | - (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc); | |
275 | - | |
276 | - if (!crc1_ok && !crc2_ok) { | |
263 | + if (read1_fail && read2_fail) { | |
277 | 264 | errmsg = "!bad CRC"; |
278 | 265 | ret = 1; |
279 | 266 | goto fini; |
280 | - } else if (crc1_ok && !crc2_ok) { | |
267 | + } else if (!read1_fail && read2_fail) { | |
281 | 268 | gd->env_valid = 1; |
282 | - } else if (!crc1_ok && crc2_ok) { | |
269 | + env_import((char *)tmp_env1, 1); | |
270 | + } else if (read1_fail && !read2_fail) { | |
283 | 271 | gd->env_valid = 2; |
272 | + env_import((char *)tmp_env2, 1); | |
284 | 273 | } else { |
285 | - /* both ok - check serial */ | |
286 | - if (tmp_env1->flags == 255 && tmp_env2->flags == 0) | |
287 | - gd->env_valid = 2; | |
288 | - else if (tmp_env2->flags == 255 && tmp_env1->flags == 0) | |
289 | - gd->env_valid = 1; | |
290 | - else if (tmp_env1->flags > tmp_env2->flags) | |
291 | - gd->env_valid = 1; | |
292 | - else if (tmp_env2->flags > tmp_env1->flags) | |
293 | - gd->env_valid = 2; | |
294 | - else /* flags are equal - almost impossible */ | |
295 | - gd->env_valid = 1; | |
274 | + env_import_redund((char *)tmp_env1, (char *)tmp_env2); | |
296 | 275 | } |
297 | 276 | |
298 | - free(env_ptr); | |
299 | - | |
300 | - if (gd->env_valid == 1) | |
301 | - ep = tmp_env1; | |
302 | - else | |
303 | - ep = tmp_env2; | |
304 | - | |
305 | - env_flags = ep->flags; | |
306 | - env_import((char *)ep, 0); | |
307 | 277 | ret = 0; |
308 | 278 | |
309 | 279 | fini: |
common/env_nand.c
... | ... | @@ -184,10 +184,6 @@ |
184 | 184 | return ret; |
185 | 185 | } |
186 | 186 | |
187 | -#ifdef CONFIG_ENV_OFFSET_REDUND | |
188 | -static unsigned char env_flags; | |
189 | -#endif | |
190 | - | |
191 | 187 | int saveenv(void) |
192 | 188 | { |
193 | 189 | int ret = 0; |
... | ... | @@ -221,7 +217,6 @@ |
221 | 217 | return ret; |
222 | 218 | |
223 | 219 | #ifdef CONFIG_ENV_OFFSET_REDUND |
224 | - env_new->flags = ++env_flags; /* increase the serial */ | |
225 | 220 | env_idx = (gd->env_valid == 1); |
226 | 221 | #endif |
227 | 222 | |
... | ... | @@ -324,8 +319,7 @@ |
324 | 319 | { |
325 | 320 | #if !defined(ENV_IS_EMBEDDED) |
326 | 321 | int read1_fail = 0, read2_fail = 0; |
327 | - int crc1_ok = 0, crc2_ok = 0; | |
328 | - env_t *ep, *tmp_env1, *tmp_env2; | |
322 | + env_t *tmp_env1, *tmp_env2; | |
329 | 323 | |
330 | 324 | tmp_env1 = (env_t *)malloc(CONFIG_ENV_SIZE); |
331 | 325 | tmp_env2 = (env_t *)malloc(CONFIG_ENV_SIZE); |
332 | 326 | |
333 | 327 | |
334 | 328 | |
335 | 329 | |
336 | 330 | |
... | ... | @@ -344,41 +338,18 @@ |
344 | 338 | puts("*** Warning - some problems detected " |
345 | 339 | "reading environment; recovered successfully\n"); |
346 | 340 | |
347 | - crc1_ok = !read1_fail && | |
348 | - (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc); | |
349 | - crc2_ok = !read2_fail && | |
350 | - (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc); | |
351 | - | |
352 | - if (!crc1_ok && !crc2_ok) { | |
353 | - set_default_env("!bad CRC"); | |
341 | + if (read1_fail && read2_fail) { | |
342 | + set_default_env("!bad env area"); | |
354 | 343 | goto done; |
355 | - } else if (crc1_ok && !crc2_ok) { | |
344 | + } else if (!read1_fail && read2_fail) { | |
356 | 345 | gd->env_valid = 1; |
357 | - } else if (!crc1_ok && crc2_ok) { | |
346 | + env_import((char *)tmp_env1, 1); | |
347 | + } else if (read1_fail && !read2_fail) { | |
358 | 348 | gd->env_valid = 2; |
349 | + env_import((char *)tmp_env2, 1); | |
359 | 350 | } else { |
360 | - /* both ok - check serial */ | |
361 | - if (tmp_env1->flags == 255 && tmp_env2->flags == 0) | |
362 | - gd->env_valid = 2; | |
363 | - else if (tmp_env2->flags == 255 && tmp_env1->flags == 0) | |
364 | - gd->env_valid = 1; | |
365 | - else if (tmp_env1->flags > tmp_env2->flags) | |
366 | - gd->env_valid = 1; | |
367 | - else if (tmp_env2->flags > tmp_env1->flags) | |
368 | - gd->env_valid = 2; | |
369 | - else /* flags are equal - almost impossible */ | |
370 | - gd->env_valid = 1; | |
351 | + env_import_redund((char *)tmp_env1, (char *)tmp_env2); | |
371 | 352 | } |
372 | - | |
373 | - free(env_ptr); | |
374 | - | |
375 | - if (gd->env_valid == 1) | |
376 | - ep = tmp_env1; | |
377 | - else | |
378 | - ep = tmp_env2; | |
379 | - | |
380 | - env_flags = ep->flags; | |
381 | - env_import((char *)ep, 0); | |
382 | 353 | |
383 | 354 | done: |
384 | 355 | free(tmp_env1); |
common/env_ubi.c
... | ... | @@ -33,8 +33,6 @@ |
33 | 33 | |
34 | 34 | #ifdef CONFIG_CMD_SAVEENV |
35 | 35 | #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT |
36 | -static unsigned char env_flags; | |
37 | - | |
38 | 36 | int saveenv(void) |
39 | 37 | { |
40 | 38 | ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); |
... | ... | @@ -50,8 +48,6 @@ |
50 | 48 | return 1; |
51 | 49 | } |
52 | 50 | |
53 | - env_new->flags = ++env_flags; /* increase the serial */ | |
54 | - | |
55 | 51 | if (gd->env_valid == 1) { |
56 | 52 | puts("Writing to redundant UBI... "); |
57 | 53 | if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME_REDUND, |
... | ... | @@ -112,8 +108,7 @@ |
112 | 108 | { |
113 | 109 | ALLOC_CACHE_ALIGN_BUFFER(char, env1_buf, CONFIG_ENV_SIZE); |
114 | 110 | ALLOC_CACHE_ALIGN_BUFFER(char, env2_buf, CONFIG_ENV_SIZE); |
115 | - int crc1_ok = 0, crc2_ok = 0; | |
116 | - env_t *ep, *tmp_env1, *tmp_env2; | |
111 | + env_t *tmp_env1, *tmp_env2; | |
117 | 112 | |
118 | 113 | /* |
119 | 114 | * In case we have restarted u-boot there is a chance that buffer |
... | ... | @@ -148,37 +143,7 @@ |
148 | 143 | CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME_REDUND); |
149 | 144 | } |
150 | 145 | |
151 | - crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc; | |
152 | - crc2_ok = crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc; | |
153 | - | |
154 | - if (!crc1_ok && !crc2_ok) { | |
155 | - set_default_env("!bad CRC"); | |
156 | - return; | |
157 | - } else if (crc1_ok && !crc2_ok) { | |
158 | - gd->env_valid = 1; | |
159 | - } else if (!crc1_ok && crc2_ok) { | |
160 | - gd->env_valid = 2; | |
161 | - } else { | |
162 | - /* both ok - check serial */ | |
163 | - if (tmp_env1->flags == 255 && tmp_env2->flags == 0) | |
164 | - gd->env_valid = 2; | |
165 | - else if (tmp_env2->flags == 255 && tmp_env1->flags == 0) | |
166 | - gd->env_valid = 1; | |
167 | - else if (tmp_env1->flags > tmp_env2->flags) | |
168 | - gd->env_valid = 1; | |
169 | - else if (tmp_env2->flags > tmp_env1->flags) | |
170 | - gd->env_valid = 2; | |
171 | - else /* flags are equal - almost impossible */ | |
172 | - gd->env_valid = 1; | |
173 | - } | |
174 | - | |
175 | - if (gd->env_valid == 1) | |
176 | - ep = tmp_env1; | |
177 | - else | |
178 | - ep = tmp_env2; | |
179 | - | |
180 | - env_flags = ep->flags; | |
181 | - env_import((char *)ep, 0); | |
146 | + env_import_redund((char *)tmp_env1, (char *)tmp_env2); | |
182 | 147 | } |
183 | 148 | #else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */ |
184 | 149 | void env_relocate_spec(void) |