Adding support for Comfast CF-E319A V2

Hey everyone!
I've been trying to build OpenWRT for CF-E319A V2.
It has QCA9563 + QCA9886 + AR8033 on board. One ethernet port.
I have got root access to the original firmware and a serial connection, so i get all boot logs.

Checked out what other Comfast boards have the same specs, the CF-E375AC has them, tried flashing OEM Firmware for that one on mine, it worked. Mind, it didn't fully function, as something was still different, but it booted ok and i got to the web-GUI.

So far I've tried building openwrt using the COMFAST CF-E375AC Target Profile: https://imgur.com/a/ZtEki2p

My results:

If left as is, it builds ok -> the system flashes -> the kernel boot starts -> tries to call the QCA9888 drivers and goes into kernel panic -> reboots...
Logs:

(the oops starts at line 515)

After that i tried building with the ath10k-qca988x board, firmware and kmods. The result is the same, but the logs are a bit different:

(line 507, the ath10k kmod tries to call qca9888 drivers, but there are none)

Finally, i deleted all wifi kmods. Now it boots fully, no kernel panic:

I thought that maybe i can just opkg install the kmods and the firmware on a live openwrt, but it refuses to connect to the internet, or be pinged by any ip in the network or be a dhcp client. At the same time it thinks that br-lan has two ports: eth0.1 and eth0.2.

root@OpenWrt:~# uci show network
network.loopback=interface
network.loopback.device='lo'
network.loopback.proto='static'
network.loopback.ipaddr='127.0.0.1'
network.loopback.netmask='255.0.0.0'
network.globals=globals
network.globals.ula_prefix='fdeb:fb14:c799::/48'
network.@device[0]=device
network.@device[0].name='eth0.1'
network.@device[0].macaddr='19:85:20:03:00:01'
network.wan=interface
network.wan.device='eth0.1'
network.wan.proto='dhcp'
network.wan6=interface
network.wan6.device='eth0.1'
network.wan6.proto='dhcpv6'
network.@device[1]=device
network.@device[1].name='br-lan'
network.@device[1].type='bridge'
network.@device[1].ports='eth0.2'
network.lan=interface
network.lan.device='br-lan'
network.lan.proto='static'
network.lan.ipaddr='192.168.1.1'
network.lan.netmask='255.255.255.0'
network.lan.ip6assign='60'
network.@switch[0]=switch
network.@switch[0].name='switch0'
network.@switch[0].reset='1'
network.@switch[0].enable_vlan='1'
network.@switch_vlan[0]=switch_vlan
network.@switch_vlan[0].device='switch0'
network.@switch_vlan[0].vlan='1'
network.@switch_vlan[0].ports='1 0t'
network.@switch_vlan[1]=switch_vlan
network.@switch_vlan[1].device='switch0'
network.@switch_vlan[1].vlan='2'
network.@switch_vlan[1].ports='2 0t'

root@OpenWrt:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP qlen 1000
    link/ether e2:fa:7a:21:52:1a brd ff:ff:ff:ff:ff:ff
    inet6 fe80::e0fa:7aff:fe21:521a/64 scope link
       valid_lft forever preferred_lft forever
4: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether e2:fa:7a:21:52:1a brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.1/24 brd 192.168.1.255 scope global br-lan
       valid_lft forever preferred_lft forever
    inet6 fdeb:fb14:c799::1/60 scope global noprefixroute
       valid_lft forever preferred_lft forever
    inet6 fe80::e0fa:7aff:fe21:521a/64 scope link
       valid_lft forever preferred_lft forever
5: eth0.2@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-lan state UP qlen 1000
    link/ether e2:fa:7a:21:52:1a brd ff:ff:ff:ff:ff:ff
6: eth0.1@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether e2:fa:7a:21:52:1a brd ff:ff:ff:ff:ff:ff
    inet6 fe80::e0fa:7aff:fe21:521a/64 scope link
       valid_lft forever preferred_lft forever

root@OpenWrt:~# ip r
192.168.1.0/24 dev br-lan scope link  src 192.168.1.1

So I ask for help on what would be a good course of action from what i have, or if something may already be done, and i am not seeing it.

1 Like

Found another router with the same hardware - TP-Link EAP225 v3.x.
Built it with only the target profile being set.
The kernel didn't start:

## Booting image at 9f050000 ...
Bad Magic Number

That is all i got from that...

So it seems you can build from source already and have a working build system?

I think the short of ith is you need to start with making a new device in the build system. Change the package selection, write a device tree file for it?

https://openwrt.org/docs/guide-developer/hw.hacking.first.steps

https://openwrt.org/docs/guide-developer/adding_new_device

https://openwrt.org/docs/guide-developer/add.new.device

https://openwrt.org/docs/guide-developer/defining-firmware-partitions

https://openwrt.org/docs/guide-developer/device-support-policies

Your bootloader is checking your image to be valid.
IT seems the comfast image passes, tp link obviously doesn't as different manufacturer?

Yep, the comfast image passes.

1 Like

Awesome. Sorry for the edit on my first reply. But I think the first two links i pasted are a good place to start?

I think that the second one fits most, but i am really not sure.
The kernel is loading, but panics after failing to initialize drivers, how to fix that - i am not sure. It seems that is expecting some files that are not there.

[   19.295189] ath10k_pci 0000:00:00.0: failed to fetch board data for bus=pci,bmi-chip-id=0,bmi-board-id=31 from ath10k/QCA9888/hw2.0/board-2.bin
[   19.819870] ath10k_pci 0000:00:00.0: failed to fetch board-2.bin or board.bin from ath10k/QCA9888/hw2.0
[   19.829645] ath10k_pci 0000:00:00.0: failed to fetch board file: -12
[   19.854880] ath10k_pci 0000:00:00.0: could not probe fw (-12)
[   19.944318] Data bus error, epc == 8033cb0c, ra == 829e27b4

Yeah first link you've pretty much achieved except for backing up all the flash partitions i guess? factory boot log should be sufficient to determine the default flash partitions.

Yeah so you should use your base device that you are already booting and copy/modify that per the second link?

Here are the commits:
https://git.openwrt.org/?p=openwrt%2Fopenwrt.git&a=search&h=HEAD&st=commit&s=CF-E375AC

4f07966696134b270e821246c8fd4624c238f1f6
bf66bb8c969c58ef658407165a74afbfb4055997
1b0e7a1453ad968cd866b9d206a588caabbbb835
355009ebe76cb7f526737a88c7683c78e6a68118

Here's a search in the source code on github.

I had a look at the commits and particularly at the
/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/11-ath10k-caldata

Now I have a question about the connection between the kmod-ath10k package and the chosen target profile.
Does the chosen target profile determine how this kmod is being initialized and what it expects to find/see on the board in the firmware?

The lines that prompted this question:

"ath10k/pre-cal-pci-0000:00:00.0.bin")
 168         case $board in
 169         comfast,cf-e313ac)
 170                 caldata_extract "art" 0x5000 0x2f20
 171                 ath10k_patch_mac $(mtd_get_mac_binary art 0x6)
 172                 ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
 173                         /lib/firmware/ath10k/QCA9888/hw2.0/board.bin
 174                 rm /lib/firmware/ath10k/QCA9888/hw2.0/board-2.bin
 175                 ;;
 176         comfast,cf-e375ac|\
 177         comfast,cf-e560ac|\
 178         comfast,cf-ew72|\
 179         comfast,cf-wr752ac-v1)
 180                 caldata_extract "art" 0x5000 0x2f20
 181                 ath10k_patch_mac $(macaddr_add $(mtd_get_mac_binary art 0x0) +2)
 182                 ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
 183                         /lib/firmware/ath10k/QCA9888/hw2.0/board.bin
 184                 rm /lib/firmware/ath10k/QCA9888/hw2.0/board-2.bin
 185                 ;;

And if it wasn't apparent yet, i am pretty new to this. :sweat_smile:
I only managed to ever build openwrt for generic x86. To test it on a VM.

No worries. I was in your position about four years ago =P And I had a programming background at that point but it took a bit...... Happy to help!

I don't have experience with firmware files, nor ath10k. I've always pointed the drivers at a partition in flash using the device tree. (In the case of one hack wih broadcom brcmfmac I had to add a firmware file in the C code and then put it into the firmware directory to find....)

So the answer is. Configuring the "target profile" then sets up the $board variable so then you can write your own device specific configuration.

i.e. yes the device tree and scripts in init/preinit etc....

I think the best place to start is create a new "target profile" and device tree.
Get everything but wireless working. Then work on how to initialise the wireless correctly?