diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2016-02-11 15:22:57 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-02-12 15:33:54 -0800 |
commit | 7dd904b8d339ea5fbcedf596ae74cb512c4d1052 (patch) | |
tree | f707b73e8ea62a00c3ad6667b9c03f74cc671dbf | |
parent | 758ef07150359389288f32c86cabfb069fad266b (diff) | |
download | chrome-ec-7dd904b8d339ea5fbcedf596ae74cb512c4d1052.tar.gz |
cr50: improve loader logic to consider build timestamp as well
When deciding which of the two images to start, A or B - consider the
image timestamp if everything else is equal. The later image should
take precedence.
Also, simplify the existing logic, and consider image A to be 'newer'
if both copies are the same otherwise.
BRANCH=none
BUG=chrome-os-partner:37754
TEST=with the rest of the patches applied, verified that the newer
image of the two gets started
Change-Id: I2c7a50ecfc8d254498c8e96f8651b8d53005897c
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/327414
Reviewed-by: Marius Schilder <mschilder@chromium.org>
-rw-r--r-- | chip/g/loader/main.c | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/chip/g/loader/main.c b/chip/g/loader/main.c index dd538e2c53..985aa34a19 100644 --- a/chip/g/loader/main.c +++ b/chip/g/loader/main.c @@ -63,19 +63,16 @@ void panic_printf(const char *format, ...) /* Returns 1 if version a is newer, 0 otherwise. */ int is_newer_than(const struct SignedHeader *a, const struct SignedHeader *b) { - if (a->epoch_ > b->epoch_) - return 1; - if (a->epoch_ < b->epoch_) - return 0; - if (a->major_ > b->major_) - return 1; - if (a->major_ < b->major_) - return 0; - if (a->minor_ > b->minor_) - return 1; - if (a->minor_ < b->minor_) - return 0; - return 0; + if (a->epoch_ != b->epoch_) + return a->epoch_ > b->epoch_; + if (a->major_ != b->major_) + return a->major_ > b->major_; + if (a->minor_ != b->minor_) + return a->minor_ > b->minor_; + if (a->timestamp_ != b->timestamp_) + return a->timestamp_ > b->timestamp_; + + return 1; /* All else being equal, consider A to be newer. */ } int main(void) @@ -96,11 +93,11 @@ int main(void) * Run from bank a if the versions are equal. */ if (is_newer_than(a, b)) { - first = b; - second = a; - } else { first = a; second = b; + } else { + first = b; + second = a; } if (GREG32(PMU, PWRDN_SCRATCH30) == 0xcafebabe) { /* Launch from the alternate bank first. |