How to Rebuild and Install the Kernel and Kernel Modules on Ubuntu

Difficulty Levels: Advanced
Date added: August 21, 2018
Affected Products: PICO-DWARF , PICO-HOBBIT , PICO-IMX6 , PICO-IMX6UL , PICO-IMX7 , PICO-IMX8M , PICO-NYMPH , PICO-PI , PICO-PI-8M , PICO-PI-IMX8M

TechNexion provides Ubuntu demo images for some SOM/baseboard configurations. While these are good for initial hardware evaluation, and make installing new applications and packages easy, sometimes developers need to extend the platform by customizing the kernel and device drivers. This is a step-by-step procedure showing you how do to this.

Download and install the toolchain by following the steps in this article:

Preparing a toolchain for building ARM binaries on x86 hosts

Get the kernel source code from the TechNexion Linux Git repository:

$ git clone https://github.com/TechNexion/linux.git

$ cd linux

$ git checkout <branch>

Branches used for Ubuntu demo images:

Ubuntu Version Supported SOM Kernel Branch
16.04 EDM1-imx6, Pico-imx6, Pico-imx6ul, Pico-imx7 revision A tn-imx_4.1.15_2.0.0_ga

Set up the kernel using the default TechNexion kernel configuration:

$ make tn_imx_defconfig

Then, you can select new drivers to be included as either built-in (compiled into the kernel image) or as kernel modules using the menuconfig tool:

$ make menuconfig

After finishing the selection, save your configuration and build the kernel and modules:

$ make zImage modules

Make a temp directory for the modules. The modules_install target wants a target directory as it normally installs to a specific path in the host system.

$ mkdir modules_temp

Install the modules to the directory:

$ make modules_install INSTALL_MOD_PATH=./modules_temp

After that is done, build the device tree for your SOM. The device tree depends on the both the SOM and SOC as well as the baseboard you are using:

$ make <device tree name – see below>

List of device tree names:

SOM Baseboard Device tree
Pico-imx6 Dual Lite or Solo Pico-Pi imx6dl-pico_pi.dtb
Pico-imx6 Quad Pico-Pi imx6q-pico_pi.dtb
Pico-imx7 Pico-Pi imx7d-pico_pi.dtb
Pico-imx6ul Pico-Pi Imx6ul-pico_pi.dtb
Pico-imx6ull Pico-Pi Imx6ull-pico_pi.dtb
Pico-imx6 Dual Lite or Solo Pico-Dwarf imx6dl-pico_dwarf.dtb
Pico-imx6 Quad Pico-Dwarf imx6q-pico_dwarf.dtb
Pico-imx7 Pico-Dwarf imx7d-pico_dwarf.dtb
Pico-imx6ul Pico-Dwarf Imx6ul-pico_dwarf.dtb
Pico-imx6ull Pico-Dwarf Imx6ull-pico_dwarf.dtb
Pico-imx6 Dual Lite or Solo Pico-Nymph imx6dl-pico_nymph.dtb
Pico-imx6 Quad Pico-Nymph imx6q-pico_nymph.dtb
Pico-imx7 Pico-Nymph imx7d-pico_nymph.dtb
Pico-imx6ul Pico-Nymph Imx6ul-pico_nymph.dtb
Pico-imx6 Dual Lite or Solo Pico-Hobbit imx6dl-pico_hobbit.dtb
Pico-imx6 Quad Pico-Hobbit imx6q-pico_hobbit.dtb
Pico-imx7 Pico-Hobbit imx7d-pico_hobbit.dtb
Pico-imx6ul Pico-Hobbit Imx6ul-pico_hobbit.dtb
Pico-imx6ull Pico-Hobbit Imx6ull-pico_hobbit.dtb

For this article, we will assume we are building for Pico-imx6 Quad running on a Pico Pi, so the command is:

$ make imx6q-pico_pi.dtb

Pack up the modules into a nice .tar.gz file:

$ cd modules_temp/lib/modules
$ tar czvf modules.tar.gz *

Make a temporary directory on your target system:

$ cd ~
$ mkdir tmp

If you have the target system on your local network, you can copy the files to the target system using scp. Note that “technexion.local” represents the target name located via MDNS/Bonjour. The default username/password is ubuntu/ubuntu.

$ scp arch/arm/boot/zImage ubuntu@technexion.local:~/tmp">ubuntu@technexion.local:~/tmp
$ scp arch/arm/boot/dts/imx6q-pico_pi.dtb ubuntu@technexion.local:~/tmp">ubuntu@technexion.local:~/tmp
$ scp modules_temp/lib/modules/modules.tar.gz ubuntu@technexion.local:~/tmp">ubuntu@technexion.local:~/tmp

Alternatively, you can transfer the files using a USB flash drive if you don’t have the target system on your local network.

On your TARGET system:

Go home:
$ cd

Make a directory to mount the boot partition (where we will replace the kernel and device tree file)

$ mkdir boot

Mount the partition

$ sudo mount /dev/mmcblk2p1 boot

Copy the kernel

$ cp tmp/zImage boot

Copy the device tree

$ cp tmp/imx6q-pico_pi.dtb boot

Unpack the modules to the right directory:

$ cd /lib/modules

$ sudo tar -xzvf ~/tmp/modules.tar.gz .

Once this is all done, you should reboot the system. If everything goes well, it should come right up.

If you’ve missed a module or two, you can always reconfigure the kernel and rebuild the modules, and transfer the modules back over.

Stay up to date with all the latest TechNexion news...

Sign-up for our Newsletter