Tutorial: Build a Linux kernel with drivers for the RTL8188CUS WiFi module for the Arietta G25 Board (Part 1)

This tutorial is a step by step guide on how to prepare an SD card with a Linux kernel that has the drivers for the custom WiFi module for Arietta G25 that is based on the Realtek RTL8188CUS USB to WiFI module. For this tutorial you need a PC running Ubuntu Linux, these steps where tested on a PC with Ubuntu 14.10.

You would need at least 1 hour to complete all the steps on this guide, it is a quite long process but hopefully you will have to do it just once, take into consideration that this is not a 5 minutes recipe and you may have to do some troubleshooting.

Requirements

  • Arietta G25 linux board
  • USB to Serial Adapter (Use one with IO levels of 3.3V)
  • micro SD card with at least 1Gb
  • Custom RTL8188CUS WiFi module
  • USB cables

Task #1: Prepare the SD Card

First things first, we need to prepare the micro SD card where the operating system for the Arietta G25 board will be stored. New SD cards have by default only one FAT partition. The Arietta G25 board needs 2 partitions in order to work. We are going to prepare them and label them as follows

Label: Format type Size
kernel FAT16 128Mb
rootfs EXT4 >1000Mb

Insert the SD card on your computer and open a terminal window pressing Ctrl+T, and type

 dmesg 

at the end of the results from the command you should find the information of the SD card you just inserted, in my case is a Lexar USB card reader with a 8Gb micro SD card inside. As you can see this indicates that the name assigned to the device is sdc.

dmesg

Now that you know which is the name of the SD card, open the application named GPARTED. On the next steps the contents of the SD card will be completely deleted please be sure that you don’t have any useful file on your microSD card.

Once GPARTED is open, look for your SD card, and in this case is /dev/sdc, one quick check is to see if it is the correct size of the one you are using. Be careful not to format another partition. Is recommended that you eject any media that could confuse you on which device you are formating.

 

gparted1

First unmount the device, select the device and right click on it, then select unmount, the logo with the two keys will disappear.

Delete the partition doing right click and select delete and click the button with the green check. Now your SD card has no partition.

gparted2

Now is the time to create the partitions needed for booting the Linux system. Create a new partition doing  right click on the unallocated space and selecting New with these parameters:

New size(MiB): 128
File system: FAT16
Label: kernel
Leave all the other fields at default values and click Add and then the button with the green check to apply the changes.

gparted3

After this step you have created the first partition

gparted4

Now is time to create the second partition, you have to select the unallocated space (the one with the grey square in the front) right click and select new with these parameters:

New size(MiB): Leave the default setting
File system: EXT4
Label: rootfs
Leave all the other fields at default values and click Add and then the button with the green check to apply the changes.

After applying the changes your SD card will be formated with two partitions, kernel and rootfs

gparted5

Remove the microSD from the computer, wait about 5 sec and insert it again. Two partitions will be mounted automatically on:
/media/$USER/kernel
/media/$USER/rootfs
where $USER will be replaced with your user name, don’t remove the SD card from your computer, we are going to copy files to it trough many steps of this tutorial.

Task #2: Compile the AT91bootstrap for the Arietta board

The first step for this task is to install the ARM toolchain (cross compiler, linker, etc) on your Linux Ubuntu PC, follow this great step by step guide on the site of the Arietta board and when you finish with it continue with this tutorial.

Install the ARM cross compiler toolchain on your Linux Ubuntu PC

After the toolchain is installed and working create a new folder named linux-g25 preferably in your Home folder download the Atmel AT91boostrap version 3.7 sources from GitHub

v3.7.zip

Open a terminal and go to your linux-g25 folder and unzip the contents of the previous file with the following command

 unzip at91bootstrap-3.7.zip 

download the patch from the Acme system GitHub repository: typing the following command

wget https://raw.githubusercontent.com/AcmeSystems/acmepatches/master/at91bootstrap-3.7.patch

Apply the patch with the following command

patch -p1 <  at91bootstrap-3.7.patch

run the make command with the def config filename of your board

for the board with 128MB run:

make arietta-128m_defconfig

for the board with 256MB run:

make arietta-256m_defconfig

To launch the compilation type:

 make CROSS_COMPILE=arm-linux-gnueabi- 

After the compilation you need to copy the binary files to the first partition of SD card renaming it to boot.bin.  Run the following command to do so

cp binaries/at91sam9x5_arietta-sdcardboot-linux-zimage-dt-3.7.bin /media/$USER/boot/boot.bin  

remember that $USER has to be replaced with your user name.

Task #3: Compiling Linux Kernel 4.4.1

Download and save in the linux-g25 directory the Linux Kernel sources:

linux-4.4.1.tar.xz

Extract the Kernel sources from the compressed file by typing the following command

tar xvfJ linux-4.4.3.tar.xz

Download this patch file from GitHub:

wget https://raw.githubusercontent.com/AcmeSystems/acmepatches/master/linux-4.4.1.patch

apply the patch typing the command

patch -p1 < linux-4.4.1.patch

Then apply the Linux configuration for your board by typing

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-aria_defconfig 

Customize the default Linux Kernel configuration

Here is the point where the drivers for the WiFi module have to be compiled and integrated into the linux kernel.

Download the drivers sources from GitHub:

Drivers source

Unzip the contents of the file inside the Linux Kernel source tree, the folder is located as:

/home/$USER/linux-g25/linux-4.4.1/drivers/net/wireless

wl-folder

The rtl8192cu folder should appear as in the image above

You have to let the Linux kernel know about your new driver.

Edit the Makefile in the /linux-4.4.1/drivers/net/wireless directory to include the following line:

obj-$(CONFIG_RTL8192CU) += rtl8192cu/
makefile1

Edit the Kconfig file in the /linux-4.4.1/drivers/net/wireless directory to include the following line:

source “drivers/net/wireless/rtl8192cu/Kconfig”

kconfig

run the following command to see the kernel configuration

make ARCH=arm menuconfig

Navigate inside the Kernel configuration using the arrow keys and follow the help provided by the menuconfig interface.

Make sure the RTL8192CU driver will be compiled into the kernel

Select: Device Drivers–>Network Device support–>Wireless LAN, and then at the bottom of the list make sure you have the Realtek 8192C USB WiFi option highlight it and select it pressing the M key, a letter M has to apear iside the < > symbols. This means that the drivers will be compiled as modules, deselect all other Realtek drivers.

<M>Realtek 8192C USB WiFi

kernel-config

Exit all the way back out remembering to save your config when prompted. Now it is build time!

Generate the Device Tree Blob file (.dtb)
Now compile the the device tree file requested by your board with this command

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-arietta.dtb 

Compile the Kernel image

Compile the Linux Kernel sources and generate the binary compressed image file to save in the first partition of microSD card.

make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- zImage 

this source compilation requires about 5 minutes so be a bit patient.

Compile the Kernel modules

The image generated contains the Linux Kernel and all the built-in device drivers (option [*] in menuconfig) compiled with it. All the drivers compiled as external modules (option [M] in menuconfig) need to be compiled and saved in the /rootfs/lib/ directory on the rootfs partition of the microSD. To compile them type these commands one after another:

make modules -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
make modules_install INSTALL_MOD_PATH=./modules ARCH=arm

When the second command finishes if everything went fine you should be able to see the 8192cu.ko file that was compiled, the rtl8192.ko file is the module with the WiFi drivers.

ko-driver

Copy the boot files into the first microSD partition

Write the Linux kernel image and device tree driver files in the first microSD partition:

cp arch/arm/boot/dts/acme-arietta.dtb /media/$USER/kernel

Save the Linux Kernel zImage:

cp arch/arm/boot/zImage /media/$USER/kernel

Write the Kernel modules in the rootfs (second microSD partition):

sudo rsync -avc modules/lib/. /media/$USER/rootfs/lib/.

At this point you should have 3 files on the kernel partition on the SD card and a lib folder on the rootfs partition

3files

rootfs1

check if the compiled wifi driver is in the /rootfs/lib/modules/4.1.0/kernel/drivers/net/wireless/rtl8192cu folder 

ko-driver2

Up to now, the Linux kernel is finished, the next step is to create the filesystem for the board, take a small pause and then continue to the second part of this guide.

Leave a Reply

Your email address will not be published. Required fields are marked *