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

From FriendlyARM WiKi
(Redirected from Mainline U-boot and Linux)
Jump to: navigation, search

查看中文

Introduction to Linux 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 H5/H3/H2+ boards.
Note: all the operations and instructions listed in this topic only apply to Linux-4.14.y. Don't apply them to H5-Linux-3.10/H3-Linux-3.4 .

Features

Make an Installation SD Card

Download Image Files

Board Type CPU Model Download Link to Image File Image File
NanoPi Duo H2+ Download official-ROMs/nanopi-duo_sd_friendlycore-xenial_4.14_armhf_YYYYMMDD.img.zip
NanoPi NEO H3 Download official-ROMs/nanopi-neo_sd_friendlycore-xenial_4.14_armhf_YYYYMMDD.img.zip
NanoPi NEO Air H3 Download official-ROMs/nanopi-neo-air_sd_friendlycore-xenial_4.14_armhf_YYYYMMDD.img.zip
NanoPi M1 H3 Download official-ROMs/nanopi-m1_sd_friendlycore-xenial_4.14_armhf_YYYYMMDD.img.zip
NanoPi M1 Plus H3 Download official-ROMs/nanopi-m1-plus_sd_friendlycore-xenial_4.14_armhf_YYYYMMDD.img.zip
NanoPi NEO Core H3 Download official-ROMs/nanopi-neo-core_sd_friendlycore-xenial_4.14_armhf_YYYYMMDD.img.zip
NanoPi Duo2 H3 Download official-ROMs/nanopi-duo2_sd_friendlycore-xenial_4.14_armhf_YYYYMMDD.img.zip
NanoPi NEO2 H5 Download official-ROMs/nanopi-neo2_sd_friendlycore-xenial_4.14_armhf_YYYYMMDD.img.zip
NanoPi NEO Plus2 H5 Download official-ROMs/nanopi-neo-plus2_sd_friendlycore-xenial_4.14_arm64_YYYYMMDD.img.zip
NanoPi NEO Core2 H5 Download official-ROMs/nanopi-neo-core2_sd_friendlycore-xenial_4.14_arm64_YYYYMMDD.img.zip
NanoPi K1 Plus H5 Download official-ROMs/nanopi-k1-plus_sd_friendlycore-xenial_4.14_arm64_YYYYMMDD.img.zip

Make an Installation TF Card with FriendlyCore 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/H2+ 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.


How to Compile Linux-4.14 BSP

How to Compile Linux-4.14 BSP for H3/H2+

Install Cross Compiler

Visit here download link and enter the toolchain directory to download the cross compiler:arm-cortexa9-linux-gnueabihf-4.9.3.tar.xz and extract it:

$ mkdir -p /opt/FriendlyARM/toolchain
$ tar xf 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)

Compile U-boot

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

$ git clone https://github.com/friendlyarm/u-boot.git -b sunxi-v2017.x --depth 1

Compile U-boot:

$ apt-get install swig python-dev python3-dev
$ make nanopi_h3_defconfig ARCH=arm CROSS_COMPILE=arm-linux-
$ make ARCH=arm CROSS_COMPILE=arm-linux-

Although this configuration file was originally made for the NanoPi M1 Plus it works for other H3 based boards too. 编译成功后会生成文件u-boot-sunxi-with-spl.bin。
在PC机上更新SD上的U-boot:

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

/dev/sdx请替换为实际的TF卡设备文件名。
sync命令可以确保数据成功写到TF卡中,eject命令用于弹出TF卡。

当正在使用SD卡运行系统时,也可以先用scp命令拷贝u-boot-sunxi-with-spl.bin到开发板上,然后用dd命令更新SD卡上的U-boot:

$ scp u-boot-sunxi-with-spl.bin root@192.168.1.230:/root/
$ dd if=/root/u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8


如果是带有eMMC的开发板,当正在使用eMMC运行系统时,也可以先用scp命令拷贝u-boot-sunxi-with-spl.bin到开发板上,然后用dd命令更新eMMC上的U-boot:

$ scp u-boot-sunxi-with-spl.bin root@192.168.1.230:/root/
$ dd if=/root/u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8

NanoPi H3/H2+开发板的启动设备的设备节点总是/dev/mmcblk0。

Compile and Update Linux Kernel

Download Linux Kernel Source Code:

$ git clone https://github.com/friendlyarm/linux.git -b sunxi-4.14.y --depth 1

Compile Linux Kernel:

$ cd linux
$ 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 partition 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-*-nanopi-*.dtb /media/SD/boot/

Compile and Update Modules:

$ cd linux
$ make modules ARCH=arm CROSS_COMPILE=arm-linux-

If your SD card's rootfs partition is mounted at "/media/SD/rootfs/" you can update its modules by running the following commands:

$ cd linux
$ make modules_install INSTALL_MOD_PATH=/media/SD/rootfs/ ARCH=arm CROSS_COMPILE=arm-linux-

How to Compile Mainline BSP for H5

Install Cross Compiler

Visit here download link and enter the toolchain directory to download the cross compiler gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu.tar.xz and extract it:

$ 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)

Compile U-boot

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

$ git clone https://github.com/friendlyarm/u-boot.git -b sunxi-v2017.x --depth 1

Compile U-boot:

$ apt-get install swig python-dev python3-dev
$ make nanopi_h5_defconfig CROSS_COMPILE=aarch64-linux-gnu-
$ make CROSS_COMPILE=aarch64-linux-gnu-

The "nanopi_h5_defconfig" works for all existing FriendlyElec's H5 based boards.

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/sdX bs=1024 seek=40

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

Compile Linux Kernel

Download Linux Kernel Source Code:

$ git clone https://github.com/friendlyarm/linux.git -b sunxi-4.x.y --depth 1

Compile and Update Linux Kernel:

$ cd linux
$ 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 partition 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/

Compile and Update Modules:

$ cd linux
$ make modules ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

If your SD card's rootfs partition is mounted at "/media/SD/rootfs/" you can update its modules by running the following commands:

$ cd linux
$ make modules_install INSTALL_MOD_PATH=/media/SD/rootfs/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

Update Log

March-05-2017

  • Released English Version

May-05-2017

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

June-04-2017

  • Updated section 2.1: updated image files' version numbers

July-02-2017

  • Updated section 1, 3.1.2 and 3.2.2

Dec-12-2017

  • Updated sections 3.1.2 and 3.2.2