Firmware build for modded TP-Link TL-WR740N v5

I have modded my WR740N v5 with 16MB flash and 64MB RAM. Taking advantage of that I am trying to build the latest openwrt firmware for it.

I have set everything up. I went in this order:

sudo apt update
sudo apt install build-essential clang flex bison g++ gawk gcc-multilib g++-multilib
gettext git libncurses-dev libssl-dev python3-distutils rsync unzip zlib1g-dev
file wget

Git clone was giving me some certificate errors so I got these commands from stackexchange:

sudo update-ca-certificates
export GIT_SSL_NO_VERIFY=1
git clone https://git.openwrt.org/openwrt/openwrt.git

cd openwrt
./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig

I chose the following configuration in the config menu:

Target System (Atheros ATH79)
Subtarget (Devices with small flash)
Target Profile (TP-Link TL-WR740N v5)

I left everything else at default without adding or removing any packages. As I am using Ubuntu in Virtual box which I have assigned 2 CPU cores, I chose 3 hardware threads.

make -j3

After a long time of successful compilation I tried to find my firmware file in /openwrt/bin/targets/ath79/tiny/ but they are not there. There are other files there but neither factory.bin nor update.bin. I read in the build guide that:

If running make does not yield images for one (or even all) of the boards linked to the device profile that you have selected, than you probably have selected/enabled too many options or packages, and the image was too big to be flashed onto your device.

How can I bypass this restriction now that I have 16MB to play with?

This string restrict firmware image size to 4m. You can change it to $(Device/tplink-16mlzma) before image building for test.

I chose that option to build again and the factory.bin file is 15872KB. Is that going to fit 16MB flash with the bootloader and ART partition?

Here you can see that max image size is 16192k

Here you can see that max image size is 16192k

I have build the images but they don't work. Router turns on and then restarts after sometime and keeps doing that. Maybe the 64MB is too low for that. I will start on an 8MB target next that many help the RAM cope better and I will have some space for additional packages afterwards. Do you have any suggestions?

Did you correct firmware partition size and art partition offset?

Did you correct firmware partition size and art partition offset?

I did not. And I don't know how to. Is there a guide somewhere? I didn't find any reference to those in any build guide.

Hi

i am far from expert in this topic, but ...

                        firmware: partition@20000 {
                                compatible = "tplink,firmware";
                                reg = <0x20000 0x3d0000>;
                                label = "firmware";
                        };

                        art: partition@3f0000 {
                                reg = <0x3f0000 0x10000>;
                                label = "art";
                                read-only;
                        };

as you could see, ART was on the end of flash
now, you make some 15M flash image and flashed without moving ART
it is a big chance that you already overwrite/destroyed ART partition and your device will not work

but, as i said, not an expert here

I have already saved the ART partition so even if I wrote over it , I can flash it again. Overwriting ART partition doesn't stop router from booting and getting into LUCI. My problem is that I cannot even get the router to boot into LUCI. It just keeps restarting.

So what will be the offsets to be used if I am using a 16MB Flash or an 8MB Flash given that the bootloader is 128KB? I guess the ones given in the above quote are for 4MB Flash.

well

you need to look at

/target/linux/ath79/dts/ar9331_tplink_tl-wr741nd-v4.dtsi

there are partition definitions
then calculate differences
build image with new DTS
and, you need serial/TTL console to see what is happening in your router

sry, it is your device, your modification :slight_smile:

Edit in /openwrt/target/linux/ath79/image/tiny-tp-link.mk
define Device/tplink_tl-wr740n-v5
$(Device/tplink-4mlzma) to $(Device/tplink-16mlzma) or $(Device/tplink-8mlzma)

Edit in /target/linux/ath79/dts/ar9331_tplink_tl-wr741nd-v4.dtsi
uboot reg 0x000000 0x020000
firmware reg (16MB---- 0x020000 0xfd0000)(8MB ----0x020000 0x7d0000)
art reg (16MB---- 0xff0000 0x010000)(8MB----0x7f0000 0x010000)

Are these offsets correct? I got them from:
https://forum.openwrt.org/t/how-to-build-for-wdr4300-with-16mb-flash/94853/7

It's simple:

                        firmware: partition@20000 {
                                compatible = "tplink,firmware";
                                reg = <0x20000 0x3d0000>;
                                label = "firmware";
                        };

                        art: partition@3f0000 {
                                reg = <0x3f0000 0x10000>;
                                label = "art";
                                read-only;
                        };

As you can see both partitions contain reg = <num1 num2>; property where num1 - offset and num2 size.
So simply add 12MB (or 0xc00000):

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

                        art: partition@ff0000 {
                                reg = <0xff0000 0x10000>;
                                label = "art";
                                read-only;
                        };
1 Like

Ah. I read your post after posting mine. We both are on the same page. I will build it and then report here.

I got it up and running!! Ethernet, WIFI, everything seems to be working.


But there were a couple of issues. LuCI was not installed by default. I had to ssh install it.

If you look at the screenshot above the architecture shows as Atheros AR9330 rev 1. My soc is AR9331. Is that normal?

Also the first boot after flashing takes a long time. So you have to be patient.

Last problem is the orientation of my LAN ports. As I have a domestic Chinese router, which has small differences from the EU model, the bootloader has marked the WAN port as LAN4 and LAN1 port as WAN. I mentioned it in detail here:
https://forum.openwrt.org/t/tp-link-tl-wr740n-v5-china-flash-upgrade-issues/163660/8?u=murabat

Is there any modification available, in the bootloader or the openwrt itself, so that I can change this?

My patch for wr740n 16mb flash (for snapshot)

diff -Naru openwrt-a/config/Config-kernel.in openwrt-b/config/Config-kernel.in
--- openwrt-a/config/Config-kernel.in	2023-07-08 12:28:21.000000000 +0300
+++ openwrt-b/config/Config-kernel.in	2023-07-08 14:55:23.326041421 +0300
@@ -26,7 +26,7 @@
 
 config KERNEL_SWAP
 	bool "Support for paging of anonymous memory (swap)"
-	default y if !SMALL_FLASH
+	default y
 
 config KERNEL_PROC_STRIPPED
 	bool "Strip non-essential /proc functionality to reduce code size"
diff -Naru openwrt-a/target/linux/ath79/dts/ar9331_tplink_tl-wr741nd-v4.dtsi openwrt-b/target/linux/ath79/dts/ar9331_tplink_tl-wr741nd-v4.dtsi
--- openwrt-a/target/linux/ath79/dts/ar9331_tplink_tl-wr741nd-v4.dtsi	2023-07-08 12:28:21.000000000 +0300
+++ openwrt-b/target/linux/ath79/dts/ar9331_tplink_tl-wr741nd-v4.dtsi	2023-07-08 14:54:44.871040626 +0300
@@ -105,12 +105,12 @@
 
 			firmware: partition@20000 {
 				compatible = "tplink,firmware";
-				reg = <0x20000 0x3d0000>;
+				reg = <0x20000 0xfd0000>;
 				label = "firmware";
 			};
 
 			art: partition@3f0000 {
-				reg = <0x3f0000 0x10000>;
+				reg = <0xff0000 0x10000>;
 				label = "art";
 				read-only;
 			};
diff -Naru openwrt-a/target/linux/ath79/image/tiny-tp-link.mk openwrt-b/target/linux/ath79/image/tiny-tp-link.mk
--- openwrt-a/target/linux/ath79/image/tiny-tp-link.mk	2023-07-08 12:28:21.000000000 +0300
+++ openwrt-b/target/linux/ath79/image/tiny-tp-link.mk	2023-07-08 14:54:44.871040626 +0300
@@ -300,7 +300,7 @@
 TARGET_DEVICES += tplink_tl-wr740n-v4
 
 define Device/tplink_tl-wr740n-v5
-  $(Device/tplink-4mlzma)
+  $(Device/tplink-16mlzma)
   SOC := ar9331
   DEVICE_MODEL := TL-WR740N
   DEVICE_VARIANT := v5