What's new

Issues compiling Realtek RTL8156 (r8152) driver for ASUS RT-AX86U

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Sanek2k6

Occasional Visitor
Hello!

I have a Plugable 2.5Gbe Ethernet USB adapter (Realtek RTL8156B) and an ASUS RT-AX86U router running the latest stable Merlin firmware (3004.388.6_2).

When I plug the adapter into the router, it is identified correctly as a USB device in the Network Map view, however I was unable to get it to work as a WAN connection (selecting WAN USB and all that), plus I see frequent log spam with dmesg. I've been following this well-known guide from a few years ago that mentions that this is due to a missing kernel module for this chipset and provides instructions how to compile one yourself (as well as optimize performance). The tutorial showed how to do this for the AX88U, so I adjusted a few things to be correct for the AX86U (i.e. to use release src-rt-5.02L.07p2axhnd). Everything seemed to work just fine compiling the firmware and tools (iperf3, ethtool) using the /gnuton/Asuswrt-Merlin-Toolchains-Docker docker container, except when building the r8152 driver, which gives me the following error:
Code:
$make ARCH=arm64 CROSS_COMPILE=aarch64-linux- -C /build/mnt/fastdata/asus/asuswrt-merlin.ng/release/src-rt-5.02L.07p2axhnd/kernel/linux-4.1 M=`pwd` modules
make: Entering directory '/build/mnt/fastdata/asus/asuswrt-merlin.ng/release/src-rt-5.02L.07p2axhnd/kernel/linux-4.1'
  CC [M]  /build/mnt/fastdata/asus/r8152-2.17.1/r8152.o
<command-line>:0:1: error: macro names must be identifiers
In file included from include/linux/kobject.h:21:0,
                 from include/linux/module.h:16,
                 from /build/mnt/fastdata/asus/r8152-2.17.1/r8152.c:15:
include/linux/sysfs.h: In function ‘sysfs_get_dirent’:
include/linux/sysfs.h:496:37: warning: pointer targets in passing argument 2 of ‘kernfs_find_and_get’ differ in signedness [-Wpointer-sign]
  return kernfs_find_and_get(parent, name);
...
make[1]: *** [scripts/Makefile.build:296: /build/mnt/fastdata/asus/r8152-2.17.1/r8152.o] Error 1
make: *** [Makefile:1748: _module_/build/mnt/fastdata/asus/r8152-2.17.1] Error 2
make: Leaving directory '/build/mnt/fastdata/asus/asuswrt-merlin.ng/release/src-rt-5.02L.07p2axhnd/kernel/linux-4.1'

I've searched all over the forum and I see some people mentioning that they got it working without compiling any driver (doesn't work for me?), while some others mentioning having similar issues when following the tutorial. If I look at the comments in the original tutorial, there are a few mentioning that they get the same issue for AX86U for some reason, but not for AX88U. When investigating the commands make is running, I can see that the issue is caused due to two missing/empty defines (" -D "):
Code:
$ make -n ARCH=arm64 CROSS_COMPILE=aarch64-linux- -C /build/mnt/fastdata/asus/asuswrt-merlin.ng/release/src-rt-5.02L.07p2axhnd/kernel/linux-4.1 M=`pwd` modules
make: Entering directory '/build/mnt/fastdata/asus/asuswrt-merlin.ng/release/src-rt-5.02L.07p2axhnd/kernel/linux-4.1'
mkdir -p /build/mnt/fastdata/asus/r8152-2.17.1/.tmp_versions ; rm -f /build/mnt/fastdata/asus/r8152-2.17.1/.tmp_versions/*
test -e ./Module.symvers || ( \
echo; \
echo "  WARNING: Symbol version dump ./Module.symvers"; \
echo "           is missing; modules will have no dependencies and modversions."; \
echo )
make -f ./scripts/Makefile.build obj=/build/mnt/fastdata/asus/r8152-2.17.1
set -e;            echo '  CC [M]  /build/mnt/fastdata/asus/r8152-2.17.1/r8152.o'; aarch64-linux-gcc -Wp,-MD,/build/mnt/fastdata/asus/r8152-2.17.1/.r8152.o.d  -nostdinc -isystem /home/docker/am-toolchains/brcm-arm-hnd/crosstools-aarch64-gcc-5.3-linux-4.1-glibc-2.22-binutils-2.25/usr/bin/../lib/gcc/aarch64-buildroot-linux-gnu/5.3.0/include -I./arch/arm64/include -Iarch/arm64/include/generated/uapi -Iarch/arm64/include/generated  -Iinclude -I./arch/arm64/include/uapi -Iarch/arm64/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -D -mgeneral-regs-only -O2 -fno-omit-frame-pointer -fno-optimize-sibling-calls  -DMODULE -mcmodel=large  -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(r8152)"  -D"KBUILD_MODNAME=KBUILD_STR(r8152)" -c -o /build/mnt/fastdata/asus/r8152-2.17.1/r8152.o /build/mnt/fastdata/asus/r8152-2.17.1/r8152.c;    scripts/basic/fixdep /build/mnt/fastdata/asus/r8152-2.17.1/.r8152.o.d /build/mnt/fastdata/asus/r8152-2.17.1/r8152.o 'aarch64-linux-gcc -Wp,-MD,/build/mnt/fastdata/asus/r8152-2.17.1/.r8152.o.d  -nostdinc -isystem /home/docker/am-toolchains/brcm-arm-hnd/crosstools-aarch64-gcc-5.3-linux-4.1-glibc-2.22-binutils-2.25/usr/bin/../lib/gcc/aarch64-buildroot-linux-gnu/5.3.0/include -I./arch/arm64/include -Iarch/arm64/include/generated/uapi -Iarch/arm64/include/generated  -Iinclude -I./arch/arm64/include/uapi -Iarch/arm64/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -D -mgeneral-regs-only -O2 -fno-omit-frame-pointer -fno-optimize-sibling-calls  -DMODULE -mcmodel=large  -D"KBUILD_STR(s)=\#s" -D"KBUILD_BASENAME=KBUILD_STR(r8152)"  -D"KBUILD_MODNAME=KBUILD_STR(r8152)" -c -o /build/mnt/fastdata/asus/r8152-2.17.1/r8152.o /build/mnt/fastdata/asus/r8152-2.17.1/r8152.c' > /build/mnt/fastdata/asus/r8152-2.17.1/.r8152.o.tmp; rm -f /build/mnt/fastdata/asus/r8152-2.17.1/.r8152.o.d; mv -f /build/mnt/fastdata/asus/r8152-2.17.1/.r8152.o.tmp /build/mnt/fastdata/asus/r8152-2.17.1/.r8152.o.cmd
{ echo /build/mnt/fastdata/asus/r8152-2.17.1/r8152.ko; echo /build/mnt/fastdata/asus/r8152-2.17.1/r8152.o; } > /build/mnt/fastdata/asus/r8152-2.17.1/.tmp_versions/r8152.mod
(cat /dev/null;   echo kernel//build/mnt/fastdata/asus/r8152-2.17.1/r8152.ko;) > /build/mnt/fastdata/asus/r8152-2.17.1/modules.order
:
echo '  Building modules, stage 2.';
make -f ./scripts/Makefile.modpost
echo '  MODPOST 0 modules'; find /build/mnt/fastdata/asus/r8152-2.17.1/.tmp_versions -name '*.mod' | xargs -r grep -h '\.ko$' | sort -u | sed 's/\.ko$/.o/' | scripts/mod/modpost   -i ./Module.symvers -I /build/mnt/fastdata/asus/r8152-2.17.1/Module.symvers  -o /build/mnt/fastdata/asus/r8152-2.17.1/Module.symvers -S -w  -s -T - vmlinux
make: Leaving directory '/build/mnt/fastdata/asus/asuswrt-merlin.ng/release/src-rt-5.02L.07p2axhnd/kernel/linux-4.1'


I'm not sure where these come from and if I get rid of them and run gcc manually, it does compile, but I see the mention in the comments of that tutorial that someone already tried that and the kernel module was not loadable as a result. I would like to understand where the issue comes from and hoping someone has successfully done this before for AX86U.

Thank you for any help!
 

Attachments

  • make-output.txt
    5.8 KB · Views: 8
Last edited:
I managed to compile this manually without a makefile by executing a modified gcc command-line from the makefile above:
Code:
/opt/toolchains/crosstools-aarch64-gcc-5.5-linux-4.1-glibc-2.26-binutils-2.28.1/usr/bin/aarch64-buildroot-linux-gnu-gcc -Wp,-MD,/build/mnt/fastdata/asus/r8152-2.17.1/.r8152.o.d  -nostdinc -isystem /home/docker/am-toolchains/brcm-arm-hnd/crosstools-aarch64-gcc-5.3-linux-4.1-glibc-2.22-binutils-2.25/usr/bin/../lib/gcc/aarch64-buildroot-linux-gnu/5.3.0/include -I./arch/arm64/include -Iarch/arm64/include/generated/uapi -Iarch/arm64/include/generated  -Iinclude -I./arch/arm64/include/uapi -Iarch/arm64/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -mgeneral-regs-only -O2 -fno-omit-frame-pointer -fno-optimize-sibling-calls -DMODULE -mcmodel=large  -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(r8152)"  -D"KBUILD_MODNAME=KBUILD_STR(r8152)" -c /build/mnt/fastdata/asus/r8152-2.17.1/r8152.c -o /build/mnt/fastdata/asus/r8152-2.17.1/r8152.ko

This defines the __KERNEL__ and MODULE macros and specifies the isystem, so the result should be a valid module, but I guess I still did something wrong and the module refused to load:
Code:
admin@RT-AX86U-AE80:/jffs/drivers# insmod /jffs/drivers/r8152.ko
insmod: can't insert '/jffs/drivers/r8152.ko': invalid module format

While dmesg logs "No module found in object" and modinfo displays the appropriate information, but its probably metadata:
Code:
docker@422ad3617361:/build/mnt/fastdata/asus/r8152-2.17.1$ modinfo r8152.ko
filename:       /build/mnt/fastdata/asus/r8152-2.17.1/r8152.ko
version:        v2.17.1 (2023/06/13)
license:        GPL
description:    Realtek RTL8152/RTL8153 Based USB Ethernet Adapters
author:         Realtek nic sw <nic_swsd@realtek.com>

The binary seems to be correct (arm, aarch64) at fist glance:
Code:
docker@422ad3617361:/build/mnt/fastdata/asus/r8152-2.17.1$ file r8152.ko
r8152.ko: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), BuildID[sha1]=57002a32d66199cfd1d6ee4bd5d0a30007d6da6a, not stripped

I noticed that the r8152 driver is included in the merlin distribution (release/src-rt-5.02L.07p2axhnd/kernel/linux-4.1/drivers/net/usb/r8152.c), but this version is very old (v1.08.0 (2015/01/13)) and does not support the RTL8156B chipset that the new r8152 driver (v2.17.1 (2023/06/13)) from Realtek supports. I cannot see the old driver in the list of modules on the AX86U router though and I don't see a .ko file being generated when I compile the kernel (maybe something is skipping it?).

I can also see that cdc_ether module defines handling of Realtek 8152 and 8153 devices - not sure how that support is compiled in (maybe thats what is referencing the r8152.c code?). I have not done Linux kernel development since college (probably 20 years ago now) and I'm moving forward pretty slowly. I'm thinking that if I could get the included r8152 driver to build, maybe I can update it manually to the new version and get that one to build as well, but I'm not sure if I'm on the right path here...
 
Last edited:
Ok just an update - we have partial success!

I managed to compile everything - using the original Makefile method. I also created another Makefile to make things even easier:
Code:
KDIR  := /build/mnt/fastdata/asus/asuswrt-merlin.ng/release/src-rt-5.02L.07p2axhnd/kernel/linux-4.1
PWD   := $(shell pwd)
obj-m := r8152.o     # same name as the .c file of your module

default:
    $(MAKE) -C $(KDIR) M=$(PWD) ARCH=arm64 CROSS_COMPILE=aarch64-linux- modules

The offending part that was causing all the issues was the missing BUILD_NAME variable in the main Makefile in the kernel. A simple "hack" to get past this was to just comment-out the KBUILD_CFLAGS line like so:
Code:
MODEL = $(subst -,,$(BUILD_NAME))
#KBUILD_CFLAGS += -D$(MODEL)
in asuswrt-merlin.ng/release/src-rt-5.02L.07p2axhndkernel/linux-4.1/Makefile

Module installs just fine, gets link, but I'm still having some issues:
1) I am unable to get the init-start and services-start scripts from the tutorial to execute on startup - or at least I don't see any evidence of them executing.
2) Even though the ETH8 device gets a link and an IP if I set it up manually, I couldn't get the ASUS router to use it as WAN. I tried setting WAN as USB and tried using both Manual Config and Legacy configurations for it. It does work fine as a LAN though, so thats how I'm using it for now (LAN -> 2.5Gbe switch -> 2.5Gbe NIC).

And the biggest issue of them all:
3) Even with the performance tweaks from the article, this router just isn't fast enough to use this beyond ~450Mbps - the CPU just gets pinned (mostly just Core 4) and I couldn't get it to do better. Not sure if I was doing something wrong or if the difference in CPU is that great between AX86U and AX88U.

If anyone wants the kernel module for the ASUS RT-AX86U and wants to experiment for themselves, you can use the one I compiled:
 
Last edited:

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top