diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2017-02-20 14:05:02 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-02-22 03:29:29 -0800 |
commit | 4236d8d3e9967b1ad9c6c26b259275e2faf6502a (patch) | |
tree | cd85f94d5482ebd8c2eb71ec7111f3328c7ea1e5 | |
parent | 30cc21b9329fa36904b164b330fa6754dff1a4fe (diff) | |
download | chrome-ec-4236d8d3e9967b1ad9c6c26b259275e2faf6502a.tar.gz |
nvmem: do not prefer old partition over new one.
The code deciding which partition to choose properly determines which
one is newer, but invariably populates the cache with the second one,
when both partitions are valid.
This is obviously wrong, on top of that there is no need to check both
partitions' validity, if the newer one checks out.
BRANCH=none
BUG=chrome-os-partner:60555, chrome-os-partner:61972
BUG=chrome-os-partner:61716, chrome-os-partner:61234
BUG=chrome-os-partner:61167, chrome-os-partner:60555
TEST=successfully ran
$ ssh 192.168.1.102 suspend_stress_test --suspend_min 10 \
--suspend_max 10 --wake_max 10 --wake_min 10
for more than 300 cycles (it still is going)
Change-Id: I02d9bb062b9edbbb9787a95ba760872e09ff2761
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/445356
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
-rw-r--r-- | common/nvmem.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/common/nvmem.c b/common/nvmem.c index e0f0ab558b..7ffde9d977 100644 --- a/common/nvmem.c +++ b/common/nvmem.c @@ -278,28 +278,27 @@ static int nvmem_compare_generation(void) static int nvmem_find_partition(void) { int n; + int newest; /* Don't know which partition to use yet */ nvmem_act_partition = NVMEM_NOT_INITIALIZED; + + /* Find the newest partition available in flash. */ + newest = nvmem_compare_generation(); + /* - * Check each partition to determine if the sha is good. If both - * partitions have valid sha(s), then compare generation numbers to - * select the most recent one. + * Find a partition with a valid sha, starting with the newest one. */ - for (n = 0; n < NVMEM_NUM_PARTITIONS; n++) - if (nvmem_partition_read_verify(n) == EC_SUCCESS) { - if (nvmem_act_partition == NVMEM_NOT_INITIALIZED) - nvmem_act_partition = n; - else - nvmem_act_partition = - nvmem_compare_generation(); - } else { - ccprintf("%s:%d partiton %d verification FAILED\n", - __func__, __LINE__, n); - } + for (n = 0; n < NVMEM_NUM_PARTITIONS; n++) { + int check_part = (n + newest) % NVMEM_NUM_PARTITIONS; - if (nvmem_act_partition != NVMEM_NOT_INITIALIZED) - return EC_SUCCESS; + if (nvmem_partition_read_verify(check_part) == EC_SUCCESS) { + nvmem_act_partition = check_part; + return EC_SUCCESS; + } + ccprintf("%s:%d partiton %d verification FAILED\n", + __func__, __LINE__, check_part); + } /* * If active_partition is still not selected, then neither partition |