forked from AndyTaylorTweet/Pi-Star_Binaries_sbin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pistar-mmdvmhshatflash-custom
executable file
·93 lines (86 loc) · 3.4 KB
/
pistar-mmdvmhshatflash-custom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
#
###############################################################################
# #
# Pi-Star Custom Firmware Update Tool #
# #
# Version 0.1, Code, Design and Development by Florian Wolters (DF2ET). #
# Based on work by Andy Taylor (MW0MZW) #
# and Andy Uribe CA6JAU #
# #
# Make it simple to update the Firmware #
# #
###############################################################################
#
if [ "$(id -u)" != "0" ]; then
echo -e "You need to be root to run this command...\n"
exit 1
fi
#
# Output some usefull information when no variables are passed
#
if [ -z "$1" ]
then
echo "This tool is used to flash a custom made firmware to your MMDVM_HS Hat Modem"
echo ""
echo "Pre-built nightly firmware configured from the templates can be downloaded from:"
echo ""
echo " https://www.df2et.de/mmdvm_hs/"
echo ""
echo "And there is also a firmware builder tool that can be used to build a fully customizable version of the firmware. It is available at:"
echo ""
echo " https://www.df2et.de/mmdvm_hs_builder/"
echo ""
echo "Use this script and the generated firmware at your own risk!"
echo "Usage: $(basename ${0}) <firmware.bin>"
echo ""
exit 0
fi
#
# OK we know what the modem is, let get the firmware string from the log...
#
tac $(ls -1rt /var/log/pi-star/MMDVM-*.log | tail -n1 ) | grep "MMDVM protocol" -m 1 | sed -n 's/description: /&\n/;s/.*\n//p'
read -n 1 -s -r -p "Press any key to write the ${1} firmware to this modem or Ctrl-C to quit..."
echo ""
#
# Download the correct firmware
#
if [ "$1" ]
then
if [ ! -e "$1" ]; then
echo "Firmware file $1 not found! Aborting."
else
# Download STM32F10X_Lib (only for binary tools)
if [ ! -d "./STM32F10X_Lib/utils" ]; then
git clone https://github.com/juribeparada/STM32F10X_Lib
fi
# Configure vars depending on OS
if [ $(uname -s) == "Linux" ]; then
DEV_USB_SER="/dev/ttyACM0"
if [ $(uname -m) == "armv7l" ]; then
echo "Raspberry Pi 3 detected"
DFU_RST="./STM32F10X_Lib/utils/rpi32/upload-reset"
DFU_UTIL="./STM32F10X_Lib/utils/rpi32/dfu-util"
ST_FLASH="./STM32F10X_Lib/utils/rpi32/st-flash"
STM32FLASH="./STM32F10X_Lib/utils/rpi32/stm32flash"
elif [ $(uname -m) == "armv6l" ]; then
echo "Raspberry Pi 2 or Pi Zero W detected"
DFU_RST="./STM32F10X_Lib/utils/rpi32/upload-reset"
DFU_UTIL="./STM32F10X_Lib/utils/rpi32/dfu-util"
ST_FLASH="./STM32F10X_Lib/utils/rpi32/st-flash"
STM32FLASH="./STM32F10X_Lib/utils/rpi32/stm32flash"
fi
fi
# Stop MMDVMHost process to free serial port
sudo killall MMDVMHost >/dev/null 2>&1
# Upload the firmware
eval sudo $STM32FLASH -v -w "$1" -g 0x0 -R -i 20,-21,21:-20,21 /dev/ttyAMA0
echo ""
rm -rf STM32F10X_Lib
read -n 1 -s -r -p "Flashing ${1} to your modem complete, press any key to reboot your Pi-Star System..."
echo ""
shutdown -r now
exit 0
fi
fi
exit 0