Wifi driver compilation Rpi 4B - kernel headers error: "no such file or directory"

Hi,

I’m trying to compile wifi drivers for RTL8812AU usb wifi. Compilation works on rasbpian and other distribution, but compilation on OSMC does not work. There is an error. Maybe you can help, because there is something different in OSMC.

Here are some information about hardware:

root@osmc:/usr/src/8814au# lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 0bda:8812 Realtek Semiconductor Corp. RTL8812AU 802.11a/b/g/n/ac 2T2R DB WLAN Adapter
root@osmc:~# uname -a
Linux osmc 5.10.78-5-osmc SMP PREEMPT Mon Feb 28 01:18:12 UTC 2022 aarch64 GNU/Linux

I’ve found, drivers to my adapter is here: GitHub - morrownr/8812au-20210629: Linux Driver for USB WiFi Adapters that are based on the RTL8812AU Chipset - v5.13.6

At first, I tried to install rbp2-headers.

apt install rbp2-headers-5.10.78-5-osmc

Compilation worked, but when I was trying to insert module, I had this error:

modprobe: ERROR: could not insert '8812au': Exec format error

I think, the main reason is, that rbp2-headers package is not for Raspberry 4.

So I tried to install these packages:

apt install rbp464-headers-5.10.78-5-osmc
apt install rbp464-headers-sanitised-5.10.78-5-osmc

But I have error during the compilation:

root@osmc:~/src/8812au-20210629# ./ARM_RPI.sh

I386 support was turned off in Makefile as planned.
Raspberry Pi OS (32 bit) support was turned on in Makefile as planned.
root@osmc:~/src/8812au-20210629#  ./install-driver.sh 


Running install-driver.sh version 20220108
Open Source Media Center
5.10.78-5-osmc
aarch64
Starting installation...
Copying source files to: /usr/src/rtl8812au-5.13.6
Copying 8812au.conf to: /etc/modprobe.d

Creating symlink /var/lib/dkms/rtl8812au/5.13.6/source ->
                 /usr/src/rtl8812au-5.13.6

DKMS: add completed.

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area...
'make' -j4 KVER=5.10.78-5-osmc KSRC=/lib/modules/5.10.78-5-osmc/build...(bad exit status: 2)
Error! Bad return status for module build on kernel: 5.10.78-5-osmc (aarch64)
Consult /var/lib/dkms/rtl8812au/5.13.6/build/make.log for more information.
An error occurred. dkms build error = 10
Please report this error.
You will need to run the following before reattempting installation.
$ sudo ./remove-driver.sh
root@osmc:~/src/8812au-20210629# cat /var/lib/dkms/rtl8812au/5.13.6/build/make.log
DKMS make.log for rtl8812au-5.13.6 for kernel 5.10.78-5-osmc (aarch64)
Po čen 13 23:50:19 CEST 2022
make ARCH=arm CROSS_COMPILE= -C /lib/modules/5.10.78-5-osmc/build M=/var/lib/dkms/rtl8812au/5.13.6/build  modules
make[1]: Vstupuje se do adresáře „/usr/src/rbp464-headers-5.10.78-5-osmc“
  CC [M]  /var/lib/dkms/rtl8812au/5.13.6/build/core/rtw_cmd.o
  CC [M]  /var/lib/dkms/rtl8812au/5.13.6/build/core/rtw_security.o
  CC [M]  /var/lib/dkms/rtl8812au/5.13.6/build/core/rtw_debug.o
  CC [M]  /var/lib/dkms/rtl8812au/5.13.6/build/core/rtw_io.o
In file included from ./include/asm-generic/int-ll64.h:11,
                 from ./arch/arm/include/uapi/asm/types.h:5,
                 from ./include/uapi/linux/types.h:5,
                 from ./include/linux/types.h:6,
                 from /var/lib/dkms/rtl8812au/5.13.6/build/include/basic_types.h:75,
                 from /var/lib/dkms/rtl8812au/5.13.6/build/include/drv_types.h:26,
                 from /var/lib/dkms/rtl8812au/5.13.6/build/core/rtw_security.c:17:
./include/uapi/asm-generic/int-ll64.h:12:10: fatal error: asm/bitsperlong.h: Adresář nebo soubor neexistuje
 #include <asm/bitsperlong.h>
          ^~~~~~~~~~~~~~~~~~~
In file included from ./include/asm-generic/int-ll64.h:11,
                 from ./arch/arm/include/uapi/asm/types.h:5,
                 from ./include/uapi/linux/types.h:5,
                 from ./include/linux/types.h:6,
                 from /var/lib/dkms/rtl8812au/5.13.6/build/include/basic_types.h:75,
                 from /var/lib/dkms/rtl8812au/5.13.6/build/include/drv_types.h:26,
                 from /var/lib/dkms/rtl8812au/5.13.6/build/core/rtw_cmd.c:17:
./include/uapi/asm-generic/int-ll64.h:12:10: fatal error: asm/bitsperlong.h: Adresář nebo soubor neexistuje
 #include <asm/bitsperlong.h>
          ^~~~~~~~~~~~~~~~~~~
In file included from ./include/asm-generic/int-ll64.h:11,
                 from ./arch/arm/include/uapi/asm/types.h:5,
                 from ./include/uapi/linux/types.h:5,
                 from ./include/linux/types.h:6,
                 from /var/lib/dkms/rtl8812au/5.13.6/build/include/basic_types.h:75,
                 from /var/lib/dkms/rtl8812au/5.13.6/build/include/drv_types.h:26,
                 from /var/lib/dkms/rtl8812au/5.13.6/build/core/rtw_io.c:47:
./include/uapi/asm-generic/int-ll64.h:12:10: fatal error: asm/bitsperlong.h: Adresář nebo soubor neexistuje
 #include <asm/bitsperlong.h>
          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
In file included from ./include/asm-generic/int-ll64.h:11,
                 from ./arch/arm/include/uapi/asm/types.h:5,
                 from ./include/uapi/linux/types.h:5,
                 from ./include/linux/types.h:6,
                 from /var/lib/dkms/rtl8812au/5.13.6/build/include/basic_types.h:75,
                 from /var/lib/dkms/rtl8812au/5.13.6/build/include/drv_types.h:26,
                 from /var/lib/dkms/rtl8812au/5.13.6/build/core/rtw_debug.c:17:
./include/uapi/asm-generic/int-ll64.h:12:10: fatal error: asm/bitsperlong.h: Adresář nebo soubor neexistuje
 #include <asm/bitsperlong.h>
          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
compilation terminated.
compilation terminated.
make[2]: *** [scripts/Makefile.build:280: /var/lib/dkms/rtl8812au/5.13.6/build/core/rtw_io.o] Chyba 1
make[2]: *** Čeká se na nedokončené úlohy…
make[2]: *** [scripts/Makefile.build:280: /var/lib/dkms/rtl8812au/5.13.6/build/core/rtw_debug.o] Chyba 1
make[2]: *** [scripts/Makefile.build:280: /var/lib/dkms/rtl8812au/5.13.6/build/core/rtw_security.o] Chyba 1
make[2]: *** [scripts/Makefile.build:280: /var/lib/dkms/rtl8812au/5.13.6/build/core/rtw_cmd.o] Chyba 1
make[1]: *** [Makefile:1825: /var/lib/dkms/rtl8812au/5.13.6/build] Chyba 2
make[1]: Opouští se adresář „/usr/src/rbp464-headers-5.10.78-5-osmc“
make: *** [Makefile:2514: modules] Chyba 2

It looks like, that it is not possible to find asm/bitsperlong.h:

./include/uapi/asm-generic/int-ll64.h:12:10: fatal error: asm/bitsperlong.h: Adresář nebo soubor neexistuje
 #include <asm/bitsperlong.h>
          ^~~~~~~~~~~~~~~~~~~

And I don’t understand, how to solve it. Compilation works on other raspberry pi distributions.

But other distributions have only one kernel headers package.

Do I have installed right kernel headers?

root@osmc:/lib/modules/5.10.78-5-osmc# ls -l
celkem 2352
lrwxrwxrwx  1 root root     38 úno 28 03:09 build -> /usr/src/rbp464-headers-5.10.78-5-osmc
root@osmc:/lib/modules/5.10.78-5-osmc# ls -l /usr/src/
celkem 12
drwxr-xr-x  3 root root 4096 čen 13 23:09 rbp464-headers-sanitised-5.10.78-5-osmc
drwxr-xr-x 23 root root 4096 čen 13 23:11 rbp464-headers-5.10.78-5-osmc
root@osmc:/usr/src/rbp464-headers-sanitised-5.10.78-5-osmc# ls -l
celkem 4
drwxr-xr-x 13 root root 4096 čen 13 23:09 include
root@osmc:/usr/src/rbp464-headers-sanitised-5.10.78-5-osmc# ls -l include/
celkem 68
drwxr-xr-x  2 root root  4096 čen 13 23:09 asm
drwxr-xr-x  2 root root  4096 čen 13 23:09 asm-generic
drwxr-xr-x  2 root root  4096 čen 13 23:09 drm
drwxr-xr-x 28 root root 24576 čen 13 23:09 linux
drwxr-xr-x  3 root root  4096 čen 13 23:09 misc
drwxr-xr-x  2 root root  4096 čen 13 23:09 mtd
drwxr-xr-x  3 root root  4096 čen 13 23:09 rdma
drwxr-xr-x  3 root root  4096 čen 13 23:09 scsi
drwxr-xr-x  3 root root  4096 čen 13 23:09 sound
drwxr-xr-x  2 root root  4096 čen 13 23:09 video
drwxr-xr-x  2 root root  4096 čen 13 23:09 xen

This is not only about RTL8812AU drivers. I tried to compile different drivers and I had the same problem with fatal error during compilation.

Avoid sanitised headers

Sam

hi, thank you, but it doesn’t work. Problem persits:

apt --purge remove rbp464-headers-sanitised-5.10.78-5-osmc

osmc@osmc:/usr/src$ ls -l
celkem 8
drwxr-xr-x 23 root root 4096 čen 13 23:11 rbp464-headers-5.10.78-5-osmc
drwxr-xr-x  9 root root 4096 čen 13 23:50 rtl8812au-5.13.6

The truth is, that I tried to compile drivers without package “rbp464-headers-sanitised-5.10.78-5-osmc” at first. Only with “rbp464-headers-5.10.78-5-osmc”. But it didn’t work. So I tried to install sanitised headers.

root@osmc:/home/osmc# ls -l /lib/modules/5.10.78-5-osmc/
celkem 2352
lrwxrwxrwx  1 root root     38 úno 28 03:09 build -> /usr/src/rbp464-headers-5.10.78-5-osmc
drwxr-xr-x 10 root root   4096 čen  5 17:26 kernel
-rw-r--r--  1 root root 578080 čen 13 22:12 modules.alias
-rw-r--r--  1 root root 601448 čen 13 22:12 modules.alias.bin
-rw-r--r--  1 root root  14394 úno 28 03:09 modules.builtin
-rw-r--r--  1 root root  15903 čen 13 22:12 modules.builtin.bin
-rw-r--r--  1 root root  79788 úno 28 03:09 modules.builtin.modinfo
-rw-r--r--  1 root root 194220 čen 13 22:12 modules.dep
-rw-r--r--  1 root root 268716 čen 13 22:12 modules.dep.bin
-rw-r--r--  1 root root    352 čen 13 22:12 modules.devname
-rw-r--r--  1 root root  64297 úno 28 03:09 modules.order
-rw-r--r--  1 root root    380 čen 13 22:12 modules.softdep
-rw-r--r--  1 root root 252430 čen 13 22:12 modules.symbols
-rw-r--r--  1 root root 307889 čen 13 22:12 modules.symbols.bin

Still fatal error without sanitized headers installed:

root@osmc:~/src/8812au-20210629# make
make ARCH=arm CROSS_COMPILE= -C /lib/modules/5.10.78-5-osmc/build M=/root/src/8812au-20210629  modules                                                                                    
make[1]: Vstupuje se do adresáře „/usr/src/rbp464-headers-5.10.78-5-osmc“
  CC [M]  /root/src/8812au-20210629/core/rtw_cmd.o
In file included from ./include/asm-generic/int-ll64.h:11,
                 from ./arch/arm/include/uapi/asm/types.h:5,
                 from ./include/uapi/linux/types.h:5,
                 from ./include/linux/types.h:6,
                 from /root/src/8812au-20210629/include/basic_types.h:75,
                 from /root/src/8812au-20210629/include/drv_types.h:26,
                 from /root/src/8812au-20210629/core/rtw_cmd.c:17:
./include/uapi/asm-generic/int-ll64.h:12:10: fatal error: asm/bitsperlong.h: Adresář nebo soubor neexistuje                                                                               
 #include <asm/bitsperlong.h>
          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [scripts/Makefile.build:280: /root/src/8812au-20210629/core/rtw_cmd.o] Chyba 1
make[1]: *** [Makefile:1825: /root/src/8812au-20210629] Chyba 2
make[1]: Opouští se adresář „/usr/src/rbp464-headers-5.10.78-5-osmc“
make: *** [Makefile:2514: modules] Chyba 2

You need to use an arm64 userland such as the arm64 toolchain

Hi, thank you. It was realy solution. So for those, who have the same problem.

At first, I installed aarch64-toolchain:

apt install aarch64-toolchain-osmc

This thread helped me too: Trying to install build-essential:arm64 on pi4 - #3 by dwardor

chROOT="/opt/osmc-tc/aarch64-toolchain-osmc"

mkdir -p $chROOT/home
mount --bind /home $chROOT/home #module source is in /home/osmc
mkdir -p $chROOT/usr/src #kernel source
mount --bind /usr/src $chROOT/usr/src
mkdir -p $chROOT/lib/modules #module makefiles refer to /lib/modules/$KVER/build
mount --bind /lib/modules $chROOT/lib/modules

chroot /opt/osmc-tc/aarch64-toolchain-osmc/

After the last command, I was in chrooted environment and I could find source drivers and compile them by tiping “make”.

cd /home/osmc/src/
make -j 4

So compilation was successfull and I could install driver.

Thank you for you tip, problem is solved.