proxmark3/.vscode/setup.sh

145 lines
3.9 KiB
Bash
Raw Normal View History

2020-12-29 23:38:02 +08:00
#!/bin/bash
###############################
# Linux #
# 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"
2020-12-30 04:02:23 +08:00
#export JLinkServerPath="C:/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
2020-12-29 23:38:02 +08:00
#Debugging on 256KB systems is not recommended
#This option does not override PLATFORM_SIZE
export DeviceMem="512"
VSCODEPATH=$(dirname "$0")
2020-12-30 01:32:22 +08:00
function print_config {
echo "Updating with following configuration:"
echo "SerialPort: $SerialPort"
echo "DebuggerPath: $DebuggerPath"
echo "JLinkServerPath: $JLinkServerPath"
}
2020-12-30 00:22:09 +08:00
function setup_serial_port {
2020-12-29 23:38:02 +08:00
if [ -z "$SerialPort" ]; then
pm3list=$($VSCODEPATH/../pm3 --list 2>/dev/null)
2023-08-09 20:30:07 +08:00
#Use first port listed
2020-12-30 04:37:01 +08:00
export SerialPort=$(echo $pm3list | head -n 1 | cut -c 4-)
2020-12-29 23:38:02 +08:00
if [ -z "$SerialPort" ]; then
echo >&2 "[!!] No serial port found, please set SerialPort manually"
exit 1
fi
fi
}
2020-12-30 00:22:09 +08:00
function setup_gdb_linux {
if [ -z "$DebuggerPath" ]; then
export DebuggerPath="/usr/bin/gdb"
fi
if [ ! -x "$DebuggerPath" ]; then
echo >&2 "[!!] gdb not found, please set DebuggerPath manually"
exit 1
fi
}
function setup_jlink_linux {
if [ -z "$JLinkServerPath" ]; then
export JLinkServerPath="/opt/SEGGER/JLink/JLinkGDBServerCLExe"
fi
if [ ! -x "$JLinkServerPath" ]; then
echo >&2 "[!!] JLinkGDBServerCLExe not found, please set JLinkServerPath manually"
exit 1
fi
}
function setup_jlink_wsl {
if [ -z "$JLinkServerPath" ]; then
export JLinkServerPath="/mnt/c/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
fi
if [ ! -x "$JLinkServerPath" ]; then
2020-12-30 03:43:24 +08:00
echo >&2 "[!!] JLinkGDBServerCL.exe not found, please set JLinkServerPath manually"
exit 1
fi
}
function setup_jlink_ps {
if [ -z "$JLinkServerPath" ]; then
2020-12-30 04:02:23 +08:00
export JLinkServerPath="c:/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
2020-12-30 03:43:24 +08:00
fi
2020-12-30 04:10:16 +08:00
jlinkpath=$(cygpath "$JLinkServerPath")
if [ ! -x "$jlinkpath" ]; then
2020-12-30 03:43:24 +08:00
echo >&2 "[!!] JLinkGDBServerCL.exe not found, please set JLinkServerPath manually"
2020-12-30 00:22:09 +08:00
exit 1
fi
}
function setup_wsl {
setup_serial_port
setup_gdb_linux
setup_jlink_wsl
2020-12-30 01:32:22 +08:00
print_config
2020-12-30 01:26:51 +08:00
envsubst '${SerialPort} ${DebuggerPath} ${JLinkServerPath} ${DeviceMem}' <"$VSCODEPATH/templates/launch_wsl.json" > "$VSCODEPATH/launch.json"
2020-12-30 00:22:09 +08:00
}
function setup_linux {
setup_serial_port
setup_gdb_linux
setup_jlink_linux
2020-12-30 01:32:22 +08:00
print_config
2020-12-30 01:26:51 +08:00
envsubst '${SerialPort} ${DebuggerPath} ${JLinkServerPath} ${DeviceMem}' <"$VSCODEPATH/templates/launch_linux.json" > "$VSCODEPATH/launch.json"
2020-12-30 00:22:09 +08:00
}
function setup_ps {
setup_serial_port
2020-12-30 03:43:24 +08:00
setup_jlink_ps
2020-12-30 04:10:16 +08:00
export DebuggerPath="Using ProxSpace gbd"
2020-12-30 01:32:22 +08:00
print_config
2020-12-30 04:10:16 +08:00
envsubst '${SerialPort} ${JLinkServerPath} ${DeviceMem}' <"$VSCODEPATH/templates/launch_ps.json" > "$VSCODEPATH/launch.json"
2020-12-30 00:22:09 +08:00
}
2020-12-30 03:43:24 +08:00
if [ -f "$VSCODEPATH/launch.json" ]; then
2020-12-30 00:22:09 +08:00
read -p "Existing configuration found, do you want to override it? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm "$VSCODEPATH/launch.json.bak" 2> /dev/null
mv "$VSCODEPATH/launch.json" "$VSCODEPATH/launch.json.bak" 2> /dev/null
else
echo >&2 "[!!] user abort"
exit 1
fi
fi
2020-12-29 23:38:02 +08:00
HOSTOS=$(uname | awk '{print toupper($0)}')
if [ "$HOSTOS" = "LINUX" ]; then
2023-08-09 20:30:07 +08:00
if uname -a|grep -q Microsoft; then
2020-12-30 00:22:09 +08:00
setup_wsl
2023-08-09 20:30:07 +08:00
else
2020-12-30 00:22:09 +08:00
setup_linux
2023-08-09 20:30:07 +08:00
fi
2020-12-29 23:38:02 +08:00
elif [ "$HOSTOS" = "DARWIN" ]; then
echo >&2 "[!!] MacOS not supported, sorry!"
exit 1
elif [[ "$HOSTOS" =~ MINGW(32|64)_NT* ]]; then
2020-12-30 00:22:09 +08:00
setup_ps
2020-12-29 23:38:02 +08:00
else
2023-08-09 20:30:07 +08:00
echo >&2 "[!!] Host OS not recognized, abort: $HOSTOS"
exit 1
2020-12-30 00:22:09 +08:00
fi