Hsuan-ting Chen has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/79229?usp=email )
Change subject: erase_func_algo: Avoid putting 0xff into buffers ......................................................................
erase_func_algo: Avoid putting 0xff into buffers
Avoid putting 0xff into either initial_buf or written_buf to prevent ambiguous behaviour.
If there are some addresses that are already 0xff, the flash algorithm might skip erasing them as long as they are already 0xff. This might introduce some ambiguities that there will be more than one valid erasing steps.
Prevent ambiguous behavior by removing all the 0xffs in initial_buf and written_buf.
Change-Id: Ibe159f9f7cf35688cfdbe18245fea2d870386412 Signed-off-by: Hsuan Ting Chen roccochen@google.com --- M tests/erase_func_algo.c 1 file changed, 54 insertions(+), 32 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/29/79229/1
diff --git a/tests/erase_func_algo.c b/tests/erase_func_algo.c index 824a03a..4955f80 100644 --- a/tests/erase_func_algo.c +++ b/tests/erase_func_algo.c @@ -175,6 +175,28 @@ g_test_write_injector = write_chip; g_test_read_injector = read_chip; g_test_erase_injector = block_erase_chip; + int i = 0; + + /* + * Validity check that all the data in the initial_buf or written_buf + * should not be equal to ERASE_VALUE. This might cause unexpected + * behavior if the flash algorithm tries to skip erasing the addresses + * that are already 0xFF. + */ + int erase_value_address_count = 0; + for (i = 0; i < MOCK_CHIP_SIZE; i++) { + if (current_test_case->initial_buf[i] == ERASE_VALUE) { + printf("initial_buf[%d] == ERASE_VALUE\n", i); + erase_value_address_count++; + } + } + for (i = 0; i < MOCK_CHIP_SIZE; i++) { + if (current_test_case->written_buf[i] == ERASE_VALUE) { + printf("written_buf[%d] == ERASE_VALUE\n", i); + erase_value_address_count++; + } + } + assert_int_equal(0, erase_value_address_count);
/* First MOCK_CHIP_SIZE bytes have a meaning and set with given values for this test case. */ memcpy(g_state.buf, current_test_case->initial_buf, MOCK_CHIP_SIZE); @@ -191,7 +213,7 @@ assert_int_equal(0, flashrom_layout_new(layout));
/* Adding regions from test case. */ - int i = 0; + i = 0; while (current_test_case->regions[i].name != NULL) { assert_int_equal(0, flashrom_layout_add_region(*layout, current_test_case->regions[i].start, @@ -266,13 +288,13 @@ */ .chip = &chip_1_2_4_8_16, .regions = {{0, MOCK_CHIP_SIZE/2 - 1, "part1"}, {MOCK_CHIP_SIZE/2, MIN_REAL_CHIP_SIZE - 1, "part2"}}, - .initial_buf = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff}, + .initial_buf = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}, .erased_buf = {ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, - .written_buf = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, + .written_buf = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, .eraseblocks_expected = {{0x8, 0x8}, {0x0, 0x8}}, .eraseblocks_expected_ind = 2, @@ -288,14 +310,14 @@ */ .chip = &chip_1_2_4_8_16, .regions = {{0, 10, "odd1"}, {11, 15, "odd2"}, {MOCK_CHIP_SIZE, MIN_REAL_CHIP_SIZE - 1, "longtail"}}, - .initial_buf = {0xff, 0xff, 0x0, 0xff, 0x0, 0xff, 0x0, 0xff, - 0x0, 0xff, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff}, + .initial_buf = {0x1f, 0x1f, 0x0, 0x1f, 0x0, 0x1f, 0x0, 0x1f, + 0x0, 0x1f, 0x0, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}, .erased_buf = {ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, - .written_buf = {0xff, 0xff, 0x0, 0xff, 0x0, 0xff, 0x20, 0x2f, - 0x20, 0x2f, 0x0, 0xff, 0xff, 0xff, 0x2f, 0x2f}, + .written_buf = {0x1f, 0x1f, 0x0, 0x1f, 0x0, 0x1f, 0x20, 0x2f, + 0x20, 0x2f, 0x0, 0x1f, 0x1f, 0x1f, 0x2f, 0x2f}, .eraseblocks_expected = {{0xb, 0x1}, {0xc, 0x4}, {0xa, 0x1}, {0x8, 0x2}, {0x0, 0x8}}, .eraseblocks_expected_ind = 5, .erase_test_name = "Erase test case #2", @@ -310,14 +332,14 @@ */ .chip = &chip_1_2_4_8_16, .regions = {{0, MIN_REAL_CHIP_SIZE - 1, "whole chip"}}, - .initial_buf = {0xff, 0xff, 0xff, 0xff, 0x11, 0x22, 0x33, 0x44, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, + .initial_buf = {0x1f, 0x1f, 0x1f, 0x1f, 0x11, 0x22, 0x33, 0x44, + 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}, .erased_buf = {ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, - .written_buf = {0xff, 0xff, 0xff, 0xff, 0x1, 0x2, 0x3, 0x4, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, + .written_buf = {0x1f, 0x1f, 0x1f, 0x1f, 0x1, 0x2, 0x3, 0x4, + 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}, .eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected_ind = 1, .erase_test_name = "Erase test case #3", @@ -332,13 +354,13 @@ */ .chip = &chip_1_2_4_8_16, .regions = {{0, MIN_REAL_CHIP_SIZE - 1, "whole chip"}}, - .initial_buf = {0x1, 0x2, 0x3, 0x4, 0xff, 0xff, 0xff, 0xff, + .initial_buf = {0x1, 0x2, 0x3, 0x4, 0x1f, 0x1f, 0x1f, 0x1f, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}, .erased_buf = {ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, - .written_buf = {0x11, 0x22, 0x33, 0x44, 0xff, 0xff, 0xff, 0xff, + .written_buf = {0x11, 0x22, 0x33, 0x44, 0x1f, 0x1f, 0x1f, 0x1f, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8}, .eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected_ind = 1, @@ -354,13 +376,13 @@ */ .chip = &chip_1_2_4_8_16, .regions = {{0, MIN_REAL_CHIP_SIZE - 1, "whole chip"}}, - .initial_buf = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0xff, + .initial_buf = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x1f, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}, .erased_buf = {ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, - .written_buf = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0xff, + .written_buf = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x1f, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8}, .eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected_ind = 1, @@ -444,14 +466,14 @@ .chip = &chip_1_8_16, .regions = {{0, MOCK_CHIP_SIZE/2 - 1, "part1"}, {MOCK_CHIP_SIZE/2, MOCK_CHIP_SIZE - 1, "part2"}, {MOCK_CHIP_SIZE, MIN_REAL_CHIP_SIZE - 1, "longtail"}}, - .initial_buf = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff}, + .initial_buf = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}, .erased_buf = {ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, - .written_buf = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, + .written_buf = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, .eraseblocks_expected = {{0x8, 0x8}, {0x0, 0x8}}, .eraseblocks_expected_ind = 2, .erase_test_name = "Erase test case #9", @@ -466,14 +488,14 @@ */ .chip = &chip_1_8_16, .regions = {{0, 10, "odd1"}, {11, 15, "odd2"}, {MOCK_CHIP_SIZE, MIN_REAL_CHIP_SIZE - 1, "longtail"}}, - .initial_buf = {0xff, 0xff, 0x0, 0xff, 0x0, 0xff, 0x0, 0xff, - 0x0, 0xff, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff}, + .initial_buf = {0x1f, 0x1f, 0x0, 0x1f, 0x0, 0x1f, 0x0, 0x1f, + 0x0, 0x1f, 0x0, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}, .erased_buf = {ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, - .written_buf = {0xff, 0xff, 0x0, 0xff, 0x0, 0xff, 0x20, 0x2f, - 0x20, 0x2f, 0x0, 0xff, 0xff, 0xff, 0x2f, 0x2f}, + .written_buf = {0x1f, 0x1f, 0x0, 0x1f, 0x0, 0x1f, 0x20, 0x2f, + 0x20, 0x2f, 0x0, 0x1f, 0x1f, 0x1f, 0x2f, 0x2f}, .eraseblocks_expected = {{0xb, 0x1}, {0xc, 0x1}, {0xd, 0x1}, {0xe, 0x1}, {0xf, 0x1}, {0x8, 0x1}, {0x9, 0x1}, {0xa, 0x1}, {0x0, 0x8}}, .eraseblocks_expected_ind = 9, @@ -489,14 +511,14 @@ */ .chip = &chip_1_8_16, .regions = {{0, MIN_REAL_CHIP_SIZE - 1, "whole chip"}}, - .initial_buf = {0xff, 0xff, 0xff, 0xff, 0x11, 0x22, 0x33, 0x44, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, + .initial_buf = {0x1f, 0x1f, 0x1f, 0x1f, 0x11, 0x22, 0x33, 0x44, + 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}, .erased_buf = {ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, - .written_buf = {0xff, 0xff, 0xff, 0xff, 0x1, 0x2, 0x3, 0x4, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, + .written_buf = {0x1f, 0x1f, 0x1f, 0x1f, 0x1, 0x2, 0x3, 0x4, + 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}, .eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected_ind = 1, .erase_test_name = "Erase test case #11", @@ -511,13 +533,13 @@ */ .chip = &chip_1_8_16, .regions = {{0, MIN_REAL_CHIP_SIZE - 1, "whole chip"}}, - .initial_buf = {0x1, 0x2, 0x3, 0x4, 0xff, 0xff, 0xff, 0xff, + .initial_buf = {0x1, 0x2, 0x3, 0x4, 0x1f, 0x1f, 0x1f, 0x1f, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}, .erased_buf = {ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, - .written_buf = {0x11, 0x22, 0x33, 0x44, 0xff, 0xff, 0xff, 0xff, + .written_buf = {0x11, 0x22, 0x33, 0x44, 0x1f, 0x1f, 0x1f, 0x1f, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8}, .eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected_ind = 1, @@ -533,13 +555,13 @@ */ .chip = &chip_1_8_16, .regions = {{0, MIN_REAL_CHIP_SIZE - 1, "whole chip"}}, - .initial_buf = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0xff, + .initial_buf = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x1f, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}, .erased_buf = {ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, - .written_buf = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0xff, + .written_buf = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x1f, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8}, .eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected_ind = 1,