mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
flasher: add option --force rather than interactive prompt
This commit is contained in:
parent
cb209a9b47
commit
da908315b0
4 changed files with 59 additions and 28 deletions
|
@ -235,17 +235,6 @@ static int check_segs(flash_file_t *ctx, int can_write_bl, uint32_t flash_size)
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ask_confirmation(void) {
|
|
||||||
PrintAndLogEx(INFO, "Make sure to flash a correct and up-to-date version");
|
|
||||||
PrintAndLogEx(NORMAL, "Do you want to flash the current image? (yes/no)");
|
|
||||||
char answer[10];
|
|
||||||
if ((fgets (answer, sizeof(answer), stdin) == NULL) || (strncmp(answer, "yes", 3) != 0)) {
|
|
||||||
return PM3_EOPABORTED;
|
|
||||||
} else {
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int print_and_validate_version(struct version_information_t *vi) {
|
static int print_and_validate_version(struct version_information_t *vi) {
|
||||||
if (vi->magic != VERSION_INFORMATION_MAGIC)
|
if (vi->magic != VERSION_INFORMATION_MAGIC)
|
||||||
return PM3_EFILE;
|
return PM3_EFILE;
|
||||||
|
@ -255,7 +244,7 @@ static int print_and_validate_version(struct version_information_t *vi) {
|
||||||
if (strlen(g_version_information.armsrc) == 9) {
|
if (strlen(g_version_information.armsrc) == 9) {
|
||||||
if (strncmp(vi->armsrc, g_version_information.armsrc, 9) != 0) {
|
if (strncmp(vi->armsrc, g_version_information.armsrc, 9) != 0) {
|
||||||
PrintAndLogEx(WARNING, _RED_("ARM firmware does not match the source at the time the client was compiled"));
|
PrintAndLogEx(WARNING, _RED_("ARM firmware does not match the source at the time the client was compiled"));
|
||||||
return ask_confirmation();
|
return PM3_EINVARG;
|
||||||
} else {
|
} else {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -264,7 +253,7 @@ static int print_and_validate_version(struct version_information_t *vi) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load an ELF file for flashing
|
// Load an ELF file for flashing
|
||||||
int flash_load(flash_file_t *ctx) {
|
int flash_load(flash_file_t *ctx, bool force) {
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
Elf32_Ehdr_t *ehdr;
|
Elf32_Ehdr_t *ehdr;
|
||||||
Elf32_Shdr_t *shdrs = NULL;
|
Elf32_Shdr_t *shdrs = NULL;
|
||||||
|
@ -364,13 +353,13 @@ int flash_load(flash_file_t *ctx) {
|
||||||
}
|
}
|
||||||
if (res == PM3_SUCCESS)
|
if (res == PM3_SUCCESS)
|
||||||
return res;
|
return res;
|
||||||
if (res == PM3_EOPABORTED)
|
// We could not find proper version_information
|
||||||
goto fail;
|
if (res == PM3_EUNDEF)
|
||||||
// We could not find proper version_information, so we ask for confirmation
|
PrintAndLogEx(WARNING, "Unable to check version_information");
|
||||||
PrintAndLogEx(WARNING, "Unable to check version_information");
|
PrintAndLogEx(INFO, "Make sure to flash a correct and up-to-date version");
|
||||||
res = ask_confirmation();
|
PrintAndLogEx(INFO, "You can force flashing this firmware by using the option '--force'");
|
||||||
if (res == PM3_SUCCESS)
|
if (force)
|
||||||
return res;
|
return PM3_SUCCESS;
|
||||||
fail:
|
fail:
|
||||||
flash_free(ctx);
|
flash_free(ctx);
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -41,7 +41,7 @@ typedef struct {
|
||||||
flash_seg_t *segments;
|
flash_seg_t *segments;
|
||||||
} flash_file_t;
|
} flash_file_t;
|
||||||
|
|
||||||
int flash_load(flash_file_t *ctx);
|
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_write(flash_file_t *ctx);
|
int flash_write(flash_file_t *ctx);
|
||||||
|
|
|
@ -576,7 +576,8 @@ static void show_help(bool showFullHelp, char *exec_name) {
|
||||||
PrintAndLogEx(NORMAL, " --incognito do not use history, prefs file nor log files");
|
PrintAndLogEx(NORMAL, " --incognito do not use history, prefs file nor log files");
|
||||||
PrintAndLogEx(NORMAL, "\nOptions in flasher mode:");
|
PrintAndLogEx(NORMAL, "\nOptions in flasher mode:");
|
||||||
PrintAndLogEx(NORMAL, " --flash flash Proxmark3, requires at least one --image");
|
PrintAndLogEx(NORMAL, " --flash flash Proxmark3, requires at least one --image");
|
||||||
PrintAndLogEx(NORMAL, " --unlock-bootloader Enable flashing of bootloader area *DANGEROUS* (need --flash or --flash-info)");
|
PrintAndLogEx(NORMAL, " --unlock-bootloader Enable flashing of bootloader area *DANGEROUS* (need --flash)");
|
||||||
|
PrintAndLogEx(NORMAL, " --force Enable flashing even if firmware seems to not match client version");
|
||||||
PrintAndLogEx(NORMAL, " --image <imagefile> image to flash. Can be specified several times.");
|
PrintAndLogEx(NORMAL, " --image <imagefile> image to flash. Can be specified several times.");
|
||||||
PrintAndLogEx(NORMAL, "\nExamples:");
|
PrintAndLogEx(NORMAL, "\nExamples:");
|
||||||
PrintAndLogEx(NORMAL, "\n to run Proxmark3 client:\n");
|
PrintAndLogEx(NORMAL, "\n to run Proxmark3 client:\n");
|
||||||
|
@ -602,7 +603,7 @@ static void show_help(bool showFullHelp, char *exec_name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int flash_pm3(char *serial_port_name, uint8_t num_files, char *filenames[FLASH_MAX_FILES], bool can_write_bl) {
|
static int flash_pm3(char *serial_port_name, uint8_t num_files, char *filenames[FLASH_MAX_FILES], bool can_write_bl, bool force) {
|
||||||
|
|
||||||
int ret = PM3_EUNDEF;
|
int ret = PM3_EUNDEF;
|
||||||
flash_file_t files[FLASH_MAX_FILES];
|
flash_file_t files[FLASH_MAX_FILES];
|
||||||
|
@ -635,7 +636,7 @@ static int flash_pm3(char *serial_port_name, uint8_t num_files, char *filenames[
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0 ; i < num_files; ++i) {
|
for (int i = 0 ; i < num_files; ++i) {
|
||||||
ret = flash_load(&files[i]);
|
ret = flash_load(&files[i], force);
|
||||||
if (ret != PM3_SUCCESS) {
|
if (ret != PM3_SUCCESS) {
|
||||||
goto finish2;
|
goto finish2;
|
||||||
}
|
}
|
||||||
|
@ -732,6 +733,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
bool flash_mode = false;
|
bool flash_mode = false;
|
||||||
bool flash_can_write_bl = false;
|
bool flash_can_write_bl = false;
|
||||||
|
bool flash_force = false;
|
||||||
bool debug_mode_forced = false;
|
bool debug_mode_forced = false;
|
||||||
int flash_num_files = 0;
|
int flash_num_files = 0;
|
||||||
char *flash_filenames[FLASH_MAX_FILES];
|
char *flash_filenames[FLASH_MAX_FILES];
|
||||||
|
@ -948,6 +950,12 @@ int main(int argc, char *argv[]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// force flash even if firmware seems to not match client version
|
||||||
|
if (strcmp(argv[i], "--force") == 0) {
|
||||||
|
flash_force = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// flash file
|
// flash file
|
||||||
if (strcmp(argv[i], "--image") == 0) {
|
if (strcmp(argv[i], "--image") == 0) {
|
||||||
if (flash_num_files == FLASH_MAX_FILES) {
|
if (flash_num_files == FLASH_MAX_FILES) {
|
||||||
|
@ -989,7 +997,7 @@ int main(int argc, char *argv[]) {
|
||||||
speed = USART_BAUD_RATE;
|
speed = USART_BAUD_RATE;
|
||||||
|
|
||||||
if (flash_mode) {
|
if (flash_mode) {
|
||||||
flash_pm3(port, flash_num_files, flash_filenames, flash_can_write_bl);
|
flash_pm3(port, flash_num_files, flash_filenames, flash_can_write_bl, flash_force);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
40
pm3
40
pm3
|
@ -288,6 +288,8 @@ elif [ "$SCRIPT" = "pm3-flash" ]; then
|
||||||
while [ "$1" != "" ]; do
|
while [ "$1" != "" ]; do
|
||||||
if [ "$1" == "-b" ]; then
|
if [ "$1" == "-b" ]; then
|
||||||
ARGS+=("--unlock-bootloader")
|
ARGS+=("--unlock-bootloader")
|
||||||
|
elif [ "$1" == "--force" ]; then
|
||||||
|
ARGS+=("--force")
|
||||||
else
|
else
|
||||||
ARGS+=("--image" "$1")
|
ARGS+=("--image" "$1")
|
||||||
fi
|
fi
|
||||||
|
@ -320,7 +322,19 @@ elif [ "$SCRIPT" = "pm3-flash-all" ]; then
|
||||||
FINDBTDONGLE=false
|
FINDBTDONGLE=false
|
||||||
FINDBTRFCOMM=false
|
FINDBTRFCOMM=false
|
||||||
FINDBTDIRECT=false
|
FINDBTDIRECT=false
|
||||||
CMD() { $CLIENT "--port" "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE" "--image" "$FULLIMAGE"; }
|
|
||||||
|
|
||||||
|
CMD() {
|
||||||
|
ARGS=("--port" "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE" "--image" "$FULLIMAGE")
|
||||||
|
shift;
|
||||||
|
while [ "$1" != "" ]; do
|
||||||
|
if [ "$1" == "--force" ]; then
|
||||||
|
ARGS+=("--force")
|
||||||
|
fi
|
||||||
|
shift;
|
||||||
|
done
|
||||||
|
$CLIENT "${ARGS[@]}";
|
||||||
|
}
|
||||||
HELP() {
|
HELP() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Quick helper script for flashing a Proxmark device via USB
|
Quick helper script for flashing a Proxmark device via USB
|
||||||
|
@ -340,7 +354,17 @@ elif [ "$SCRIPT" = "pm3-flash-fullimage" ]; then
|
||||||
FINDBTDONGLE=false
|
FINDBTDONGLE=false
|
||||||
FINDBTRFCOMM=false
|
FINDBTRFCOMM=false
|
||||||
FINDBTDIRECT=false
|
FINDBTDIRECT=false
|
||||||
CMD() { $CLIENT "--port" "$1" "--flash" "--image" "$FULLIMAGE"; }
|
CMD() {
|
||||||
|
ARGS=("--port" "$1" "--flash" "--image" "$FULLIMAGE")
|
||||||
|
shift;
|
||||||
|
while [ "$1" != "" ]; do
|
||||||
|
if [ "$1" == "--force" ]; then
|
||||||
|
ARGS+=("--force")
|
||||||
|
fi
|
||||||
|
shift;
|
||||||
|
done
|
||||||
|
$CLIENT "${ARGS[@]}";
|
||||||
|
}
|
||||||
HELP() {
|
HELP() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Quick helper script for flashing a Proxmark device via USB
|
Quick helper script for flashing a Proxmark device via USB
|
||||||
|
@ -360,7 +384,17 @@ elif [ "$SCRIPT" = "pm3-flash-bootrom" ]; then
|
||||||
FINDBTDONGLE=false
|
FINDBTDONGLE=false
|
||||||
FINDBTRFCOMM=false
|
FINDBTRFCOMM=false
|
||||||
FINDBTDIRECT=false
|
FINDBTDIRECT=false
|
||||||
CMD() { $CLIENT "--port" "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE"; }
|
CMD() {
|
||||||
|
ARGS=("--port" "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE")
|
||||||
|
shift;
|
||||||
|
while [ "$1" != "" ]; do
|
||||||
|
if [ "$1" == "--force" ]; then
|
||||||
|
ARGS+=("--force")
|
||||||
|
fi
|
||||||
|
shift;
|
||||||
|
done
|
||||||
|
$CLIENT "${ARGS[@]}";
|
||||||
|
}
|
||||||
HELP() {
|
HELP() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Quick helper script for flashing a Proxmark device via USB
|
Quick helper script for flashing a Proxmark device via USB
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue