HOW-TO compile Chip's Linux kernel and modules on Chip itself

Da raspibo.
Jump to navigation Jump to search

Chip is a tiny workstation. So you do not need any external hardware for its development platform. Software for chip can be developed on chip itself. Including the kernel.

What you need is:

  • a Chip running ChipOS (like a Chip v1 out-of-the-box)
  • a way to connect Chip to the Internet
  • a good PSU (power supply unit).
  • a lot of patience

In one of my tests I tried to compile the kernel using a Chip simply connected to my laptop using a USB cable. This kernel compilation procedure keeps the CPU fully loaded for a long time. It seems that the AXP209 power system management is quite sensible... and it switched off my chip after a while. Using a PSU or a good powered HUB I solved the problem.

And it is warmly suggested to have a console cable to recover if something goes wrong during the boot (see how to connect a console cable in my previous posting Chip9$ U-Boot: how to test a new kernel (in a safe way)

Step by Step, get the tools to build a kernel

If your Chip is up, running and connected in some way to the Internet, you can install all the Debian packets needed. As a first substep upgrade the whole distribution to the latest updates available.

sudo apt-get update   
sudo apt-get upgrade
sudo apt-get install locales
sudo apt-get clean

(this substep is not required) If you want to get rid of all the warnings about the undefined locale do:

sudo dpkg-reconfigure locales

for example you can add en_US.UTF-8 and set it as the default one.

A reboot at this point is a good idea as maybe the kernel has been updated, too. When your chip is up, running and connected to the Internet again add the required packets:

sudo apt-get install git build-essential zlib1g-dev libncurses5-dev lzop
sudo apt-get clean

Set up a src directory and get the source code

You do not need to be root to compile a Linux Kernel. In this tutorial all the kernel generation procedure will take place in the home directory of the user named "chip".

So log-in as chip (it is the standard situation if you are using the auto-starting graphical interface). Open a terminal (or open an ssh connection to chip). I assume you are using a shell. Create a src directory and enter it.

cd
mkdir src
cd src

Now download the kernel from git. (The following command downloads just the latest version of the required branch and not the entire history as git would usually do).

git clone --single-branch --branch debian/4.3.0-ntc-4 --depth 1 https://github.com/NextThingCo/CHIP-linux.git

then change to the CHIP-linux dir:

cd CHIP-linux

Now configure your kernel. You can either use NTC's kernel configuration as a starting point or my kernel configuration. To start from NTC conf:

cp /boot/config-4.3.0 .config

To start from my configuration:

mkdir /tmp/chiplinux4.3.0rd235+
pushd /tmp/chiplinux4.3.0rd235+
wget http://www.raspibo.org/renzo/chiplinux4.3.0rd235+.tgz
tar zxf chiplinux4.3.0rd235+.tgz
popd
cp /tmp/chiplinux4.3.0rd235+/boot/config-4.3.0rd235+ .config

Now configure your kernel:

make menuconfig

N.B. add a local version suffix. Follow the menus:

    General setup  --->
    () Local version - append to kernel release

This step is crucial otherwise during the installation phase modules provided by the distribution packets and your own modules can be mixed up and overwritten.

You may want to pass through the menus and add the modules you need.

Now take a long breath and type

make

... wait for several hours. Using my configuration file it took about 4:30 hours to complete this command.

after the long break

Provided the compilation command completed uneventfully, now you can install the modules:

sudo make INSTALL_FW_PATH=/lib/firmware/new modules_install

There will be a new dir in /lib/modules named after your kernel version and local suffix. In my case the output of the command:

ls /lib/modules

is

4.3.0  4.3.0rd235+

Move the firmware files in a directory having the same name under /lib/firmware (use your suffix instead of rd235+):

sudo rm -rf /lib/firmware/4.3.0rd235+
sudo mv /lib/firmware/new /lib/firmware/4.3.0rd235+

(the first command deletes firmware previously installed using the same suffix, if any).

and now let us install RTL8723BS module out-of tree

Return to the $HOME/src directory

cd
cd src

get the module's source from git (again without the whole history).

git clone --single-branch --branch debian https://github.com/NextThingCo/RTL8723BS.git

Now, apply the debian patches and compile the module:

cd RTL8723BS
for i in debian/patches/0*; do  echo $i; patch -p 1 <$i ; done
make CONFIG_PLATFORM_ARM_SUNxI=y -C /home/chip/src/CHIP-linux/ M=$PWD CONFIG_RTL8723BS=m

and install it:

sudo make -C /home/chip/src/CHIP-linux/ M=$PWD modules_install

final steps to finalize the installation

Now it is time to move the kernel to /boot.

sudo cp arch/arm/boot/zImage /boot/vmlinuz-4.3.0rd235+
sudo cp .config /boot/config-4.3.0rd235+
sudo cp System.map /boot/System.map-4.3.0rd235+

(obviously use your local suffix instead of rd235+)

if you don't have a weak heart you can set the new kernel as the default one:

sudo cp /boot/vmlinuz-4.3.0rd235+ /boot/zImage

If you have a console cable you can test the new kernel in a safe way by editing the boot command as explained in Chip9$ U-Boot: how to test a new kernel (in a safe way)

That's all, folks

Here it works like a charm. I hope you'll succeed, too.

If you have your kernel src hierarchy on your chip you'll be able to add or remove modules and supports as you please. The only backside of this is that it takes 1.3GB of your flash.