Template:RK3399-BuildFromSource/zh

From FriendlyARM WiKi
Revision as of 08:19, 24 August 2018 by Tzs (Talk | contribs) (updated by API)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

1 如何编译系统

1.1 搭建编译环境

搭建编译Android的环境建议使用64位的Ubuntu 16.04,安装需要的包即可。

sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zip
sudo apt-get install flex curl libncurses5-dev libssl-dev zlib1g-dev gawk minicom
sudo apt-get install openjdk-8-jdk
sudo apt-get install exfat-fuse exfat-utils device-tree-compiler liblz4-tool

更多说明可查看 https://source.android.com/source/initializing.html

1.2 安装交叉编译器

1.2.1 安装aarch64-linux-gcc 6.4

首先下载并解压编译器:

git clone https://github.com/friendlyarm/prebuilts.git
sudo mkdir -p /opt/FriendlyARM/toolchain
sudo tar xf prebuilts/gcc-x64/aarch64-cortexa53-linux-gnu-6.4.tar.xz -C /opt/FriendlyARM/toolchain/

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

export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin:$PATH
export GCC_COLORS=auto

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

. ~/.bashrc

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

aarch64-linux-gcc -v
Using built-in specs.
COLLECT_GCC=aarch64-linux-gcc
COLLECT_LTO_WRAPPER=/opt/FriendlyARM/toolchain/6.4-aarch64/libexec/gcc/aarch64-cortexa53-linux-gnu/6.4.0/lto-wrapper
Target: aarch64-cortexa53-linux-gnu
Configured with: /work/toolchain/build/aarch64-cortexa53-linux-gnu/build/src/gcc/configure --build=x86_64-build_pc-linux-gnu
--host=x86_64-build_pc-linux-gnu --target=aarch64-cortexa53-linux-gnu --prefix=/opt/FriendlyARM/toolchain/6.4-aarch64
--with-sysroot=/opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot --enable-languages=c,c++
--enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419 --with-cpu=cortex-a53
...
Thread model: posix
gcc version 6.4.0 (ctng-1.23.0-150g-FA)

1.3 编译Android7源代码

1.3.1 下载Android7源代码

NanoPC-T4 源代码托管在 gitlab 上,使用以下命令进行下载:

git clone https://gitlab.com/friendlyelec/rk3399-nougat.git

1.3.2 编译并生成Image文件

使用以下命令编译 Android7:

cd rk3399-nougat
./build-nanopc-t4.sh -F -M

1.3.3 更新系统为自已编译的Image

编译完成后,image文件会存放在Android7源代码目录的 rockdev/Image-nanopc_t4/ 子目录下,参考以下步骤更新到 NanoPC-T4上:
1) 将 EFlasher 启动SD卡 通过读卡器插入电脑,电脑上的Ubuntu系统会自动挂载 SD卡的分区;
2) 我们需要将 rockdev/Image-nanopc_t4/ 子目录下的所有文件,拷贝并覆盖到 SD卡 FRIENDLYARM 分区里的 nougat 目录;
3) 将SD卡插入NanoPC-T4,重新烧写Andorid系统即可;

1.4 编译Lubuntu内核源代码

1.4.1 compile Linux kernel

git clone https://github.com/friendlyarm/kernel-rockchip --depth 1 -b nanopi4-linux-v4.4.y
cd kernel-rockchip
make ARCH=arm64 nanopi4_linux_defconfig
make ARCH=arm64 nanopi4-images

1.4.2 更新内核到Lubuntu

需要使用原厂的Linux_Upgrade_Tool_1.27.rar工具烧写,请本文参考上面的章节。