Cross-compiling a kernel module

HIi,

i have a wifi adapter not working, after trying all the steps, including copying firmware in /data/firmware as suggested in WiFi - MOD Wiki

I have some experience of cross compiling and embedded developing, so I would like to build this driver GitHub - lwfinger/rtl8188eu: Repository for stand-alone RTL8188EU driver. which seems to be a possible solution.
Could please someone point me to the cross-developent tools (toolchain and kernel includes, I guess) for the Dwarf? @falkTX ?

Z

the toolchain is always the same in mod-plugin-builder, but to be honest I have never tried to build an out-of-tree driver like that before…

in any case, the linux kernel code is at GitHub - moddevices/linux-mainline at linux-6.1.y-patches
we apply the RT kernel patch on top of this, not sure if needed for building a driver or not.

1 Like

Thanks

Today I managed to build the mod-plugin-builder container, will let you know if I get somewhere with the module

1 Like

Ok, I think I just (almost) succeeded on using the usb key with the dwarf.

As you may have noticed by my PM I have done some mistake, building the docker image with platform=moddwarf instead of moddwarf-new

(i really hate docker)

ANYWAY, after installing in the beforementioned image an up-to-date cross toolchain (and some header), cloning your kernel repo, checkout the right branch, patch with the “patch-6.1.12-rt7.patch” patchset from Index of /pub/linux/kernel/projects/rt/ and build the kernel. I have used as a starting point the /proc/config.gz file on the dwarf

I have then cloned the driver repo from GitHub - lwfinger/rtl8188eu: Repository for stand-alone RTL8188EU driver. and built with

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- KSRC=../linux-mainline/ (…/linux-mainline is where I built the kernel)

it (kinda) worked, the module could not be loaded due to non-matching magic. I had to manually change two files

include/config/kernel.release
include/generated/utsrelease.h

to match to your kernel version (it added che commit at the end of name)

AT THE END (after many try and fail) I transferred 8188eu.ko to /root/data on the dwarf, where I had previously configured wpa_supplicant.conf and the firmware files as per the wiki. I have manually loaded with insmod ./8188eu.ko and voila! It works!


root@moddwarf mod_dwarf_8188]# insmod ./8188eu.ko 



Jan 01 01:30:45 moddwarf kernel: 8188eu: loading out-of-tree module taints kernel.
Jan 01 01:30:45 moddwarf kernel: Chip Version Info: CHIP_8188E_Normal_Chip_TSMC_D_CUT_1T1R_RomVer(0)
Jan 01 01:30:45 moddwarf kernel: EEPROM ID = 0x8129
Jan 01 01:30:45 moddwarf kernel: usbcore: registered new interface driver r8188eu
Jan 01 01:30:45 moddwarf systemd[1]: Started WPA supplicant for wlan0.
Jan 01 01:30:45 moddwarf systemd[1]: Starting WPA supplicant for wlan0...
Jan 01 01:30:45 moddwarf systemd[1]: Starting DHCP for wlan0...
Jan 01 01:30:45 moddwarf wpa_supplicant[8649]: Successfully initialized wpa_supplicant
Jan 01 01:30:45 moddwarf dhcpcd[8650]: forked to background, child pid 8651
Jan 01 01:30:45 moddwarf dhcpcd[8650]: forked to background, child pid 8651
Jan 01 01:30:45 moddwarf systemd[1]: Started DHCP for wlan0.
Jan 01 01:30:45 moddwarf wpa_supplicant[8649]: nl80211: Driver does not support authentication/association or connect commands
Jan 01 01:30:45 moddwarf wpa_supplicant[8649]: nl80211: deinit ifname=wlan0 disabled_11b_rates=0
Jan 01 01:30:45 moddwarf kernel: R8188EU: Firmware Version 11, SubVersion 1, Signature 0x88e1
...
Jan 01 01:30:46 moddwarf wpa_supplicant[8649]: ioctl[SIOCSIWAP]: Operation not permitted
Jan 01 01:30:46 moddwarf dhcpcd[8651]: wlan0: waiting for carrier
Jan 01 01:30:47 moddwarf kernel: R8188EU: INFO indicate disassoc
Jan 01 01:30:47 moddwarf wpa_supplicant[8649]: wlan0: Trying to associate with xxxxxxxxxxxxxxx (SSID='xxxxxxxxxxxxxxx' freq=2437 MHz)
Jan 01 01:30:47 moddwarf kernel: R8188EU: INFO assoc success
Jan 01 01:30:47 moddwarf wpa_supplicant[8649]: wlan0: Associated with 04:95:e6:ee:11:41
Jan 01 01:30:47 moddwarf wpa_supplicant[8649]: wlan0: WPA: Key negotiation completed with 04:95:e6:ee:11:41 [PTK=CCMP GTK=CCMP]
Jan 01 01:30:47 moddwarf wpa_supplicant[8649]: wlan0: CTRL-EVENT-CONNECTED - Connection to 04:95:e6:ee:11:41 completed [id=0 id_str=]
Jan 01 01:30:47 moddwarf dhcpcd[8651]: wlan0: carrier acquired
Jan 01 01:30:47 moddwarf dhcpcd[8651]: wlan0: soliciting a DHCP lease
Jan 01 01:30:50 moddwarf dhcpcd[8651]: wlan0: offered 192.168.1.35 from 192.168.1.1
Jan 01 01:30:51 moddwarf dhcpcd[8651]: wlan0: probing address 192.168.1.35/24
Jan 01 01:30:56 moddwarf dhcpcd[8651]: wlan0: leased 192.168.1.35 for 86400 seconds
Jan 01 01:30:56 moddwarf avahi-daemon[1523]: Joining mDNS multicast group on interface wlan0.IPv4 with address 192.168.1.35.
Jan 01 01:30:56 moddwarf avahi-daemon[1523]: New relevant interface wlan0.IPv4 for mDNS.
Jan 01 01:30:56 moddwarf dhcpcd[8651]: wlan0: adding route to 192.168.1.0/24
Jan 01 01:30:56 moddwarf avahi-daemon[1523]: Registering new address record for 192.168.1.35 on wlan0.IPv4.
Jan 01 01:30:56 moddwarf dhcpcd[8651]: wlan0: adding default route via 192.168.1.1
Jan 01 01:30:56 moddwarf dhcpcd[8651]: wlan0: removing route to 192.168.1.0/24

When I have some time I will try to build it again with the “moddwarf-new” docker, but I am not sure how to get the correct kernel version without having to manually change those files.

So, after all, if you have a working docker to build the kernel all you have to do to build the module is this one-liner
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- KSRC=../linux-mainline/

I cannot attach here the module I built, let me know if it cam be useful to you

1 Like

very interesting, so it works in the end nice nice

the version thing might be due to the RT kernel being applied, I know that adds a suffix to the version. was that your issue, or something else?

No, I have deleted it now, it was something like

‘6.1.15-rt7-moddwarf-gacbab9e4b11d-dirty

So it seems it added some info for the git status

1 Like

right yes, because of small (super ugly) hacks to get a few things right. the hacks are too ugly to be on the official repo… :sweat_smile:

2 Likes

How can we arrange to distribute the module to other people? I have noticed many similar requests on the forum.

Having the right kernel tree and toolchain it is really simple to build

Also, I don’t know how to permanently load it from /data. Is there something like rc.local I can permanently change?

Ok, I have rebuilt all with the updated toolchain, this is what i did on my fedora laptop:

on laptop

retrieve kernel config from mod dwarf

scp root@192.168.50.1:/proc/config.gz /home/giorgio
gunzip /home/giorgio/config.gz ; mv /home/giorgio/config /home/giorgio/config.moddwarf

build docker image (see How To Use Docker Toolbox With MPB - MOD Wiki)

git clone --depth 1 GitHub - moddevices/mod-plugin-builder: MOD Plugin Builder
cd mod-plugin-builder/docker
docker build -t mpb --build-arg “platform=moddwarf-new minimal” .

Run docker

sudo docker run -ti -p 9000:9000 -v /home/giorgio/:/home/giorgio mpb

download, patch and build kernel with the mod config

install missing deps

sudo apt install libssl-dev

download kernel

git clone GitHub - moddevices/linux-mainline: Linux kernel source tree -b linux-6.1.y-patches

apply runtime patches

wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/6.1/older/patch-6.1.12-rt7.patch.gz
gunzip patch-6.1.12-rt7.patch.gz
cat patch-6.1.12-rt7.patch | patch -p1 --verbose

apply dwarf config

cp /home/giorgio/config.moddwarf .config

build kernel

make ARCH=arm64 CROSS_COMPILE=/home/builder/mod-workdir/moddwarf-new/toolchain/bin/aarch64-modaudio-linux-gnu- oldconfig
make ARCH=arm64 CROSS_COMPILE=/home/builder/mod-workdir/moddwarf-new/toolchain/bin/aarch64-modaudio-linux-gnu-
echo ‘#define UTS_RELEASE “6.1.15-rt7-moddwarf”’ > include/generated/utsrelease.h
echo “6.1.15-rt7-moddwarf” > include/config/kernel.release
cd …

download and build driver

clone GitHub - lwfinger/rtl8188eu: Repository for stand-alone RTL8188EU driver.
cd rtl8188eu/
make ARCH=arm64 CROSS_COMPILE=/home/builder/mod-workdir/moddwarf-new/toolchain/bin/aarch64-modaudio-linux-gnu- KSRC=…/linux-mainline/

copy rtl8188eufw.bin and 8188eu.ko to dwarf , configure wpa_supplicant.conf according to WiFi - MOD Wiki

TODO: load driver at boot

Hope it helps

2 Likes