Monthly Archive: December 2017

How to compile the Kernel

Compiling a kernel for A20 is a little more difficult that the way is done on linux.
We need to do three important things:

  • Creating a bootstrap binary
  • Compiling a kernel
  • Compiling specific modules
  • Creating a SD Card

To simplify the process I created a script that automatizes this process,from the start to the copy to the SD card.
To use it:

git clone git@github.com:fflayol/olinuxino-lfs.git
cd system/kernel
./generate.sh

But for a pedagogic purpose I will detailed what this script do.

Creating a bootstrap binary

To begin you have to create a boostrap binary. This binary will be used to initialize and start the box when power on.
After that this binary will start the linux kernel.

sudo apt-get install gcc-4.6-arm-linux-gnueabihf ncurses-dev uboot-mkimage build-essential
git clone -b sunxi https://github.com/linux-sunxi/u-boot-sunxi.git
cd u-boot-sunxi/
make A20-OLinuXino_MICRO_config
make CROSS_COMPILE=arm-linux-gnueabihf-

Compiling the Kernel

Now the next is to compile a kernel to have a specific arm kernel, and support all features we need.
It is an official-modified linux kernel by linux-sunxi.

git clone https://github.com/linux-sunxi/linux-sunxi -b stage/sunxi-3.4
cd linux-sunxi/
cp ../olinuxinoa20_defconfig arch/arm/configs/.config
cp ../olinuxinoa20_defconfig arch/arm/configs/
make ARCH=arm olinuxinoa20_defconfig
patch -p0 < ../sunxi-i2c.patch
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 uImage

Compiling modules

Modules are small programs that handles different service in your box. As the kernel is « generalistic » it doesn’t includes all available. If you do not put your specific modules, you won’t be able to use « graphic acceleration » of your box. As a result you will have poor performance.
To do so:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 INSTALL_MOD_PATH=out modules

This command compiles all modules and put them into out directory.

Creating a SD Card

Now as we have to compile all things,to put them altogether.
The solution is to use a SD Card of at least class 10 4GO.
We split this SDCard in two partition. The first part will include th bootstrap and the second partition will be looks like what we used to have. As this part is quite tricky I didn’t included in the script.

Put you SDCard in the reader (we assume that it can be accessed under /dev/mmcblk )

sudo fdisk /dev/mmcblk
n p 1
start: 2048 end: 34815
n p 2
leave the start and end value to default
w

Be careful when doing that you erase everything you have on your card !
Now format you partition:

sudo mkfs.vfat /dev/mmcblk0p1
sudo mkfs.ext3 /dev/mmcblk0p2

Now add files to the partition

cd ../u-boot-sunxi/
#to simply path
export card=/dev/mmcblk0
#add boot part on partition 1
sudo dd if=/dev/zero of=${card} bs=1M count=1
sudo dd if=u-boot-sunxi-with-spl.bin of=${card} bs=1024 seek=8

Now add the kernel the second partition.

cd ../linux-sunxi/
sudo mkdir -p /mnt/sdmedia
sudo mount /dev/mmcblk0p1 /mnt/sdmedia
sudo cp arch/arm/boot/uImage /mnt/sdmedia
sudo cp script.bin /mnt/sdmedia
sudo sync
sudo umount /mnt/sdmedia
sudo rmdir /mnt/sdmedia 

Now the last part is to add the rootfs and erase nominal driver by the one we’ve just compiled.

Just do the rootfs part, already described in a previous article.

Copy all files into /dev/mmcblk0p1