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


Note: all of the following instructions (and also in the sections 2, 3 and 4 
following on from this page) have to be carried out on a Linux computer, not the B-Pi itself!!


This page describes the process of combining sunxi u-boot, the Linux kernel and other bits together to create the basis of a bootable OS from scratch, and which can also be the basis for further hacking. 

Of course, we are not building a whole distribution here, we're only building u-boot, the kernel and a handful of tools, and then using an existing root file system to get a usable OS. Depending on the size of the root file system, we suggest you use a 4GB or larger SD card – a type class 10 would be faster and more stable. SD card partitioning and formatting will be taken care of later. 

We'll outline on this page two methods to build what 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 Ubuntu or Debian, you can get all you need by installing 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, the uboot-mkimage package has been removed; the mkimage command is included in the 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-gnueabihf 
respectively.


You also can use the Linaro tool chain or the Code Sourcery tool chain - they are standalone toolchains with big tarballs which come with everything you need.

Use the BSP

BSP stands for “Board Support Package”.


Installation

Get the BSP repository:

git clone https://github.com/LeMaker/bananapro-bsp.git


Build

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

If for Banana Pro:

./configure BananaPro
make

If for Banana Pi:

./configure BananaPi
make

This will take a long time to build all the things. After it has been built, you can get all you want from the build/BananaPro_hwpack or build/BananaPi_hwpackdirectory, such as the u-boot-sunxi-with-spl.bin, uImage, and scritp.bin, modules. You can tweak your kernel configuration too by running:

make linux-config

This will override the .config file in the bananapro-bsp/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 to clone the repository from Github:

git clone https://github.com/LeMaker/u-boot-sunxi.git

After the repository has been retrieved, you can build the u-boot.

First make the u-boot configure:

If for Banana Pro:

make CROSS_COMPILE=arm-linux-gnueabihf- BananaPro_config

If for Banana Pi:

make CROSS_COMPILE=arm-linux-gnueabihf- BananaPi_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 are only using the u-boot-sunxi-with-spl.bin file.

Building script.bin

First, get the following repositories:

git clone https://github.com/LeMaker/sunxi-tools.git
git clone https://github.com/LeMaker/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 tools fex2bin, bin2fex and some others.

Then go into the sunxi-boards tree and find the fex file for the Banana Pi. We can customize some of the configurations in the file, such as [gmac_para], [usb_wifi_para], etc.

Create the script.bin file:
If for Banana Pro:

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

If for Banana Pi:

${sunxi-tools}/fex2bin BananaPi.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 the u-boot installation.

Building the kernel

First, get the linux kernel repository by following:

git clone https://github.com/LeMaker/linux-sunxi.git

Second, set default kernel configuration:

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

Third, tweak the config. You can open some kind of kernel configuring software or close the useless kernel configuration 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 the bsp”, you will get at least the four files or packages you need, which are:

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


We will use these four files to set up the bootable SD card in Part 2, Setting up the bootable SD card.

References

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


http://wiki.lemaker.org/Building_u-boot,_script.bin_and_linux-kernel

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值