From 2c0978215be468e8a6db1f8b933e73032160f7fd Mon Sep 17 00:00:00 2001 From: Bartlomiej Grzeskowiak <bartlomiej.grzeskowiak@iopsys.eu> Date: Fri, 26 Nov 2021 12:27:59 +0100 Subject: [PATCH] iopsys-econet: Add mtd_squashfs sysupgrade This flash layout is not supposed to be used in the future. But more development devices will be delivered with non UBIFS flash chip. Therefore mtd squashfs sysupgrade is added to feeds. Signed-off-by: Bartlomiej Grzeskowiak <bartlomiej.grzeskowiak@iopsys.eu> --- .../base-files/lib/upgrade/platform.sh | 7 ++- iopsys-econet/en7562/boot.its | 8 +++ iopsys-econet/image/Makefile | 3 +- iopsys-econet/image/upgrade-bundle/upgrade | 56 ++++++++++++++++++- 4 files changed, 69 insertions(+), 5 deletions(-) diff --git a/iopsys-econet/base-files/lib/upgrade/platform.sh b/iopsys-econet/base-files/lib/upgrade/platform.sh index 333504656..3fe21e1f0 100644 --- a/iopsys-econet/base-files/lib/upgrade/platform.sh +++ b/iopsys-econet/base-files/lib/upgrade/platform.sh @@ -1,5 +1,10 @@ platform_check_image() { - return 0 + if [[ "ubifs" != "$(fw_printenv -n rootfstype)" ]]; then + #squashfs sysupgrade MUST be executed at early stage. Before including unsupported /lib/upgrade/iopsys.sh. + log sysupgrade "- Squshfs detected -" + iopsys_process_upgrade_bundle "$1" pre_upgrade || return + fi + return 0 } platform_do_upgrade() { diff --git a/iopsys-econet/en7562/boot.its b/iopsys-econet/en7562/boot.its index 004fcd2ab..c03717563 100755 --- a/iopsys-econet/en7562/boot.its +++ b/iopsys-econet/en7562/boot.its @@ -34,6 +34,14 @@ algo = "sha256"; }; }; + squashfs { + description = "squashfs"; + data = /incbin/("root.squashfs"); + compression = "none"; + hash@1 { + algo = "sha256"; + }; + }; upgrade_bundle { description = "upgrade_bundle"; data = /incbin/("upgrade-bundle.tar.gz"); diff --git a/iopsys-econet/image/Makefile b/iopsys-econet/image/Makefile index 3c729f4d8..0a616b811 100755 --- a/iopsys-econet/image/Makefile +++ b/iopsys-econet/image/Makefile @@ -86,6 +86,7 @@ define Image/Build cp $(KDIR)/root.ubifs $(BIN_DIR) cp $(KDIR)/root.ubifs ./ cp $(KDIR)/root.squashfs $(BIN_DIR) + cp $(KDIR)/root.squashfs $(PLATFORM_DIR)/$(SUBTARGET) ifneq ($(CONFIG_PACKAGE_tcboot),) #Copy compiled bootloader cp $(KDIR)/tcboot/src/tcboot.bin $(BIN_DIR)/iopboot.bin @@ -101,7 +102,7 @@ endif $(call Image/Build/GenerateUbifsFIT) #Cleanup temporary files - rm -f $(PLATFORM_DIR)/$(SUBTARGET)/linux.7z $(PLATFORM_DIR)/$(SUBTARGET)/ecnt.dtb $(PLATFORM_DIR)/$(SUBTARGET)/root.ubifs ./root.ubifs $(PLATFORM_DIR)/$(SUBTARGET)/ubilinux $(PLATFORM_DIR)/$(SUBTARGET)/upgrade-bundle.tar.gz $(PLATFORM_DIR)/$(SUBTARGET)/iopboot.bin + rm -f $(PLATFORM_DIR)/$(SUBTARGET)/linux.7z $(PLATFORM_DIR)/$(SUBTARGET)/ecnt.dtb $(PLATFORM_DIR)/$(SUBTARGET)/root.ubifs ./root.ubifs $(PLATFORM_DIR)/$(SUBTARGET)/root.squashfs $(PLATFORM_DIR)/$(SUBTARGET)/ubilinux $(PLATFORM_DIR)/$(SUBTARGET)/upgrade-bundle.tar.gz $(PLATFORM_DIR)/$(SUBTARGET)/iopboot.bin endef # diff --git a/iopsys-econet/image/upgrade-bundle/upgrade b/iopsys-econet/image/upgrade-bundle/upgrade index dc9618d5b..0c22cc761 100755 --- a/iopsys-econet/image/upgrade-bundle/upgrade +++ b/iopsys-econet/image/upgrade-bundle/upgrade @@ -1,6 +1,5 @@ #!/bin/sh - invocation=$1 image=$2 log_tag="$0 $1" @@ -14,6 +13,11 @@ do_pre_upgrade() { log "- pre_upgrade -" log "- dump u-boot env -" nanddump -s 0x7c000 -f ./uboot_env.bin /dev/mtd0 + + if [[ "ubifs" != "$(fw_printenv -n rootfstype)" ]]; then + log "- Squshfs detected -" + do_squashfs_update $image + fi } do_post_upgrade() { @@ -32,9 +36,55 @@ do_post_upgrade() { log "- Fixing uboot serdes_sel variable -" fw_setenv serdes_sel 2 fi +} + +do_exit_reboot() { + log "- exit and reboot -" + reboot && sleep 60 ; reboot -f ; sleep 60 ; exit 1 +} + +do_squashfs_update() { + local image=$1 + local next_bank_boot_mtd="mtd2" + local next_bank_rootfs_mtd="mtd4" + local next_bank_id="2" + + if [[ "1" != "$(fw_printenv -n active_image)" ]]; then + next_bank_boot_mtd="mtd1" + next_bank_rootfs_mtd="mtd3" + next_bank_id="1" + fi + + if [ ! -f "$image" ]; then + log "- $image does not exist -" + exit 1 + fi + + log "- Start squashfs bank$next_bank_id sysupgrade -" + fdtextract -e bootloader $image -o /tmp/bootloader.bin + if [ -f "bootloader.bin" ]; then + log "- Upgrading bootloader -" + flash_erase /dev/mtd0 0 0 + nandwrite -p /dev/mtd0 /tmp/bootloader.bin + rm /tmp/bootloader.bin + fi + + log "- Upgrading kernel -" + fdtextract -e boot $image -o /tmp/boot.bin + flash_erase /dev/$next_bank_boot_mtd 0 0 + nandwrite -p /dev/$next_bank_boot_mtd /tmp/boot.bin + rm /tmp/boot.bin + + log "- Upgrading rootfs -" + fdtextract -e squashfs $image -o /tmp/squashfs.bin + flash_erase /dev/$next_bank_rootfs_mtd 0 0 + nandwrite -p /dev/$next_bank_rootfs_mtd /tmp/squashfs.bin + rm /tmp/squashfs.bin - #For future use - #reboot && sleep 60 ; reboot -f ; sleep 60 ; exit 1 + do_post_upgrade $image + log "- Set boot bank $next_bank_id and reboot-" + fw_setenv active_image $next_bank_id + do_exit_reboot } case $invocation in -- GitLab