mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-27 10:29:18 +08: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;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (vi->magic != VERSION_INFORMATION_MAGIC)
|
||||
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 (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"));
|
||||
return ask_confirmation();
|
||||
return PM3_EINVARG;
|
||||
} else {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
@ -264,7 +253,7 @@ static int print_and_validate_version(struct version_information_t *vi) {
|
|||
}
|
||||
|
||||
// Load an ELF file for flashing
|
||||
int flash_load(flash_file_t *ctx) {
|
||||
int flash_load(flash_file_t *ctx, bool force) {
|
||||
FILE *fd;
|
||||
Elf32_Ehdr_t *ehdr;
|
||||
Elf32_Shdr_t *shdrs = NULL;
|
||||
|
@ -364,13 +353,13 @@ int flash_load(flash_file_t *ctx) {
|
|||
}
|
||||
if (res == PM3_SUCCESS)
|
||||
return res;
|
||||
if (res == PM3_EOPABORTED)
|
||||
goto fail;
|
||||
// We could not find proper version_information, so we ask for confirmation
|
||||
PrintAndLogEx(WARNING, "Unable to check version_information");
|
||||
res = ask_confirmation();
|
||||
if (res == PM3_SUCCESS)
|
||||
return res;
|
||||
// We could not find proper version_information
|
||||
if (res == PM3_EUNDEF)
|
||||
PrintAndLogEx(WARNING, "Unable to check version_information");
|
||||
PrintAndLogEx(INFO, "Make sure to flash a correct and up-to-date version");
|
||||
PrintAndLogEx(INFO, "You can force flashing this firmware by using the option '--force'");
|
||||
if (force)
|
||||
return PM3_SUCCESS;
|
||||
fail:
|
||||
flash_free(ctx);
|
||||
return res;
|
||||
|
|
|
@ -41,7 +41,7 @@ typedef struct {
|
|||
flash_seg_t *segments;
|
||||
} 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_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t *max_allowed);
|
||||
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, "\nOptions in flasher mode:");
|
||||
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, "\nExamples:");
|
||||
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;
|
||||
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) {
|
||||
ret = flash_load(&files[i]);
|
||||
ret = flash_load(&files[i], force);
|
||||
if (ret != PM3_SUCCESS) {
|
||||
goto finish2;
|
||||
}
|
||||
|
@ -732,6 +733,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
bool flash_mode = false;
|
||||
bool flash_can_write_bl = false;
|
||||
bool flash_force = false;
|
||||
bool debug_mode_forced = false;
|
||||
int flash_num_files = 0;
|
||||
char *flash_filenames[FLASH_MAX_FILES];
|
||||
|
@ -948,6 +950,12 @@ int main(int argc, char *argv[]) {
|
|||
continue;
|
||||
}
|
||||
|
||||
// force flash even if firmware seems to not match client version
|
||||
if (strcmp(argv[i], "--force") == 0) {
|
||||
flash_force = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// flash file
|
||||
if (strcmp(argv[i], "--image") == 0) {
|
||||
if (flash_num_files == FLASH_MAX_FILES) {
|
||||
|
@ -989,7 +997,7 @@ int main(int argc, char *argv[]) {
|
|||
speed = USART_BAUD_RATE;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
40
pm3
40
pm3
|
@ -288,6 +288,8 @@ elif [ "$SCRIPT" = "pm3-flash" ]; then
|
|||
while [ "$1" != "" ]; do
|
||||
if [ "$1" == "-b" ]; then
|
||||
ARGS+=("--unlock-bootloader")
|
||||
elif [ "$1" == "--force" ]; then
|
||||
ARGS+=("--force")
|
||||
else
|
||||
ARGS+=("--image" "$1")
|
||||
fi
|
||||
|
@ -320,7 +322,19 @@ elif [ "$SCRIPT" = "pm3-flash-all" ]; then
|
|||
FINDBTDONGLE=false
|
||||
FINDBTRFCOMM=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() {
|
||||
cat << EOF
|
||||
Quick helper script for flashing a Proxmark device via USB
|
||||
|
@ -340,7 +354,17 @@ elif [ "$SCRIPT" = "pm3-flash-fullimage" ]; then
|
|||
FINDBTDONGLE=false
|
||||
FINDBTRFCOMM=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() {
|
||||
cat << EOF
|
||||
Quick helper script for flashing a Proxmark device via USB
|
||||
|
@ -360,7 +384,17 @@ elif [ "$SCRIPT" = "pm3-flash-bootrom" ]; then
|
|||
FINDBTDONGLE=false
|
||||
FINDBTRFCOMM=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() {
|
||||
cat << EOF
|
||||
Quick helper script for flashing a Proxmark device via USB
|
||||
|
|
Loading…
Reference in a new issue