From a60b2f24a8dfc4704a66648bc067333e25adc84d Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 26 Apr 2019 23:51:43 +0200 Subject: [PATCH 1/6] update.sh flash boot only if option -b --- update.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/update.sh b/update.sh index fe5f0dd95..aa58b693e 100755 --- a/update.sh +++ b/update.sh @@ -1,5 +1,10 @@ #!/bin/bash +FULLIMAGE="armsrc/obj/fullimage.elf" +if [ "$1" == "-b" ]; then + FLASHBOOT="-b bootrom/obj/bootrom.elf" +fi + function wait4proxmark_Linux { echo >&2 "Waiting for Proxmark to appear..." while [ ! -c /dev/ttyACM? -a ! -L /dev/pm3-? ]; do @@ -26,7 +31,7 @@ function wait4proxmark_macOS { # Detect OS and flash bootroom & system image if [[ $(uname | awk '{print toupper($0)}') == "LINUX" ]]; then - client/flasher $(wait4proxmark_Linux) -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf + client/flasher $(wait4proxmark_Linux) $FLASHBOOT $FULLIMAGE elif [[ $(uname | awk '{print toupper($0)}') == "DARWIN" ]]; then - client/flasher $(wait4proxmark_macOS) -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf + client/flasher $(wait4proxmark_macOS) $FLASHBOOT $FULLIMAGE fi From d3cc0bb71c5f4f270df78116bfedaaab10d5fc03 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 27 Apr 2019 00:30:44 +0200 Subject: [PATCH 2/6] Add support for: proxmark3 -c "hw ping;hw version;hw ping" --- client/proxmark3.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/proxmark3.c b/client/proxmark3.c index 0ada54e78..f1cf3a056 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -62,6 +62,9 @@ main_loop(char *script_cmds_file, char *script_cmd, bool pm3_present) { char *cmd = NULL; bool execCommand = (script_cmd != NULL); + uint16_t script_cmd_len = strlen(script_cmd); + if (execCommand) + strcreplace(script_cmd, script_cmd_len, ';', '\0'); bool stdinOnPipe = !isatty(STDIN_FILENO); FILE *sf = NULL; char script_cmd_buf[256] = {0x00}; // iceman, needs lua script the same file_path_buffer as the rest @@ -134,11 +137,13 @@ main_loop(char *script_cmds_file, char *script_cmd, bool pm3_present) { } else { // If there is a script command if (execCommand) { - if ((cmd = strmcopy(script_cmd)) != NULL) PrintAndLogEx(NORMAL, PROXPROMPT"%s", cmd); - - execCommand = false; + uint16_t len = strlen(script_cmd) + 1; + script_cmd += len; + if (script_cmd_len == len - 1) + execCommand = false; + script_cmd_len -= len; } else { // exit after exec command if (script_cmd) From 200290bc567751f5af954870bdbec20dc26a8e01 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 27 Apr 2019 00:33:14 +0200 Subject: [PATCH 3/6] doc multiple commands with -c --- client/proxmark3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/proxmark3.c b/client/proxmark3.c index f1cf3a056..010fd6ff0 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -259,7 +259,7 @@ static void show_help(bool showFullHelp, char *exec_name) { PrintAndLogEx(NORMAL, " -b/--baud serial port speed"); PrintAndLogEx(NORMAL, " -w/--wait 20sec waiting the serial port to appear in the OS"); PrintAndLogEx(NORMAL, " -f/--flush output will be flushed after every print"); - PrintAndLogEx(NORMAL, " -c/--command execute one proxmark3 command."); + PrintAndLogEx(NORMAL, " -c/--command execute one proxmark3 command (or several separated by ';')."); PrintAndLogEx(NORMAL, " -l/--lua execute lua script."); PrintAndLogEx(NORMAL, " -s/--script-file script file with one proxmark3 command per line"); PrintAndLogEx(NORMAL, "\nsamples:"); From a555799a7c489cae41895df79e773669fb2107ba Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 27 Apr 2019 10:41:10 +0200 Subject: [PATCH 4/6] Stop poking Internet when compiling --- tools/mkversion.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/mkversion.pl b/tools/mkversion.pl index ed5cea206..a71aac96f 100644 --- a/tools/mkversion.pl +++ b/tools/mkversion.pl @@ -32,7 +32,8 @@ my $commandGIT = "env which git"; if ( defined($commandGIT) ) { - my $githistory = `git fetch --all`; + # this goes on Internet and cause major slowdowns on poor connections or intranets, let's comment it + #my $githistory = `git fetch --all`; # now avoiding the "fatal: No names found, cannot describe anything." error by fallbacking to abbrev hash in such case my $gitversion = `git describe --dirty --always`; my $gitbranch = `git rev-parse --abbrev-ref HEAD`; From ae5b6fa169fba2fffe40ae0f05b07ebfe3ac1279 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 27 Apr 2019 11:25:07 +0200 Subject: [PATCH 5/6] rework shell scripts for easy client or flasher --- flash-all.sh | 4 ++++ flash-bootrom.sh | 4 ++++ flash-fullimage.sh | 4 ++++ proxmark3.sh | 43 ++++++++++++++++++++++++++++++++++++++----- tools/mkversion.pl | 2 +- update.sh | 37 ------------------------------------- 6 files changed, 51 insertions(+), 43 deletions(-) create mode 100755 flash-all.sh create mode 100755 flash-bootrom.sh create mode 100755 flash-fullimage.sh delete mode 100755 update.sh diff --git a/flash-all.sh b/flash-all.sh new file mode 100755 index 000000000..27e1fb526 --- /dev/null +++ b/flash-all.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +cd $(dirname "$0") +. proxmark3.sh diff --git a/flash-bootrom.sh b/flash-bootrom.sh new file mode 100755 index 000000000..27e1fb526 --- /dev/null +++ b/flash-bootrom.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +cd $(dirname "$0") +. proxmark3.sh diff --git a/flash-fullimage.sh b/flash-fullimage.sh new file mode 100755 index 000000000..27e1fb526 --- /dev/null +++ b/flash-fullimage.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +cd $(dirname "$0") +. proxmark3.sh diff --git a/proxmark3.sh b/proxmark3.sh index 4a7a004d5..0d7b36657 100755 --- a/proxmark3.sh +++ b/proxmark3.sh @@ -1,5 +1,10 @@ #!/bin/bash +FULLIMAGE="armsrc/obj/fullimage.elf" +BOOTIMAGE="bootrom/obj/bootrom.elf" + +cd $(dirname "$0") + function wait4proxmark_Linux { echo >&2 "Waiting for Proxmark to appear..." while [ ! -c /dev/ttyACM? -a ! -c /dev/pm3-? ]; do @@ -23,10 +28,38 @@ function wait4proxmark_macOS { echo $PM3 } -# start proxmark with first detected interface +SCRIPT=$(basename -- "$0") -if [[ $(uname | awk '{print toupper($0)}') == "LINUX" ]]; then - client/proxmark3 $(wait4proxmark_Linux) "$@" -elif [[ $(uname | awk '{print toupper($0)}') == "DARWIN" ]]; then - client/proxmark3 $(wait4proxmark_macOS) "$@" +if [ "$SCRIPT" = "proxmark3.sh" ]; then + CMD=client/proxmark3 +elif [ "$SCRIPT" = "flash-all.sh" ]; then + CMD=client/flasher + ARG1="-b $BOOTIMAGE" + ARG2="$FULLIMAGE" +elif [ "$SCRIPT" = "flash-fullimage.sh" ]; then + CMD=client/flasher + ARG2="$FULLIMAGE" +elif [ "$SCRIPT" = "flash-bootrom.sh" ]; then + CMD=client/flasher + ARG1="-b $BOOTIMAGE" +else + echo "Script ran under unknown name, abort: $SCRIPT" + exit 1 fi +HOSTOS=$(uname | awk '{print toupper($0)}') +if [ "$HOSTOS" = "LINUX" ]; then + PORT=$(wait4proxmark_Linux) +elif [ "$HOSTOS" = "DARWIN" ]; then + PORT=$(wait4proxmark_macOS) +else + echo "Host OS not recognized, abort: $HOSTOS" + exit 1 +fi +if [ "$PORT" = "" ]; then + echo "No port, abort" + exit 1 +fi + +echo Running "$CMD" "$PORT" $ARG1 $ARG2 "$@" +"$CMD" "$PORT" $ARG1 $ARG2 "$@" +exit $? diff --git a/tools/mkversion.pl b/tools/mkversion.pl index a71aac96f..715b8081c 100644 --- a/tools/mkversion.pl +++ b/tools/mkversion.pl @@ -14,7 +14,7 @@ $ENV{'LC_ALL'} = "C"; $ENV{'LANG'} = "C"; # if you are making your own fork, change this line to reflect your fork-name -my $fullgitinfo = 'iceman'; +my $fullgitinfo = 'RRG'; my $ctime; # GIT status 0 = dirty, 1 = clean , 2 = undecided my $clean = 2; diff --git a/update.sh b/update.sh deleted file mode 100755 index aa58b693e..000000000 --- a/update.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -FULLIMAGE="armsrc/obj/fullimage.elf" -if [ "$1" == "-b" ]; then - FLASHBOOT="-b bootrom/obj/bootrom.elf" -fi - -function wait4proxmark_Linux { - echo >&2 "Waiting for Proxmark to appear..." - while [ ! -c /dev/ttyACM? -a ! -L /dev/pm3-? ]; do - sleep .1 - done - local PM3=`ls -1 /dev/pm3-? /dev/ttyACM? 2>/dev/null | head -1` - echo >&2 -e "Found proxmark on ${PM3}\n" - echo $PM3 -} - -function wait4proxmark_macOS { - echo >&2 "Waiting for Proxmark to appear..." - while true; do - PM3=$(ls /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1) - if [[ $PM3 != "" ]]; then - #echo >&2 -e "Found proxmark on $(ls /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1)\n" - break - fi - sleep .1 - done - echo $PM3 -} - -# Detect OS and flash bootroom & system image - -if [[ $(uname | awk '{print toupper($0)}') == "LINUX" ]]; then - client/flasher $(wait4proxmark_Linux) $FLASHBOOT $FULLIMAGE -elif [[ $(uname | awk '{print toupper($0)}') == "DARWIN" ]]; then - client/flasher $(wait4proxmark_macOS) $FLASHBOOT $FULLIMAGE -fi From 8ebc44ee81ec9c36a5732b5a369c97db263fcf0f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 27 Apr 2019 16:52:23 +0200 Subject: [PATCH 6/6] fix segfault --- client/proxmark3.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/proxmark3.c b/client/proxmark3.c index 010fd6ff0..47ea28e36 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -62,9 +62,11 @@ main_loop(char *script_cmds_file, char *script_cmd, bool pm3_present) { char *cmd = NULL; bool execCommand = (script_cmd != NULL); - uint16_t script_cmd_len = strlen(script_cmd); - if (execCommand) + uint16_t script_cmd_len = 0; + if (execCommand) { + script_cmd_len = strlen(script_cmd); strcreplace(script_cmd, script_cmd_len, ';', '\0'); + } bool stdinOnPipe = !isatty(STDIN_FILENO); FILE *sf = NULL; char script_cmd_buf[256] = {0x00}; // iceman, needs lua script the same file_path_buffer as the rest