From 0d41ed0bba1ca6788f01c799b5986f4509f6eb22 Mon Sep 17 00:00:00 2001 From: nemanjan00 Date: Tue, 5 Jul 2022 16:15:05 +0200 Subject: [PATCH] --reboot-to-bootloader --- client/src/flash.c | 9 +++++++++ client/src/flash.h | 1 + client/src/proxmark3.c | 46 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/client/src/flash.c b/client/src/flash.c index ad627ffb6..3ced486a6 100644 --- a/client/src/flash.c +++ b/client/src/flash.c @@ -595,6 +595,15 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t return PM3_SUCCESS; } +// Reboot into bootloader +int flash_reboot_bootloader(char *serial_port_name) { + int ret; + + ret = enter_bootloader(serial_port_name); + + return ret; +} + static int write_block(uint32_t address, uint8_t *data, uint32_t length) { uint8_t block_buf[BLOCK_SIZE]; memset(block_buf, 0xFF, BLOCK_SIZE); diff --git a/client/src/flash.h b/client/src/flash.h index 5c2535620..fa5694dbd 100644 --- a/client/src/flash.h +++ b/client/src/flash.h @@ -44,6 +44,7 @@ typedef struct { int flash_load(flash_file_t *ctx, bool force); int flash_prepare(flash_file_t *ctx, int can_write_bl, int flash_size); int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t *max_allowed); +int flash_reboot_bootloader(char *serial_port_name); int flash_write(flash_file_t *ctx); void flash_free(flash_file_t *ctx); int flash_stop_flashing(void); diff --git a/client/src/proxmark3.c b/client/src/proxmark3.c index e15c9ff9f..750d585f3 100644 --- a/client/src/proxmark3.c +++ b/client/src/proxmark3.c @@ -696,6 +696,38 @@ finish2: PrintAndLogEx(INFO, "\nHave a nice day!"); return ret; } + +static int reboot_bootloader_pm3(char *serial_port_name) { + + int ret = PM3_EUNDEF; + + if (serial_port_name == NULL) { + PrintAndLogEx(ERR, "You must specify a port.\n"); + return PM3_EINVARG; + } + + if (OpenProxmark(&g_session.current_device, serial_port_name, true, 60, true, FLASHMODE_SPEED)) { + PrintAndLogEx(NORMAL, _GREEN_(" found")); + } else { + PrintAndLogEx(ERR, "Could not find Proxmark3 on " _RED_("%s") ".\n", serial_port_name); + ret = PM3_ETIMEOUT; + goto finish2; + } + + ret = flash_reboot_bootloader(serial_port_name); + return ret; + +finish2: + if (ret == PM3_SUCCESS) + PrintAndLogEx(SUCCESS, _CYAN_("All done")); + else if (ret == PM3_EOPABORTED) + PrintAndLogEx(FAILED, "Aborted by user"); + else + PrintAndLogEx(ERR, "Aborted on error"); + PrintAndLogEx(INFO, "\nHave a nice day!"); + return ret; +} + #endif //LIBPM3 void pm3_init(void) { @@ -732,6 +764,7 @@ int main(int argc, char *argv[]) { strncpy(exec_name, basename(argv[0]), sizeof(exec_name) - 1); bool flash_mode = false; + bool reboot_bootloader_mode = false; bool flash_can_write_bl = false; bool flash_force = false; bool debug_mode_forced = false; @@ -944,6 +977,12 @@ int main(int argc, char *argv[]) { continue; } + // go to flash mode + if (strcmp(argv[i], "--reboot-to-bootloader") == 0) { + reboot_bootloader_mode = true; + continue; + } + // unlock bootloader area if (strcmp(argv[i], "--unlock-bootloader") == 0) { flash_can_write_bl = true; @@ -1001,6 +1040,11 @@ int main(int argc, char *argv[]) { exit(EXIT_SUCCESS); } + if (reboot_bootloader_mode) { + reboot_bootloader_pm3(port); + exit(EXIT_SUCCESS); + } + if (script_cmd) { while (script_cmd[strlen(script_cmd) - 1] == ' ') script_cmd[strlen(script_cmd) - 1] = 0x00; @@ -1043,7 +1087,7 @@ int main(int argc, char *argv[]) { PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") " mode. Check " _YELLOW_("\"%s -h\"") " if it's not what you want.\n", exec_name); // ascii art only in interactive client - if (!script_cmds_file && !script_cmd && g_session.stdinOnTTY && g_session.stdoutOnTTY && !flash_mode) + if (!script_cmds_file && !script_cmd && g_session.stdinOnTTY && g_session.stdoutOnTTY && !flash_mode && !reboot_bootloader_mode) showBanner(); // Save settings if not loaded from settings json file.