WR841N V13 USB,SPI MOD. Universal solution for TP-LINKS(ramips) routers

This tutorial is not about soldering, and flashing SPI chips. Who can solder SPI flash, and USB port, he knows what to do. Backup u-boot, art partitions and so on.

I like to mod routers, but i don't like to rebuild every time openwrt when new release or trunk comes out.

pros:

  • router uses official openwrt build
    • i can use official kmods when they suddenly needed
    • i think there is more but can't remember right now

cons:

  • loose some space versus custom build

Ok .Lets assume we have WR841N V13. We already solder USB(WR841N V13 USB Mod) port and changed SPI flash to 16mb. We flashed chip with u-boot and install openwrt( https://github.com/lede-project/source/commit/24043a0d2e01b9843c0dc529205b3b0bc7ecbbf9)
But USB is disabled in official openwrt release, and still 8m is accessible.

First of all

git clone https://git.openwrt.org/openwrt/openwrt.git/ myrepack
cd myrepack
git checkout openwrt-18.06
./scripts/feeds update -a
./scripts/feeds install -a

Then we have to add new flash layout. I think layouts is bad, why just not use direct values for every router.
Edit tools/firmware-utils/src/mktplinkfw2.c to look like this

                .kernel_ep      = 0x80000000,
                .rootfs_ofs     = 0x140000,
        }, {
                .id             = "16Mmtk",
                .fw_max_len     = 0xfa0000,
                .kernel_la      = 0x80000000,
                .kernel_ep      = 0x80000000,
                .rootfs_ofs     = 0x140000,
        }, {
                .id             = "8MLmtk",
                .fw_max_len     = 0x7b0000,

Next

cp target/linux/ramips/dts/TL-WR841NV13.dts target/linux/ramips/dts/TL-WR841NV13.dts.my

Change target/linux/ramips/dts/TL-WR841NV13.dts.my first line

#include "TPLINK-8M.dtsi" to #include "TPLINK-16M.dtsi"

Then create cp target/linux/ramips/dts/TPLINK-8M.dtsi target/linux/ramips/dts/TPLINK-16M.dtsi with this inside

#include "mt7628an.dtsi"

/ {
        chosen {
                bootargs = "console=ttyS0,115200";
        };

        memory@0 {
                device_type = "memory";
                reg = <0x0 0x4000000>;
        };
};

&spi0 {
        status = "okay";

        m25p80@0 {
                #address-cells = <1>;
                #size-cells = <1>;
                compatible = "jedec,spi-nor";
                reg = <0>;
                spi-max-frequency = <10000000>;
                m25p,chunked-io = <32>;

                partition@0 {
                        label = "boot";
                        reg = <0x0 0x20000>;
                        read-only;
                };

                partition@20000 {
                        label = "firmware";
                        reg = <0x20000 0xfa0000>;
                };

                factory: partition@fc0000 {
                        label = "factory";
                        reg = <0xfc0000 0x30000>;
                        read-only;
                };
        };
};

&ehci {
        status = "okay";
};

&ohci {
        status = "okay";
};

&wmac {
        status = "okay";
        mtd-mac-address = <&factory 0xf100>;
        mediatek,mtd-eeprom = <&factory 0x20000>;
};

&ethernet {
        mtd-mac-address = <&factory 0xf100>;
        mediatek,portmap = "llllw";
};

Now we need a bunch of host binaries to extract official release, build dts inject dtb to kernel and pack everything back

Here is my script, but you can run line by line

cat megarepack.sh
#!/bin/bash -x

make="make -j 9"

echo "CONFIG_TARGET_ramips=y" > .config
echo "CONFIG_TARGET_ramips_mt76x8=y" >> .config
echo "CONFIG_TARGET_ramips_mt76x8_DEVICE_tl-wr841n-v13=y" >> .config
make defconfig
make dirclean

#make prepare
$make tools/firmware-utils/compile
$make tools/lzma/compile
$make tools/patch-image/compile
$make toolchain/gcc/final/compile
$make target/linux/compile
$make toolchain/kernel-headers/compile

sed -i 's@$(eval $(call BuildPackage,fwtool))@#$(eval $(call BuildPackage,fwtool))@' package/system/fwtool/Makefile
$make package/fwtool/compile

The result must be binaries in ls staging_dir/host/bin/{fwtool,lzma,mktplinkfw2,patch-dtb}
and ls staging_dir/toolchain-mipsel_24kc_gcc-7.3.0_musl/bin/mipsel-openwrt-linux-musl-c++

Now the trickiest part, dtc can be compiled in kernel. Here is the source build_dir/toolchain-mipsel_24kc_gcc-7.3.0_musl/linux/scripts/dtc but i don't know how, so i simply install dtc in centos 7
yum install dtc

Lets compile our dts to dtb. Here is my script

cat build_dtb.sh
#!/bin/bash -x
STAGING_DIR=`pwd` staging_dir/toolchain-mipsel_24kc_gcc-7.3.0_musl/bin/mipsel-openwrt-linux-musl-cpp -nostdinc -x assembler-with-cpp \
-Ibuild_dir/toolchain-mipsel_24kc_gcc-7.3.0_musl/linux/arch/mips/boot/dts \
-Ibuild_dir/toolchain-mipsel_24kc_gcc-7.3.0_musl/linux/include \
-undef -D__DTS__  -o tl-wr841n-v13-kernel.bin.dtb.tmp target/linux/ramips/dts/TL-WR841NV13.dts.my

dtc -O dtb --phandle both \
-i build_dir/toolchain-mipsel_24kc_gcc-7.3.0_musl/linux/arch/mips/boot/dts \
-o tl-wr841n-v13-kernel.bin.dtb tl-wr841n-v13-kernel.bin.dtb.tmp

And here we are, we got tl-wr841n-v13-kernel.bin.dtb with usb and new layout partitions activated. Now we need to unpack openwrt release to kernel and rootfs. Inject dtb to kernel, and pack everything back.

Here is how i'm doing it

wget "https://downloads.openwrt.org/releases/18.06.1/targets/ramips/mt76x8/openwrt-18.06.1-ramips-mt76x8-tl-wr841n-v13-squashfs-sysupgrade.bin"

And then a little script $1 is openwrt-18.06.1-ramips-mt76x8-tl-wr841n-v13-squashfs-sysupgrade.bin

#!/bin/bash -x

#extract kernel and rootfs
staging_dir/host/bin/mktplinkfw2 -x -i $1
#unzip kernel
staging_dir/host/bin/lzma d $1-kernel $1-kernel-decoded
#inject our dtb
staging_dir/host/bin/patch-dtb $1-kernel-decoded tl-wr841n-v13-kernel.bin.dtb
#zip kernel back
staging_dir/host/bin/lzma e $1-kernel-decoded $1-kernel-decoded.new

#create sysupgrade image
staging_dir/host/bin//mktplinkfw2 -H 0x08410013 -W 0x268 -w 0x13 -F "16Mmtk" -T 3 -V "ver. 2.0" -a 0x4 -j -k $1-kernel-decoded.new -r $1-rootfs -o openwrt-ramips-mt76x8-tl-wr841n-v13-squashfs-sysupgrade.bin.new -s -e
#make it sysupgradable
echo '{  "supported_devices":["tl-wr841n-v13"], "version": { "dist": "OpenWrt", "version": "18.06.1", "revision": "r7258-5eb055306f", "board": "ramips" } }' | staging_dir/host/bin/fwtool -I - openwrt-ramips-mt76x8-tl-wr841n-v13-squashfs-sysupgrade.bin.new

openwrt-ramips-mt76x8-tl-wr841n-v13-squashfs-sysupgrade.bin.new Is our new sysupgradable image with USB support and 16mb flash layout. Now you can just sysupgrade it. Then restore the art partition with

insmod mtd-rw i_want_a_brick=1
mtd write art.bin factory

Now you can fast repack any release or trunk snapshot for you moded tl-wr841n-v13

This is draft. Or this knowledge will be lost :slight_smile:

Hi. Can You compile and upload img only with USB enabled? Make images from Image Builder is not a problem for me, but using git and make is.

If you can build custom images, then you already have all stuff compiled. You need to edit target/linux/ramips/dts/TPLINK-8M.dtsi

'''

&ehci {

    status = "okay";

};

&ohci {

    status = "okay";

};

'''

Compile dts to dtb, and inject it into official build.

Or wait when my 12 days vacation ends so I can inject and repack

Here it is. https://cloud.mail.ru/public/F5zJ/xjTFsFAnR

By the way official release wastes 128k for not needed partition. So it can be added to firmware partition and repack again.

<------><------>partition@7c0000 {
<------><------><------>label = "config";
<------><------><------>reg = <0x7c0000 0x10000>;
<------><------><------>read-only;
<------><------>};

can you help me? I want to upgrade ROM Tplink MR3020-V3 8MB flash to 16MB flash

Please open a new topic for TL-MR3020 v3 flash upgrade.

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