古人智慧

Just Do it!
上士聞道,勤而行之;中士聞道,若存若亡;下士聞道,大笑之。不笑,不足以爲道。
~ 道德經 41

「實現夢想不是追逐成功,而是在於賦予生命意義,人生中的每個決定與聲音都有其重要含義。」"The key to realizing a dream is to focus not on success but on significance — and then even the small steps and little victories along your path will take on greater meaning."
電視名人-歐普拉·溫芙蕾(OPRAH WINFREY)

搜尋此網誌

Translation

2015年5月30日 星期六

[Banana Pro] Building u-boot, script.bin and linux-kernel

這幾天這個link被移掉,好不容易找到,就乾脆把它copy下來。。。
因爲要開始做一些device driver,最好是kernel自己重新build,並把header file和相關files保留給接下來build driver module使用,不然會遇到module無法被kernel接受。


只要照着做,把script.bin, uImage, modules做好copy到SD卡就可開機。


refer to:

BananaPro/Pi: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 Bananan Pro/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 theu-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/lemaker-bsp.git

Build

After getting the BSP, then navigate into the lemaker-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 orbuild/BananaPi_hwpack directory, 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 /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

(With thanks to native speaker “roses” for checking and upgrading this document)

1 則留言:

  1. 表哥,我是蔡明希
    這幾個星期也都在使用banana pi,
    但有個Linux header的問題困擾我,
    結果找資料找到你這邊。

    在bsp compile 之後, linux header 是放置在哪?
    想請教你,對於header的部分你如何做的?

    回覆刪除