From fe0081eecf43bfd92ac68aa0f3ce7165aaddb4f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Tue, 30 Jan 2024 21:30:20 +0100 Subject: [PATCH] bcm27xx: use PARTUUID for root in cmdline MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This allows booting from USB/NVME while keeping SD compatibility. Signed-off-by: Álvaro Fernández Rojas --- .../base-files/lib/preinit/79_move_config | 5 ++- .../base-files/lib/preinit/81_set_root_part | 12 +++++++ .../base-files/lib/upgrade/platform.sh | 33 ++++++++++++++++++- target/linux/bcm27xx/image/Makefile | 8 ++++- target/linux/bcm27xx/image/cmdline.txt | 2 +- 5 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 target/linux/bcm27xx/base-files/lib/preinit/81_set_root_part diff --git a/target/linux/bcm27xx/base-files/lib/preinit/79_move_config b/target/linux/bcm27xx/base-files/lib/preinit/79_move_config index db5bf93b62..fed5278130 100644 --- a/target/linux/bcm27xx/base-files/lib/preinit/79_move_config +++ b/target/linux/bcm27xx/base-files/lib/preinit/79_move_config @@ -16,7 +16,10 @@ move_config() { insmod vfat mkdir -p /boot mount -t vfat -o rw,noatime /dev/$partdev /boot - [ -f "/boot/$BACKUP_FILE" ] && mv -f "/boot/$BACKUP_FILE" / + if [ -f "/boot/$BACKUP_FILE" ]; then + mv -f "/boot/$BACKUP_FILE" / + export BCM27XX_SET_ROOT_PART=1 + fi fi } diff --git a/target/linux/bcm27xx/base-files/lib/preinit/81_set_root_part b/target/linux/bcm27xx/base-files/lib/preinit/81_set_root_part new file mode 100644 index 0000000000..a915150213 --- /dev/null +++ b/target/linux/bcm27xx/base-files/lib/preinit/81_set_root_part @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only + +. /lib/upgrade/platform.sh + +do_set_root_part() { + if [ "$BCM27XX_SET_ROOT_PART" -eq "1" ]; then + bcm27xx_set_root_part + unset BCM27XX_SET_ROOT_PART + fi +} + +[ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_set_root_part diff --git a/target/linux/bcm27xx/base-files/lib/upgrade/platform.sh b/target/linux/bcm27xx/base-files/lib/upgrade/platform.sh index 3182a555a9..69cc60e2bc 100644 --- a/target/linux/bcm27xx/base-files/lib/upgrade/platform.sh +++ b/target/linux/bcm27xx/base-files/lib/upgrade/platform.sh @@ -85,15 +85,46 @@ platform_do_upgrade() { get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync } +bcm27xx_set_root_part() { + local root_part + + if [ -f "/boot/partuuid.txt" ]; then + root_part="PARTUUID=$(cat "/boot/partuuid.txt")-02" + else + root_part="/dev/mmcblk0p2" + fi + + sed -i "s#\broot=[^ ]*#root=${root_part}#g" "/boot/cmdline.txt" +} + platform_copy_config() { local partdev if export_partdevice partdev 1; then mkdir -p /boot [ -f /boot/kernel*.img ] || mount -t vfat -o rw,noatime "/dev/$partdev" /boot - cp -af "$UPGRADE_BACKUP" "/boot/$BACKUP_FILE" + tar -C / -zxvf "$UPGRADE_BACKUP" boot/cmdline.txt boot/config.txt + bcm27xx_set_root_part + + local backup_tmp="/tmp/backup-update" + mkdir -p $backup_tmp + tar -C $backup_tmp -zxvf $UPGRADE_BACKUP + cp -af /boot/cmdline.txt $backup_tmp/boot/ + + local work_dir=$(pwd) + cd $backup_tmp + tar -C $backup_tmp -zcvf /boot/$BACKUP_FILE * + cd $work_dir + sync umount /boot fi } + +platform_restore_backup() { + local TAR_V=$1 + + tar -C / -x${TAR_V}zf "$CONF_RESTORE" + bcm27xx_set_root_part +} diff --git a/target/linux/bcm27xx/image/Makefile b/target/linux/bcm27xx/image/Makefile index e45f53de8e..9d41e47bac 100644 --- a/target/linux/bcm27xx/image/Makefile +++ b/target/linux/bcm27xx/image/Makefile @@ -15,13 +15,19 @@ endef ### Image scripts ### define Build/boot-common + echo $(IMG_PART_SIGNATURE) > $@-partuuid.txt + sed \ + -e 's#@ROOT@#PARTUUID=$(IMG_PART_SIGNATURE)-02#g' \ + cmdline.txt > $@-cmdline.txt + rm -f $@.boot mkfs.fat -n boot -C $@.boot $(FAT32_BLOCKS) mcopy -i $@.boot $(KDIR)/COPYING.linux :: mcopy -i $@.boot $(KDIR)/LICENCE.broadcom :: - mcopy -i $@.boot cmdline.txt :: + mcopy -i $@.boot $@-cmdline.txt ::cmdline.txt mcopy -i $@.boot config.txt :: mcopy -i $@.boot distroconfig.txt :: + mcopy -i $@.boot $@-partuuid.txt ::partuuid.txt mcopy -i $@.boot $(IMAGE_KERNEL) ::$(KERNEL_IMG) $(foreach dts,$(shell echo $(DEVICE_DTS)),mcopy -i $@.boot $(DTS_DIR)/$(dts).dtb ::;) mmd -i $@.boot ::/overlays diff --git a/target/linux/bcm27xx/image/cmdline.txt b/target/linux/bcm27xx/image/cmdline.txt index d9b7d867a7..41f76f10af 100644 --- a/target/linux/bcm27xx/image/cmdline.txt +++ b/target/linux/bcm27xx/image/cmdline.txt @@ -1 +1 @@ -console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=squashfs,ext4 rootwait +console=serial0,115200 console=tty1 root=@ROOT@ rootfstype=squashfs,ext4 rootwait -- 2.30.2