Merge pull request #2208 from wh201906/bootloader

Add hw bootloader
This commit is contained in:
Iceman 2023-12-13 17:55:30 +01:00 committed by GitHub
commit 599b4f6e73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 7 deletions

View file

@ -19,6 +19,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
- Changed `hf 14a info` - now reads and prints QL88 sigantures (@iceman1001) - Changed `hf 14a info` - now reads and prints QL88 sigantures (@iceman1001)
- Fixed `hf iclass dump` truncating AA2 blocks and improve reliability (@nvx) - Fixed `hf iclass dump` truncating AA2 blocks and improve reliability (@nvx)
- Added some info about UMC in "doc/magic_cards_notes.md" (@temskiy) - Added some info about UMC in "doc/magic_cards_notes.md" (@temskiy)
- Added `hw bootloader` to reboot to the bootloader mode (@wh201906)
## [Faraday.4.17511][2023-11-13] ## [Faraday.4.17511][2023-11-13]
- Fixed Python support of `experimental_client_with_swig` (@doegox) - Fixed Python support of `experimental_client_with_swig` (@doegox)

View file

@ -37,6 +37,7 @@
#include "cmdflashmem.h" // get_signature.. #include "cmdflashmem.h" // get_signature..
#include "uart/uart.h" // configure timeout #include "uart/uart.h" // configure timeout
#include "util_posix.h" #include "util_posix.h"
#include "flash.h" // reboot to bootloader mode
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
@ -1100,6 +1101,25 @@ static int CmdBreak(const char *Cmd) {
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static int CmdBootloader(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hw bootloader",
"Reboot Proxmark3 into bootloader mode",
"hw bootloader\n"
);
void *argtable[] = {
arg_param_begin,
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
CLIParserFree(ctx);
clearCommandBuffer();
flash_reboot_bootloader(g_conn.serial_port_name, false);
return PM3_SUCCESS;
}
int set_fpga_mode(uint8_t mode) { int set_fpga_mode(uint8_t mode) {
if (mode < FPGA_BITSTREAM_LF || mode > FPGA_BITSTREAM_HF_15) { if (mode < FPGA_BITSTREAM_LF || mode > FPGA_BITSTREAM_HF_15) {
return PM3_EINVARG; return PM3_EINVARG;
@ -1122,6 +1142,7 @@ static command_t CommandTable[] = {
{"-------------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Hardware") " -----------------------"}, {"-------------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Hardware") " -----------------------"},
{"help", CmdHelp, AlwaysAvailable, "This help"}, {"help", CmdHelp, AlwaysAvailable, "This help"},
{"break", CmdBreak, IfPm3Present, "Send break loop usb command"}, {"break", CmdBreak, IfPm3Present, "Send break loop usb command"},
{"bootloader", CmdBootloader, IfPm3Present, "Reboot Proxmark3 into bootloader mode"},
{"connect", CmdConnect, AlwaysAvailable, "Connect Proxmark3 to serial port"}, {"connect", CmdConnect, AlwaysAvailable, "Connect Proxmark3 to serial port"},
{"dbg", CmdDbg, IfPm3Present, "Set Proxmark3 debug level"}, {"dbg", CmdDbg, IfPm3Present, "Set Proxmark3 debug level"},
{"detectreader", CmdDetectReader, IfPm3Present, "Detect external reader field"}, {"detectreader", CmdDetectReader, IfPm3Present, "Detect external reader field"},

View file

@ -427,7 +427,7 @@ static int get_proxmark_state(uint32_t *state) {
} }
// Enter the bootloader to be able to start flashing // Enter the bootloader to be able to start flashing
static int enter_bootloader(char *serial_port_name) { static int enter_bootloader(char *serial_port_name, bool wait_appear) {
uint32_t state; uint32_t state;
int ret; int ret;
@ -457,7 +457,9 @@ static int enter_bootloader(char *serial_port_name) {
// Let time to OS to make the port disappear // Let time to OS to make the port disappear
msleep(1000); msleep(1000);
if (OpenProxmark(&g_session.current_device, serial_port_name, true, 60, true, FLASHMODE_SPEED)) { if (wait_appear == false) {
return PM3_SUCCESS;
} else if (OpenProxmark(&g_session.current_device, serial_port_name, true, 60, true, FLASHMODE_SPEED)) {
PrintAndLogEx(NORMAL, _GREEN_(" found")); PrintAndLogEx(NORMAL, _GREEN_(" found"));
return PM3_SUCCESS; return PM3_SUCCESS;
} else { } else {
@ -512,7 +514,7 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t
uint32_t chipinfo = 0; uint32_t chipinfo = 0;
int ret; int ret;
ret = enter_bootloader(serial_port_name); ret = enter_bootloader(serial_port_name, true);
if (ret != PM3_SUCCESS) if (ret != PM3_SUCCESS)
return ret; return ret;
@ -601,8 +603,8 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t
} }
// Reboot into bootloader // Reboot into bootloader
int flash_reboot_bootloader(char *serial_port_name) { int flash_reboot_bootloader(char *serial_port_name, bool wait_appear) {
return enter_bootloader(serial_port_name); return enter_bootloader(serial_port_name, wait_appear);
} }
static int write_block(uint32_t address, uint8_t *data, uint32_t length) { static int write_block(uint32_t address, uint8_t *data, uint32_t length) {

View file

@ -44,7 +44,7 @@ typedef struct {
int flash_load(flash_file_t *ctx, bool force); 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_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_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t *max_allowed);
int flash_reboot_bootloader(char *serial_port_name); int flash_reboot_bootloader(char *serial_port_name, bool wait_appear);
int flash_write(flash_file_t *ctx); int flash_write(flash_file_t *ctx);
void flash_free(flash_file_t *ctx); void flash_free(flash_file_t *ctx);
int flash_stop_flashing(void); int flash_stop_flashing(void);

View file

@ -733,7 +733,7 @@ static int reboot_bootloader_pm3(char *serial_port_name) {
} }
PrintAndLogEx(NORMAL, _GREEN_(" found")); PrintAndLogEx(NORMAL, _GREEN_(" found"));
return flash_reboot_bootloader(serial_port_name); return flash_reboot_bootloader(serial_port_name, true);
} }
#endif //LIBPM3 #endif //LIBPM3