Building u-boot, script.bin and linux-kernel

From Orange Pi
Jump to: navigation, search

This page describes the process to combine sunxi u-boot, linux kernel and other bits together to create basis of a bootable OS from scratch,and also the basis for further hacking.
We of course do not build a whole distribution, we only build u-boot, the kernel and a handful of tools, and then use an existing root file system to get an useful system. Depending on the root file system size, we suggest you to use a 4GB or larger SD card, type class 10 would be more stable. SD card partitioning and formatting will be taken care of later.
We have two method to build all we need, one is step by step, the other is the easiest way by using sunxi BSP.

Get a cross toolchain

The toolchain is a set of binaries, system libraries and tools which allow you to build (in our case, cross-compile) u-boot and the kernel for a target platform. This will, to some limited extent, need to match the target rootfs. If you use the Ubuntu or Debian, you can get all you need by install the tools below:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential u-boot-tools uboot-mkimage binutils-arm-linux-gnueabihf gcc-4.7-arm-linux-gnueabihf-base \
                     g++-4.7-arm-linux-gnueabihf sudo apt-get install gcc-arm-linux-gnueabihf cpp-arm-linux-gnueabihf libusb-1.0-0 libusb-1.0-0-dev git wget fakeroot kernel-package \
                     zlib1g-dev libncurses5-dev

Note: On Debian (wheezy)/Ubuntu 13.10 (saucy) onwards, uboot-mkimage package is removed, mkimage command is included in u-boot-tools package. On Ubuntu 12.04, change gcc-4.7-arm-linux-gnueabihf-base and g++-4.7-arm-linux-gnueabihf to gcc-4.6-arm-linux-gnueabihf-base and g++-4.6-arm-linux-gnueabih.
You also can use the Linaro tool chain or Code Sourcery tool chain, they are standalone toolchains with big tarballs which come with everything you need.

Use Orange Pi BSP

BSP means “Board Support Package”.

Installation

Get the BSP repository:

git clone https://github.com/orangepi-xunlong/orangepi-bsp.git

Build

After get the BSP, then get into sunxi-bsp directory, and run build command:

./configure OrangePi
make

This will take a long time to build all things. After all have been built, you will get all you want in the build/OrangePi_hwpack directory, such as u-boot-sunxi-with-spl.bin, uImage, scritp.bin, modules. You can tweak your kernel configuration too by running:

make linux-config

This will override the .config file in the /build/sun7i_defconfig-linux.

Step by step

Building u-boot

U-boot is the bootloader commonly used on our allwinner SoCs. Similar to many others, it provides the basic infrastructure to bring an SBC (single board computer) up to a point where it can load a Linux kernel and start booting your operating system.
First you need clone the repository from Github:

git clone https://github.com/orangepi-xunlong/u-boot-orangepi.git

After the repository has been pull down, you can build the u-boot
First make the u-boot configure:

make CROSS_COMPILE=arm-linux-gnueabihf- Orangepi_config

And then make the u-boot:

make CROSS_COMPILE=arm-linux-gnueabihf-


After that you may get the u-boot-sunxi-with-spl.bin, u-boot.img, u-boot.bin, spl/sunxi-spl.bin. Here we only use u-boot-sunxi-with-spl.bin file.

Building script.bin

First, get the following repositories:

git clone https://github.com/orangepi-xunlong/sunxi-tools.git
git clone https://github.com/orangepi-xunlong/sunxi-boards.git

Go into sunxi-tools and run the command

make

You may need install the dependent packages:

sudo apt-get install pkg-config

you will get the tool fex2bin, bin2fex and others.
Then get into the sunxi-boards tree and find the fex file for Orange Pi. We can customize some of the configurations in the file, such as [gmac_para], [usb_wifi_para], etc.
Create the script.bin file:

${sunxi-tools}/fex2bin OrangePi.fex script.bin

The prefix ${sunxi-tools} indicates that you are in your sunxi-tools tree.

You will need this script.bin file later on when finishing u-boot installation.

Building the kernel

First, get the linux kernel repository by following:

git clone https://github.com/orangepi-xunlong/linux-orangepi.git

Second, set default kernel configuration:

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

Third, tweak the config. You can open some necessary kernel configure or close the useless kernel configure by editing your kernel configuration:

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

Building uImage and modules:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage modules

As a final step, create the full module tree:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules_install

The INSTALL_MOD_PATH option specifies the directory where the full module tree will be made available. In this example, it will be the output directory under the kernel build directory itself.
Now you have the following residing in your kernel tree:

arch/arm/boot/uImage
output/lib/modules/3.4.XX/

The uImage file needs to be started by u-boot, and the modules directory needs to be copied to the /lib/modules on the target root file system.

Using four files

Through either “step by step” or “using sunxi bsp”, you will get at least four files or packages you need, they are:

u-boot-sunxi-with-spl.bin
uImage
script.bin
modules/3.4.XX

We will use this four files to set up the bootable SD card.

Reference

1. http://sunxi.org/Manual_build_howto
2. http://sunxi.org/U-Boot#Compilation
3. http://sunxi.org/Linux_Kernel#Compilation
4. http://sunxi.org/BSP