mirror of
https://review.coreboot.org/flashrom.git
synced 2025-10-20 17:20:53 +02:00
erase: Print message when prepare_flash_access failed
prepare_flash_access provides check the required conditions for erase operation to be performed. If the check fails, operation aborts, i.e. erase does not start. However for the user this information is not clearly messaged, and even more, user still has emergency_help_message. The patch adds message for the user when prepare_flash_access failed and operation itself hasn't started. The message can be repro with dummyflasher for erase ./flashrom -p dummy:hwwp=yes,emulate=S25FL128L --wp-enable \ --wp-range 0x00040000,0x00fc0000 \ -l <(echo '00000000:0004ffff part1') -i part1 -E for write ./flashrom -p dummy:hwwp=yes,emulate=S25FL128L --wp-enable \ --wp-range 0x00040000,0x00fc0000 \ -l <(echo '00000000:0004ffff part1') -i part1 -w <some file> BEFORE for erase, output ends with: can_change_target_regions: cannot fully update part1 region (00000000..0x04ffff) due to chip's write-protection. At least one target region is not fully writable. Aborting. Your flash chip is in an unknown state. Please report this to the mailing list at flashrom@flashrom.org or on chat (see https://flashrom.org/contact.html for details), thanks! So it says "Aborting" but then "Your flash chip is in an unknown state" and likely the user will focus on the second part, the scary message for write, the operation is actually Aborting (no unknown state message) AFTER for erase, output ends with: can_change_target_regions: cannot fully update part1 region (00000000..0x04ffff) due to chip's write-protection. At least one target region is not fully writable. Aborting. Error: some of the required checks to prepare flash access failed. Earlier messages should give more details. Erase operation has not started. for write I added the same info for consistency: can_change_target_regions: cannot fully update part1 region (00000000..0x04ffff) due to chip's write-protection. At least one target region is not fully writable. Aborting. Error: some of the required checks to prepare flash access failed. Earlier messages should give more details. Write operation has not started. Change-Id: Id251c2b7f12df3378feb84b5761581dd272240be Tested-by: Michał Iwanicki <michal.iwanicki@3mdeb.com> Signed-off-by: Anastasia Klimchuk <aklm@flashrom.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/89413 Reviewed-by: Peter Marheine <pmarheine@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Michał Iwanicki <michal.iwanicki@3mdeb.com> Reviewed-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
This commit is contained in:
@@ -1491,15 +1491,6 @@ int main(int argc, char *argv[])
|
|||||||
ret = do_extract(&context);
|
ret = do_extract(&context);
|
||||||
else if (options.erase_it) {
|
else if (options.erase_it) {
|
||||||
ret = flashrom_flash_erase(&context);
|
ret = flashrom_flash_erase(&context);
|
||||||
/*
|
|
||||||
* FIXME: Do we really want the scary warning if erase failed?
|
|
||||||
* After all, after erase the chip is either blank or partially
|
|
||||||
* blank or it has the old contents. A blank chip won't boot,
|
|
||||||
* so if the user wanted erase and reboots afterwards, the user
|
|
||||||
* knows very well that booting won't work.
|
|
||||||
*/
|
|
||||||
if (ret)
|
|
||||||
emergency_help_message();
|
|
||||||
}
|
}
|
||||||
else if (options.write_it)
|
else if (options.write_it)
|
||||||
ret = do_write(&context, options.filename, options.referencefile);
|
ret = do_write(&context, options.filename, options.referencefile);
|
||||||
|
24
flashrom.c
24
flashrom.c
@@ -1966,13 +1966,27 @@ void finalize_flash_access(struct flashctx *const flash)
|
|||||||
|
|
||||||
int flashrom_flash_erase(struct flashctx *const flashctx)
|
int flashrom_flash_erase(struct flashctx *const flashctx)
|
||||||
{
|
{
|
||||||
if (prepare_flash_access(flashctx, false, false, true, flashctx->flags.verify_after_write))
|
if (prepare_flash_access(flashctx, false, false, true, flashctx->flags.verify_after_write)) {
|
||||||
return 1;
|
msg_gerr("Error: some of the required checks to prepare flash access failed. "
|
||||||
|
"Earlier messages should give more details.\n"
|
||||||
|
"Erase operation has not started.\n");
|
||||||
|
return ERROR_FLASHROM_PREPARE_FLASH_ACCESS;
|
||||||
|
}
|
||||||
|
|
||||||
const int ret = erase_by_layout(flashctx);
|
const int ret = erase_by_layout(flashctx);
|
||||||
|
|
||||||
finalize_flash_access(flashctx);
|
finalize_flash_access(flashctx);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FIXME: Do we really want the scary warning if erase failed?
|
||||||
|
* After all, after erase the chip is either blank or partially
|
||||||
|
* blank or it has the old contents. A blank chip won't boot,
|
||||||
|
* so if the user wanted erase and reboots afterwards, the user
|
||||||
|
* knows very well that booting won't work.
|
||||||
|
*/
|
||||||
|
if (ret)
|
||||||
|
emergency_help_message();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2063,8 +2077,12 @@ int flashrom_image_write(struct flashctx *const flashctx, void *const buffer, co
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (prepare_flash_access(flashctx, false, true, false, verify))
|
if (prepare_flash_access(flashctx, false, true, false, verify)) {
|
||||||
|
msg_gerr("Error: some of the required checks to prepare flash access failed. "
|
||||||
|
"Earlier messages should give more details.\n"
|
||||||
|
"Write operation has not started.\n");
|
||||||
goto _free_ret;
|
goto _free_ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* If given, assume flash chip contains same data as `refcontents`. */
|
/* If given, assume flash chip contains same data as `refcontents`. */
|
||||||
if (refcontents) {
|
if (refcontents) {
|
||||||
|
@@ -712,6 +712,7 @@ int write_flash(struct flashctx *flash, const uint8_t *buf, unsigned int start,
|
|||||||
|
|
||||||
#define ERROR_FLASHROM_PROBE_NO_CHIPS_FOUND -1
|
#define ERROR_FLASHROM_PROBE_NO_CHIPS_FOUND -1
|
||||||
#define ERROR_FLASHROM_PROBE_INTERNAL_ERROR -2
|
#define ERROR_FLASHROM_PROBE_INTERNAL_ERROR -2
|
||||||
|
#define ERROR_FLASHROM_PREPARE_FLASH_ACCESS -3
|
||||||
|
|
||||||
struct cli_progress {
|
struct cli_progress {
|
||||||
unsigned int stage_pc[FLASHROM_PROGRESS_NR];
|
unsigned int stage_pc[FLASHROM_PROGRESS_NR];
|
||||||
|
@@ -285,7 +285,7 @@ void full_chip_erase_with_wp_dummyflasher_test_success(void **state)
|
|||||||
/* Try erasing the chip again. Now that WP is active, the first 4 KiB is
|
/* Try erasing the chip again. Now that WP is active, the first 4 KiB is
|
||||||
protected and we're trying to erase the whole chip, erase should
|
protected and we're trying to erase the whole chip, erase should
|
||||||
fail. */
|
fail. */
|
||||||
assert_int_equal(1, flashrom_flash_erase(&flash));
|
assert_int_equal(ERROR_FLASHROM_PREPARE_FLASH_ACCESS, flashrom_flash_erase(&flash));
|
||||||
|
|
||||||
teardown(&layout);
|
teardown(&layout);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user