Skip to content

Commit

Permalink
Port to ramips/rt305x HooToo HT-TM02
Browse files Browse the repository at this point in the history
  • Loading branch information
xabolcs committed Oct 16, 2022
1 parent bb4e1e9 commit dd8ee07
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 66 deletions.
40 changes: 24 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
ALL_CURL_OPTS := $(CURL_OPTS) -L --fail --create-dirs

VERSION := 21.02.3
BOARD := ath79
SUBTARGET := tiny
SOC := qca9563
BOARD := ramips
SUBTARGET := rt305x
SOC := rt5350
BUILDER := openwrt-imagebuilder-$(VERSION)-$(BOARD)-$(SUBTARGET).Linux-x86_64
PROFILES := tplink_tl-wpa8630p-v2.0-eu tplink_tl-wpa8630p-v2-int
PACKAGES := luci
EXTRA_IMAGE_NAME := patch
PROFILES := hootoo_ht-tm02
PACKAGES := -wpad-mini -wpad-basic -wpad-basic-wolfssl wpad-mesh-wolfssl
PACKAGES += -ppp -ppp-mod-pppoe
EXTRA_IMAGE_NAME := stocklayout+mesh+noppp
BASE_FILES := $(subst $(CURDIR)/,,$(wildcard $(CURDIR)/files/*))

TOPDIR := $(CURDIR)/$(BUILDER)
KDIR := $(TOPDIR)/build_dir/target-mips_24kc_musl/linux-$(BOARD)_$(SUBTARGET)
KDIR := $(TOPDIR)/build_dir/target-mipsel_24kc_musl/linux-$(BOARD)_$(SUBTARGET)
PATH := $(TOPDIR)/staging_dir/host/bin:$(PATH)
LINUX_VERSION = $(shell sed -n -e '/Linux-Version: / {s/Linux-Version: //p;q}' $(BUILDER)/.targetinfo)

Expand All @@ -32,33 +34,39 @@ $(BUILDER).tar.xz:

$(BUILDER): $(BUILDER).tar.xz
tar -xf $(BUILDER).tar.xz

# Fetch firmware utility sources to apply patches
curl $(ALL_CURL_OPTS) "https://git.openwrt.org/?p=openwrt/openwrt.git;hb=refs/tags/v21.02.3;a=blob_plain;f=tools/firmware-utils/src/tplink-safeloader.c" -o $(BUILDER)/tools/firmware-utils/src/tplink-safeloader.c
curl $(ALL_CURL_OPTS) "https://git.openwrt.org/?p=openwrt/openwrt.git;hb=refs/tags/v21.02.3;a=blob_plain;f=tools/firmware-utils/src/md5.h" -o $(BUILDER)/tools/firmware-utils/src/md5.h


# Fetch OpenWrt sources to apply patches
curl $(ALL_CURL_OPTS) "https://git.openwrt.org/?p=openwrt/openwrt.git;hb=refs/tags/v$(VERSION);a=blob_plain;f=package/boot/uboot-envtools/files/ramips" -o $(BUILDER)/package/boot/uboot-envtools/files/ramips
mkdir $(BUILDER)/target/linux/ramips/rt305x/base-files/etc/uci-defaults
touch $(BUILDER)/target/linux/ramips/rt305x/base-files/etc/uci-defaults/05_fix-compat-version

# Apply all patches
$(foreach file, $(sort $(wildcard patches/*.patch)), patch -d $(BUILDER) --posix -p1 < $(file);)
gcc -Wall -o $(TOPDIR)/staging_dir/host/bin/tplink-safeloader $(BUILDER)/tools/firmware-utils/src/tplink-safeloader.c -lcrypto -lssl

# Regenerate .targetinfo
cd $(BUILDER) && make -f include/toplevel.mk TOPDIR="$(TOPDIR)" prepare-tmpinfo || true
cp -f $(BUILDER)/tmp/.targetinfo $(BUILDER)/.targetinfo

ifneq "$(strip $(BASE_FILES))" ""
base-files: $(BASE_FILES)
$(info base-files are "$(BASE_FILES)")
cp -pvur $(BASE_FILES) $(TOPDIR)/target/linux/$(BOARD)/$(SUBTARGET)/base-files
else
base-files:
endif

linux-sources: $(BUILDER)
# Fetch DTS includes and other kernel source files
curl $(ALL_CURL_OPTS) "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/dt-bindings/clock/ath79-clk.h?h=v$(LINUX_VERSION)" -o linux-sources.tmp/include/dt-bindings/clock/ath79-clk.h
curl $(ALL_CURL_OPTS) "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/dt-bindings/gpio/gpio.h?h=v$(LINUX_VERSION)" -o linux-sources.tmp/include/dt-bindings/gpio/gpio.h
curl $(ALL_CURL_OPTS) "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/dt-bindings/input/input.h?h=v$(LINUX_VERSION)" -o linux-sources.tmp/include/dt-bindings/input/input.h
curl $(ALL_CURL_OPTS) "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/uapi/linux/input-event-codes.h?h=v$(LINUX_VERSION)" -o linux-sources.tmp/include/dt-bindings/input/linux-event-codes.h
rm -rf linux-sources
mv -T linux-sources.tmp linux-sources


images: $(BUILDER) linux-sources
images: $(BUILDER) linux-sources base-files
# Build this device's DTB and firmware kernel image. Uses the official kernel build as a base.
ln -sf /usr/bin/cpp $(BUILDER)/staging_dir/host/bin/mips-openwrt-linux-musl-cpp
ln -sf /usr/bin/cpp $(BUILDER)/staging_dir/host/bin/mipsel-openwrt-linux-musl-cpp
ln -sf ../../../../../linux-sources/include $(KDIR)/linux-$(LINUX_VERSION)/include
cd $(BUILDER) && $(foreach PROFILE,$(PROFILES),\
env PATH=$(PATH) make --trace -C target/linux/$(BOARD)/image $(KDIR)/$(PROFILE)-kernel.bin TOPDIR="$(TOPDIR)" INCLUDE_DIR="$(TOPDIR)/include" TARGET_BUILD=1 BOARD="$(BOARD)" SUBTARGET="$(SUBTARGET)" PROFILE="$(PROFILE)" DEVICE_DTS="$(SOC)_$(PROFILE)"\
Expand Down
39 changes: 12 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,33 @@
## Overview

This repository contains a simple patch to enable the [OpenWrt firmware for the TP-Link TL-WPA8630P v2](https://openwrt.org/toh/tp-link/tl-wpa8630p_v2) to be flashed to the following devices which are not officially supported.
This repository contains a few simple patch to allow a few `ramips/rt305x` Sunvalleytek Tripmate devices to be flashed with **stock compatible flash layout** custom OpenWrt build.

It builds the images using the [OpenWrt ImageBuilder](https://openwrt.org/docs/guide-user/additional-software/imagebuilder). One advantage of this over from-source custom builds is that the kernel is the same as the official builds, so all kmods from the standard repos are installable.

The only difference between these firmwares and the offical firmwares is the extra model version in the firmware file's SupportList required to perform the upgrade. After installing, the device will be identical to the official OpenWrt image (i.e. `v2-int`, `v2.0-eu`, `v2.1-eu`). You can upgrade using the official sysupgrade firmwares matching the patched firmware. If you are reverting to stock later, make sure to use the exact same stock firmware version as you originally upgraded from.
The only difference between these firmwares and the offical HT-TM02 firmware is the [installation method](https://openwrt.org/toh/hootoo/ht-tm01_tripmate#installation): the firmwares in this repository need to be installed with TFTP recovery.

And because of this, you should never ever cross upgrade between official OpenWrt build and this custom build!

## Supported versions

| Hardware Version | Stock Firmware Version | Patched OpenWrt Firmware | Sysupgrade to official OpenWrt official image after install |
| --- | --- | --- | --- |
| `Model: TL-WPA8630(CA) Ver: 2.0` | All | `openwrt-patch-ath79-tiny-tplink_tl-wpa8630p-v2-int-squashfs-factory.bin` | `tplink_tl-wpa8630p-v2-int` |
| `Model: TL-WPA8630(US) Ver: 2.0` | `2.0.1 Build 20171011 Rel.33916` | `openwrt-patch-ath79-tiny-tplink_tl-wpa8630p-v2-int-squashfs-factory.bin` | `tplink_tl-wpa8630p-v2-int` |
| `Model: TL-WPA8630(EU) Ver: 2.0` | `2.0.2 Build 20171017 Rel.43480` | `openwrt-patch-ath79-tiny-tplink_tl-wpa8630p-v2.0-eu-squashfs-factory.bin` | `tplink_tl-wpa8630p-v2.0-eu` |

**!!! ONLY INSTALL THESE FIRMWARES IF YOUR CURRENT HARDWARE AND FIRMWARE VERSIONS EXACTLY MATCHES THE ENTRY IN THIS TABLE !!!**

If your device is running a different firmware version than those listed below, installing these firmwares will prevent your device from booting and turn it into a [brick](https://en.wikipedia.org/wiki/Brick_%28electronics%29). This is because the bootloader in the newer versions of the stock firmwares load the kernal and filesystem from a different memory location. It will not be recoverable without physically opening the device (which should not be attempted as it contains hazardous 110-230V voltages) and writing directly to the flash memory chip with a flash programmer. So only install this firmware on your device if its a complete match! For support for other versions, ask in the [OpenWrt forum](https://forum.openwrt.org/).

Where to find this information:
## Supported versions

* Hardware Version
* Where: On the barcode sticker on the back of the device.
* Example: `Model: TL-WPA8630P(EU) Ver: 2.0`
* Firmware Version
* Where: In the Web UI of the device under "System Tools -> Firmware Upgrade"
* Example: `2.0.3 Build 20171018 Rel.36564`
| Vendor | Model | Vendor Product Line | Stock firmware | Stock backup <small>from a random user</small> | OpenWrt Wiki device page |
| --- | --- | --- | --- | --- | --- |
| HooToo | HT-TM02 | `WiFiPort` | ... | [backup-fw-WiFiPort-HooToo-TM02-2.000.018-8850119415](https://drive.google.com/drive/folders/1PnhUEnPvaC5h0kxtm30y-SiWqHzyFvty?usp=sharing) | [HooToo HT-TM02 (TripMate Nano)](https://openwrt.org/toh/hootoo/tripmate-nano) |


## Download firmware

See the [releases page](https://github.com/jwmullally/openwrt_wpa8630pv2_patched_firmware/releases/) for links to the firmware images.
See the [releases page](https://github.com/xabolcs/openwrt_hootoo_ht-tm02_oldstable/releases) for links to the firmware images.

These are built using [this Github workflow](./.github/workflows/build_release_images.yml). You can see the build logs [here](https://github.com/jwmullally/openwrt_wpa8630pv2_patched_firmware/actions?query=workflow%3ABuild-Release-Images).
These are built using [this Github workflow](./.github/workflows/build_release_images.yml). You can see the build logs for a few days [here](https://github.com/xabolcs/openwrt_hootoo_ht-tm02_oldstable/actions?query=workflow%3ABuild-Release-Images).


## Installing

Choose the correct file from the table above and follow the [standard installation instructions](https://openwrt.org/toh/tp-link/tl-wpa8630p_v2#oem_easy_installation).

If you get "Wrong file" message during firmware upgrade, try renaming the file to something shorter like `openwrt-firmware.bin`.
Create a system backup first, write file `EnterRouterMode.sh` from [here](https://forum.openwrt.org/t/hootoo-ht-tm01-how-to-flash-stock-firmware/31436/50) to a USB stick (needs not be empty), and insert it to the device while it's running. This script will create a new folder on the USB stick with copies of the device's original partitions.

After installing, you should then sysupgrade to the corresponding official OpenWrt images and continue using those images as normal.
After you placed the backup to a safe place choose the `kernel.bin` and `rootfs.bin` for your device and follow the [TFTP recovery installation instructions](https://openwrt.org/toh/hootoo/ht-tm01_tripmate#installation)!


## Building
Expand All @@ -53,4 +38,4 @@ If you want to build the firmwares yourself, checkout this repo and do the follo
make
```

The firmware will be located at `openwrt-imagebuilder-ath79-tiny.Linux-x86_64/bin/targets/ath79/tiny/`. To customize the firmware further (packages etc), see the ImageBuilder wiki.
The firmware will be located at `openwrt-imagebuilder-*-ramips-rt305x.Linux-x86_64/bin/targets/ramips/rt305x/`. To customize the firmware further (packages etc), see the ImageBuilder wiki.
253 changes: 253 additions & 0 deletions patches/0001-ramips-fix-partitions-for-HooToo-HT-TM02.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Szabolcs Hubai <[email protected]>
Date: Sun, 16 Oct 2022 22:02:03 +0200
Subject: [PATCH] ramips: fix partitions for HooToo HT-TM02

to avoid overwriting unique stock partitions.
Due to this, sysupgrade.bin recipe have to be changed,
and the upgrade scripts also, as there are now partitions kernel
and rootfs instead firmware.

While at it, limit kernel and rootfs sizes:
- kernel to 1.5M to avoid boot loop (LZMA ERROR 1)
- rootfs to 6M to avoid hard bricked devices due to overflowing TFTP recovery

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 RAVPower RP-WD03 partition fix commit 07aa858a73e6,
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-rt305x-hootoo_ht-tm02-squashfs-kernel.bin => kernel
- openwrt-ramips-rt305x-hootoo_ht-tm02-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 extend rootfs partition by
"appending" the OEM user and userbackup partitions to rootfs

Most of the changes in this commit are the work of Russell Morris and
Adrian Schmutzler (as credited below), I just backported to HT-TM02.

Suggested-by: Russell Morris <[email protected]>
Suggested-by: Adrian Schmutzler <[email protected]>
Signed-off-by: Szabolcs Hubai <[email protected]>
---
package/boot/uboot-envtools/files/ramips | 1 +
.../ramips/dts/rt5350_hootoo_ht-tm02.dts | 45 ++++++++++++++++---
target/linux/ramips/image/rt305x.mk | 11 ++++-
.../etc/uci-defaults/05_fix-compat-version | 10 +++++
.../rt305x/base-files/lib/upgrade/platform.sh | 36 +++++++++++++++
5 files changed, 96 insertions(+), 7 deletions(-)
create mode 100644 target/linux/ramips/rt305x/base-files/etc/uci-defaults/05_fix-compat-version

diff --git a/package/boot/uboot-envtools/files/ramips b/package/boot/uboot-envtools/files/ramips
index 3e358ec6ac..f295580bae 100644
--- a/package/boot/uboot-envtools/files/ramips
+++ b/package/boot/uboot-envtools/files/ramips
@@ -44,6 +44,7 @@ zbtlink,zbt-wg2626|\
zte,mf283plus)
ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000"
;;
+hootoo,ht-tm02|\
hootoo,ht-tm05|\
ravpower,rp-wd03)
idx="$(find_mtd_index u-boot-env)"
diff --git a/target/linux/ramips/dts/rt5350_hootoo_ht-tm02.dts b/target/linux/ramips/dts/rt5350_hootoo_ht-tm02.dts
index 543fda74b7..36503860ab 100644
--- a/target/linux/ramips/dts/rt5350_hootoo_ht-tm02.dts
+++ b/target/linux/ramips/dts/rt5350_hootoo_ht-tm02.dts
@@ -4,7 +4,7 @@
#include <dt-bindings/input/input.h>

/ {
- compatible = "hootoo,ht-tm02", "ralink,rt5350-soc";
+ compatible = "hootoo,ht-tm02-stock", "ralink,rt5350-soc";
model = "HooToo HT-TM02";

aliases {
@@ -45,6 +45,23 @@
linux,input-type = <EV_SW>;
};
};
+
+ virtual_flash {
+ compatible = "mtd-concat";
+
+ devices = <&rootfs1 &rootfs2>;
+
+ partitions {
+ compatible = "fixed-partitions";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ partition@0 {
+ label = "rootfs";
+ reg = <0x0 0x0>;
+ };
+ };
+ };
};

&spi0 {
@@ -53,7 +70,7 @@
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
- spi-max-frequency = <10000000>;
+ spi-max-frequency = <50000000>;

partitions {
compatible = "fixed-partitions";
@@ -67,7 +84,7 @@
};

partition@30000 {
- label = "u-boot-env";
+ label = "config";
reg = <0x30000 0x10000>;
read-only;
};
@@ -79,9 +96,25 @@
};

partition@50000 {
- compatible = "denx,uimage";
- label = "firmware";
- reg = <0x50000 0x7b0000>;
+ label = "kernel";
+ reg = <0x50000 0x180000>;
+ };
+
+ partition@1d0000 {
+ label = "u-boot-env";
+ reg = <0x1d0000 0x10000>;
+ read-only;
+ };
+
+ rootfs2: partition@1e0000 {
+ label = "rootfs2";
+ reg = <0x1e0000 0x20000>;
+ read-only;
+ };
+
+ rootfs1: partition@200000 {
+ label = "rootfs1";
+ reg = <0x200000 0x600000>;
};
};
};
diff --git a/target/linux/ramips/image/rt305x.mk b/target/linux/ramips/image/rt305x.mk
index 9b498fa5ab..0f174faf04 100644
--- a/target/linux/ramips/image/rt305x.mk
+++ b/target/linux/ramips/image/rt305x.mk
@@ -600,7 +600,16 @@ define Device/hootoo_ht-tm02
DEVICE_VENDOR := HooToo
DEVICE_MODEL := HT-TM02
DEVICE_PACKAGES := kmod-usb-ohci kmod-usb2 kmod-usb-ledtrig-usbport
- SUPPORTED_DEVICES += ht-tm02
+ SUPPORTED_DEVICES += hootoo,ht-tm02-stock
+ IMAGE_SIZE := 6144k
+ KERNEL_SIZE := 1536k
+ IMAGES += kernel.bin rootfs.bin
+ IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
+ IMAGE/kernel.bin := append-kernel | check-size $$$$(KERNEL_SIZE)
+ IMAGE/rootfs.bin := append-rootfs | pad-rootfs | check-size $$$$(IMAGE_SIZE)
+ 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.
DEFAULT := n
endef
TARGET_DEVICES += hootoo_ht-tm02
diff --git a/target/linux/ramips/rt305x/base-files/etc/uci-defaults/05_fix-compat-version b/target/linux/ramips/rt305x/base-files/etc/uci-defaults/05_fix-compat-version
new file mode 100644
index 0000000000..3995a2731c
--- /dev/null
+++ b/target/linux/ramips/rt305x/base-files/etc/uci-defaults/05_fix-compat-version
@@ -0,0 +1,10 @@
+. /lib/functions.sh
+
+case "$(board_name)" in
+ hootoo,ht-tm02)
+ uci set system.@system[0].compat_version="2.0"
+ uci commit system
+ ;;
+esac
+
+exit 0
diff --git a/target/linux/ramips/rt305x/base-files/lib/upgrade/platform.sh b/target/linux/ramips/rt305x/base-files/lib/upgrade/platform.sh
index 786d57fc70..2138503823 100755
--- a/target/linux/ramips/rt305x/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ramips/rt305x/base-files/lib/upgrade/platform.sh
@@ -6,13 +6,49 @@ PART_NAME=firmware
REQUIRE_IMAGE_METADATA=1

platform_check_image() {
+ case "$(board_name)" in
+ ht-tm02)
+ local config_size=$(mtd_get_part_size config)
+
+ [ -n "$config_size" ] || return 0
+
+ cat << EOF
+The "config" partitions is not present.
+Probably you are using wingspinner's image.
+You need to roll back to vendor firmware + U-Boot first!
+After that you should install OpenWrt through
+"kernel" + "rootfs" TFTP recovery!
+Once this is done, retry!
+EOF
+ return 1
+ ;;
+ esac
return 0
}

+
+hootoo_do_upgrade() {
+ local tar_file="$1"
+
+ local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
+ board_dir=${board_dir%/}
+
+ tar Oxf $tar_file ${board_dir}/kernel | mtd write - kernel
+
+ if [ -n "$UPGRADE_BACKUP" ]; then
+ tar Oxf $tar_file ${board_dir}/root | mtd -j "$UPGRADE_BACKUP" write - rootfs
+ else
+ tar Oxf $tar_file ${board_dir}/root | mtd write - rootfs
+ fi
+}
+
+
platform_do_upgrade() {
local board=$(board_name)

case "$board" in
+ ht-tm02)
+ hootoo_do_upgrade "$1"
*)
default_do_upgrade "$1"
;;
Loading

0 comments on commit dd8ee07

Please sign in to comment.