[openwrt/openwrt] mediatek: filogic: wax220: support factory image

LEDE Commits lede-commits at lists.infradead.org
Tue Aug 22 04:40:52 PDT 2023


blocktrron pushed a commit to openwrt/openwrt.git, branch openwrt-23.05:
https://git.openwrt.org/16aecc12c23235a38e7e09d45b2ceea6fd54a147

commit 16aecc12c23235a38e7e09d45b2ceea6fd54a147
Author: Stefan Agner <stefan at agner.ch>
AuthorDate: Fri Jun 30 11:52:37 2023 +0200

    mediatek: filogic: wax220: support factory image
    
    Enable building a factory image which can be flashed through the OEM
    firmware's web interface. It seems that the web interface requires a
    minimum file size of 10MiB, otherwise it will not accept the image.
    
    The update image is a regular sysupgrade tarball packed in a Netgear
    encrypted image. The Netgear encrypted image is the same as used in
    WAX202 or WAX206, including the encryption keys and IV.
    
    This adds a script which creates the rootfs_data volume on first
    startup. This is required since the OEM firmware's sysupgrade scripts
    do not create such a paritition. Note that any script ordered after
    70_initramfs_test will not get executed on initramfs. Hence this new
    script 75_rootfs_prepare won't create the rootfs_data volume when
    using the recovery initramfs.
    
    Also, this deletes the kernel_backup and rootfs_backup volumes in case
    we have to create the rootfs_data volumes. This makes sure that
    OpenWrt is the actual backup firmware instead of the stock firmware.
    
    References in WAX220 GPL source:
    https://www.downloads.netgear.com/files/GPL/WAX220-V1.0.2.8-gpl-src.tar.gz
    
    * package/base-files/files/lib/upgrade/nand.sh:186
      Creation of rootfs_data is disabled
    
    * Uboot-upstream/board/mediatek/common/ubi_helper.c
      Automatic creation of UBI backup volumes
    
    Signed-off-by: Stefan Agner <stefan at agner.ch>
    (cherry picked from commit fa9d977f979461628161085dcd0e9dd8b9e2c66b)
---
 .../base-files/lib/preinit/75_rootfs_prepare       | 35 ++++++++++++++++++++++
 target/linux/mediatek/image/filogic.mk             | 16 +++++-----
 2 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/target/linux/mediatek/filogic/base-files/lib/preinit/75_rootfs_prepare b/target/linux/mediatek/filogic/base-files/lib/preinit/75_rootfs_prepare
new file mode 100644
index 0000000000..0a32073e0b
--- /dev/null
+++ b/target/linux/mediatek/filogic/base-files/lib/preinit/75_rootfs_prepare
@@ -0,0 +1,35 @@
+# SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause
+
+rootfs_create() {
+	local blocks
+
+	blocks=$(cat /sys/class/ubi/ubi0/avail_eraseblocks)
+	[ -z "$blocks" ] && {
+		echo "Failed to read amount of available erase blocks" >&2
+		return
+	}
+
+	# Delete after getting available blocks: Make sure enough space is
+	# left to recreate these volumes.
+	ubirmvol /dev/ubi0 -N kernel_backup
+	ubirmvol /dev/ubi0 -N rootfs_backup
+
+	# Use 90% of remaining flash size for "rootfs_data"
+	ubimkvol /dev/ubi0 -n 20 -N rootfs_data --lebs $((blocks / 100 * 90))
+	mknod -m 0600 /dev/ubi0_20 c 250 21
+}
+
+rootfs_prepare() {
+	case $(board_name) in
+	netgear,wax220)
+		if ! ubinfo /dev/ubi0 -N rootfs_data &>/dev/null; then
+			echo "Creating \"rootfs_data\" UBI volume"
+			rootfs_create
+		fi
+		;;
+	*)
+		;;
+	esac
+}
+
+boot_hook_add preinit_main rootfs_prepare
diff --git a/target/linux/mediatek/image/filogic.mk b/target/linux/mediatek/image/filogic.mk
index b00c9f6897..f61efca05e 100644
--- a/target/linux/mediatek/image/filogic.mk
+++ b/target/linux/mediatek/image/filogic.mk
@@ -225,18 +225,20 @@ endef
 TARGET_DEVICES += h3c_magic-nx30-pro
 
 define Device/netgear_wax220
-  DEVICE_VENDOR := Netgear
+  DEVICE_VENDOR := NETGEAR
   DEVICE_MODEL := WAX220
   DEVICE_DTS := mt7986b-netgear-wax220
   DEVICE_DTS_DIR := ../dts
+  NETGEAR_ENC_MODEL := WAX220
+  NETGEAR_ENC_REGION := US
   DEVICE_PACKAGES := kmod-mt7986-firmware mt7986-wo-firmware
-  IMAGES := sysupgrade.bin
-  KERNEL_IN_UBI := 1
-  KERNEL := kernel-bin | lzma | \
-        fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb
-  KERNEL_INITRAMFS := kernel-bin | lzma | \
-        fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb with-initrd | pad-to 64k
+  KERNEL_INITRAMFS_SUFFIX := -recovery.itb
+  IMAGE_SIZE := 32768k
   IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
+  IMAGES += factory.img
+  # Padding to 10M seems to be required by OEM web interface
+  IMAGE/factory.img := sysupgrade-tar | \
+	  pad-to 10M | check-size | netgear-encrypted-factory
 endef
 TARGET_DEVICES += netgear_wax220
 




More information about the lede-commits mailing list