From 49e444b773b70e6f03d1b04b8701847961a73f2e Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Fri, 6 Nov 2026 22:15:28 +0100 Subject: [PATCH] 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 --- CHANGELOG.md | 2 ++ client/src/flash.c | 10 ++++++---- client/src/proxmark3.c | 20 ++++++++++++-------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e135b090..c11771727 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Fixed flashing with redirected output - the progress animation is drawn only when stdout is a terminal (@matrix) +- Fixed `proxmark3 --flash`, `--dumpmem` and `--reboot-to-bootloader` exit status - a failure exits 1, a failed flash no longer ends with `All done` (@matrix) - Fixed `mfulc_des_brute` build on macOS without `openssl@3.6` - OpenSSL is found with `brew --prefix openssl` as in `mfd_aes_brute` (@matrix) - Fixed CI - ProxSpace installs its packages again, WSL builds in its own file system, Ubuntu skips the slow Azure apt mirror (@matrix) - Fixed `recovery.bin` on the AT91 platforms - the bootrom is padded to 0x102000 again, so the OS image is at its load address (@matrix) diff --git a/client/src/flash.c b/client/src/flash.c index 7366bc007..931d055de 100644 --- a/client/src/flash.c +++ b/client/src/flash.c @@ -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); } diff --git a/client/src/proxmark3.c b/client/src/proxmark3.c index 7655800e0..4e7791dc3 100644 --- a/client/src/proxmark3.c +++ b/client/src/proxmark3.c @@ -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) {