ramips: fix partitions and boot for RAVPower RP-WD03
authorAdrian Schmutzler <freifunk@adrianschmutzler.de>
Fri, 11 Sep 2020 15:40:46 +0000 (17:40 +0200)
committerAdrian Schmutzler <freifunk@adrianschmutzler.de>
Fri, 11 Sep 2020 17:31:03 +0000 (19:31 +0200)
The RAVPower RP-WD03 is a battery powered router, with an Ethernet and
USB port. Due due a limitation in the vendor supplied U-Boot bootloader,
we cannot exceed a 1.5 MB kernel size, as is the case with recent builds
(i.e. post v19.07). This breaks both factory and sysupgrade images.

To address this, use the lzma loader (loader-okli) to work around this
limitation.

The improvements here also address the "misplaced" U-Boot environment
partition, which is located between the kernel and rootfs in the stock
image / implementation. This is addressed by making use of mtd-concat,
maximizing space available in the booted image.
This will make sysupgrade from earlier versions impossible.

Changes are based on the recently supported HooToo HT-TM05, as the
hardware is almost identical (except for RAM size) and is from the same
vendor (SunValley). While at it, also change the SPI frequency
accordingly.

Installation:

 - Download the needed OpenWrt install files, place them in the root
   of a clean TFTP server running on your computer. Rename the files as,
   - openwrt-ramips-mt7620-ravpower_rp-wd03-squashfs-kernel.bin => kernel
   - openwrt-ramips-mt7620-ravpower_rp-wd03-squashfs-rootfs.bin => rootfs
 - Plug the router into your computer via Ethernet
 - Set your computer to use 10.10.10.254 as its IP address
 - With your router shut down, hold down the power button until the first
   white LED lights up.
 - Push and hold the reset button and release the power button. Continue
   holding the reset button for 30 seconds or until it begins searching
   for files on your TFTP server, whichever comes first.
 - The router (10.10.10.128) will look for your computer at 10.10.10.254
   and install the two files. Once it has finished installation, it will
   automatically reboot and start up OpenWrt.
 - Set your computer to use DHCP for its IP address

Notes:

 - U-Boot environment can be modified, u-boot-env is preserved on initial
   install or sysupgrade
 - mtd-concat functionality is included, to leave a "hole" for u-boot-env,
   combining the OEM kernel and rootfs partitions

Most of the changes in this commit are the work of Russell Morris (as
credited below), I only wrapped them up and added compat-version.
Thanks to @mpratt14 and @xabolcs for their help getting the lzma loader
to work!

Fixes: 5ef79af4f80f ("ramips: add support for Ravpower WD03")
Suggested-by: Russell Morris <rmorris@rkmorris.us>
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
package/boot/uboot-envtools/Makefile
package/boot/uboot-envtools/files/ramips
target/linux/ramips/dts/mt7620n_ravpower_rp-wd03.dts
target/linux/ramips/image/mt7620.mk
target/linux/ramips/mt7620/base-files/etc/uci-defaults/05_fix-compat-version [new file with mode: 0644]

index 7a27a295967cfb7d840b9cd72e448c8c02c4ea11..7d464f8d08b97a19dbb1214189d264415bba3e69 100644 (file)
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=uboot-envtools
 PKG_DISTNAME:=u-boot
 PKG_VERSION:=2020.04
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE:=$(PKG_DISTNAME)-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:= \
index 6be2f6dcaeeff4ca6752322e3de0bf71bd1a8d05..6ff04b26e8fca8d742604edd7d9de394017dbe9e 100644 (file)
@@ -33,7 +33,8 @@ xiaomi,miwifi-nano|\
 zbtlink,zbt-wg2626)
        ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000"
        ;;
-hootoo,ht-tm05)
+hootoo,ht-tm05|\
+ravpower,rp-wd03)
        idx="$(find_mtd_index u-boot-env)"
        [ -n "$idx" ] && \
                ubootenv_add_uci_config "/dev/mtd$idx" "0x4000" "0x1000" "0x1000"
index 31ecd4dd85b9d863cbc7e8221aebc6cac6d1e37d..407697a5e3f522dfc1eed0e476ea8fc23d3b8ddd 100644 (file)
                        linux,code = <KEY_RESTART>;
                };
        };
+
+       virtual_flash {
+               compatible = "mtd-concat";
+
+               devices = <&firmware1 &firmware2 &firmware3>;
+
+               partitions {
+                       compatible = "fixed-partitions";
+                       #address-cells = <1>;
+                       #size-cells = <1>;
+
+                       partition@0 {
+                               compatible = "openwrt,okli";
+                               label = "firmware";
+                               reg = <0x0 0x0>;
+                       };
+               };
+       };
 };
 
 &gpio2 {
@@ -56,7 +74,8 @@
        flash@0 {
                compatible = "jedec,spi-nor";
                reg = <0>;
-               spi-max-frequency = <10000000>;
+               spi-max-frequency = <50000000>;
+               m25p,fast-read;
 
                partitions {
                        compatible = "fixed-partitions";
@@ -70,7 +89,7 @@
                        };
 
                        partition@30000 {
-                               label = "u-boot-env";
+                               label = "config";
                                reg = <0x30000 0x10000>;
                                read-only;
                        };
                        };
 
                        partition@50000 {
-                               compatible = "denx,uimage";
-                               label = "firmware";
-                               reg = <0x50000 0x7b0000>;
+                               label = "loader";
+                               reg = <0x50000 0x10000>;
+                               read-only;
+                       };
+
+                       firmware2: partition@60000 {
+                               label = "firmware2";
+                               reg = <0x60000 0x170000>;
+                       };
+
+                       partition@1d0000 {
+                               label = "u-boot-env";
+                               reg = <0x1d0000 0x10000>;
+                       };
+
+                       firmware3: partition@1e0000 {
+                               label = "firmware3";
+                               reg = <0x1e0000 0x20000>;
+                       };
+
+                       firmware1: partition@200000 {
+                               label = "firmware1";
+                               reg = <0x200000 0x600000>;
                        };
                };
        };
index a3a468324ba7ab4cad04f67f6a0b777a81370cd9..d9725c9e696fa684a3097e62322da609e3902825 100644 (file)
@@ -488,11 +488,9 @@ define Device/hnet_c108
 endef
 TARGET_DEVICES += hnet_c108
 
-define Device/hootoo_ht-tm05
+define Device/sunvalley_filehub_common
   SOC := mt7620n
   IMAGE_SIZE := 6144k
-  DEVICE_VENDOR := HooToo
-  DEVICE_MODEL := HT-TM05
   DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-i2c-ralink
   LOADER_TYPE := bin
   LOADER_FLASH_OFFS := 0x200000
@@ -505,6 +503,12 @@ define Device/hootoo_ht-tm05
   IMAGE/kernel.bin := append-loader-okli $(1) | check-size 64k
   IMAGE/rootfs.bin := $$(sysupgrade_bin) | check-size
 endef
+
+define Device/hootoo_ht-tm05
+  $(Device/sunvalley_filehub_common)
+  DEVICE_VENDOR := HooToo
+  DEVICE_MODEL := HT-TM05
+endef
 TARGET_DEVICES += hootoo_ht-tm05
 
 define Device/iodata_wn-ac1167gr
@@ -925,13 +929,13 @@ endef
 TARGET_DEVICES += ralink_mt7620a-v22sg-evb
 
 define Device/ravpower_rp-wd03
-  SOC := mt7620n
-  IMAGE_SIZE := 7872k
+  $(Device/sunvalley_filehub_common)
   DEVICE_VENDOR := RAVPower
   DEVICE_MODEL := RP-WD03
-  DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci
   SUPPORTED_DEVICES += ravpower,wd03
-  DEFAULT := n
+  DEVICE_COMPAT_VERSION := 2.0
+  DEVICE_COMPAT_MESSAGE := Partition design has changed compared to older versions (up to 19.07) due to kernel size restrictions. \
+       Upgrade via sysupgrade mechanism is not possible, so new installation via TFTP is required.
 endef
 TARGET_DEVICES += ravpower_rp-wd03
 
diff --git a/target/linux/ramips/mt7620/base-files/etc/uci-defaults/05_fix-compat-version b/target/linux/ramips/mt7620/base-files/etc/uci-defaults/05_fix-compat-version
new file mode 100644 (file)
index 0000000..9f981df
--- /dev/null
@@ -0,0 +1,10 @@
+. /lib/functions.sh
+
+case "$(board_name)" in
+       ravpower,rp-wd03)
+               uci set system.@system[0].compat_version="2.0"
+               uci commit system
+               ;;
+esac
+
+exit 0