mirror of
https://review.coreboot.org/flashrom.git
synced 2025-11-17 21:20:40 +01:00
Complete and fix progress feature implementation for all operations
Original progress reporting implemented in CB:49643 and it has some
issues, for example:
size_t start_address = start;
size_t end_address = len - start;
End address is anything but length minus start address.
update_progress(flash,
FLASHROM_PROGRESS_READ,
/*current*/ start - start_address + to_read,
/*total*/ end_address);
Total should just be length if that's how current value is computed.
---
libflashrom needs to know total size ahead of time.
That's init_progress() and changed update_progress().
It also needs to store the last current value to be able to update it.
That's stage_progress in flashrom_flashctx.
Measuring accurately amount of data which will be read/erased/written
isn't easy because things can be skipped as optimizations. The next
patch in the chain aims to address this, there are TODO/FIXME
comments there.
---
CLI shares terminal with the rest of the code and has to maintain more
state to handle that reasonably well.
Similar to CB:64668, an effort is made to keep the progress on a
single line. Non-progress output is kept track of to know when
moving to a new line cannot be avoided.
---
A script to test the CLI:
\#!/bin/bash
t=${1:-rewW}
shift
if [[ $t =~ r ]]; then
echo ">>> READ"
./flashrom -p dummy:emulate=W25Q128FV,freq=64mhz -r dump.rom --progress "$@"
echo
fi
if [[ $t =~ e ]]; then
echo ">>> ERASE"
./flashrom -p dummy:emulate=W25Q128FV,freq=64mhz -E --progress "$@"
echo
fi
if [[ $t =~ w ]]; then
echo ">>> WRITE (without erase)"
dd if=/dev/zero of=zero.rom bs=1M count=16 2> /dev/null
./flashrom -p dummy:emulate=W25Q128FV,freq=64mhz -w zero.rom --progress "$@"
echo
fi
if [[ $t =~ W ]]; then
echo ">>> WRITE (with erase)"
dd if=/dev/zero of=zero.rom bs=1M count=16 2> /dev/null
dd if=/dev/random of=random.rom bs=1M count=16 2> /dev/null
./flashrom -p dummy:emulate=W25Q128FV,freq=64mhz,image=random.rom -w zero.rom --progress "$@"
echo
fi
Co-developed-by: Anastasia Klimchuk <aklm@flashrom.org>
Co-developed-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Change-Id: If1e40fc97f443c4f0c0501cef11cff1f3f84c051
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Signed-off-by: Anastasia Klimchuk <aklm@flashrom.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/84102
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
This commit is contained in:
@@ -55,7 +55,9 @@ int __wrap_spi_send_command(const struct flashctx *flash,
|
||||
*/
|
||||
return __real_spi_send_command(flash, writecnt, readcnt, writearr, readarr);
|
||||
|
||||
check_expected_ptr(flash);
|
||||
if (!flash->progress_callback)
|
||||
check_expected_ptr(flash);
|
||||
|
||||
assert_int_equal(writecnt, mock_type(int));
|
||||
assert_int_equal(writearr[0], mock_type(int));
|
||||
|
||||
@@ -71,22 +73,22 @@ static void spi_read_progress_cb(struct flashrom_flashctx *flashctx)
|
||||
{
|
||||
struct flashrom_progress *progress_state = flashctx->progress_state;
|
||||
uint32_t *cnt = (uint32_t *) progress_state->user_data;
|
||||
assert_int_equal(0x300, progress_state->total);
|
||||
assert_int_equal(0x400, progress_state->total);
|
||||
switch (*cnt) {
|
||||
case 0:
|
||||
assert_int_equal(0x100, progress_state->current);
|
||||
assert_int_equal(0x0, progress_state->current);
|
||||
break;
|
||||
case 1:
|
||||
assert_int_equal(0x200, progress_state->current);
|
||||
assert_int_equal(0x100, progress_state->current);
|
||||
break;
|
||||
case 2:
|
||||
assert_int_equal(0x300, progress_state->current);
|
||||
assert_int_equal(0x200, progress_state->current);
|
||||
break;
|
||||
case 3:
|
||||
assert_int_equal(0x300, progress_state->current);
|
||||
break;
|
||||
case 4:
|
||||
assert_int_equal(0x300, progress_state->current);
|
||||
assert_int_equal(0x400, progress_state->current);
|
||||
break;
|
||||
default:
|
||||
fail();
|
||||
@@ -94,7 +96,7 @@ static void spi_read_progress_cb(struct flashrom_flashctx *flashctx)
|
||||
(*cnt)++;
|
||||
}
|
||||
|
||||
void spi_read_chunked_test_success(void **state)
|
||||
void default_spi_read_test_success(void **state)
|
||||
{
|
||||
(void) state; /* unused */
|
||||
uint8_t buf[0x400] = { 0x0 };
|
||||
@@ -115,15 +117,16 @@ void spi_read_chunked_test_success(void **state)
|
||||
.user_data = (void *) &cnt,
|
||||
};
|
||||
flashrom_set_progress_callback(&flashctx, spi_read_progress_cb, &progress_state);
|
||||
init_progress(&flashctx, FLASHROM_PROGRESS_READ, 0x400);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
expect_memory(__wrap_spi_send_command, flash,
|
||||
&flashctx, sizeof(flashctx));
|
||||
will_return(__wrap_spi_send_command, JEDEC_WRDI);
|
||||
will_return(__wrap_spi_send_command, JEDEC_READ);
|
||||
will_return(__wrap_spi_send_command, max_data_read);
|
||||
}
|
||||
assert_int_equal(0, spi_chip_read(&flashctx, buf, offset, sizeof(buf)));
|
||||
assert_int_equal(0, default_spi_read(&flashctx, buf, offset, sizeof(buf)));
|
||||
assert_int_equal(5, cnt);
|
||||
|
||||
flashrom_set_progress_callback(&flashctx, NULL, NULL);
|
||||
}
|
||||
|
||||
void spi_write_enable_test_success(void **state)
|
||||
|
||||
Reference in New Issue
Block a user