Porting guide ar71xx to ath79?

I upgraded from some older version of OpenWRT, possibly 18.06, via sysupgrade (but I did not choose to keep settings).


What's the situation with porting buffalo wzr-hp-g300nh to ath79? I searched about and found two-year-old forks (musashino's) of OpenWrt that added said support and the device boots. Those changes were never pushed to OpenWrt tree, though. I am interesting in giving it a shot but as people clearly have made attempts already I am hesitant whether I can bring anything new in to this scene.

-- Mauri

I made an attempt at the Buffalo WZR-HP-G300NH and got pretty close but then I ran into something that I would require a bit help with. Could you please comment on items below whether they are of consequence?

In my bootlog, as compared to 19.07

  • I am missing entry 'PID hash table entries: 256 (order: -2, 1024 bytes)'
  • I do not get frequencies for DDR, AHB and REF, only "CPU clock: 400.000 MHz"
  • I get an error 'ar7200-usb-phy usb-phy: phy reset is missing'
  • I see an extra RedBoot search entry at unknown address '0x1fa0000'. That is, I have not specified that address.

Also, the old boot log entry says this about flash partitions:

2 uimage-fw partitions found on MTD device firmware
0x000000060000-0x0000001e3492 : "kernel"
0x0000001e3492-0x000001fc0000 : "rootfs"

and mine says this:

Creating 2 MTD partitions on "firmware":
0x000000000000-0x0000001ba594 : "kernel"
0x0000001ba594-0x000001f60000 : "rootfs"

Otherwise they are identic. Do differing start points for the 'kernel' make a difference? My image fails to execute 'mount_rootfs'. It just keeps running and running and never finishes.

On top of the above things I had to disable failsafe as the device has sliding 'buttons' and some key is being pressed all the time while booting and that is caught always resulting in failsafe prompt. Is it possible to narrow down the buttons, pressing which results in failsafe?

You can safely ignore this. All other ath79 devices are missing this too.

This is expected and no other device shows this on ath79 because of different arch code.

This is only a cosmetic error that is caused by to early probing of the usb-phy driver...
See my pending PR on github for more info.

I don know... Can you post the dmesg output of this?

This different offsets results from different kernel image sizes.
The rootfs starts right after the kernel image to save expensive flash space and will always have a different offset depending on the kernel image size.
But probably you have done something wrong in the partition definition. Please share your dts file for further assistance.

For sure. Probably you have selected the wrong gpio or something else. It would be easier to assist you if you share your dts file.

Hi and thanks for prompt reply.

1e000000.cfi: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer ID 0x000001 Chip ID 0x002201
Amd/Fujitsu Extended Query Table at 0x0040
Amd/Fujitsu Extended Query version 1.3.
number of CFI chips: 1
Searching for RedBoot partition table in 1e000000.cfi at offset 0x1fa0000
Searching for RedBoot partition table in 1e000000.cfi at offset 0x1fc0000
Searching for RedBoot partition table in 1e000000.cfi at offset 0x1fe0000

0x1fc0000 and 0x1fe0000 are in the old one and 0x1fa0000 is a new one.

It's probably easiest to see it here:

Can anybody figure out what would be the correct way to implement the antenna config for wndr3700?

When the device was ported to ath79 two years ago, the goal was to get WiFi working at all, so the antenna thing was overlooked.

Ar71xx code:

 158         /* 2.4 GHz uses the first fixed antenna group (1, 0, 1, 0) */
 159         ap9x_pci_setup_wmac_gpio(0, (0xf << 6), (0xa << 6));
 161         /* 5 GHz uses the second fixed antenna group (0, 1, 1, 0) */
 162         ap9x_pci_setup_wmac_gpio(1, (0xf << 6), (0x6 << 6));

Are you sure this is realy needed and not encoded in the ath9k eeprom?
Probably this was done because the driver hasn´t access to the nand???
What are the values from debugfs?

cat /sys/kernel/debug/ieee80211/phy*/ath9k/gpio_mask
cat /sys/kernel/debug/ieee80211/phy*/ath9k/gpio_val

If they are really required to set manually, you will need a device tree property that is parsed in the of (device tree) init function ath9k_of_init() in drivers/net/wireless/ath/ath9k/init.c like it´s done in the old ath9k_init_platform() for the old mach behavior.

Your dts looks good so far. Can you also post a serial boot log or dmesg?

Starting kernel ...

[    0.000000] Linux version 4.19.115 (ubuntu@ubuntu) (gcc version 8.4.0 (OpenWrt GCC 8.4.0 r12903+10-c30220d458)) #0 Tue Apr 28 16:56:07 2020
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 00019374 (MIPS 24Kc)
[    0.000000] MIPS: machine is Buffalo WZR-HP-G300NH
[    0.000000] SoC: Atheros AR9132 rev 2
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 04000000 @ 00000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 bytes
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x0000000003ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000003ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000003ffffff]
[    0.000000] random: get_random_bytes called from start_kernel+0x98/0x4a8 with crng_init=0
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 16240
[    0.000000] Kernel command line: console=ttyS0,115200 rootfstype=squashfs,jffs2
[    0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
[    0.000000] Writing ErrCtl register=00000000
[    0.000000] Readback ErrCtl register=00000000
[    0.000000] Memory: 57516K/65536K available (4296K kernel code, 183K rwdata, 1016K rodata, 1216K init, 206K bss, 8020K reserved, 0K cma-reserved)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 51
[    0.000000] CPU clock: 400.000 MHz
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 9556302233 ns
[    0.000013] sched_clock: 32 bits at 200MHz, resolution 5ns, wraps every 10737418237ns
[    0.007904] Calibrating delay loop... 265.98 BogoMIPS (lpj=531968)
[    0.050069] pid_max: default: 32768 minimum: 301
[    0.055047] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.061675] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.075565] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.085348] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.091621] pinctrl core: initialized pinctrl subsystem
[    0.098116] NET: Registered protocol family 16
[    0.142632] clocksource: Switched to clocksource MIPS
[    0.149240] NET: Registered protocol family 2
[    0.154873] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes)
[    0.162652] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[    0.169637] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    0.176021] TCP: Hash tables configured (established 1024 bind 1024)
[    0.182591] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.188502] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.195269] NET: Registered protocol family 1
[    0.203892] Crashlog allocated RAM at address 0x3f00000
[    0.211087] workingset: timestamp_bits=14 max_order=14 bucket_order=0
[    0.227428] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.233305] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.259671] io scheduler noop registered
[    0.263668] io scheduler deadline registered (default)
[    0.269166] ar7200-usb-phy usb-phy: phy reset is missing
[    0.275746] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.283171] console [ttyS0] disabled
[    0.286842] 18020000.uart: ttyS0 at MMIO 0x18020000 (irq = 9, base_baud = 12500000) is a 8250
[    0.295387] console [ttyS0] enabled
[    0.295387] console [ttyS0] enabled
[    0.302418] bootconsole [early0] disabled
[    0.302418] bootconsole [early0] disabled
[    0.312376] 1e000000.cfi: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer ID 0x000001 Chip ID 0x002201
[    0.322529] Amd/Fujitsu Extended Query Table at 0x0040
[    0.327736]   Amd/Fujitsu Extended Query version 1.3.
[    0.332846] number of CFI chips: 1
[    0.342337] Searching for RedBoot partition table in 1e000000.cfi at offset 0x1fa0000
[    0.365833] Searching for RedBoot partition table in 1e000000.cfi at offset 0x1fc0000
[    0.389298] Searching for RedBoot partition table in 1e000000.cfi at offset 0x1fe0000
[    0.412754] No RedBoot partition table detected in 1e000000.cfi
[    0.418883] 5 fixed-partitions partitions found on MTD device 1e000000.cfi
[    0.425836] Creating 5 MTD partitions on "1e000000.cfi":
[    0.431215] 0x000000000000-0x000000040000 : "u-boot"
[    0.437325] 0x000000040000-0x000000060000 : "u-boot-env"
[    0.443826] 0x000000060000-0x000001fc0000 : "firmware"
[    0.452897] 2 uimage-fw partitions found on MTD device firmware
[    0.458931] Creating 2 MTD partitions on "firmware":
[    0.463961] 0x000000000000-0x0000001ba5d2 : "kernel"
[    0.470018] 0x0000001ba5d2-0x000001f60000 : "rootfs"
[    0.476085] mtd: device 4 (rootfs) set to be root filesystem
[    0.481885] 1 squashfs-split partitions found on MTD device rootfs
[    0.488143] 0x000000440000-0x000001f60000 : "rootfs_data"
[    0.494611] 0x000001fc0000-0x000001fe0000 : "user_property"
[    0.501389] 0x000001fe0000-0x000002000000 : "art"
[    0.508042] Realtek RTL8366S ethernet switch driver version 0.2.2
[    0.514350] rtl8366s switch: cannot find mdio bus from bus handle (yet)
[    0.521058] rtl8366s switch: using GPIO pins 19 (SDA) and 20 (SCK)
[    0.527457] rtl8366s switch: RTL8366 ver. 1 chip found
[    0.582251] libphy: switch: probed
[    0.589270] libphy: Fixed MDIO Bus: probed
[    0.912697] libphy: ag71xx_mdio: probed
[    0.918267] ag71xx 19000000.eth: connected to PHY at fixed-0:00 [uid=00000000, driver=Generic PHY]
[    0.928253] eth0: Atheros AG71xx at 0xb9000000, irq 4, mode: rgmii
[    1.138629] random: fast init done
[    1.252733] libphy: ag71xx_mdio: probed
[    1.257526] ag71xx 1a000000.eth: connected to PHY at switch:04 [uid=001cc960, driver=Generic PHY]
[    1.267436] eth1: Atheros AG71xx at 0xba000000, irq 5, mode: rgmii
[    1.277089] NET: Registered protocol family 10
[    1.289028] Segment Routing with IPv6
[    1.292967] NET: Registered protocol family 17
[    1.297572] 8021q: 802.1Q VLAN Support v1.8
[    1.311394] VFS: Mounted root (squashfs filesystem) readonly on device 31:4.
[    1.326101] Freeing unused kernel memory: 1216K
[    1.330706] This architecture does not have kernel memory protection.
[    1.337200] Run /sbin/init as init process
[    2.214420] init: Console is alive
[    2.218248] init: - watchdog -
[    3.487832] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    3.598600] usbcore: registered new interface driver usbfs
[    3.604336] usbcore: registered new interface driver hub
[    3.609859] usbcore: registered new device driver usb
[    3.623061] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    3.632000] ehci-platform: EHCI generic platform driver
[    3.637633] ehci-platform 1b000100.usb: EHCI Host Controller
[    3.643436] ehci-platform 1b000100.usb: new USB bus registered, assigned bus number 1
[    3.651473] ehci-platform 1b000100.usb: irq 3, io mem 0x1b000100
[    3.670661] ehci-platform 1b000100.usb: USB 2.0 started, EHCI 1.00
[    3.678068] hub 1-0:1.0: USB hub found
[    3.682478] hub 1-0:1.0: 1 port detected
[    3.688470] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    3.706379] init: - preinit -
[    4.794179] random: procd: uninitialized urandom read (4 bytes read)
Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level
[    7.059687] mount_root: jffs2 not ready yet, using temporary tmpfs overlay
[    7.100513] urandom-seed: Seed file not found (/etc/urandom.seed)
[    7.352686] procd: - early -
[    7.355921] procd: - watchdog -
[    8.040761] procd: - watchdog -
[    8.044463] procd: - ubus -
[    8.141429] random: ubusd: uninitialized urandom read (4 bytes read)
[    8.240159] random: ubusd: uninitialized urandom read (4 bytes read)
[    8.247253] random: ubusd: uninitialized urandom read (4 bytes read)
[    8.255057] procd: - init -
Please press Enter to activate this console.
[    9.341245] kmodloader: loading kernel modules from /etc/modules.d/*
[    9.582149] Loading modules backported from Linux version v5.4.27-0-g585e0cc08069
[    9.589755] Backport generated by backports.git v5.4.27-1-0-gf6e8852f
[    9.676053] xt_time: kernel timezone is -0000
[    9.869153] PPP generic driver version 2.4.2
[    9.888176] NET: Registered protocol family 24
[   10.120059] ieee80211 phy0: Atheros AR9100 MAC/BB Rev:7 AR2133 RF Rev:a2 mem=0xb80c0000, irq=2
[   10.304449] urngd: v1.0.2 started.
[   10.393493] kmodloader: done loading kernel modules from /etc/modules.d/*
[   10.953734] random: crng init done
[   10.957210] random: 6 urandom warning(s) missed due to ratelimiting
[   60.808840] jffs2_scan_eraseblock(): End of filesystem marker found at 0x0
[   60.830300] jffs2_build_filesystem(): unlocking the mtd device...
[   60.830311] done.
[   60.838554] jffs2_build_filesystem(): erasing all blocks after the end marker...
[   61.025248] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[   61.064605] br-lan: port 1(eth0.1) entered blocking state
[   61.070125] br-lan: port 1(eth0.1) entered disabled state
[   61.076071] device eth0.1 entered promiscuous mode
[   61.080953] device eth0 entered promiscuous mode
[   61.119000] IPv6: ADDRCONF(NETDEV_UP): br-lan: link is not ready
[   61.198078] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
[   62.047600] eth0: link up (1000Mbps/Full duplex)
[   62.066838] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   62.092929] br-lan: port 1(eth0.1) entered blocking state
[   62.098450] br-lan: port 1(eth0.1) entered forwarding state
[   62.129210] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready
[   64.256340] eth1: link up (1000Mbps/Full duplex)
[   64.270678] IPv6: ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready

BusyBox v1.31.1 () built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 OpenWrt SNAPSHOT, r13090-4209d17c0b
=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.

After this I am able to access internet etc, but mount_root just keeps muching on at CPU 100%

Is there a way to configure squashfs/jffs2 somehow? I am thinkg I will be pointing a finger in that direction now. Is there something board/device specific that should be done in the base files?

And is the device entry in image/generic.mk all right?

define Device/buffalo_wzr-hp-g300nh
  SOC := ar9132
  DEVICE_VENDOR := Buffalo
  DEVICE_PACKAGES := kmod-usb-core kmod-usb2 kmod-usb-ledtrig-usbport \
  BLOCKSIZE := 128k
  IMAGE_SIZE := 32128k
  IMAGES += factory.bin tftp.bin
  IMAGE/default := append-kernel | append-rootfs | pad-rootfs | check-size
  IMAGE/factory.bin := $$(IMAGE/default) | buffalo-enc WZR-HP-G300NH 1.99 | \
  buffalo-tag WZR-HP-G300NH 1
  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata
  IMAGE/tftp.bin := $$(IMAGE/default) | buffalo-tftp-header
  SUPPORTED_DEVICES += wzr-hp-g300nh
TARGET_DEVICES += buffalo_wzr-hp-g300nh

The found end address looks very confusing. Never seen a address of 0x0 before.
Is there any other device with "cfi-flash"?
Does your device boots normally after it stated that everything after 0x0 gets erased?

I assumed it standard behaviour as I purged the old config. JFFS2 portion (rootfs_data) is being prepared. The log 19.07 gives me this:

[ 46.051197] jffs2_scan_eraseblock(): End of filesystem marker found at 0x0
[ 46.058186] jffs2_build_filesystem(): unlocking the mtd device...
[ 46.058193] done.
[ 166.097389] jffs2: notice: (1242) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found.
[ 166.915966] overlayfs: upper fs does not support tmpfile.

My new one behaves similary but does not get to the end.

Looks like there a plenty of them, just not under 'ath79'. Cannot notice them doing anything differently.

In 19.07 it does. In my own it does not.

Looks like the values do not get set in ath79, but are set by that old routine in ar71xx. Below are current examples of both.

 OpenWrt SNAPSHOT, r13068-71d5a0d92b   (ath79)
root@router2:~# cat /sys/kernel/debug/ieee80211/phy*/ath9k/gpio_mask
root@router2:~# cat /sys/kernel/debug/ieee80211/phy*/ath9k/gpio_val
 OpenWrt SNAPSHOT, r13125-d9ff499671   (ar71xx)
root@router2:~# cat /sys/kernel/debug/ieee80211/phy*/ath9k/gpio_mask
root@router2:~# cat /sys/kernel/debug/ieee80211/phy*/ath9k/gpio_val

Have you seen suitable examples of proprietary device tree wifi properties recently?

I tried two years ago to introduce one for the MAC address tweaking in the 3700 series, but that was disapproved by the devs as they (or at least the reviewer) seemed to frown upon new OpenWrt-specific device tree properties.

I returned to the antenna subject two years after porting the device, as I saw some comments where some users complain about the wndr3800 wifi in ath79:

1 Like

A ugly workaround could be to write this values with echo into debugfs with a script like rc.local...

Sorry no and I haven't a bullet proof suggestion too.
Probably you can ask this on the openwrt or linux mailing list.

As gpio_mask and gpio_val are configurable through platform code, there is also a requirement to add this to the of/dt initialization code.
This shouldn't be openwrt specific, so there are a good chance to get this into the mainline linux, too.

Currently there is only qca,no-eeprom which i know only for ath9k defined:

Probably this can be one little starting point...

A small update on the wzr-hp-g300nh issue. It appears mount_root hangs at this line in overlay.c. It never returns.

ret = mount(v->blk, "/rom/overlay", "jffs2", MS_NOATIME, NULL);

'v->blk' there evaluates to '/dev/mtdblock5'

Trying to mount the same thing at console hangs indefinitely too. The mount process hog all cpu and renders the device almost inoperable. There are problems loading the Luci interface etc. But it connects to internet, though.

Are there known issues with CFI flash and JFFS2?

What puzzles me how it works in ar71xx then. At the end of the day, the ath79 version works other than that it cannot mount the overylay filesystem.

This was the key. I brought over a patch from ar71xx side for cfi cmd set and it's all working now. I read somewhere saying that the said patch was made obsolete by fixing the root cause but apparently not.

That leaves me with the issue of fail safe getting caught every time. How do I configure that? That is, can I configure somehow that pressing only a certain key gets me to failsafe?

The gpio/key with the linux code KEY_RESTART is used for triggering failsave.

If you comment this line, you have disabled the failsave trigger...

The problem was buttons like 'BTN_4' causing the failsafe. But it should be only the KEY_RESTART? That said, which branch is better basis for testing things, master or 19.07?

I made an attempt with PR to add support for wzr-hp-g300nh in 19.07 branch but it was shot down insisting that new devices should go to master. Should this ar71xx-ath79 porting work go to master really?

Yes. All new stuff goes to master.

(19.07 is the stable branch, and not for experimental stuff. New developments, like ath79 support for some device, go to master first. Later they might be backported to the stable branch, but they are first tested in master.)


Is there something different how keys are handled between master and 19.07 branch? When using gpio-keys-polled in 19.07 I get expected results: keys just work and I can enter failsafe by pressing reset key at appropriate point during the boot.

On top of master, with the same change set, I end up in failsafe always.

I was suggested to use gpio-keys instead of gpio-keys-polled but that fails with messages as below.

[ 3.498802] gpio-keys keys: failed to get irq for gpio:504
[ 3.504409] gpio-keys keys: failed to get irq for gpio:505
[ 3.509944] gpio-keys keys: failed to get irq for gpio:506
[ 3.515479] gpio-keys keys: failed to get irq for gpio:507
[ 3.521017] gpio-keys keys: failed to get irq for gpio:509
[ 3.526554] gpio-keys keys: failed to get irq for gpio:510
[ 3.532091] gpio-keys keys: failed to get irq for gpio:511

WZR-HP_G300NH has an gpio expander that does not provide irq interrupts and it must be polled as far as I understood correctly. I was dubious about the change proposal in the first place but I gave it a go just to eliminate possible non-working solutions.