How to build for WDR4300 with 16MB flash?

Hello everybody,

this was the first time I built openwrt myself (so far only stock images). The reason is that I have a TPlink WDR4300 which has been modified with a 16MB flash (not by me) and came with LEDE Reboot, which is a bit dated now...

I first made a full backup, documented some stuff of the existing install, verified that the bootloader was indeed pepe2k (it was) and the serial pin header did work (it didn't, the person who did the mod failed to get a good ground connection - as did I in several tries - a jumper wire fixed that).

As a first try, I used the generic 19.07.7 sysupgrade image via luci. This worked in the sense that I had a booting router, but as expected with an 8MB flash layout and no wifi (as the art partition was not where it should be in the 8MB layout). The latter was of course easily fixed from backup...

Then I got the 19.7.07 source tree and went on to build it as per https://openwrt.org/docs/guide-user/additional-software/beginners-build-guide and https://openwrt.org/docs/guide-developer/quickstart-build-images.

Before I edited target/linux/ath79/image/generic-tp-link.mk as shown in https://tbspace.de/wr84116mbflashmod.html (which is for a LEDE based Freifunk Gluon, which might be the reason why it didn't work) to have a 16MB model of the 4300 by adding this:

define Device/tplink_tl-wdr4300-v1-16
  $(Device/tplink-16mlzma)
  ATH_SOC := ar9344
  DEVICE_TITLE := TP-Link TL-WDR4300 v1 16MB
  DEVICE_PACKAGES := kmod-usb-core kmod-usb2 kmod-usb-ledtrig-usbport
  TPLINK_HWID := 0x43000001
  SUPPORTED_DEVICES += tl-wdr4300
endef
TARGET_DEVICES += tplink_tl-wdr4300-v1-16

I then chose the 16MB version in make menuconfig and built it with make. After some time, the make stopped with the complaint that ./target/linux/ath79/dts/ar9344_tplink_tl-wdr4300-v1-16.dts could not be found. I did find ./target/linux/ath79/dts/ar9344_tplink_tl-wdr4300-v1.dts though and since it didn't seem to contain anything related to the flash size, I just made a copy with the new name and tried again.
This did indeed result into a 16MB factory image, which I could install (via webserver in pepe2k BL) and could boot from. Unfortunately the flash layout was still 8MB like this:

dev:    size   erasesize  name
mtd0: 00020000 00010000 "u-boot"
mtd1: 007d0000 00010000 "firmware"
mtd2: 0018e10f 00010000 "kernel"
mtd3: 00641ef0 00010000 "rootfs"
mtd4: 00430000 00010000 "rootfs_data"
mtd5: 00010000 00010000 "art"

while the LEDE reboot I had originally had the correct length 0f 00fd0000:

dev:    size   erasesize  name
mtd0: 00020000 00010000 "u-boot"
mtd1: 001333cc 00010000 "kernel"
mtd2: 00e9cc34 00010000 "rootfs"
mtd3: 00c60000 00010000 "rootfs_data"
mtd4: 00010000 00010000 "art"
mtd5: 00fd0000 00010000 "firmware"

So what is the correct procedure to build a current openwrt for a larger than stock flash (I'm not adverse to try the 21 RC or master but thought stable would be easiest as a first try)?

Thanks in advance,

Joachim

For openwrt-19.7.07.
Enter the spoiler content in the file ar9344_tplink_tl-wdr4300-v1-16.dts.

ar9344_tplink_tl-wdr4300-v1-16.dts
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/dts-v1/;

#include "ar9344_tplink_tl-wdr4300.dtsi"

/ {
	model = "TP-Link TL-WDR4300 v1 16MB";
	compatible = "tplink,tl-wdr4300-v1-16", "qca,ar9344";
};

&spi {
	num-cs = <1>;

	status = "okay";

	flash@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <25000000>;

		partitions {
			compatible = "fixed-partitions";
			#address-cells = <1>;
			#size-cells = <1>;

			/delete-node/ art;

			uboot: partition@0 {
				label = "u-boot";
				reg = <0x000000 0x020000>;
				read-only;
			};

			partition@20000 {
				compatible = "tplink,firmware";
				label = "firmware";
				reg = <0x020000 0xfd0000>;
			};

			art: partition@ff0000 {
				label = "art";
				reg = <0xff0000 0x010000>;
				read-only;
			};
		};
	};
};
2 Likes

Hi,

thank you very much, will try and post results here...

Joachim

Hi,

ok, after a long night of hacking, I have gotten a bit closer to the target - but not quite there:

As for the flash layout, the solution from skreyda was close. When I applied it as given, dtc complained about a duplicate label art as follows:

/home/ringo/openwrt-19.07.7/build_dir/target-mips_24kc_musl/linux-ath79_generic/linux-4.14.221/scripts/dtc/dtc -O dtb -i../dts/ -Wno-unit_address_vs_reg -Wno-unit_address_vs_reg -Wno-simple_bus_reg -Wno-unit_address_format -Wno-pci_bridge -Wno-pci_device_bus_num -Wno-pci_device_reg  -o /home/ringo/openwrt-19.07.7/build_dir/target-mips_24kc_musl/linux-ath79_generic/image-ar9344_tplink_tl-wdr4300-v1-16.dtb /home/ringo/openwrt-19.07.7/build_dir/target-mips_24kc_musl/linux-ath79_generic/image-ar9344_tplink_tl-wdr4300-v1-16.dtb.tmp
/home/ringo/openwrt-19.07.7/build_dir/target-mips_24kc_musl/linux-ath79_generic/image-ar9344_tplink_tl-wdr4300-v1-16.dtb: ERROR (duplicate_label): Duplicate label 'art' on /ahb/spi@1f000000/flash@0/partitions/partition@ff0000 and /ahb/spi@1f000000/flash@0/partitions/partition@7f0000
ERROR: Input tree has errors, aborting (use -f to force output)

I first tried to change the label in ar9344_tplink_tl-wdr4300-v1-16.dts to art16 which built but left me with two art partitions... probably not ideal later.

I then went reading and learned a bit about linux device trees and tried to remove the partition@7f0000 node from the ar9344_tplink_tl-wdrxxxx.dtsi like this:

                    /delete-node/ partition@7f0000;
                    art: partition@ff0000 {
                            label = "art";
                            reg = <0xff0000 0x010000>;
                            read-only;

which built fine and gave an image using the 16MB flash and an art partition at 0xff0000. Since the we actually are creating a different node partition@ff0000 instead of partition@7f0000, the normal overwrite mechanism does not work here... not sure if there is another way to do it... or whether it's safe... comments welcome
I found the following page on device tree dark arts: https://elinux.org/Device_Tree_Source_Undocumented

Unfortunately my new image did only have eth0 and wlan0 running... the switch was unconfigured as I found after some research. I stole /etc/config/network from the stock 19.07.7 factory image which did the trick...

Same for the rather short distfeeds.conf with only core and base repos... I added the missing ones manually...

What do I have to include in menuconfig to get those two as in the stock image? Or can I even download the config which was used to build the stock image somewhere?

TIA and good night,

Joachim

Also edit the files before building.

patch
--- a/target/linux/ath79/base-files/etc/board.d/02_network	2021-02-17 00:30:28.000000000 +0200
+++ b/target/linux/ath79/base-files/etc/board.d/02_network	2021-04-27 11:49:02.707512666 +0300
@@ -223,6 +223,7 @@
 	tplink,archer-c7-v5|\
 	tplink,tl-wdr3600-v1|\
 	tplink,tl-wdr4300-v1|\
+	tplink,tl-wdr4300-v1-16|\
 	tplink,tl-wdr4300-v1-il|\
 	tplink,tl-wdr4310-v1|\
 	tplink,tl-wr941n-v7-cn)
--- a/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom	2021-02-17 00:30:28.000000000 +0200
+++ b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom	2021-04-27 11:50:18.966208476 +0300
@@ -161,6 +161,7 @@
 	tplink,tl-wdr3500-v1|\
 	tplink,tl-wdr3600-v1|\
 	tplink,tl-wdr4300-v1|\
+	tplink,tl-wdr4300-v1-16|\
 	tplink,tl-wdr4300-v1-il|\
 	tplink,tl-wdr4310-v1|\
 	tplink,tl-wdr4900-v2|\
--- a/target/linux/ath79/base-files/etc/uci-defaults/04_led_migration	2021-02-17 00:30:28.000000000 +0200
+++ b/target/linux/ath79/base-files/etc/uci-defaults/04_led_migration	2021-04-27 11:51:54.660666557 +0300
@@ -24,6 +24,7 @@
 tplink,archer-c7-v2|\
 tplink,tl-wdr3600-v1|\
 tplink,tl-wdr4300-v1|\
+tplink,tl-wdr4300-v1-16|\
 tplink,tl-wdr4300-v1-il|\
 tplink,tl-wdr4310-v1|\
 tplink,tl-wr802n-v1)
1 Like

Hi,

thanks again, that did the trick for the switch config 19.07 - so marked as solved now.

The distfeeds.conf can be manipulated in make menuconfig under Image Configuration -> Separate feed repositories.

Will test 21 RC tomorrow and post a writeup for the record.

Joachim

Hi,

for the record, I have successfully applied the procedure described below to v21.02.0-rc1. There is a good chance that it will also work on other TPLink models based on the ar9344 (aka those that include ./target/linux/ath79/dts/ar9344_tplink_tl-wdrxxxx.dtsi).

Cheers,

Joachim

First of all: Remember to save what you need - at least the bootloeader and the arm partition...

Edit target/linux/ath79/image/generic-tp-link.mk and copy the tplink_tl-wdr4300-v1 entry and add as follows:

define Device/tplink_tl-wdr4300-v1-16
  $(Device/tplink-16mlzma)
  SOC := ar9344
  DEVICE_MODEL := TL-WDR4300
  DEVICE_VARIANT := v1 16MB
  DEVICE_PACKAGES := kmod-usb2 kmod-usb-ledtrig-usbport
  TPLINK_HWID := 0x43000001
  SUPPORTED_DEVICES += tl-wdr4300-
endef
TARGET_DEVICES += tplink_tl-wdr4300-v1-16

Copy the dts file and change copy as follows:
cp ./target/linux/ath79/dts/ar9344_tplink_tl-wdr4300-v1.dts ./target/linux/ath79/dts/ar9344_tplink_tl-wdr4300-v1-16.dts
vi ./target/linux/ath79/dts/ar9344_tplink_tl-wdr4300-v1-16.dts

// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include "ar9344_tplink_tl-wdr4300.dtsi"

/ {
        model = "TP-Link TL-WDR4300 v1 16";
        compatible = "tplink,tl-wdr4300-v1", "qca,ar9344";
};

&spi {
        num-cs = <1>;

        status = "okay";

        flash@0 {
                compatible = "jedec,spi-nor";
                reg = <0>;
                spi-max-frequency = <25000000>;

                partitions {
                        compatible = "fixed-partitions";
                        #address-cells = <1>;
                        #size-cells = <1>;

                        uboot: partition@0 {
                                label = "u-boot";
                                reg = <0x000000 0x020000>;
                                read-only;
                        };

                        partition@20000 {
                                compatible = "tplink,firmware";
                                label = "firmware";
                                reg = <0x020000 0xfd0000>;
                        };
                        /delete-node/ partition@7f0000;
                        art: partition@ff0000 {
                                label = "art";
                                reg = <0xff0000 0x010000>;
                                read-only;
                        };
                };
        };
};

Search recursively for "tplink,tl-wdr4300-v1|" in target and add a new line with our new 16MB model after each occurence:

grep -r "tplink,tl-wdr4300-v1|" target
target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom: tplink,tl-wdr4300-v1|
target/linux/ath79/generic/base-files/etc/uci-defaults/04_led_migration:tplink,tl-wdr4300-v1|
target/linux/ath79/generic/base-files/etc/board.d/02_network: tplink,tl-wdr4300-v1|
target/linux/ath79/generic/base-files/etc/board.d/02_network: tplink,tl-wdr4300-v1|\

tplink,tl-wdr4300-v1|
tplink,tl-wdr4300-v1-16|\

make menuconfig
choose Target Profile TP-Link TL-WDR4300 v1 16MB
choose Image Configuration -> Separate Feed repositories and tag all.
exit and save config

make
flash image
flash arm backup
Enjoy!

1 Like

Could you please add these changes to the official repository so that there is a 16MB flash model in the official repository. I have two such modified 16m flash WDR4300 routers and I still have trouble keeping the modified files in the local repository.

Hi,

if you (or somebody else) can give me some guidance on how to get this in the official repos, I'll try. Would this have to go into master first?

Joachim

Custom hardware means custom patches, OpenWrt can't carry support for one-off modified devices.

--
Disclaimer: I'm not an OpenWrt developer and can't speak for the project.

1 Like

How can I create path to dts, dtsi and mk files in target directory?

Problem is that when there is change in one of this file in oryginal repo, I can't sync sources.

I think, that making a patch file for this would resolve problem, but I can't manage with this tutorial:

You will need to rebase your changes, that's generic git usage and not really OpenWrt specific.

That is the problem... my git knowledge is very limited up to now... just enough to copypasta the build tutorial...

I can diff my patched tree vs a stock one in the old style, so kmaras77 can apply it with patch...

Or I find a tutorial for rebasing my changes in git...

Joachim

When I have WDR4300 with 16m, I haven't 8m version so this image is useless for me.
Thus this I have modified only 3 lines in my sources - changing partitions art and firmware and image definition in generic-tp-link.mk file.
I need simple local patch file, that does this during building on oryginal source..

Hi,

here's a patchfile against v21.02.0-rc1...

diff -Naur openwrt/target/linux/ath79/dts/ar9344_tplink_tl-wdr4300-v1-16.dts openwrt-wdr4300-16/target/linux/ath79/dts/ar9344_tplink_tl-wdr4300-v1-16.dts
--- openwrt/target/linux/ath79/dts/ar9344_tplink_tl-wdr4300-v1-16.dts	1970-01-01 01:00:00.000000000 +0100
+++ openwrt-wdr4300-16/target/linux/ath79/dts/ar9344_tplink_tl-wdr4300-v1-16.dts	2021-05-04 22:28:12.870137111 +0200
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+
+#include "ar9344_tplink_tl-wdr4300.dtsi"
+
+/ {
+        model = "TP-Link TL-WDR4300 v1 16";
+        compatible = "tplink,tl-wdr4300-v1", "qca,ar9344";
+};
+
+&spi {
+        num-cs = <1>;
+
+        status = "okay";
+
+        flash@0 {
+                compatible = "jedec,spi-nor";
+                reg = <0>;
+                spi-max-frequency = <25000000>;
+
+                partitions {
+                        compatible = "fixed-partitions";
+                        #address-cells = <1>;
+                        #size-cells = <1>;
+
+                        uboot: partition@0 {
+                                label = "u-boot";
+                                reg = <0x000000 0x020000>;
+                                read-only;
+                        };
+
+                        partition@20000 {
+                                compatible = "tplink,firmware";
+                                label = "firmware";
+                                reg = <0x020000 0xfd0000>;
+                        };
+                        /delete-node/ partition@7f0000;
+                        art: partition@ff0000 {
+                                label = "art";
+                                reg = <0xff0000 0x010000>;
+                                read-only;
+                        };
+                };
+        };
+};
+
diff -Naur openwrt/target/linux/ath79/generic/base-files/etc/board.d/02_network openwrt-wdr4300-16/target/linux/ath79/generic/base-files/etc/board.d/02_network
--- openwrt/target/linux/ath79/generic/base-files/etc/board.d/02_network	2021-05-04 22:23:55.409445782 +0200
+++ openwrt-wdr4300-16/target/linux/ath79/generic/base-files/etc/board.d/02_network	2021-05-04 22:31:02.011216281 +0200
@@ -287,6 +287,7 @@
 	tplink,archer-c7-v5|\
 	tplink,tl-wdr3600-v1|\
 	tplink,tl-wdr4300-v1|\
+	tplink,tl-wdr4300-v1-16|\
 	tplink,tl-wdr4300-v1-il|\
 	tplink,tl-wdr4310-v1)
 		ucidef_add_switch "switch0" \
@@ -583,6 +584,7 @@
 	mercury,mw4530r-v1|\
 	tplink,tl-wdr3600-v1|\
 	tplink,tl-wdr4300-v1|\
+	tplink,tl-wdr4300-v1-16|\
 	tplink,tl-wdr4300-v1-il)
 		base_mac=$(mtd_get_mac_binary u-boot 0x1fc00)
 		wan_mac=$(macaddr_add "$base_mac" 1)
diff -Naur openwrt/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom openwrt-wdr4300-16/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
--- openwrt/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom	2021-05-04 22:20:16.646634511 +0200
+++ openwrt-wdr4300-16/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom	2021-05-04 22:29:33.272823270 +0200
@@ -94,6 +94,7 @@
 	tplink,tl-wdr3500-v1|\
 	tplink,tl-wdr3600-v1|\
 	tplink,tl-wdr4300-v1|\
+	tplink,tl-wdr4300-v1-16|\
 	tplink,tl-wdr4300-v1-il|\
 	tplink,tl-wdr4310-v1|\
 	tplink,tl-wdr4900-v2|\
diff -Naur openwrt/target/linux/ath79/generic/base-files/etc/uci-defaults/04_led_migration openwrt-wdr4300-16/target/linux/ath79/generic/base-files/etc/uci-defaults/04_led_migration
--- openwrt/target/linux/ath79/generic/base-files/etc/uci-defaults/04_led_migration	2021-05-04 22:20:16.646634511 +0200
+++ openwrt-wdr4300-16/target/linux/ath79/generic/base-files/etc/uci-defaults/04_led_migration	2021-05-04 22:30:14.199236628 +0200
@@ -57,6 +57,7 @@
 tplink,archer-c7-v2|\
 tplink,tl-wdr3600-v1|\
 tplink,tl-wdr4300-v1|\
+tplink,tl-wdr4300-v1-16|\
 tplink,tl-wdr4300-v1-il|\
 tplink,tl-wdr4310-v1)
 	migrate_leds "blue:=green:"
diff -Naur openwrt/target/linux/ath79/image/generic-tp-link.mk openwrt-wdr4300-16/target/linux/ath79/image/generic-tp-link.mk
--- openwrt/target/linux/ath79/image/generic-tp-link.mk	2021-05-04 22:23:55.409445782 +0200
+++ openwrt-wdr4300-16/target/linux/ath79/image/generic-tp-link.mk	2021-05-04 22:27:17.137735165 +0200
@@ -531,6 +531,17 @@
 endef
 TARGET_DEVICES += tplink_tl-wdr4300-v1
 
+define Device/tplink_tl-wdr4300-v1-16
+  $(Device/tplink-16mlzma)
+  SOC := ar9344
+  DEVICE_MODEL := TL-WDR4300
+  DEVICE_VARIANT := v1 16MB
+  DEVICE_PACKAGES := kmod-usb2 kmod-usb-ledtrig-usbport
+  TPLINK_HWID := 0x43000001
+  SUPPORTED_DEVICES += tl-wdr4300-
+endef
+TARGET_DEVICES += tplink_tl-wdr4300-v1-16
+
 define Device/tplink_tl-wdr4300-v1-il
   $(Device/tplink-8mlzma)
   SOC := ar9344

cp wdr-4300-16.patch /tmp
cd /tmp (I had problems with too long path in my home directory)
git clone https://git.openwrt.org/openwrt/openwrt.git
cd opewrt
git checkout v21.02.0-rc1
./scripts/feeds update -a
./scripts/feeds install -a
patch -p1 < ../wdr4300-16.patch
patching file target/linux/ath79/dts/ar9344_tplink_tl-wdr4300-v1-16.dts
patching file target/linux/ath79/generic/base-files/etc/board.d/02_network
patching file target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
patching file target/linux/ath79/generic/base-files/etc/uci-defaults/04_led_migration
patching file target/linux/ath79/image/generic-tp-link.mk
make menuconfig
choose Target Profile TP-Link TL-WDR4300 v1 16MB
choose Image Configuration -> Separate Feed repositories and tag all.
exit and save config
make
Don't forget to backup your art partition before flashing anything...

I tried the patch against master - it did go in w/o manual fixes... havent built and tested master yet though...

Joachim

I Have created simpler patch.

--- ./target/linux/ath79/dts/ar9344_tplink_tl-wdrxxxx.dtsi
+++ ./target/linux/ath79/dts/ar9344_tplink_tl-wdrxxxx.dtsi
@@ -88,12 +88,12 @@
 			partition@20000 {
 				compatible = "tplink,firmware";
 				label = "firmware";
-				reg = <0x020000 0x7d0000>;
+				reg = <0x020000 0xfd0000>;
 			};
 
-			art: partition@7f0000 {
+			art: partition@ff0000 {
 				label = "art";
-				reg = <0x7f0000 0x010000>;
+				reg = <0xff0000 0x010000>;
 				read-only;
 			};
 		};
--- ./target/linux/ath79/image/generic-tp-link.mk
+++ ./target/linux/ath79/image/generic-tp-link.mk
@@ -521,7 +521,7 @@ endef
 TARGET_DEVICES += tplink_tl-wdr3600-v1
 
 define Device/tplink_tl-wdr4300-v1
-  $(Device/tplink-8mlzma)
+  $(Device/tplink-16mlzma)
   SOC := ar9344
   DEVICE_MODEL := TL-WDR4300
   DEVICE_VARIANT := v1

It works as expected.
It replaces partitions layout in normal WDR4300 8m model.

Hi,

that is most certainly correct, if you do not try to build a stock 8MB image with that tree and try to flash it on a stock model... which will nuke your art partition of which you hopefully have a backup...

Thus I would strongly recommend my more complicated patch for general use...

Joachim

I think that someone who exchanges flash on a larger one knows what he does and copying the flash content by programmer saves backup of the ART partition, the more that he must move it to the end of the new flash. Usually during this operation a u-boot replacement on the Pepe2K mod version takes place.

Usually compiling ROMs for a larger flash, it is bigger than standard 8 m.

Perfect patch should be the same like ar71 arch, where partition layout is dynamically created during installation and based on flash size.

Well, having had a look at the shell magic in the ar71 tree I can understand why they wanted to get rid of it... might have been nifty to use but maintaining it seems... interesting.

Plus ath79 uses the device tree (as upstream likes things to be done) which needs to have the mtd partitions in there... and this is in dtb blob appended to the kernel image...

You probably could dump the kernel image from its partition, separate kernel and dtb with extract-dtb or split-appended-dtb, manipulate partition sizes in the dtb with fdtput, concatenate kernel and dtb again and write it back to its parttion...

Joachim