Adding modules to kernel (PART 3)

Rhythm Chopra
3 min readOct 19, 2018

--

This is the third part of series, Libretech tritium Board Bringup.
Part 2 is available here.

If you followed part 1 and 2, you must be knowing where this will be heading. And for others we will be adding support for usb-storage, wifi and soundcard in custom build kernel.

So let’s get started, supposing you have the linux kernel already cloned.
I’ll be using TP-Link USB-WIFI dongle to test wifi connectivity.

Initial kernelconfig for the board

make ARCH=arm sunxi_defconfig

Menuconfig to add modules

 make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

For usb mass storage, go to

Device Drivers -> USB Support -> USB Mass Storage Support
and press `m` key to enable it as module

For soundcard support, go to

Device drivers -> Sound card support -> Advance Linux Sound Architecture (m)
Then enable following:
Enable OSS Emulation (y)
OSS Mixer API (m)
OSS PCM API (m)
ALSA for SoC audio support(m)
Now Goto, Allwinner SoC audio support and enable all configs as modules(m)

For wireless support, go to

a) Networking support -> Wireless -> cfg80211 — Wireless configuration API (m)
b) Device drivers -> Network device support -> wireless LAN (y)
c) Device Drivers -> Staging drivers -> Support for rtllib wireless drivers (m)
And then enable all REALTEK NIC drivers as modules(m)

Exit menuconfig with saving configuration to `.config`

Build kernel again

make -j 8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs
make -j 8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules

Connect and mount sdcard in host machine

sudo mount /dev/sdX1 /mnt

Install kernel modules and update zImage and device-tree

sudo make -j 8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=/mnt/ modules_install
sudo cp arch/arm/boot/zImage /mnt
sudo cp arch/arm/boot/dts/sun8i-h2-plus-libretech-all-h3-cc.dtb /mnt/device_tree.dtb

Adding RTLwifi firmware blobs

Now for wireless driver to work, you need to corresponding linux firmware for the same, because in recent versions, firmware blobs were removed my kernel source. So clone the firmware repository.

git clone git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git linux-firmware

Since I’m using TP-Link USB-WIFI Dongle, which requires RTLWifi firmware. So just copy the following directory into mounted sdcard.

sudo cp -r linux-firmware/rtlwifi/ /mnt/lib/firmware/

Unmount sdcard, and plug it in the board and boot it up

sudo umount /mnt

Testing above created modules

USB Storage

To test USB storage support, connect any usb device into USB Port and you will have a new device node under `/dev/` namely `/dev/sdX`.

Soundcard support

For soundcard support install alsa-utils package using

apt-get install alsa-utilsAnd run `speaker-test` command. You will hear the sound in your headphones.

WIFI support

To test usb wifi dongle, first update /etc/network/interfaces to add wlan0 to it. Add following snippet.
If you have onboard wifi support, change allow-hotplug to auto

allow-hotplug wlan0
iface wlan0 inet dhcp
pre-up wpa_supplicant -Dwext -i wlan0 -c /etc/wpa_supplicant.conf -B

Now create a file /etc/wpa_supplicant.conf to save wifi credentails so that it connects automatically.

network={
ssid=”< wifi-ssid >”
psk=”< wifi-password >”
}

For multiple wifis, just keep appending nodes with same structure in the file. Now restart `networking manager`.

systemctl restart NetworkingManager

6. Connect USB dongle, and run

ip a

you will see wlan0.

iwconfig

will show whether you are connected to a router or not, you should be.
If you don’t see any IP after few seconds. Run

dhclient

command and you will have the IP.

Now you can use wifi, usb storage and soundcard support on your board.

Now you have completed a board bringup from scratch. That’s cool.

You can also checkout the ready-to-use build scripts on https://github.com/rhythmize/kali-build-scripts

Cheers.

--

--

Rhythm Chopra

Tech Enthusiast | Software Engineer | Trying out new stuff