client: flash animation only on a terminal, exit 1 on failure

Since cd5906674 the flash animation runs whatever stdout is, and a
redirected flash of fullimage.elf wrote a 7 MB log.

flash_pm3() replaced a flash error with the result of
flash_stop_flashing(), always PM3_SUCCESS, so a failed flash ended with
"All done". main() exited 0 after --flash, --dumpmem and
--reboot-to-bootloader whatever happened. dumpmem printed its negative
error code with %u.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Gabriele GristinaandClaude Opus 5.5 committed 2026-11-06 22:15:28 +01:00
1 parent 04cac2724b
commit 49e444b773
3 files changed
+20 -12

No files matched your search

+6 -4
View File
@@ -1027,7 +1027,9 @@ int flash_write(flash_file_t *ctx, flash_dev_t *flash_dev) {
void (*old_sigint)(int) = SIG_ERR;
void (*old_sigwinch)(int) = SIG_ERR;
if (blocks > 50) {
// escape sequences only where they work, not in a redirected stdout
bool animate = (blocks > 50) && g_session.stdoutOnTTY;
if (animate) {
old_sigint = signal(SIGINT, hadouken_on_sigint);
#ifndef _WIN32
@@ -1045,7 +1047,7 @@ int flash_write(flash_file_t *ctx, flash_dev_t *flash_dev) {
}
if (write_block(baddr, ctx->ver_info->magic, data, block_size, flash_dev) < 0) {
if (blocks > 50) {
if (animate) {
hadouken_stop();
restore_progress_signals(old_sigint, old_sigwinch);
}
@@ -1058,13 +1060,13 @@ int flash_write(flash_file_t *ctx, flash_dev_t *flash_dev) {
length -= block_size;
block++;
if (blocks > 50) {
if (animate) {
pct = (int)(block * 100) / blocks;
hadouken_set_progress(pct);
}
}
if (blocks > 50) {
if (animate) {
hadouken_stop();
restore_progress_signals(old_sigint, old_sigwinch);
}
+12 -8
View File
@@ -978,7 +978,7 @@ finish:
} else if (ret == PM3_EOPABORTED) {
PrintAndLogEx(FAILED, "Aborted by user");
} else {
PrintAndLogEx(ERR, "Aborted on error %u", ret);
PrintAndLogEx(ERR, "Aborted on error %d", ret);
}
return ret;
}
@@ -1071,7 +1071,11 @@ finish:
PrintAndLogEx(WARNING, "The flashing procedure failed, follow the suggested steps!");
}
ret = flash_stop_flashing();
// the reset must not hide the error that ended the flashing
int stop_ret = flash_stop_flashing();
if (ret == PM3_SUCCESS) {
ret = stop_ret;
}
CloseProxmark(g_session.current_device);
finish2:
@@ -1500,18 +1504,18 @@ int main(int argc, char *argv[]) {
}
if (dumpmem_mode) {
dumpmem_pm3(port, dumpmem_filename, dumpmem_addr, dumpmem_len, dumpmem_raw);
exit(EXIT_SUCCESS);
int ret = dumpmem_pm3(port, dumpmem_filename, dumpmem_addr, dumpmem_len, dumpmem_raw);
exit((ret == PM3_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE);
}
if (flash_mode) {
flash_pm3(port, flash_num_files, flash_filenames, flash_can_write_bl, flash_force);
exit(EXIT_SUCCESS);
int ret = flash_pm3(port, flash_num_files, flash_filenames, flash_can_write_bl, flash_force);
exit((ret == PM3_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE);
}
if (reboot_bootloader_mode) {
reboot_bootloader_pm3(port);
exit(EXIT_SUCCESS);
int ret = reboot_bootloader_pm3(port);
exit((ret == PM3_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE);
}
if (script_cmd) {