Skip to content

Commit e4a76a4

Browse files
committed
Fix config settings issues with device tree, 1-wire and serial.
1 parent b6ba71e commit e4a76a4

File tree

3 files changed

+101
-61
lines changed

3 files changed

+101
-61
lines changed

myDevices/cloud/cayennemqtt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
SYS_I2C = 'sys:i2c'
2323
SYS_SPI = 'sys:spi'
2424
SYS_UART = 'sys:uart'
25+
SYS_ONEWIRE = 'sys:1wire'
2526
SYS_DEVICETREE = 'sys:devicetree'
2627
SYS_GPIO = 'sys:gpio'
2728
SYS_POWER_RESET = 'sys:pwr:reset'

myDevices/cloud/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ def SendSystemInfo(self):
248248
cayennemqtt.DataChannel.add(data, cayennemqtt.SYS_POWER_HALT, value=0)
249249
config = SystemConfig.getConfig()
250250
if config:
251-
channel_map = {'I2C': cayennemqtt.SYS_I2C, 'SPI': cayennemqtt.SYS_SPI, 'Serial': cayennemqtt.SYS_UART, 'DeviceTree': cayennemqtt.SYS_DEVICETREE}
251+
channel_map = {'I2C': cayennemqtt.SYS_I2C, 'SPI': cayennemqtt.SYS_SPI, 'Serial': cayennemqtt.SYS_UART,
252+
'OneWire': cayennemqtt.SYS_ONEWIRE, 'DeviceTree': cayennemqtt.SYS_DEVICETREE}
252253
for key, channel in channel_map.items():
253254
try:
254255
cayennemqtt.DataChannel.add(data, channel, value=config[key])
@@ -385,7 +386,7 @@ def ExecuteMessage(self, message):
385386
self.ProcessGpioCommand(message)
386387
elif channel == cayennemqtt.AGENT_DEVICES:
387388
self.ProcessDeviceCommand(message)
388-
elif channel in (cayennemqtt.SYS_I2C, cayennemqtt.SYS_SPI, cayennemqtt.SYS_UART, cayennemqtt.SYS_DEVICETREE):
389+
elif channel in (cayennemqtt.SYS_I2C, cayennemqtt.SYS_SPI, cayennemqtt.SYS_UART, cayennemqtt.SYS_ONEWIRE):
389390
self.ProcessConfigCommand(message)
390391
elif channel == cayennemqtt.AGENT_MANAGE:
391392
self.ProcessAgentCommand(message)
@@ -442,7 +443,7 @@ def ProcessConfigCommand(self, message):
442443
error = None
443444
try:
444445
value = 1 - int(message['payload']) #Invert the value since the config script uses 0 for enable and 1 for disable
445-
command_id = {cayennemqtt.SYS_I2C: 11, cayennemqtt.SYS_SPI: 12, cayennemqtt.SYS_UART: 13, cayennemqtt.SYS_DEVICETREE: 9}
446+
command_id = {cayennemqtt.SYS_I2C: 11, cayennemqtt.SYS_SPI: 12, cayennemqtt.SYS_UART: 13, cayennemqtt.SYS_ONEWIRE: 19}
446447
result, output = SystemConfig.ExecuteConfigCommand(command_id[message['channel']], value)
447448
debug('ProcessConfigCommand: {}, result: {}, output: {}'.format(message, result, output))
448449
if result != 0:

scripts/config.sh

Lines changed: 96 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -315,35 +315,35 @@ do_ssh() {
315315
}
316316

317317
do_devicetree() {
318-
CURRENT_SETTING="enabled" # assume not disabled
319-
DEFAULT=
320-
if [ -e $CONFIG ] && grep -q "^device_tree=$" $CONFIG; then
321-
CURRENT_SETTING="disabled"
322-
DEFAULT=--defaultno
323-
fi
324-
RET=${args[1]}
325-
if [ $RET -eq 0 ]; then
326-
sed $CONFIG -i -e "s/^\(device_tree=\)$/#\1/"
327-
sed $CONFIG -i -e "s/^#\(device_tree=.\)/\1/"
328-
SETTING=enabled
329-
elif [ $RET -eq 1 ]; then
330-
sed $CONFIG -i -e "s/^#\(device_tree=\)$/\1/"
331-
sed $CONFIG -i -e "s/^\(device_tree=.\)/#\1/"
332-
if ! grep -q "^device_tree=$" $CONFIG; then
333-
printf "device_tree=\n" >> $CONFIG
334-
fi
335-
SETTING=disabled
336-
else
337-
return 0
338-
fi
339-
TENSE=is
340-
REBOOT=
341-
if [ $SETTING != $CURRENT_SETTING ]; then
342-
TENSE="will be"
343-
REBOOT=" after a reboot"
344-
ASK_TO_REBOOT=1
345-
fi
346-
318+
return 1 # No longer allow disabling the device tree since it is required and can prevent the Pi from booting
319+
# CURRENT_SETTING="enabled" # assume not disabled
320+
# DEFAULT=
321+
# if [ -e $CONFIG ] && grep -q "^device_tree=$" $CONFIG; then
322+
# CURRENT_SETTING="disabled"
323+
# DEFAULT=--defaultno
324+
# fi
325+
# RET=${args[1]}
326+
# if [ $RET -eq 0 ]; then
327+
# sed $CONFIG -i -e "s/^\(device_tree=\)$/#\1/"
328+
# sed $CONFIG -i -e "s/^#\(device_tree=.\)/\1/"
329+
# SETTING=enabled
330+
# elif [ $RET -eq 1 ]; then
331+
# sed $CONFIG -i -e "s/^#\(device_tree=\)$/\1/"
332+
# sed $CONFIG -i -e "s/^\(device_tree=.\)/#\1/"
333+
# if ! grep -q "^device_tree=$" $CONFIG; then
334+
# printf "device_tree=\n" >> $CONFIG
335+
# fi
336+
# SETTING=disabled
337+
# else
338+
# return 0
339+
# fi
340+
# TENSE=is
341+
# REBOOT=
342+
# if [ $SETTING != $CURRENT_SETTING ]; then
343+
# TENSE="will be"
344+
# REBOOT=" after a reboot"
345+
# ASK_TO_REBOOT=1
346+
# fi
347347
}
348348

349349
get_devicetree() {
@@ -524,27 +524,77 @@ get_spi() {
524524
fi
525525
}
526526

527-
do_serial() {
528-
CURRENT_STATUS="yes" # assume ttyAMA0 output enabled
529-
if ! grep -q "^T.*:.*:respawn:.*ttyAMA0" /etc/inittab; then
530-
CURRENT_STATUS="no"
527+
get_serial() {
528+
if grep -q -E "console=(serial0|ttyAMA0|ttyS0)" $CMDLINE ; then
529+
echo 0
530+
else
531+
echo 1
531532
fi
533+
}
532534

533-
#"Would you like a login shell to be accessible over serial?"
535+
get_serial_hw() {
536+
if grep -q -E "^enable_uart=1" $CONFIG ; then
537+
echo 0
538+
elif grep -q -E "^enable_uart=0" $CONFIG ; then
539+
echo 1
540+
elif [ -e /dev/serial0 ] ; then
541+
echo 0
542+
else
543+
echo 1
544+
fi
545+
}
546+
547+
do_serial() {
548+
CMDLINE=/boot/cmdline.txt
549+
DEFAULTS=--defaultno
550+
DEFAULTH=--defaultno
551+
CURRENTS=0
552+
CURRENTH=0
553+
554+
if [ $(get_serial) -eq 0 ]; then
555+
DEFAULTS=
556+
CURRENTS=1
557+
fi
558+
if [ $(get_serial_hw) -eq 0 ]; then
559+
DEFAULTH=
560+
CURRENTH=1
561+
fi
534562
RET=${args[1]}
535-
if [ $RET -eq 1 ]; then
536-
sed -i /etc/inittab -e "s|^.*:.*:respawn:.*ttyAMA0|#&|"
537-
sed -i /boot/cmdline.txt -e "s/console=ttyAMA0,[0-9]\+ //"
538-
#"Serial is now disabled"
539-
elif [ $RET -eq 0 ]; then
540-
sed -i /etc/inittab -e "s|^#\(.*:.*:respawn:.*ttyAMA0\)|\1|"
541-
if ! grep -q "^T.*:.*:respawn:.*ttyAMA0" /etc/inittab; then
542-
printf "T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100\n" >> /etc/inittab
563+
if [ $RET -eq $CURRENTS ]; then
564+
ASK_TO_REBOOT=1
565+
fi
566+
567+
if [ $RET -eq 0 ]; then
568+
if grep -q "console=ttyAMA0" $CMDLINE ; then
569+
if [ -e /proc/device-tree/aliases/serial0 ]; then
570+
sed -i $CMDLINE -e "s/console=ttyAMA0/console=serial0/"
571+
fi
572+
elif ! grep -q "console=ttyAMA0" $CMDLINE && ! grep -q "console=serial0" $CMDLINE ; then
573+
if [ -e /proc/device-tree/aliases/serial0 ]; then
574+
sed -i $CMDLINE -e "s/root=/console=serial0,115200 root=/"
575+
else
576+
sed -i $CMDLINE -e "s/root=/console=ttyAMA0,115200 root=/"
577+
fi
543578
fi
544-
if ! grep -q "console=ttyAMA0" /boot/cmdline.txt; then
545-
sed -i /boot/cmdline.txt -e "s/root=/console=ttyAMA0,115200 root=/"
579+
set_config_var enable_uart 1 $CONFIG
580+
SSTATUS=enabled
581+
HSTATUS=enabled
582+
elif [ $RET -eq 1 ]; then
583+
sed -i $CMDLINE -e "s/console=ttyAMA0,[0-9]\+ //"
584+
sed -i $CMDLINE -e "s/console=serial0,[0-9]\+ //"
585+
SSTATUS=disabled
586+
if [ $RET -eq $CURRENTH ]; then
587+
ASK_TO_REBOOT=1
588+
fi
589+
if [ $RET -eq 0 ]; then
590+
set_config_var enable_uart 1 $CONFIG
591+
HSTATUS=enabled
592+
elif [ $RET -eq 1 ]; then
593+
set_config_var enable_uart 0 $CONFIG
594+
HSTATUS=disabled
595+
else
596+
return $RET
546597
fi
547-
#"Serial is now enabled"
548598
else
549599
return $RET
550600
fi
@@ -561,18 +611,6 @@ get_camera() {
561611
echo $OUTPUT
562612
}
563613

564-
get_serial() {
565-
if grep -q -E "^enable_uart=1" $CONFIG ; then
566-
echo 0
567-
elif grep -q -E "^enable_uart=0" $CONFIG ; then
568-
echo 1
569-
elif [ -e /dev/serial0 ] ; then
570-
echo 0
571-
else
572-
echo 1
573-
fi
574-
}
575-
576614
get_w1(){
577615
if grep -q -E "^dtoverlay=w1-gpio" $CONFIG; then
578616
echo 0
@@ -618,7 +656,7 @@ case "$FUN" in
618656
15) get_timezone ;;
619657
16) do_timezone ;;
620658
17) get_camera ;;
621-
18) get_serial ;;
659+
18) get_serial_hw ;;
622660
19) do_w1 ;;
623661
20) get_w1 ;;
624662
21) get_i2c ;;

0 commit comments

Comments
 (0)