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

From FriendlyELEC WiKi
Revision as of 14:41, 5 March 2017 by Yftan (Talk | contribs) (制作一张带运行系统的SD卡)

Jump to: navigation, search

查看中文

1 Introduction to Mainline

Linux kernel development has several lines: the Mainline is maintained by Linus and other variants and branches are maintained by various groups and organizations. All the variants and branches 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 SoC. FriendlyElec customized the latest mainline u-boot and Linux kernel and made that u-boot and kernel work for all FriendlyElec's H3 boards.

2 Make an Installation SD Card

2.1 Download Image Files

Visit this download link to download the image files under the "officail-ROMs" directory and flashing utility under the "tools" directory:

Image Files
h3-mainline-ubuntu-core-qte-sd4g.img.zip Ubuntu-Core with Qt-Embedded Image File, for NanoPi NEO Only
Flash Utility:
win32diskimager.rar Windows utility. Under Linux users can use "dd"

2.2 制作Ubuntu-Core with Qt-Embedded系统TF卡

将固件 h3-mainline-ubuntu-core-qte-sd4g.img.zip 和烧写工具 win32diskimager.rar 分别解压,在 Windows 下插入TF卡(限4G及以上的卡),以管理员身份运行 win32diskimager 工具, 在 win32diskimager 工具的界面上,选择你的SD卡盘符,选择系统固件,点击 Write 按钮烧写即可。烧写完成后,将制作好SD卡插入 NanoPi H3 开发板,使用USB供电(5V/2A),看到板上的蓝色LED闪烁,这说明系统已经开始启动了。

3 Mainline ROM特性

3.1 Ubuntu-Core with Qt-Embedded

序号 NanoPi NEO
1 使用U-boot-2017.03和Linux-4.10.y
2 支持CPU频率和CPU电压动态调节
3 支持100M以太网,MAC地址固定
4 支持1路USB Host
5 支持多款USB WiFi
6 支持第一次开机自动扩展文件系统
7 支持开机修复文件系统

4 如何编译

4.1 安装交叉编译器

首先下载并解压编译器:

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

然后将编译器的路径加入到PATH中,用vi编辑vi ~/.bashrc,在末尾加入以下内容:

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

执行一下~/.bashrc脚本让设置立即在当前shell窗口中生效,注意"."后面有个空格:

. ~/.bashrc

这个编译器是64位的,不能在32位的Linux系统上运行,安装完成后,你可以快速的验证是否安装成功:

arm-linux-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gcc
COLLECT_LTO_WRAPPER=/opt/FriendlyARM/toolchain/4.9.3/libexec/gcc/arm-cortexa9-linux-gnueabihf/4.9.3/lto-wrapper
Target: arm-cortexa9-linux-gnueabihf
Configured with: /work/toolchain/build/src/gcc-4.9.3/configure --build=x86_64-build_pc-linux-gnu
--host=x86_64-build_pc-linux-gnu --target=arm-cortexa9-linux-gnueabihf --prefix=/opt/FriendlyARM/toolchain/4.9.3
--with-sysroot=/opt/FriendlyARM/toolchain/4.9.3/arm-cortexa9-linux-gnueabihf/sys-root --enable-languages=c,c++
--with-arch=armv7-a --with-tune=cortex-a9 --with-fpu=vfpv3 --with-float=hard
...
Thread model: posix
gcc version 4.9.3 (ctng-1.21.0-229g-FA)

4.2 编译U-boot

下载U-boot源码,切换到分支master-h3:

git clone https://github.com/friendlyarm/uboot.git
cd u-boot
git checkout master-h3

编译U-boot:

make nanopi_h3_defconfig
make

更新SD上的U-boot:

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

/dev/sdx请替换为实际的TF卡设备文件名。

4.3 编译Linux内核

下载Linux内核源码:

git clone https://github.com/friendlyarm/linux.git
cd linux
git checkout h3-4.10.y

编译Linux内核:

touch .scmversion
make sunxi_defconfig
make zImage dtbs

编译完成后会在arch/arm/boot/目录下生成zImage,并且在arch/arm/boot/dts/目录下生成dtb文件。

假设SD卡的boot分区挂载在/media/SD/boot/,更新SD卡上的zImage和dtb文件:

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