detect serial port

This commit is contained in:
gator96100 2020-12-29 16:38:02 +01:00
parent 9e224b011b
commit 6f316b8e29
2 changed files with 90 additions and 24 deletions

69
.vscode/setup.sh vendored
View file

@ -1,4 +1,65 @@
export SerialPort="/dev/ttyACM0" #!/bin/bash
export DebuggerPath="/usr/bin/gdb" ###############################
export JLinkServerPath="/opt/SEGGER/JLink/JLinkGDBServerCLExe" # Linux #
export DeviceMem="512" # Uncomment to override #
###############################
#export SerialPort="/dev/ttyACM0"
#export DebuggerPath="/usr/bin/gdb"
#export JLinkServerPath="/opt/SEGGER/JLink/JLinkGDBServerCLExe"
###############################
# WSL #
# Uncomment to override #
###############################
#export SerialPort="/dev/ttyS4"
#export DebuggerPath="/usr/bin/gdb"
#export JLinkServerPath="/mnt/c/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
###############################
# ProxSpace #
# Uncomment to override #
###############################
#export SerialPort="COM5"
#export DebuggerPath="${workspaceFolder}/../../msys2/mingw64/bin/gdb.exe"
#export JLinkServerPath="c/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
#Debugging on 256KB systems is not recommended
#This option does not override PLATFORM_SIZE
export DeviceMem="512"
VSCODEPATH=$(dirname "$0")
function get_serial_port {
if [ -z "$SerialPort" ]; then
pm3list=$($VSCODEPATH/../pm3 --list 2>/dev/null)
#Use first port listed
SerialPort=$(echo $pm3list | head -n 1 | cut -c 4-)
if [ -z "$SerialPort" ]; then
echo >&2 "[!!] No serial port found, please set SerialPort manually"
exit 1
fi
fi
echo "Using $SerialPort as port"
}
HOSTOS=$(uname | awk '{print toupper($0)}')
if [ "$HOSTOS" = "LINUX" ]; then
if uname -a|grep -q Microsoft; then
echo "WSL"
else
echo "LINUX"
fi
elif [ "$HOSTOS" = "DARWIN" ]; then
echo >&2 "[!!] MacOS not supported, sorry!"
exit 1
elif [[ "$HOSTOS" =~ MINGW(32|64)_NT* ]]; then
echo "ProxSpace"
else
echo >&2 "[!!] Host OS not recognized, abort: $HOSTOS"
exit 1
fi
get_serial_port

45
pm3
View file

@ -14,27 +14,32 @@ PM3PATH=$(dirname "$0")
EVALENV="" EVALENV=""
FULLIMAGE="fullimage.elf" FULLIMAGE="fullimage.elf"
BOOTIMAGE="bootrom.elf" BOOTIMAGE="bootrom.elf"
# try pm3 dirs in current repo workdir
if [ -d "$PM3PATH/client/" ]; then #Skip check if --list is used
if [ -x "$PM3PATH/client/proxmark3" ]; then if [ ! "$1" == "--list" ]; then
CLIENT="$PM3PATH/client/proxmark3" # try pm3 dirs in current repo workdir
elif [ -x "$PM3PATH/client/build/proxmark3" ]; then if [ -d "$PM3PATH/client/" ]; then
CLIENT="$PM3PATH/client/build/proxmark3" if [ -x "$PM3PATH/client/proxmark3" ]; then
else CLIENT="$PM3PATH/client/proxmark3"
echo >&2 "[!!] In devel workdir but no executable found, did you compile it?" elif [ -x "$PM3PATH/client/build/proxmark3" ]; then
exit 1 CLIENT="$PM3PATH/client/build/proxmark3"
fi else
# Devel mode: point to workdir pm3.py module echo >&2 "[!!] In devel workdir but no executable found, did you compile it?"
EVALENV+=" PYTHONPATH=$PM3PATH/client/src" exit 1
# try install dir fi
elif [ -x "$PM3PATH/proxmark3" ]; then # Devel mode: point to workdir pm3.py module
CLIENT="$PM3PATH/proxmark3" EVALENV+=" PYTHONPATH=$PM3PATH/client/src"
EVALENV+=" PYTHONPATH=$PM3PATH/../share/proxmark3/pyscripts/" # try install dir
# or /usr/[local/]lib/python3/dist-packages/pm3.py ? elif [ -x "$PM3PATH/proxmark3" ]; then
else CLIENT="$PM3PATH/proxmark3"
# hope it's installed somehow, still not sure where fw images and pm3.py are... EVALENV+=" PYTHONPATH=$PM3PATH/../share/proxmark3/pyscripts/"
CLIENT="proxmark3" # or /usr/[local/]lib/python3/dist-packages/pm3.py ?
else
# hope it's installed somehow, still not sure where fw images and pm3.py are...
CLIENT="proxmark3"
fi
fi fi
# LeakSanitizer suppressions # LeakSanitizer suppressions
if [ -e .lsan_suppressions ]; then if [ -e .lsan_suppressions ]; then
EVALENV+=" LSAN_OPTIONS=suppressions=.lsan_suppressions" EVALENV+=" LSAN_OPTIONS=suppressions=.lsan_suppressions"