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

Display progress for what is actually erased/written

The patch updates calculation of total length for the operation
which is displayed with progress.

The reason is: even if, for example the whole chip erase or write
was requested, the actual length of bytes modified can be less than
whole chip size (areas which already have expected content,
are skipped).

Change-Id: I88ac4d40f1b6ccc1636b1efb690d8d68bdebec08
Co-developed-by: Anastasia Klimchuk <aklm@flashrom.org>
Co-developed-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Signed-off-by: Anastasia Klimchuk <aklm@flashrom.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/84439
Reviewed-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Anastasia Klimchuk
2024-09-20 23:33:07 +10:00
parent 34b1a6aa57
commit cbdb8534d2
5 changed files with 113 additions and 9 deletions

View File

@ -47,7 +47,8 @@ static struct {
};
struct progress_user_data {
size_t last_seen; /* % of progress last reported, to be asserted in the progress callback. */
/* % of progress last reported for each operation, to be asserted in the progress callback. */
size_t last_seen[FLASHROM_PROGRESS_NR];
};
static int read_chip(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
@ -86,13 +87,14 @@ static void progress_callback(struct flashctx *flash) {
printf("Progress started for stage %d, initial callback call\n", flash->progress_state->stage);
} else {
/* Progress cannot go backwards. */
assert_true(flash->progress_state->current >= progress_user_data->last_seen);
assert_true(flash->progress_state->current >= progress_user_data->last_seen[flash->progress_state->stage]);
}
if (flash->progress_state->current >= flash->progress_state->total)
printf("Progress complete for stage %d, final callback call\n", flash->progress_state->stage);
if (flash->progress_state->current >= flash->progress_state->total - 1)
printf("Progress almost complete for stage %d, current %ld, total %ld\n",
flash->progress_state->stage, flash->progress_state->current, flash->progress_state->total);
progress_user_data->last_seen = flash->progress_state->current;
progress_user_data->last_seen[flash->progress_state->stage] = flash->progress_state->current;
}
static void setup_chip(struct flashrom_flashctx *flashctx, struct flashrom_layout **layout,
@ -144,6 +146,7 @@ static const struct flashchip chip_8MiB = {
.tested = TEST_OK_PREW,
.read = TEST_READ_INJECTOR,
.write = TEST_WRITE_INJECTOR,
.page_size = 256,
.block_erasers =
{{
/* All blocks within total size of the chip. */
@ -586,6 +589,55 @@ void write_chip_feature_no_erase(void **state)
free(newcontents);
}
void write_chip_feature_no_erase_with_progress(void **state)
{
(void) state; /* unused */
static struct io_mock_fallback_open_state data = {
.noc = 0,
.paths = { NULL },
};
const struct io_mock chip_io = {
.fallback_open_state = &data,
};
struct flashrom_flashctx flashctx = { 0 };
struct flashrom_layout *layout;
/*
* Tricking the dummyflasher by asking to emulate W25Q128FV but giving to it
* mock chip with FEATURE_NO_ERASE.
* As long as chip size is the same, this is fine.
*/
struct flashchip mock_chip = chip_no_erase;
const char *param_dup = "bus=spi,emulate=W25Q128FV";
setup_chip(&flashctx, &layout, &mock_chip, param_dup, &chip_io);
/* See comment in write_chip_test_success */
const char *const filename = "-";
unsigned long size = mock_chip.total_size * 1024;
uint8_t *const newcontents = malloc(size);
assert_non_null(newcontents);
struct progress_user_data progress_user_data = {0};
struct flashrom_progress progress_state = {
.user_data = &progress_user_data
};
flashrom_set_progress_callback(&flashctx, progress_callback, &progress_state);
printf("Write chip operation started.\n");
assert_int_equal(0, read_buf_from_file(newcontents, size, filename));
assert_int_equal(0, flashrom_image_write(&flashctx, newcontents, size, NULL));
assert_int_equal(0, flashrom_image_verify(&flashctx, newcontents, size));
printf("Write chip operation done.\n");
teardown(&layout);
free(newcontents);
}
void write_nonaligned_region_with_dummyflasher_test_success(void **state)
{
(void) state; /* unused */

View File

@ -504,6 +504,7 @@ int main(int argc, char *argv[])
cmocka_unit_test(write_chip_with_progress),
cmocka_unit_test(write_chip_with_dummyflasher_test_success),
cmocka_unit_test(write_chip_feature_no_erase),
cmocka_unit_test(write_chip_feature_no_erase_with_progress),
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),

View File

@ -91,6 +91,7 @@ void write_chip_test_success(void **state);
void write_chip_with_progress(void **state);
void write_chip_with_dummyflasher_test_success(void **state);
void write_chip_feature_no_erase(void **state);
void write_chip_feature_no_erase_with_progress(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);