Adding OpenWrt support for Archer A6 v3

use
swconfig dev switch0 show
to figure out which port numbers are for which physical ports based on link status
these are the numbers used in the UCI script 02_network for
ucidef_add_switch

(if it is not switch0 do swconfig list for the name of the switch)

thanks @mpratt14 networking works now. Submitted patch with networking working(wan, lan & 2.4GHz probably 5GHz also).

Now trying to boot from flash, but unable to flash the Squashfs.bin through TP-link web interface

upgrade firmware...
Reading Partition Table from NVRAM ... OK
Parsing Partition Table ... OK
file_len:7142652
fw_type_name :
md5 verify ok!
[NM_Error](nm_checkUpgradeMode) 00805: Up file partition-table base address changed up(0x00fdf800) flash(0x00fe0000)!

[NM_Error](nm_checkUpdateContent) 01038: upgrade boot mode check fail.
[NM_Error](nm_buildUpgradeStruct) 01159: checkUpdateContent failed.
check firmware error!
[NM_Error](nvrammanager_checkUpgradeFile) 00784: check firmware file failed!

[NM_Error](main) 01160: firmware upgrade file check error

Also found LED GPIO ports for LEDs(except 2.4GHz WIfi) , but LEDs are not updated actively in the booted initramfs image.

It's possible that the board has a unique header for firmware images
you probably need to compare OEM images with other openwrt images for other TP-link boards

TP-link boards have a unique ID that needs to be included in this file
tools/firmware-utils/src/tplink-safeloader.c

study the commit for other archer a6 boards like this one

the last resort is TFTP is the only way to install

Made some progress in understadning, it is coming due to partition-table position in tplink-safeloader.c, there is a partition table definition mismatching with TP-link partition table.

Found the tp-link partition map from factory image, but now facing a new issue while trying creating the SquashFS image.

The OpenWRT OS image size coming around 2.3MB while the standard TP-link partition size reserved only to 2MB. And it is failing in SquashFS creation.

Any suggestions how this issue is addressed in other products?

if you mean the kernel is too large, then you can use the kernel loader instead of the kernel in that partition, it is like a second bootloader. when it is configured correctly, the bootloader loads the kernel loader, and the kernel loader then loads the kernel from the rootfs paritition. This means the rootfs partition actually would contain both kernel and rootfs.

some functions from ath79 would have to be copied / edited

target/linux/ath79/image/common-tp-link.mk

look at the makefile definition
Device/tplink-safeloader-okli

other devices that use this are in this file, you can see their DTS for how partitioning has to be

target/linux/ath79/image/generic-tp-link.mk

1 Like

Will have a look.

Is it fine to change DTS partition layout in OpenWrt from TP-Link defined one? Wouldnt break things while reverting back to factory firmware?

Are below partitions from ar9344-tplink-CPE are part of OKLI?

			partition@20000 {
				label = "partition-table";
				reg = <0x020000 0x010000>;
				read-only;
			};

			info: partition@30000 {
				label = "info";
				reg = <0x030000 0x010000>;
				read-only;
			};

No these are not the partitions you would change

The only partitions you change are the ones with the kernel and rootfs

OKLI would go into the os-image partition I think
and the real kernel goes after whereever the rootfs is
sometimes called file-system

Don't change any partitions unless you have to

1 Like

Still seeing the error of Kernel size too big, am I missing something?

os-image partition too big (more than 2097152 bytes): Success

Also, Not sure if the below build commands remain same for OKLI loader, ramips uses Uimage with lzma,

  LOADER_TYPE := elf
  LOADER_FLASH_OFFS := 0x43000
  COMPILE := loader-$(1).elf
  COMPILE/loader-$(1).elf := loader-okli-compile
  KERNEL := kernel-bin | append-dtb | lzma | uImage lzma -M 0x4f4b4c49 | \
	loader-okli $(1) 12288

I had to change the INITRAMFS as below to make work with OKLI changes

KERNEL_INITRAMFS := $(KERNEL_DTB) | uImage lzma

TP-Link partition layout is like below

dev:    size   erasesize  name offset
mtd0: 00040000 00010000 "uboot" 00000000
mtd1: 00200000 00010000 "uImage" 00040000
mtd2: 00db0000 00010000 "rootfs" 00240000
mtd3: 00010000 00010000 "ART" 00ff0000

try this

  KERNEL := $(KERNEL_DTB) | uImage lzma -M 0x4f4b4c49
  LOADER_TYPE := bin
  LOADER_FLASH_OFFS := 0x240000
  COMPILE := loader-$(1).bin loader-$(1).uImage
  COMPILE/loader-$(1).bin := loader-okli-compile
  COMPILE/loader-$(1).uImage := append-loader-okli $(1) | pad-to 64k | lzma
  IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | \
	append-metadata | check-size
  IMAGE/factory.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | \
	tplink-safeloader-okli factory

and in the file
include/image-commands.mk

add this new image command which is based on tplink-safeloader...

define Build/tplink-safeloader-okli
	-$(STAGING_DIR_HOST)/bin/tplink-safeloader \
		-B $(TPLINK_BOARD_ID) \
		-V $(REVISION) \
		-k $(KDIR)/loader-$(DEVICE_NAME).uImage \
		-r $@ \
		-o $@.new \
		-j \
		$(wordlist 2,$(words $(1)),$(1)) \
		$(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv $@.new $@ || rm -f $@
endef

Edit: earlier I was wrong about comparing to boards in ath79. What you need seems to be unique

there is really only 4 partitions? and the log from original tp-link firmware shows something like this too?

can we see your DTS?

you have to be very careful with the value of

LOADER_FLASH_OFFS

in this case it needs to be the start of the rootfs partition

Yes only 4 partitions, TP-Link FW boot logs snippet for reference

flash manufacture id: ef, device id 40 18
W25Q128BV(ef 40180000) (16384 Kbytes)
mtd .name = raspi, .size = 0x01000000 (16M) .erasesize = 0x00010000 (64K) .numeraseregions = 0
4 cmdlinepart partitions found on MTD device raspi
Creating 4 MTD partitions on "raspi":
0x000000000000-0x000000040000 : "uboot"
0x000000040000-0x000000240000 : "uImage"
0x000000240000-0x000000ff0000 : "rootfs"
0x000000ff0000-0x000001000000 : "ART"
Register flash device:flash_chrdev
PPP generic driver version 2.4.2

My WIP DTS is here, with OKLI changes included

https://github.com/vrpatil/openwrt/blob/flashboot/target/linux/ramips/dts/mt7621_tplink_archer-a6-v3.dts

LOADER_FLASH_OFFS just to confirm needs to be beginning of firmware partition(which host Uimage+rootfs): 0x240000? or 0x240000+0x300000?

Also, do I need to enable MTD_SPLIT_UIMAGE_FW?

Sorry I should not have told you to compare to other tp-link devices, this is a unique situation

DTS partitions should be like this

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

			partition@40000 {
				label = "uImage";
				reg = <0x40000 0x200000>;
			};

			partition@240000 {
				compatible = "openwrt,okli";
				label = "firmware";
				reg = <0x240000 0xdb0000>;
			};

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

Sorry there is some things wrong with what I had

  KERNEL := $(KERNEL_DTB) | uImage lzma -M 0x4f4b4c49
  LOADER_TYPE := bin
  LOADER_FLASH_OFFS := 0x240000
  COMPILE := loader-$(1).bin loader-$(1).uImage
  COMPILE/loader-$(1).bin := loader-okli-compile
  COMPILE/loader-$(1).uImage := append-loader-okli $(1) | pad-to 64k | lzma
  IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | \
	append-metadata | check-size
  IMAGE/factory.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | \
	tplink-safeloader-okli factory

I'm not sure what this does....dynamic partitioning already works in ramips

this is the partition that will be called "firmware" that will have both kernel + rootfs and the offset for LOADER_FLASH_OFFS

ok thanks.

And I found below missing in ramips/Makefile, but bs value seems not parsed properly.

# Arguments: <output name> <kernel offset>
define Build/loader-okli
	dd if=$(KDIR)/loader-$(word 1,$(1)).$(LOADER_TYPE) bs=$(word 2,$(1)) conv=sync of="$@.new"
	cat "$@" >> "$@.new"
	mv "$@.new" "$@"
endef

compile is throwing error like below

dd if=/xxxxx/Documents/archera6v3/xxxxx/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/tmp/openwrt-ramips-mt7621-tplink_archer-a6-v3-squashfs-sysupgrade.bin of=/home/xxxxx/Documents/archera6v3/xxxxx/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/tmp/openwrt-ramips-mt7621-tplink_archer-a6-v3-squashfs-sysupgrade.bin.new bs= conv=sync
dd: invalid number: ''
1 Like

the two functions we are using are

Build/loader-okli-compile
Build/append-loader-okli

and they are in this file
target/linux/ramips/image/Makefile

Removed that change from rampis/image/makefile, but still getting following error

dd if=/home/xxx/Documents/archera6v3/xxx/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/tmp/openwrt-ramips-mt7621-tplink_archer-a6-v3-squashfs-sysupgrade.bin of=/home/xxx/Documents/archera6v3/xxx/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/tmp/openwrt-ramips-mt7621-tplink_archer-a6-v3-squashfs-sysupgrade.bin.new bs= conv=sync
dd: invalid number: ''

It is coming from some other build statement.

(nevermind what I said)

I think it is from pad-to but not sure

just remove IMAGE/sysupgrade.bin we will fix it later...
or maybe look at other boards makefile to compare...

Edit: try this

  IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
	pad-rootfs | append-metadata | check-size

Edit 2: also for factory.bin

  IMAGE/factory.bin := append-kernel | append-rootfs | pad-rootfs | \
	tplink-safeloader-okli factory

With some additional corrections flashed the factory.bin successfully, but now facing below error while booting.

^M3: System Boot system code via Flash.
^M## Booting image at bc040000 ...
^M   Image Name:   MIPS OpenWrt Linux-5.4.87
^M   Image Type:   MIPS Linux Kernel Image (lzma compressed)
^M   Data Size:    3295 Bytes =  3.2 kB
^M   Load Address: 80001000
^M   Entry Point:  80001000
^M   Verifying Checksum ... OK
^M   Uncompressing Kernel Image ... OK
^MNo initrd
^M## Transferring control to Linux (at address 80001000) ...
^M## Giving linux memsize in MB, 128
^M
^MStarting kernel ...
^M
^M
^M
^MOpenWrt kernel loader for MIPS based SoC
^MCopyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
^MLooking for OpenWrt image... not found!
^M
^MSystem halted!