How to edit partition positions after a SPI flash upgrade?

I have a lot of TP-Link TL-WR841N v11 which I bought in bulk for a cheap price. The strange thing about them is the inability to install OpenWrt. The TP-Link web interface throws a wrong image error when trying to flash. Even with TFTP recovery method -- the image file does get transferred on TFTP server log, but then the router immediately reboots without flashing.

I created a thread about this issue long ago, and after 3 years I finally discover the cause of the problem myself. The device is in fact a limited version made by TP-Link for a local ISP namely FPT Telecom.

The SPI flash chip on the board is a GigaDevice 625Q64CSIG which is 64 mebibit (8MiB). And that was the reason it refused to accept 4MiB image files, even those downloaded from TP-Link official website.

Here is a snippet of the output when booting the stock firmware:

5 cmdlinepart partitions found on MTD device ath-nor0
Creating 5 MTD partitions on "ath-nor0":
0x000000000000-0x000000020000 : "u-boot"
0x000000020000-0x000000120000 : "kernel"
0x000000120000-0x0000007e0000 : "rootfs"
0x0000007e0000-0x0000007f0000 : "config"
0x0000007f0000-0x000000800000 : "art"

So, we have 128KiB u-boot partition, a 1MiB kernel partition, a 6912KiB rootfs partition, a 64KiB config partition, and a 64KiB art partition. Pay attention to the position of the art partition: it is located at the end of the flash chip.

By modding a serial connection and flashing OpenWrt image via u-boot, I was able to force a successful installation of OpenWrt. Here is the kernel boot log:

[    0.334371] m25p80 spi0.0: gd25q64 (8192 Kbytes)
[    0.339204] 3 fixed-partitions partitions found on MTD device spi0.0
[    0.345785] Creating 3 MTD partitions on "spi0.0":
[    0.350748] 0x000000000000-0x000000020000 : "u-boot"
[    0.356841] 0x000000020000-0x0000003f0000 : "firmware"
[    0.363225] 2 tplink-fw partitions found on MTD device firmware
[    0.369427] Creating 2 MTD partitions on "firmware":
[    0.374584] 0x000000000000-0x00000015dd78 : "kernel"
[    0.380546] 0x00000015dd78-0x0000003d0000 : "rootfs"
[    0.386595] mtd: device 3 (rootfs) set to be root filesystem
[    0.392501] 1 squashfs-split partitions found on MTD device rootfs
[    0.398966] 0x000000380000-0x0000003d0000 : "rootfs_data"
[    0.405399] 0x0000003f0000-0x000000400000 : "art"

OpenWrt assumes that the art partition is located at offset 0x3f0000 (4,032KiB), but in reality that partition is located at offset 0x7f0000 (8,128KiB). Hence Wi-Fi functionality is out of the question.

I was able to use dd to move the art partition to offset 0x3f0000 and Wi-Fi worked. But I am still stuck with a 4MiB usable storage.

Where is the partition offset information stored? And how can I edit it to use all available flash? Specifically, I need to:

  1. Change the offset of the art partition to 0x7f0000 (8,128KiB).
  2. Change the size of the rootfs partition to all available space.
  3. If the mtdsplit rootfs_data partition is not auto-detected, I need to change its offsets too.

I am using images built from 19.07.10 ImageBuilder, if that matters.

It's a bit more complicated for this devices, as it's entangled with other tl-wr841 variants, to do it properly, you'd have to move the flash partitioning into the various *.dts, but have a look at:

I've had pretty good results by identifying another model that has the same SoC and 8M flash, and using the build for that model. Almost all TP-Link has the first 128k u-boot and the last 64k ART, so the firmware is more interchangeable. The main problem is that the LEDs may not always work.

Try this by booting an initramfs from the u-boot CLI. First thing is to copy out the ART and u-boot partitions in case they get clobbered.

32 MB of RAM is not enough for version 21 onward.

It is too complicated for me to handle. I do not expect some source code editing and recompiling of the firmware. :frowning:

WR841HPv3 looks like a close match.
There's a small chance these were also fitted with 64 MB RAM, which would be nice. Look up the part number of the RAM chip.