@@ -315,35 +315,35 @@ do_ssh() {
315
315
}
316
316
317
317
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
347
347
}
348
348
349
349
get_devicetree () {
@@ -524,27 +524,77 @@ get_spi() {
524
524
fi
525
525
}
526
526
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
531
532
fi
533
+ }
532
534
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
534
562
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
543
578
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
546
597
fi
547
- # "Serial is now enabled"
548
598
else
549
599
return $RET
550
600
fi
@@ -561,18 +611,6 @@ get_camera() {
561
611
echo $OUTPUT
562
612
}
563
613
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
-
576
614
get_w1 (){
577
615
if grep -q -E " ^dtoverlay=w1-gpio" $CONFIG ; then
578
616
echo 0
@@ -618,7 +656,7 @@ case "$FUN" in
618
656
15) get_timezone ;;
619
657
16) do_timezone ;;
620
658
17) get_camera ;;
621
- 18) get_serial ;;
659
+ 18) get_serial_hw ;;
622
660
19) do_w1 ;;
623
661
20) get_w1 ;;
624
662
21) get_i2c ;;
0 commit comments