]> git.karo-electronics.de Git - karo-tx-uboot.git/commitdiff
env_sf: Fix recovery default
authorMario Schuknecht <mario.schuknecht@dresearch-fe.de>
Tue, 24 Mar 2015 07:59:00 +0000 (08:59 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 7 Apr 2015 12:41:10 +0000 (08:41 -0400)
The u-boot environment is redundantly stored in a NOR flash on our boards.
Redundant means that there are two places to store the environment. But only
one of the two is active. I discovered that on one board the u-boot (env_sf)
uses the environment from the second place and the Kernel (fw_printenv) uses
the environment from the first place.
To decide which is the active environment there is a byte inside the
environment. 1 means active and 0 means obsolete. But on that board both
environments had have a 1. This can happen if a power loss or reset occurs
during writing the environment. In this situation the u-boot (env_sf)
implementation uses the second environment as default. But the Kernel
(fw_printenv) implementation uses the first environment as default.

This commit corrects the default in the u-boot env_sf implementation when a
problem was detected. Now the recovery default is the same like in all other
environment implementations. E.g. fw_printenv and env_flash. This ensures that
u-boot and Kernel use the same environment.

Signed-off-by: Mario Schuknecht <mario.schuknecht@dresearch-fe.de>
common/env_sf.c

index 5e3729c2c2d62dfb201e2329081318f1657fa422..e928f5752cc7c5dddaf13b329a8f1eb67b8b669e 100644 (file)
@@ -188,15 +188,17 @@ void env_relocate_spec(void)
                   tmp_env2->flags == ACTIVE_FLAG) {
                gd->env_valid = 2;
        } else if (tmp_env1->flags == tmp_env2->flags) {
-               gd->env_valid = 2;
+               gd->env_valid = 1;
        } else if (tmp_env1->flags == 0xFF) {
+               gd->env_valid = 1;
+       } else if (tmp_env2->flags == 0xFF) {
                gd->env_valid = 2;
        } else {
                /*
                 * this differs from code in env_flash.c, but I think a sane
                 * default path is desirable.
                 */
-               gd->env_valid = 2;
+               gd->env_valid = 1;
        }
 
        if (gd->env_valid == 1)