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>
This commit is contained in:
Vadim Bendebury
2016-02-11 15:22:57 -08:00
committed by chrome-bot
parent 758ef07150
commit 7dd904b8d3

View File

@@ -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.