1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-07-03 06:53:18 +02:00

erasure_layout: Fix get_flash_region bug

When flash regions are protected, erase could incorrectly erase regions
which were meant to be protected by requesting the correct size but
using an erase opcode with coarser granularity than desired (for
instance using a 16-byte erase command while attempting to erase only 8
bytes).

This fixes that by exchanging the nesting of the loops over erase blocks
and flash regions.

Old:
 - Select erasefns
 - Loop over blocks to erase for each selected erasefn
  - Loop over programmer flash regions within erase block
    - Erase regions (may fail since selected erasefn will be
      too big if flash region is smaller than erase block)

New:
 - Loop over programmer flash regions within erase block
   - Select erasefns within programer flash region
     - Loop over blocks to erase for each selected erasefn
     - Erase regions

Eraser selection and erasing has also been factored out into a helper
function to manage nesting depth.

TEST=New test cases pass, whereas some of them fail without the changes
     to erasure_layout.c
BUG=https://ticket.coreboot.org/issues/525

Change-Id: Ic5bf9d0f0e4a94c48d6f6e74e3cb9cccdc7adec9
Co-authored-by: Nikolai Artemiev <nartemiev@google.com>
Co-authored-by: Anastasia Klimchuk <aklm@flashrom.org>
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
Signed-off-by: Anastasia Klimchuk <aklm@flashrom.org>
Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/82393
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
This commit is contained in:
Peter Marheine
2024-05-13 15:25:29 +10:00
parent 1ed95233e8
commit 077c641c33
4 changed files with 602 additions and 95 deletions

View File

@ -107,6 +107,7 @@ void selfcheck_board_matches_table(void **state);
/* erase_func_algo.c */
struct CMUnitTest *get_erase_func_algo_tests(size_t *num_tests);
struct CMUnitTest *get_erase_protected_region_algo_tests(size_t *num_tests);
void erase_function_algo_test_success(void **state);
void write_function_algo_test_success(void **state);