How to cross compile rtl8192eu driver for imx8mp?

Hi,

For a few days, I have been looking for how to install the RTL8192EU driver for my Wi-Fi dongle that does not work with the one that is already installed basic.

The idea is to create an AP (access point) with my WIFI dongle, but the current installed driver (rtl8192eu_nic.bin) only makes me create a Wi-Fi network interface (which also has trouble connecting to Wi-Fi devices). so, I tried to install this GitHub - Mange/rtl8192eu-linux-driver: Drivers for the rtl8192eu chipset for wireless adapters (D-Link DWA-131 rev E1 included!) but I could not do it on my torizoncore as I don’t have dkms, make, apt … installed.

I had the idea of cross compile the driver on a docker machine with toolchain arm64 installed that I retrieved from : torizon/debian-cross-toolchain-arm64 - Docker Image | Docker Hub and then, compile this project : GitHub - Mange/rtl8192eu-linux-driver: Drivers for the rtl8192eu chipset for wireless adapters (D-Link DWA-131 rev E1 included!)

After doing this, i copied the 8192eu.ko to /lib/firmware/..../wireless/ and I tried to load it by executing the cmd : insmod /path-to-ko-file/ but it tells me that the kernel version is not the same.

When I did uname -r on my torizon machine and on the docker image, both versions were the same.

I certainly missed something and that’s why I’m asking you to give me a hand.

I am here for more information and details… thanks !

Greetings @Samir1,

I believe you want to look at this article: Building External Kernel Modules With Torizon | Toradex Developer Center

As documented, with TorizonCore Builder you should be able to compile out-of-kernel code as a kernel module and insert it into your TorizonCore image. The TorizonCore Builder tool should automate the cross-compiling process for you.

Best Regards,
Jeremias

Hello @jeremias.tx ,

I did exactly this : Building External Kernel Modules With Torizon | Toradex Developer Center… i replaced all KSRC in the Makefile by KERNEL_SRC and i ran the command: torizoncore-builder build

Now, i see that the torizoncore-builder is trying to build the module.
But, I get this error :

samiro@samiro-VirtualBox:~/tcbdir$ torizoncore-builder build
Building image as per configuration file 'tcbuild.yaml'...

=>> Handling input section
Unpacking Toradex Easy Installer image.
Copying Toradex Easy Installer image.
Unpacking TorizonCore Toradex Easy Installer image.
Importing OSTree revision 7b671c2c471331a20eb8c36485acddcdf9abf27d5c725b6a8baaad2692656341 from local repository...
1140 metadata, 12738 content objects imported; 529.7 MB content written                                                                             
Unpacked OSTree from Toradex Easy Installer image:
  Commit checksum: 7b671c2c471331a20eb8c36485acddcdf9abf27d5c725b6a8baaad2692656341
  TorizonCore Version: 5.7.2+build.20

=>> Handling customization section

=> Building module located at 'rtl8192eu-linux-driver/'
make: Entering directory '/workdir/rtl8192eu-linux-driver'
/bin/sh: line 1: bc: command not found
make ARCH=arm64 CROSS_COMPILE= -C /storage/linux M=/workdir/rtl8192eu-linux-driver  modules
make[1]: Entering directory '/storage/linux'
arch/arm64/Makefile:27: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum
arch/arm64/Makefile:38: LSE atomics not supported by binutils
arch/arm64/Makefile:52: Detected assembler with broken .inst; disassembly will be unreliable
/bin/sh: line 1: bc: command not found
  CC [M]  /workdir/rtl8192eu-linux-driver/core/rtw_cmd.o
gcc: error: unrecognized argument in option ‘-mstack-protector-guard=sysreg’
gcc: note: valid arguments to ‘-mstack-protector-guard=’ are: global tls
gcc: error: unrecognized command-line option ‘-mlittle-endian’
make[2]: *** [scripts/Makefile.build:262: /workdir/rtl8192eu-linux-driver/core/rtw_cmd.o] Error 1
make[1]: *** [Makefile:1734: /workdir/rtl8192eu-linux-driver] Error 2
make[1]: Leaving directory '/storage/linux'
make: *** [Makefile:2289: modules] Error 2
make: Leaving directory '/workdir/rtl8192eu-linux-driver'
Traceback (most recent call last):
  File "/builder/tcbuilder/backend/kernel.py", line 88, in build_module
    subprocess.run(f"""PATH=$PATH:{toolchain} KERNEL_SRC={linux_src} KDIR={linux_src} \
  File "/usr/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'PATH=$PATH:/storage/toolchain/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin KERNEL_SRC=/storage/linux KDIR=/storage/linux             CROSS_COMPILE=aarch64-none-linux-gnu- ARCH=arm64 make -C /workdir/rtl8192eu-linux-driver' returned non-zero exit status 2.

Error: Error building kernel module(s)!

Do you have any idea about that? thanks !

Hi @Samir1,

before we dive into the error messages.

When building the kernel module, did you follow this guide here?

Best Regards
Kevin

Hello @kevin.tx ,
Yes, I successfully built the hello-mod project and tested it … it worked fine.

I did the same thing with the rtl8192eu module, I changed KSRC to KERNEL_SRC and activated the AARCH64 platform as mentioned in the README file of rtl8192eu-linux-driver . … It seems like a problem with gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu version that does not supports this flags ( -mstack-protector-guard=sysreg , -mlittle-endian ).

Best Regards

How exactly did you do this? I just tried myself and it compiled fine for me. I’m not sure if the driver is working correctly but it at least compiled successfully it seems.

For reference here’s what my tcbuild.yaml looks like:

# Sample configuration file:
input:
  easy-installer:
    local: torizon-core-docker-verdin-imx8mp-Tezi_5.7.2+build.20
# Sample customization: build hello-mod module into the image
customization:
  kernel:
    modules:
      - source-dir: rtl8192eu-linux-driver
        autoload: no
output:
  easy-installer:
    local: test

And here’s the change I did to the repo’s Makefile:

diff --git a/Makefile b/Makefile
index 8ecdb72..6c64e40 100644
--- a/Makefile
+++ b/Makefile
@@ -2284,7 +2284,7 @@ export CONFIG_RTL8192EU = m
 all: modules
 
 modules:
-       $(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KSRC) M=$(shell pwd)  modules
+       $(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNEL_SRC) M=$(shell pwd)  modules
 
 strip:
        $(CROSS_COMPILE)strip $(MODULE_NAME).ko --strip-unneeded

With that I can see the compilation completed successfully. Are you doing other changes to the Makefile or anything else?

Best Regards,
Jeremias

Hello @jeremias.tx,
Actually, these two lines that cause the problem :

CONFIG_PLATFORM_ARM_AARCH64 = y
CONFIG_PLATFORM_I386_PC = n

I compiled without making these changes and it compiles without errors, I will test it on the toradex and let you know if it works.

Thanks a lot !

Hello @jeremias.tx,
I tested it and it seems to work. a small problem is when I create the AP (access point) and I try to connect from another device, it connects then disconnects at the same time.
this is the journalctl log:

torizon@verdin-imx8mp-14871021:~$ journalctl | grep hostapd
Jul 18 07:02:04 verdin-imx8mp-14871021 sudo[923]:  torizon : TTY=pts/0 ; PWD=/var/rootdirs/home/torizon ; USER=root ; COMMAND=/usr/bin/systemctl start hostapd
Jul 18 07:02:04 verdin-imx8mp-14871021 hostapd[926]: Configuration file: /etc/hostapd.conf
Jul 18 07:02:05 verdin-imx8mp-14871021 hostapd[926]: Using interface wlan0 with hwaddr 3e:f5:9d:7a:a4:c1 and ssid "test"
Jul 18 07:02:06 verdin-imx8mp-14871021 hostapd[926]: wlan0: interface state UNINITIALIZED->ENABLED
Jul 18 07:02:06 verdin-imx8mp-14871021 hostapd[926]: wlan0: AP-ENABLED
Jul 18 07:02:06 verdin-imx8mp-14871021 systemd[1]: hostapd.service: Can't open PID file /run/hostapd.pid (yet?) after start: Operation not permitted
Jul 18 07:02:33 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: associated
Jul 18 07:02:33 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c RADIUS: starting accounting session 0F211878D4685622
Jul 18 07:02:51 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: disassociated
Jul 18 07:02:54 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: associated
Jul 18 07:02:54 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c RADIUS: starting accounting session BD845DD63C5E8203
Jul 18 07:03:12 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: disassociated
Jul 18 07:03:15 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: associated
Jul 18 07:03:15 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c RADIUS: starting accounting session 164DC2F4F9B95311
Jul 18 07:03:33 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: disassociated
Jul 18 07:03:42 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: associated
Jul 18 07:03:42 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c RADIUS: starting accounting session BA29620DD2309580
Jul 18 07:04:01 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: disassociated
Jul 18 07:04:07 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: associated
Jul 18 07:04:07 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c RADIUS: starting accounting session 49776524052B9C41
Jul 18 07:04:25 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: disassociated
Jul 18 07:04:32 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: associated
Jul 18 07:04:32 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c RADIUS: starting accounting session 240DFA7545570ACC
Jul 18 07:04:50 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: disassociated
Jul 18 07:05:33 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA d8:c0:a6:0b:52:01 IEEE 802.11: associated
Jul 18 07:05:33 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA d8:c0:a6:0b:52:01 RADIUS: starting accounting session 817DEFC9A402B4FB
Jul 18 07:05:54 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA d8:c0:a6:0b:52:01 IEEE 802.11: disassociated
Jul 18 07:06:00 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA d8:c0:a6:0b:52:01 IEEE 802.11: associated
Jul 18 07:06:00 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA d8:c0:a6:0b:52:01 RADIUS: starting accounting session 8168F5E534CD3137
Jul 18 07:07:00 verdin-imx8mp-14871021 hostapd[927]: wlan0: STA d8:c0:a6:0b:52:01 IEEE 802.11: disassociated
Jul 18 07:11:53 verdin-imx8mp-14871021 sudo[1027]:  torizon : TTY=pts/0 ; PWD=/var/rootdirs/home/torizon ; USER=root ; COMMAND=/usr/bin/systemctl restart hostapd
Jul 18 07:11:53 verdin-imx8mp-14871021 systemd[1]: hostapd.service: Succeeded.
Jul 18 07:11:53 verdin-imx8mp-14871021 hostapd[1030]: Configuration file: /etc/hostapd.conf
Jul 18 07:11:54 verdin-imx8mp-14871021 hostapd[1030]: Using interface wlan0 with hwaddr fe:2b:c8:76:4d:42 and ssid "test"
Jul 18 07:11:54 verdin-imx8mp-14871021 hostapd[1030]: wlan0: interface state UNINITIALIZED->ENABLED
Jul 18 07:11:54 verdin-imx8mp-14871021 hostapd[1030]: wlan0: AP-ENABLED
Jul 18 07:12:11 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: associated
Jul 18 07:12:11 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c RADIUS: starting accounting session 872724D87889D51F
Jul 18 07:12:30 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: disassociated
Jul 18 07:12:33 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: associated
Jul 18 07:12:33 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c RADIUS: starting accounting session A643BDC8CCC4441E
Jul 18 07:12:51 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: disassociated
Jul 18 07:12:54 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: associated
Jul 18 07:12:54 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c RADIUS: starting accounting session 51C590A45C0B65EB
Jul 18 07:13:12 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: disassociated
Jul 18 07:13:17 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: associated
Jul 18 07:13:17 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c RADIUS: starting accounting session CC5A47C1B6C07D1F
Jul 18 07:13:35 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: disassociated
Jul 18 07:13:42 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: associated
Jul 18 07:13:42 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c RADIUS: starting accounting session 8C1E7363FCD91832
Jul 18 07:14:00 verdin-imx8mp-14871021 hostapd[1031]: wlan0: STA e0:cc:f8:fd:d8:5c IEEE 802.11: disassociated
torizon@verdin-imx8mp-14871021:~$ 

Any idea ?

My only idea is that I see you are using hostapd for the AP. Did you configure NetworkManager to not manage this network interface? This can cause conflicts/issues between NetworkManager and hostapd.

Other than that, I’m not entirely sure. If it’s an issue with this driver then that’s a bit out of our expertise.

Best Regards,
Jeremias

Hello @jeremias.tx,

You are right, I fixed this by creating Wi-Fi Direct (I stopped NetworkManager service) then, i ran hostapd to create the AP.

For all those who have the same problem, it is absolutely necessary to update the rtl8192eu driver.

Thanks !

Glad to hear you were able to solve the issue!