mirror of
https://github.com/LIV2/pistorm.git
synced 2025-12-05 22:52:44 +00:00
CPLD detection would sometimes fail if emulator was running, so fail with a message to stop the emulator _before_ detection. The emulator check will remain in nprog too for those who run that directly.
35 lines
648 B
Bash
Executable File
35 lines
648 B
Bash
Executable File
#!/bin/bash
|
|
set -o pipefail
|
|
if pgrep -x "emulator" > /dev/null
|
|
then
|
|
echo "PiStorm emulator is running, please stop it first"
|
|
exit 1
|
|
fi
|
|
if ! command -v openocd &> /dev/null
|
|
then
|
|
echo "openocd is not installed, please run \"sudo apt install openocd\""
|
|
exit 1
|
|
fi
|
|
echo -ne "Detecting CPLD... "
|
|
version=$(sudo openocd -f nprog/detect.cfg 2>/dev/null | awk 'FNR == 3 { print $4 }')
|
|
if [ $? -ne 0 ]
|
|
then
|
|
echo "Error detecting CPLD."
|
|
exit 1
|
|
fi
|
|
case $version in
|
|
"0x020a10dd")
|
|
echo "EPM240 detected!"
|
|
./nprog_240.sh
|
|
;;
|
|
"0x020a20dd")
|
|
echo "EPM570 detected!"
|
|
./nprog.sh
|
|
;;
|
|
*)
|
|
echo "Could not detect CPLD"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|