-
Notifications
You must be signed in to change notification settings - Fork 0
/
hm-mod-rpi-pcb
executable file
·326 lines (282 loc) · 11.4 KB
/
hm-mod-rpi-pcb
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#!/bin/bash
#
# Leon265130/leonsio http://homematic-forum.de
#
# HM-MOD-RPI-PBC Modul for Raspberry Pi2 / Raspberry Pi3
#
description="GPIO Funkmodul für Raspberry Pi2/3 (deprecated)"
module_version="1.0"
# Default Parameter
file_hm_mod_rpi_pcb='/etc/init.d/hm-mod-rpi-pcb'
file_cmdline_txt='/boot/cmdline.txt'
file_rfd_conf="${LXC_ROOT_FS}/usr/local/etc/config/rfd.conf"
reboot=0 # Neustart ausfuehren
kernel_version=$(uname -r | sed -e 's/-.*//i')
if [ $(ver ${kernel_version}) -ge $(ver 4.4.9) ]
then
overlay_file="pi3-miniuart-bt"
else
overlay_file="pi3-miniuart-bt-overlay"
fi
_module_install()
{
if [ -e ${LXC_ROOT_MODULES}/hm-fake-lan-gw ] && [ $IS_FORCE -ne 1 ]
then
die "ERROR: hm-mod-rpi-pcb module is installed, please remove it first"
fi
if [ "$BOARD_TYPE" != "Raspberry Pi" ] && [ $IS_FORCE -ne 1 ]
then
info "See Wiki for manual installation"
die "ERROR: This module is for Raspberry Pi only, use -f flag to overwrite this check"
fi
[ "x$(id -un)" == "xroot" ] || die "Sorry, this script must be run as root. Try sudo ...."
info "Found hardware: $BOARD_TYPE $BOARD_VERSION"
if [ "$BOARD_TYPE" = "Raspberry Pi" ]
then
if [ ! -f /boot/config.txt ] && [ $IS_FORCE -ne 1 ]
then
die "ERROR: File /boot/config.txt does not exist!"
fi
fi
# Raspberry 2 oder 3 ?
if [ "$BOARD_TYPE" = "Raspberry Pi" ] && [ "$BOARD_VERSION" = "3" ]
then
progress "Trying to disable bluetooth on Raspberry Pi 3 to use HM-MOD-RPI-PCB"
if [ $(cat /boot/config.txt | grep ${overlay_file} | wc -l ) -eq 0 ]
then
echo -e "\n# Allow the normal UART pins to work\ndtoverlay=${overlay_file}\nenable_uart=1\nforce_turbo=1" >> /boot/config.txt
info "Modification /boot/config.txt done."
reboot=$((reboot+1))
fi
elif [ "$BOARD_TYPE" = "Raspberry Pi" ] && [ "$BOARD_VERSION" = "2" ]
then
if [ $(ver ${kernel_version}) -ge $(ver 4.4.9) ]
then
# enable_uart ist nicht vorhanden
if [ $(cat /boot/config.txt | grep "^enable_uart" | wc -l) -eq 0 ]
then
echo -e "\n# Allow the normal UART pins to work\nenable_uart=1" >> /boot/config.txt
info "Modification /boot/config.txt done."
reboot=$((reboot+1))
fi
if [ $(cat /boot/config.txt | grep "^enable_uart=0" | wc -l) -eq 1 ]
then
sed -i /boot/config.txt -e "s/enable_uart=0/enable_uart=1/"
info "Modification /boot/config.txt done."
reboot=$((reboot+1))
fi
fi
fi
# Disable serial
progress "Trying to disable serial console"
if [ ! -f $file_cmdline_txt ] && [ $IS_FORCE -ne 1 ]
then
die "ERROR: File $file_cmdline_txt does not exist!"
fi
if [ $(cat /boot/cmdline.txt|grep "console=serial0,115200"|wc -l) -gt 0 ];then
sed -i /boot/cmdline.txt -e "s/console=ttyAMA0,[0-9]\+ //"
sed -i /boot/cmdline.txt -e "s/console=serial0,[0-9]\+ //"
reboot=$((reboot+1))
info "Serial disabled successfully."
else
info "Serial already disabled"
fi
# Create service for enabling gpio pin for reset
if [ ! -f $file_hm_mod_rpi_pcb ]; then
progress "Create service for enabling gpio pin for reset line of hm-mod-rpi-pcb on every reboot"
cat > $file_hm_mod_rpi_pcb <<EOF
#!/bin/sh
### BEGIN INIT INFO
# Provides: hm-mod-rpi-pcb yahm
# Required-Start: udev mountkernfs \$remote_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Enables GPIO 18 as reset Interface for HM RF Module for Raspberry
# Description:
### END INIT INFO
. /lib/lsb/init-functions
case "\$1" in
start)
log_daemon_msg "Enables GPIO 18 as Reset Interface for Homematic RF wireless module"
printf " Enables GPIO 18 as Reset Interface for Homematic RF wireless module"
if [ ! -d /sys/class/gpio/gpio18 ]
then
echo "Preparing GPIO for HM-MOD-UART..."
echo 18 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio18/direction
printf "Preparing GPIO for HM-MOD-UART done!"
printf "Reseting PCB"
fi
# hold reset until rfd starts
echo 0 > /sys/class/gpio/gpio18/value
sleep 0.1
echo 1 > /sys/class/gpio/gpio18/value
log_end_msg 0
;;
*)
echo "Usage: \$0 start" >&2
exit 3
;;
esac
EOF
chmod +x $file_hm_mod_rpi_pcb
if [ "$CODENAME" = "stretch" ] ;
then
update-rc.d hm-mod-rpi-pcb remove
update-rc.d hm-mod-rpi-pcb defaults
update-rc.d hm-mod-rpi-pcb enable
systemctl daemon-reload
else
insserv $file_hm_mod_rpi_pcb
fi
info "Installing reset gpio as service is done."
fi
# im Gast
progress "Preparing devices inside LXC container"
if [ ! -e $LXC_ROOT_FS/dev/ttyAMA0 ];then
info "Creating device /dev/ttyAMA0..."
mknod -m 666 ${LXC_ROOT_FS}/dev/ttyAMA0 c 204 64
fi
if [ ! -e $LXC_ROOT_FS/dev/mmd_bidcos ];then
info "Creating symlink /dev/mmd_bidcos..."
cd ${LXC_ROOT_FS}/dev/
ln -s ttyAMA0 mmd_bidcos
fi
if [ ! -L $LXC_ROOT_FS/dev/ccu2-ic200 ];then
info "Creating symlink /dev/ccu2-ic200..."
cd ${LXC_ROOT_FS}/dev/
ln -s /sys/class/gpio/gpio18/value ccu2-ic200
fi
progress "Preparing modification rfd.conf..."
if [ ! -f $file_rfd_conf ]
then
die "RDF.conf not found, maybe your YAHM instance is not running, please start it first"
fi
if [ $(cat $file_rfd_conf|grep "\[Interface 0\]"|wc -l) -eq 0 ];then
info "[Interface 0] block in rfd.conf not found, insert it..."
echo -e "\n[Interface 0]\nType = CCU2\nComPortFile = /dev/mmd_bidcos\nAccessFile = /dev/null\nResetFile = /dev/ccu2-ic200" >> $file_rfd_conf
info "Insert in rfd.conf done."
else
info "[Interface 0] block found in rfd.conf checking it..."
# aendern
sed -e 's/#\[Interface 0\]/\[Interface 0\]/' -i $file_rfd_conf
sed -e 's/#Type = CCU2/Type = CCU2/' -i $file_rfd_conf
sed -e 's/#ComPortFile = \/dev\/mmd_bidcos/ComPortFile = \/dev\/mmd_bidcos/' -i $file_rfd_conf
sed -e 's/#AccessFile = \/dev\/null/AccessFile = \/dev\/null/' -i $file_rfd_conf
sed -e 's/#ResetFile = \/dev\/ccu2-ic200/ResetFile = \/dev\/ccu2-ic200/' -i $file_rfd_conf
#remove Improved Coprocessor Stuff
if [ $(cat $file_rfd_conf|grep "\Improved\ Coprocessor\ Initialization\ =\ true"|wc -l) -eq 1 ];then
progress "disabling new coprocessor initialization"
sed 's/Improved Coprocessor Initialization = true/Improved Coprocessor Initialization = false/' -i $file_rfd_conf
fi
info "Modification rfd.conf done."
fi
# Reboot
if [ $reboot -gt 0 ]
then
echo "======================================"
echo "Rebooting in 60 seconds to apply settings (to chancel reboot type 'shutdown -c')..."
echo "======================================"
shutdown -r +1 "Rebooting to disable serial console"
else
info "HM-MOD-RPI-PCB was installed successfully, please restart YAHM to apply changes"
progress "Trying to start service"
systemctl enable hm-mod-rpi-pcb
systemctl start hm-mod-rpi-pcb
fi
}
_module_remove()
{
if [ "$BOARD_TYPE" != "Raspberry Pi" ] && [ $IS_FORCE -ne 1 ]
then
die "ERROR: This module is for Raspberry Pi only, use -f flag to overwrite this check"
fi
info "Found hardware: $BOARD_TYPE $BOARD_VERSION"
# Raspberry 2 oder 3 ?
if [ "$BOARD_TYPE" = "Raspberry Pi" ] && [ "$BOARD_VERSION" = "3" ]
then
progress "Trying to enable bluetooth"
if [ ! -f /boot/config.txt ] && [ $IS_FORCE -ne 1 ]
then
die "ERROR: File /boot/config.txt does not exist!"
fi
if [ $(cat /boot/config.txt | grep ${overlay_file} | wc -l ) -gt 0 ]
then
sed -i '/^\# Allow the normal UART pins to work/d' /boot/config.txt
sed -i "/^dtoverlay=${overlay_file}/d" /boot/config.txt
sed -i "/^enable_uart=1/d" /boot/config.txt
sed -i "/^force_turbo=1/d" /boot/config.txt
progress "Modification in /boot/config.txt is done."
reboot=$((reboot+1))
fi
fi
info "Uninstall modification in rfd.conf..."
if [ $(cat $file_rfd_conf|grep "\[Interface 0\]"|wc -l) -gt 0 ];then
info "[Interface 0] block found in rfd.conf checking it..."
# aendern
sed -e 's/\[Interface 0\]/#\[Interface 0\]/' -i $file_rfd_conf
sed -e 's/Type = CCU2/#Type = CCU2/' -i $file_rfd_conf
sed -e 's/Description = CCU2-Coprocessor/#Description = CCU2-Coprocessor/' -i $file_rfd_conf
sed -e 's/ComPortFile = \/dev\/mmd_bidcos/#ComPortFile = \/dev\/mmd_bidcos/' -i $file_rfd_conf
sed -e 's/AccessFile = \/dev\/null/#AccessFile = \/dev\/null/' -i $file_rfd_conf
sed -e 's/ResetFile = \/dev\/ccu2-ic200/#ResetFile = \/dev\/ccu2-ic200/' -i $file_rfd_conf
if [ $(cat $file_rfd_conf|grep "\Improved\ Coprocessor\ Initialization\ =\ false"|wc -l) -eq 1 ];then
progress "enabling new coprocessor initialization again"
sed 's/Improved Coprocessor Initialization = false/Improved Coprocessor Initialization = true/' -i $file_rfd_conf
fi
progress "Uninstall modification in rfd.conf is done."
fi
progress "Removing devices inside LXC container"
if [ -e $LXC_ROOT_FS/dev/mmd_bidcos ];then
info "Remove link /dev/mmd_bidcos."
rm $LXC_ROOT_FS/dev/mmd_bidcos
fi
if [ -L $LXC_ROOT_FS/dev/ccu2-ic200 ];then
info "Remove link /dev/ccu2-ic200."
rm $LXC_ROOT_FS/dev/ccu2-ic200
fi
if [ -e $LXC_ROOT_FS/dev/ttyAMA0 ];then
info "Remove device /dev/ttyAMA0."
rm $LXC_ROOT_FS/dev/ttyAMA0
fi
#progress "Uninstall Yahm setup is done."
info "Uninstall gpio reset service..."
if [ -e $file_hm_mod_rpi_pcb ];then
if [ "$CODENAME" = "stretch" ] ;
then
update-rc.d hm-mod-rpi-pcb remove
else
insserv -r $file_hm_mod_rpi_pcb
fi
rm $file_hm_mod_rpi_pcb
progress "Remove $file_hm_mod_rpi_pcb."
fi
# enable serial
info "Enable serial..."
if grep -q "console=ttyAMA0" $file_cmdline_txt;then
if [ -e /proc/device-tree/aliases/serial0 ]; then
sed -i $file_cmdline_txt -e "s/console=ttyAMA0/console=serial0/"
reboot=$((reboot+1))
fi
progress "Enable serial is done."
elif ! grep -q "console=ttyAMA0" $file_cmdline_txt && ! grep -q "console=serial0" $file_cmdline_txt; then
if [ -e /proc/device-tree/aliases/serial0 ]; then
sed -i $file_cmdline_txt -e "s/root=/console=serial0,115200 root=/"
else
sed -i $file_cmdline_txt -e "s/root=/console=ttyAMA0,115200 root=/"
fi
reboot=$((reboot+1))
progress "Enable serial is done."
fi
# Reboot
if [ $reboot -gt 0 ]
then
echo "======================================"
echo "Rebooting in 60 seconds to apply settings (to chancel reboot type 'shutdown -c')..."
echo "======================================"
shutdown -r +1 "Rebooting to enable serial console"
else
info "HM-MOD-RPI-PCB was uninstalled successfully"
fi
}