Building U-boot and Linux for H5/H3/H2+

From FriendlyELEC WiKi
Revision as of 07:27, 19 May 2017 by Cjlcjl (Talk | contribs) (Download Image Files)

Jump to: navigation, search

查看中文

1 Introduction to Mainline

Linux kernel distributions have several lines. The Mainline is maintained by Linus. Other variants and distributions are maintained by various groups and organizations. All the variants and distributions are submitted to Linux and will be merged to the Mainline. The latest mainline of U-boot and Linux kernel already has support for H3/H5 SoC. FriendlyElec customized the latest mainline u-boot and Linux kernel and made that u-boot and kernel work for all FriendlyElec's H3/H5 boards.

2 Make an Installation SD Card

2.1 Download Image Files

Board Type Download Link to Image File Image File
NanoPi NEO Download official-ROMs/nanopi-neo_ubuntu-core-xenial_4.11.0.img.zip
NanoPi NEO Air Download official-ROMs/nanopi-neo-air_ubuntu-core-xenial_4.11.0.img.zip
NanoPi M1 Download official-ROMs/nanopi-m1_ubuntu-core-xenial_4.11.0.img.zip
NanoPi M1 Plus Download official-ROMs/nanopi-m1-plus_ubuntu-core-xenial_4.11.0.img.zip
NanoPi NEO2 Download official-ROMs/nanopi-neo2_ubuntu-core-xenial_4.11.0.img.zip

2.2 Make an Installation TF Card with Ubuntu-Core with Qt-Embedded

Extract an image file and win32diskimager.rar. Insert a TF card(at least 8G) into a Windows PC and run the win32diskimager utility as administrator. On the utility's main window select your TF card's drive, the wanted image file and click on "write" to start flashing the SD card till it is done.Insert this card into your H3/H5 board's MicroSD card slot and power on (with a 5V/2A power source). If the blue LED blinks this indicates your board has successfully booted.

3 How to Compile Mainline BSP

3.1 How to Compile Mainline BSP for H3

3.1.1 Install Cross Compiler

Download and extract cross compiler:

$ git clone https://github.com/friendlyarm/prebuilts.git
$ mkdir -p /opt/FriendlyARM/toolchain
$ tar xf prebuilts/gcc-x64/arm-cortexa9-linux-gnueabihf-4.9.3.tar.xz -C /opt/FriendlyARM/toolchain/

Add the compiler's path to the "PATH" variable by appending the following lines in the ~/.bashrc file:

$ export PATH=/opt/FriendlyARM/toolchain/4.9.3/bin:$PATH
$ export GCC_COLORS=auto

Run the ~/.bashrc script to make the changes in effect immediately in your working shell. Attention: there is a space after ".":

$ . ~/.bashrc

This is a 64-bit compiler and it cannot run on a 32-bit Linux. You can check whether or not your compiler is setup correctly by running the following commands:

$ arm-linux-gcc -v
gcc version 4.9.3 (ctng-1.21.0-229g-FA)

3.2 Compile U-boot

Download the U-boot source code and enter the master-h3 branch:

$ git clone https://github.com/friendlyarm/u-boot.git
$ cd u-boot
$ git checkout sunxi-v2017.03

Compile U-boot:

$ make nanopi_neo_defconfig ARCH=arm CROSS_COMPILE=arm-linux-
$ make ARCH=arm CROSS_COMPILE=arm-linux-

Update U-boot on SD Card:

$ dd if=u-boot-sunxi-with-spl.bin of=/dev/sdX bs=1024 seek=8

Note: you need to replace "/dev/sdx" with the device name in your system.

3.3 Compile Linux Kernel

Download Linux Kernel Source Code:

$ git clone https://github.com/friendlyarm/linux.git
$ cd linux
$ git checkout sunxi-4.11.y

Compile Linux Kernel:

$ touch .scmversion
$ make sunxi_defconfig ARCH=arm CROSS_COMPILE=arm-linux-
$ make zImage dtbs ARCH=arm CROSS_COMPILE=arm-linux-

If your compilation is successful a zImage will be generated under "arch/arm/boot/" and a dtb file will be generated under "arch/arm/boot/dts/".

If your SD card's boot section is mounted at "/media/SD/boot/" you can update its zImage and dtb files by running the following commands:

$ cp arch/arm/boot/zImage /media/SD/boot/
$ cp arch/arm/boot/dts/sun8i-h3-nanopi*.dtb /media/SD/boot/

3.4 How to Compile Mainline BSP for H5

3.4.1 Install Cross Compiler

Download and extract cross compiler:

$ mkdir -p /opt/FriendlyARM/toolchain
$ tar xf gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu.tar.xz -C /opt/FriendlyARM/toolchain/

Add the compiler's path to the "PATH" variable by appending the following lines in the ~/.bashrc file:

$ export PATH=/opt/FriendlyARM/toolchain/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin:$PATH
$ export GCC_COLORS=auto

Run the ~/.bashrc script to make the changes in effect immediately in your working shell. Attention: there is a space after ".":

$ . ~/.bashrc

You can check whether or not your compiler is setup correctly by running the following commands:

$ aarch64-linux-gnu-gcc -v
gcc version 6.3.1 20170109 (Linaro GCC 6.3-2017.02)

3.4.2 Compile U-boot

Download the U-boot source code and enter the master-h3 branch:

$ git clone https://github.com/friendlyarm/u-boot.git
$ cd u-boot
$ git checkout sunxi-v2017.03

Compile U-boot:

$ make nanopi_neo2_defconfig ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

Update U-boot on SD Card:

$ dd if=spl/sunxi-spl.bin of=/dev/sdX bs=1024 seek=8
$ dd if=u-boot.itb of=/dev/sdg bs=1024 seek=40

Note: you need to replace "/dev/sdx" with the device name in your system.

3.4.3 Compile Linux Kernel

Download Linux Kernel Source Code:

$ git clone https://github.com/friendlyarm/linux.git
$ cd linux
$ git checkout sunxi-4.11.y

Compile Linux Kernel:

$ touch .scmversion
$ make sunxi_arm64_defconfig ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
$ make Image dtbs ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

If your compilation is successful an Image will be generated under "arch/arm64/boot/" and a dtb file will be generated under "arch/arm64/boot/dts/allwinner/".

If your SD card's boot section is mounted at "/media/SD/boot/" you can update its Image and dtb files by running the following commands:

$ cp arch/arm64/boot/Image /media/SD/boot/
$ cp arch/arm64/boot/dts/allwinner/sun50i-h5-nanopi*.dtb /media/SD/boot/

4 Update Log

4.1 March-05-2017

  • Released English Version

4.2 May-05-2017

  • Added Section 3 by adding a mainline kernel development timetable
  • Added Section 4.4 by adding support for H5