Build OpenWrt for router with flash mod (tplink tl-mr3020-v1)

Hello,
been using OpenWrt 19.07 on a TL-MR3020 for quite a while, and would like to upgrade to the latest 21.02, but I can't get a custom build to work.
First of all, yes, I know it is a 4/32 router and shouldn't be supported, but long ago I soldered in an 8MB SPI flash and rebuilt uboot, it's been working with 19.07 ever since.

Now, to build openwrt I am applying the following patch (basically the same I was using with 19.07):

diff --git a/target/linux/ath79/image/tiny-tp-link.mk b/target/linux/ath79/image/tiny-tp-link.mk
index c918c6baa6..a123a3a8bd 100644
--- a/target/linux/ath79/image/tiny-tp-link.mk
+++ b/target/linux/ath79/image/tiny-tp-link.mk
@@ -11,8 +11,7 @@ endef
 TARGET_DEVICES += tplink_tl-mr10u
 
 define Device/tplink_tl-mr3020-v1
-  $(Device/tplink-4mlzma)
-  IMAGE_SIZE := 3840k
+  $(Device/tplink-8mlzma)
   SOC := ar9331
   DEVICE_MODEL := TL-MR3020
   DEVICE_VARIANT := v1

but the resulting firmware enters a bootloop trying to find the start of the jffs2 partition, here's an excerpt of the bootlogs taken via serial port:

[    0.321141] spi-nor spi0.0: s25fl064k (8192 Kbytes)
[    0.324666] 4 fixed-partitions partitions found on MTD device spi0.0
[    0.330925] Creating 4 MTD partitions on "spi0.0":
[    0.335713] 0x000000000000-0x000000020000 : "u-boot"
[    0.342249] 0x000000020000-0x0000003e0000 : "firmware"
[    0.350243] 2 tplink-fw partitions found on MTD device firmware
[    0.354807] Creating 2 MTD partitions on "firmware":
[    0.359692] 0x000000000000-0x000000174330 : "kernel"
[    0.366123] 0x000000174330-0x0000003c0000 : "rootfs"
[    0.371249] mtd: device 3 (rootfs) set to be root filesystem
[    0.378182] mtdsplit: squashfs has invalid size in "rootfs"
[    0.382466] 0x0000003e0000-0x0000003f0000 : "config"
[    0.388813] 0x0000003f0000-0x000000400000 : "art"
...
[    1.127925] Flash size not aligned to erasesize, reducing to 2348KiB
[    1.133403] jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000000: 0x6873 instead
[    1.142353] jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000004: 0xf504 instead
[    1.151772] jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000008: 0xef20 instead
[    1.161233] jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000010: 0x0c00 instead
[    1.170695] jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000014: 0x0400 instead
[    1.180156] jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000018: 0xc004 instead
[    1.189619] jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x0000001c: 0x0400 instead
[    1.199081] jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000020: 0xcb03 instead
[    1.208541] jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000028: 0xcea2 instead
[    1.218003] jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000030: 0xc6a2 instead
[    1.227458] jffs2: Further such events for this erase block will not be printed
[    1.235820] jffs2: Empty flash at 0x00000038 ends at 0x00000040
[    1.241145] jffs2: Old JFFS2 bitmask found at 0x00000fc8
[    1.245945] jffs2: You cannot use older JFFS2 filesystems with newer kernels

for comparison, here's the bootlogs of the previous openwrt 19.07 I reinstalled while i figure out how to fix this (this is the first boot after flashing):

[    0.564319] m25p80 spi0.0: found s25fl064k, expected m25p80
[    0.580728] m25p80 spi0.0: s25fl064k (8192 Kbytes)
[    0.584442] 5 tp-link partitions found on MTD device spi0.0
[    0.589667] Creating 5 MTD partitions on "spi0.0":
[    0.594410] 0x000000000000-0x000000020000 : "u-boot"
[    0.601391] 0x000000020000-0x000000164628 : "kernel"
[    0.608070] 0x000000164628-0x0000007f0000 : "rootfs"
[    0.612760] mtd: device 2 (rootfs) set to be root filesystem
[    0.617363] 1 squashfs-split partitions found on MTD device rootfs
[    0.623406] 0x0000003b0000-0x0000007f0000 : "rootfs_data"
[    0.632152] 0x0000007f0000-0x000000800000 : "art"
[    0.637554] 0x000000020000-0x0000007f0000 : "firmware"
...
[   58.004393] jffs2_scan_eraseblock(): End of filesystem marker found at 0x0
[   58.016717] jffs2_build_filesystem(): unlocking the mtd device... 
[   58.016800] done.
[   58.023435] jffs2_build_filesystem(): erasing all blocks after the end marker... 

it's as-if the partitions in the new build are wrong and still refer to the 4MB flash size despite my attempt to tell the build system we have 8MB flash... any idea how to fix this?

Are you sure that this one change was all that you have done???
It does not touch the DTS at all.

(Was your previous build with ath79, or was it old-fashioned ar71xx without DTS?)

See e.g. 3020v1

2 Likes

That's a good reason for not working.
My previous build was ar71xx, I was not aware that now there's also to modify the DTS.
Will try and report back if it works, thanks.

1 Like

Thanks. That indeed got me closer to the solution.
Now the router boots fine but there's no wireless interface.

In the bootlogs I noticed the following lines:

[   20.120706] ath: phy0: Unable to initialize hardware; initialization status: -5
[   20.126599] ath9k 18100000.wmac: failed to initialize device
[   20.132313] ath9k: probe of 18100000.wmac failed with error -5

Searching online I found this link: https://patchwork.ozlabs.org/project/openwrt/patch/20200408132229.3873-2-freifunk@adrianschmutzler.de/
which links this error to missing caldata.

Despite not knowing how this code works, I had a look and it turns out that in the file target/linux/ath79/tiny/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom there's no mention of tl-mr3020-v1, maybe no one bothered to support it since it is a 4/32 router?

So I came up with this patch, that in my opinion could have fixed the problem:

diff --git a/target/linux/ath79/tiny/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/ath79/tiny/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
index ffbc46afd0..127d2303e6 100644
--- a/target/linux/ath79/tiny/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
+++ b/target/linux/ath79/tiny/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
 case "$FIRMWARE" in
 "ath9k-eeprom-pci-0000:00:00.0.bin")
 	case $board in
@@ -30,6 +33,7 @@ case "$FIRMWARE" in
 	netgear,wnr2000-v3|\
 	netgear,wnr612-v2|\
 	on,n150r|\
+	tplink,tl-mr3020-v1|\
 	tplink,tl-mr3220-v1|\
 	tplink,tl-mr3420-v1|\
 	tplink,tl-wr740n-v1|\

but nope, it still fails with the same error. Now I'm trying to do a "make clean; make" just in case the change to that file wasn't propagated.
In any case, if someone has an idea to fix the problem, that would be helpful.

Also, what's the second number for the caldata in target/linux/ath79/tiny/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom?
I see in my dumps that at offset 0x1000 from the beginning of the art partition there's something (not 0xff), and the size of that stuff is 0x440, after which there's all 0xff again. Should I add "caldata_extract "art" 0x1000 0x440" or the "caldata_extract "art" 0x1000 0x1000" that is common to all tplinks is good enough?

PS: in case someone has a flash modded router, I'm attaching the DTS patch that made it boot, maybe it could be useful to someone:

diff --git a/target/linux/ath79/dts/ar9331_tplink_tl-mr3020-v1.dts b/target/linux/ath79/dts/ar9331_tplink_tl-mr3020-v1.dts
index 7df4ed9a98..773adc45b6 100644
--- a/target/linux/ath79/dts/ar9331_tplink_tl-mr3020-v1.dts
+++ b/target/linux/ath79/dts/ar9331_tplink_tl-mr3020-v1.dts
@@ -122,21 +122,17 @@
 				read-only;
 			};
 
+			/* https://forum.openwrt.org/t/build-openwrt-for-router-with-flash-mod-tplink-tl-mr3020-v1/111164 */
+			/* numbers are start address and size */
 			partition@20000 {
 				compatible = "tplink,firmware";
 				label = "firmware";
-				reg = <0x020000 0x3c0000>;
+				reg = <0x020000 0x7d0000>;
 			};
 
-			partition@3e0000 {
-				label = "config";
-				reg = <0x3e0000 0x010000>;
-				read-only;
-			};
-
-			art: partition@3f0000 {
+			art: partition@7f0000 {
 				label = "art";
-				reg = <0x3f0000 0x010000>;
+				reg = <0x7f0000 0x010000>;
 				read-only;
 			};
 		};
diff --git a/target/linux/ath79/image/tiny-tp-link.mk b/target/linux/ath79/image/tiny-tp-link.mk
index c918c6baa6..a123a3a8bd 100644
--- a/target/linux/ath79/image/tiny-tp-link.mk
+++ b/target/linux/ath79/image/tiny-tp-link.mk
@@ -11,8 +11,7 @@ endef
 TARGET_DEVICES += tplink_tl-mr10u
 
 define Device/tplink_tl-mr3020-v1
-  $(Device/tplink-4mlzma)
-  IMAGE_SIZE := 3840k
+  $(Device/tplink-8mlzma)
   SOC := ar9331
   DEVICE_MODEL := TL-MR3020
   DEVICE_VARIANT := v1

Nope, make clean; make did nothing. I'm stuck with no wireless interface.

You might need to ask @lucize who added ath79 support for that device with

ART needs to be valid and at the correct location.

1 Like

Apparently while making the patch for the DTS I accidentally corrupted the ART partition, as now it reads as jffs2 stuff. Luckily I had a copy of it, that I restored using uboot. Now the wireless interface is present. Thanks.

2 Likes

You already found the error (detroyed art contents), but I am still answering:

That should likely be 0x1000 0x1000, as the original caldata definition in ar71xx specifies that it is max 2048 x 16bit words = 4096 bytes = 0x1000

E.g. in my own WNDR3700 series routers, the two radios have ath9k caldata at 0x1000 and 0x5000, so the reserved size for one is 0x4000.

1 Like

I would like to add a short recap just in case someone else is interested (including myself an year from now trying to upgrade OpenWrt again ;)).

The patch above, the one modifying

target/linux/ath79/dts/ar9331_tplink_tl-mr3020-v1.dts
target/linux/ath79/image/tiny-tp-link.mk

is all that's needed to build OpenWrt for a tl-mr3020 with a modded 8MB flash.
The patch includes a comment: "numbers are start address and size" because initially I thought that addresses in partitions were <start_address end_address> instead of the correct <start_address size>. Silly mistake, but that's how I corrupted the art partition.

The other patch, the one to

target/linux/ath79/tiny/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom

is not needed. Most likely, the cal data is loaded directly by the DTS with the line

	mtd-cal-data = <&art 0x1000>;

so nothing more is needed.

Big thanks again!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.