Skip to content

Commit f054a6f

Browse files
authored
Add CMDLINETXT variable for flexible boot file paths (#2080)
Definition of cmdline.txt path via existence check in subfolder firmware Signed-off-by: pudermueller <[email protected]>
1 parent 85aa7fb commit f054a6f

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

build-image/first-boot.bash

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
CONFIGFILE="/etc/openhabian.conf"
55

6+
CONFIGTXT=/boot/config.txt
7+
if [ -e /boot/firmware/config.txt ] ; then
8+
CONFIGTXT=/boot/firmware/config.txt
9+
fi
10+
611
# apt/dpkg commands will not try interactive dialogs
712
export DEBIAN_FRONTEND="noninteractive"
813
export SILENT="1"
@@ -110,7 +115,7 @@ if is_pi && is_bookworm; then
110115
elif grep -qs "up" /sys/class/net/eth0/operstate; then
111116
# Actually check if ethernet is working
112117
echo "$(timestamp) [openHABian] Setting up Ethernet connection... OK"
113-
elif [[ -n $wifiSSID ]] && grep -qs "openHABian" /etc/wpa_supplicant/wpa_supplicant.conf && ! grep -qsE "^[[:space:]]*dtoverlay=(pi3-)?disable-wifi" /boot/config.txt; then
118+
elif [[ -n $wifiSSID ]] && grep -qs "openHABian" /etc/wpa_supplicant/wpa_supplicant.conf && ! grep -qsE "^[[:space:]]*dtoverlay=(pi3-)?disable-wifi" "${CONFIGTXT}"; then
114119
echo -n "$(timestamp) [openHABian] Checking if WiFi is working... "
115120
if iwlist wlan0 scan |& grep -qs "Interface doesn't support scanning"; then
116121
ip link set wlan0 up

functions/ext-storage.bash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ move_root2usb() {
2424
local srcSize
2525
local destSize
2626

27-
rootPart="$(tr ' ' '\n' < /boot/cmdline.txt | grep 'root=PARTUUID=' | cut -d'=' -f2-)"
27+
rootPart="$(tr ' ' '\n' < "${CMDLINETXT}" | grep 'root=PARTUUID=' | cut -d'=' -f2-)"
2828
srcSize="$(blockdev --getsize64 /dev/mmcblk0)"
2929
destSize="$(blockdev --getsize64 "$newRootDev")"
3030

@@ -100,8 +100,8 @@ move_root2usb() {
100100
if ! cond_redirect sed -i 's|'"${rootPart}"'|'"${newRootPart}"'|' /mnt/etc/fstab; then echo "FAILED (fstab)"; return 1; fi
101101

102102
cond_echo "\\nAdjusting system root in cmdline.txt"
103-
if ! cond_redirect cp /boot/cmdline.txt /boot/cmdline.txt.sdcard; then echo "FAILED (backup cmdline.txt)"; return 1; fi
104-
if cond_redirect sed -i 's|root='"${rootPart}"'|root='"${newRootPart}"'|' /boot/cmdline.txt; then echo "OK (reboot required)"; else echo "FAILED"; return 1; fi
103+
if ! cond_redirect cp "${CMDLINETXT}" "${CMDLINETXT}.sdcard"; then echo "FAILED (backup cmdline.txt)"; return 1; fi
104+
if cond_redirect sed -i 's|root='"${rootPart}"'|root='"${newRootPart}"'|' "${CMDLINETXT}"; then echo "OK (reboot required)"; else echo "FAILED"; return 1; fi
105105

106106
whiptail --title "Operation successful" --msgbox "The system root has successfully been moved to the USB. PLEASE REBOOT!\\n\\nIn the unlikely case that the reboot does not succeed, please put the SD card into another device and copy back '/boot/cmdline.txt.sdcard' to '/boot/cmdline.txt'." 11 80
107107
}

functions/system.bash

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -561,19 +561,19 @@ prepare_serial_port() {
561561
else
562562
if ! (echo "enable_uart=1" >> "${CONFIGTXT}"); then echo "FAILED (uart)"; return 1; fi
563563
fi
564-
if ! cond_redirect cp /boot/cmdline.txt /boot/cmdline.txt.bak; then echo "FAILED (backup cmdline.txt)"; return 1; fi
565-
if ! cond_redirect sed -i -e 's|console=tty.*console=tty1|console=tty1|g' /boot/cmdline.txt; then echo "FAILED (console)"; return 1; fi
566-
if ! cond_redirect sed -i -e 's|console=serial.*console=tty1|console=tty1|g' /boot/cmdline.txt; then echo "FAILED (serial)"; return 1; fi
564+
if ! cond_redirect cp "${CMDLINETXT}" "${CMDLINETXT}.bak"; then echo "FAILED (backup cmdline.txt)"; return 1; fi
565+
if ! cond_redirect sed -i -e 's|console=tty.*console=tty1|console=tty1|g' "${CMDLINETXT}"; then echo "FAILED (console)"; return 1; fi
566+
if ! cond_redirect sed -i -e 's|console=serial.*console=tty1|console=tty1|g' "${CMDLINETXT}"; then echo "FAILED (serial)"; return 1; fi
567567
cond_echo "Disabling serial-getty service"
568568
if ! cond_redirect systemctl disable --now [email protected]; then echo "FAILED (disable [email protected])"; return 1; fi
569569
if ! cond_redirect systemctl disable --now [email protected]; then echo "FAILED (disable [email protected])"; return 1; fi
570570
if cond_redirect systemctl disable --now [email protected]; then echo "OK (reboot required)"; else echo "FAILED (disable [email protected])"; return 1; fi
571571
else
572-
if [[ -f /boot/cmdline.txt.bak ]]; then
572+
if [[ -f "${CMDLINETXT}.bak" ]]; then
573573
echo -n "$(timestamp) [openHABian] Disabling serial port and enabling serial console... "
574574
if ! cond_redirect sed -i -e '/^#*.*enable_uart=.*$/d' "${CONFIGTXT}"; then echo "FAILED (uart)"; return 1; fi
575-
if ! cond_redirect cp /boot/cmdline.txt.bak /boot/cmdline.txt; then echo "FAILED (restore cmdline.txt)"; return 1; fi
576-
if ! cond_redirect rm -f /boot/cmdline.txt.bak; then echo "FAILED (remove backup)"; return 1; fi
575+
if ! cond_redirect cp "${CMDLINETXT}.bak" "${CMDLINETXT}"; then echo "FAILED (restore cmdline.txt)"; return 1; fi
576+
if ! cond_redirect rm -f "${CMDLINETXT}.bak"; then echo "FAILED (remove backup)"; return 1; fi
577577
cond_echo "Enabling serial-getty service"
578578
if ! cond_redirect systemctl enable --now [email protected]; then echo "FAILED (enable [email protected])"; return 1; fi
579579
if ! cond_redirect systemctl enable --now [email protected]; then echo "FAILED (enable [email protected])"; return 1; fi

openhabian-setup.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,13 @@ OLDWD="$(pwd)"
7777
cd /opt || exit 1
7878

7979
CONFIGTXT=/boot/config.txt
80+
CMDLINETXT=/boot/cmdline.txt
8081
if is_bookworm; then
8182
CONFIGTXT=/boot/firmware/config.txt
83+
CMDLINETXT=/boot/firmware/cmdline.txt
8284
fi
8385
export CONFIGTXT
86+
export CMDLINETXT
8487

8588
# update openhabian.conf to have latest set of parameters
8689
update_openhabian_conf

0 commit comments

Comments
 (0)