mirror of
https://review.coreboot.org/flashrom.git
synced 2025-07-01 06:01:16 +02: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:
@ -549,6 +549,11 @@ typedef int (*chip_restore_fn_cb_t)(struct flashctx *flash, void *data);
|
||||
typedef int (blockprotect_func_t)(struct flashctx *flash);
|
||||
blockprotect_func_t *lookup_blockprotect_func_ptr(const struct flashchip *const chip);
|
||||
|
||||
struct stage_progress {
|
||||
size_t current;
|
||||
size_t total;
|
||||
};
|
||||
|
||||
struct flashrom_flashctx {
|
||||
struct flashchip *chip;
|
||||
/* FIXME: The memory mappings should be saved in a more structured way. */
|
||||
@ -587,6 +592,7 @@ struct flashrom_flashctx {
|
||||
/* Progress reporting */
|
||||
flashrom_progress_callback *progress_callback;
|
||||
struct flashrom_progress *progress_state;
|
||||
struct stage_progress stage_progress[FLASHROM_PROGRESS_NR];
|
||||
};
|
||||
|
||||
/* Timing used in probe routines. ZERO is -2 to differentiate between an unset
|
||||
@ -677,6 +683,12 @@ int write_flash(struct flashctx *flash, const uint8_t *buf, unsigned int start,
|
||||
*/
|
||||
#define ERROR_FLASHROM_LIMIT -201
|
||||
|
||||
struct cli_progress {
|
||||
unsigned int stage_pc[FLASHROM_PROGRESS_NR];
|
||||
unsigned int visible_stages; /* Bitmask of stages with non-zero progress. */
|
||||
bool stage_setup; /* Flag to know when to reset progress data. */
|
||||
};
|
||||
|
||||
/* cli_common.c */
|
||||
void print_chip_support_status(const struct flashchip *chip);
|
||||
|
||||
@ -716,7 +728,8 @@ __attribute__((format(printf, 2, 3)));
|
||||
#define msg_gspew(...) print(FLASHROM_MSG_SPEW, __VA_ARGS__) /* general debug spew */
|
||||
#define msg_pspew(...) print(FLASHROM_MSG_SPEW, __VA_ARGS__) /* programmer debug spew */
|
||||
#define msg_cspew(...) print(FLASHROM_MSG_SPEW, __VA_ARGS__) /* chip debug spew */
|
||||
void update_progress(struct flashctx *flash, enum flashrom_progress_stage stage, size_t current, size_t total);
|
||||
void init_progress(struct flashctx *flash, enum flashrom_progress_stage stage, size_t total);
|
||||
void update_progress(struct flashctx *flash, enum flashrom_progress_stage stage, size_t increment);
|
||||
|
||||
/* spi.c */
|
||||
struct spi_command {
|
||||
@ -730,4 +743,5 @@ int spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsign
|
||||
int spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
|
||||
|
||||
enum chipbustype get_buses_supported(void);
|
||||
|
||||
#endif /* !__FLASH_H__ */
|
||||
|
Reference in New Issue
Block a user