diff --git a/cli_classic.c b/cli_classic.c index 21a9424fd..e39496101 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -1491,15 +1491,6 @@ int main(int argc, char *argv[]) ret = do_extract(&context); else if (options.erase_it) { 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) ret = do_write(&context, options.filename, options.referencefile); diff --git a/flashrom.c b/flashrom.c index c5a2d6941..100fc480a 100644 --- a/flashrom.c +++ b/flashrom.c @@ -1966,13 +1966,27 @@ void finalize_flash_access(struct flashctx *const flash) int flashrom_flash_erase(struct flashctx *const flashctx) { - if (prepare_flash_access(flashctx, false, false, true, flashctx->flags.verify_after_write)) - return 1; + if (prepare_flash_access(flashctx, false, false, true, flashctx->flags.verify_after_write)) { + 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); 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; } @@ -2063,8 +2077,12 @@ int flashrom_image_write(struct flashctx *const flashctx, void *const buffer, co } #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; + } /* If given, assume flash chip contains same data as `refcontents`. */ if (refcontents) { diff --git a/include/flash.h b/include/flash.h index c3321fcee..d66556249 100644 --- a/include/flash.h +++ b/include/flash.h @@ -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_INTERNAL_ERROR -2 +#define ERROR_FLASHROM_PREPARE_FLASH_ACCESS -3 struct cli_progress { unsigned int stage_pc[FLASHROM_PROGRESS_NR]; diff --git a/tests/chip_wp.c b/tests/chip_wp.c index d735b0cfd..5061a666e 100644 --- a/tests/chip_wp.c +++ b/tests/chip_wp.c @@ -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 protected and we're trying to erase the whole chip, erase should fail. */ - assert_int_equal(1, flashrom_flash_erase(&flash)); + assert_int_equal(ERROR_FLASHROM_PREPARE_FLASH_ACCESS, flashrom_flash_erase(&flash)); teardown(&layout);