Anastasia Klimchuk has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/84203?usp=email )
Change subject: [WIP] Fix FEATURE_NO_ERASE chips and add test for them ......................................................................
[WIP] Fix FEATURE_NO_ERASE chips and add test for them
Change-Id: I582fe00da0715e9b5e92fcc9d15d5a90a2615117 Signed-off-by: Anastasia Klimchuk aklm@flashrom.org --- M flashrom.c M tests/chip.c M tests/tests.c M tests/tests.h 4 files changed, 45 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/03/84203/1
diff --git a/flashrom.c b/flashrom.c index 01a41c4..5dee1fc 100644 --- a/flashrom.c +++ b/flashrom.c @@ -482,7 +482,7 @@ return 1; }
- if (flash->mst->buses_supported & BUS_SPI) { + if (!(flash->chip->feature_bits & FEATURE_NO_ERASE) && flash->mst->buses_supported & BUS_SPI) { const uint8_t *opcode = spi_get_opcode_from_erasefn(eraser.block_erase); for (int i = 0; opcode[i]; i++) { if (!spi_probe_opcode(flash, opcode[i])) { diff --git a/tests/chip.c b/tests/chip.c index 3e1ae3b..9e87d30 100644 --- a/tests/chip.c +++ b/tests/chip.c @@ -132,6 +132,22 @@ }}, };
+static const struct flashchip chip_no_erase = { + .vendor = "aklm", + .bustype = BUS_SPI, + .total_size = MOCK_CHIP_SIZE / KiB, + .tested = TEST_OK_PREW, + .read = TEST_READ_INJECTOR, + .write = TEST_WRITE_INJECTOR, + .page_size = 256, + .feature_bits = FEATURE_NO_ERASE | FEATURE_ERASED_ZERO, + .block_erasers = + {{ + .eraseblocks = { {MOCK_CHIP_SIZE, 1} }, + .block_erase = SPI_BLOCK_ERASE_EMULATION, + }}, +}; + /* Setup the struct for W25Q128.V, all values come from flashchips.c */ static const struct flashchip chip_W25Q128_V = { .vendor = "aklm&dummyflasher", @@ -384,6 +400,32 @@ free(newcontents); }
+void write_chip_feature_no_erase(void **state) +{ + (void) state; /* unused */ + + g_test_write_injector = write_chip; + g_test_read_injector = read_chip; + struct flashrom_flashctx flashctx = { 0 }; + struct flashrom_layout *layout; + struct flashchip mock_chip = chip_no_erase; + const char *param = "bus=spi"; + + setup_chip(&flashctx, &layout, &mock_chip, param, NULL); + + uint8_t *const newcontents = malloc(MOCK_CHIP_SIZE); + assert_non_null(newcontents); + memset(newcontents, 0xCC, MOCK_CHIP_SIZE); + + printf("Write chip operation started.\n"); + assert_int_equal(0, flashrom_image_write(&flashctx, newcontents, MOCK_CHIP_SIZE, NULL)); + assert_int_equal(0, flashrom_image_verify(&flashctx, newcontents, MOCK_CHIP_SIZE)); + printf("Write chip operation done.\n"); + + teardown(&layout); + + free(newcontents); +} void write_nonaligned_region_with_dummyflasher_test_success(void **state) { (void) state; /* unused */ diff --git a/tests/tests.c b/tests/tests.c index 165390a..78f1b47 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -498,6 +498,7 @@ cmocka_unit_test(read_chip_with_dummyflasher_test_success), cmocka_unit_test(write_chip_test_success), cmocka_unit_test(write_chip_with_dummyflasher_test_success), + cmocka_unit_test(write_chip_feature_no_erase), cmocka_unit_test(write_nonaligned_region_with_dummyflasher_test_success), cmocka_unit_test(verify_chip_test_success), cmocka_unit_test(verify_chip_with_dummyflasher_test_success), diff --git a/tests/tests.h b/tests/tests.h index 8cf8be0..3536d1d 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -86,6 +86,7 @@ void read_chip_with_dummyflasher_test_success(void **state); void write_chip_test_success(void **state); void write_chip_with_dummyflasher_test_success(void **state); +void write_chip_feature_no_erase(void **state); void write_nonaligned_region_with_dummyflasher_test_success(void **state); void verify_chip_test_success(void **state); void verify_chip_with_dummyflasher_test_success(void **state);