Difference between revisions of "Template:RK3399-BuildFromSource"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
(updated by API)
Line 1: Line 1:
==Make Your Own OS Image==
+
==如何编译系统==
===Setup Development Environment===
+
===搭建编译环境===
If you want to compile an Android image we suggest you use a PC running a 64-bit Ubuntu 16.04.
+
搭建用于编译Android的环境,建议使用64位的Ubuntu 16.04,需要安装如下软件包:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zip
 
sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zip
Line 8: Line 8:
 
sudo apt-get install exfat-fuse exfat-utils device-tree-compiler liblz4-tool
 
sudo apt-get install exfat-fuse exfat-utils device-tree-compiler liblz4-tool
 
</syntaxhighlight>
 
</syntaxhighlight>
For more details refer to https://source.android.com/source/initializing.html
+
更多说明可查看 https://source.android.com/source/initializing.html; <br />
 +
也可以使用Docker环境:[http://github.com/friendlyarm/friendlyelec-android-docker friendlyelec-android-docker]<br />
  
===Install Cross Compiler===
+
===安装交叉编译器===
====Install aarch64-linux-gcc 6.4====
+
====安装aarch64-linux-gcc 6.4====
Download and extract compiler:
+
该编译器可用来编译Linux系统的内核和u-boot,用以下命令下载并安装:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git clone https://github.com/friendlyarm/prebuilts.git
 
git clone https://github.com/friendlyarm/prebuilts.git
Line 19: Line 20:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Add the compiler's path to the PATH variable by appending the following lines to the "~/.bashrc" file:
+
然后将编译器的路径加入到PATH中,用vi编辑vi ~/.bashrc,在末尾加入以下内容:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin:$PATH
 
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin:$PATH
Line 25: Line 26:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Run the "~/.bashrc" script to make the compiler setting effective in the current shell. Note:there is a space after ".":
+
执行一下~/.bashrc脚本让设置立即在当前shell窗口中生效,注意"."后面有个空格:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
. ~/.bashrc
 
. ~/.bashrc
 
</syntaxhighlight>
 
</syntaxhighlight>
  
This is a 64-bit compiler and cannot be run on a 32-bit Linux. After installation is done you can verify it by running the following commands:
+
这个编译器是64位的,不能在32位的PC Linux系统上运行,安装完成后,用以下命令可以验证是否安装成功:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
aarch64-linux-gcc -v
 
aarch64-linux-gcc -v
Line 46: Line 47:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===Compile Android7 Source Code===
+
===编译Android8.1源代码===
====Download Android7 Source Code====
+
====下载Android8.1源代码====
All the {{{1}}}'s source code is hosted at gitlab, you can download it by running the following commands:
+
{{{1}}} 源代码托管在 gitlab 上,使用以下命令进行下载:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://gitlab.com/friendlyelec/rk3399-nougat.git
+
git clone https://gitlab.com/friendlyelec/rk3399-android-8.1 --depth 1 -b master
 
</syntaxhighlight>
 
</syntaxhighlight>
  
====Compile & Make Image File====
+
====编译并生成Image文件====
Compile Android7 by running the following commands:
+
使用以下命令编译 Android7:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
cd rk3399-nougat
+
cd rk3399-android-8.1
 
./build-nanopc-t4.sh -F -M
 
./build-nanopc-t4.sh -F -M
 
</syntaxhighlight>
 
</syntaxhighlight>
  
====Update Image File====
+
====更新系统为自已编译的Image====
After compilation is done an image file will be generated under Android7's "rockdev/Image-nanopc_t4/" directory. Update the image file on {{{1}}} by running the following commands:<br />
+
编译完成后,image文件会存放在Android8.1源代码目录的 rockdev/Image-nanopc_t4/ 子目录下,参考以下步骤更新到 {{{1}}}上: <br />
1) Insert a bootable SD card with EFLASHER to a card adapter and insert this adapter to a host PC and the SD card's sections will be automatically mounted;<br />
+
1) 将 EFlasher 启动SD卡 通过读卡器插入电脑,电脑上的Ubuntu系统会自动挂载 SD卡的分区; <br />
2) Copy all the files under "rockdev/Image-nanopc_t4/" to the "nougat" directory of this SD card's FRIENDLYARM section;<br />
+
2) 我们需要将 rockdev/Image-nanopc_t4/ 子目录下的所有文件,拷贝并覆盖到 SD卡 FRIENDLYARM 分区里的 android8 目录; <br />
3) Insert this SD card to your {{{1}}} and reinstall Android;<br />
+
3) 将SD卡插入{{{1}}},重新烧写Andorid系统即可; <br />
 +
也可参考这个github仓库的方法来更新:[https://github.com/friendlyarm/sd-fuse_rk3399 sd-fuse_rk3399]<br />
  
===Compile Lubuntu Kernel===
+
===编译Android7源代码===
<!---
+
====下载Android7源代码====
====Install toolchain====
+
{{{1}}} 源代码托管在 gitlab 上,使用以下命令进行下载:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://github.com/friendlyarm/prebuilts.git
+
git clone https://gitlab.com/friendlyelec/rk3399-nougat --depth 1 -b nanopc-t4-nougat
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/
+
 
</syntaxhighlight>
 
</syntaxhighlight>
--->
+
 
====compile Linux kernel====
+
====编译并生成Image文件====
 +
使用以下命令编译 Android7:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://github.com/friendlyarm/kernel-rockchip --depth 1 -b nanopi4-linux-v4.4.y
+
cd rk3399-nougat
 +
./build-nanopc-t4.sh -F -M
 +
</syntaxhighlight>
 +
 
 +
====更新系统为自已编译的Image====
 +
编译完成后,image文件会存放在Android7源代码目录的 rockdev/Image-nanopc_t4/ 子目录下,参考以下步骤更新到 {{{1}}}上: <br />
 +
1) 将 EFlasher 启动SD卡 通过读卡器插入电脑,电脑上的Ubuntu系统会自动挂载 SD卡的分区; <br />
 +
2) 我们需要将 rockdev/Image-nanopc_t4/ 子目录下的所有文件,拷贝并覆盖到 SD卡 FRIENDLYARM 分区里的  nougat 目录; <br />
 +
3) 将SD卡插入{{{1}}},重新烧写Andorid系统即可; <br />
 +
也可参考这个github仓库的方法来更新:[https://github.com/friendlyarm/sd-fuse_rk3399 sd-fuse_rk3399]<br />
 +
 
 +
===编译 FriendlyCore/FriendlyDesktop/Lubuntu 内核源代码===
 +
<syntaxhighlight lang="bash">
 +
git clone https://github.com/friendlyarm/kernel-rockchip --depth 1 -b nanopi4-linux-v4.4.y kernel-rockchip
 
cd kernel-rockchip
 
cd kernel-rockchip
 
make ARCH=arm64 nanopi4_linux_defconfig
 
make ARCH=arm64 nanopi4_linux_defconfig
 +
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
 
make ARCH=arm64 nanopi4-images
 
make ARCH=arm64 nanopi4-images
 
</syntaxhighlight>
 
</syntaxhighlight>
  
====Update Lubuntu Kernel====
+
编译完成后会生成 kernel.img resource.img 这两个文件,将其拷贝到eflasher系统的SD卡覆盖旧文件即可, 假设SD卡的FRIENDLYARM分区挂载到FRIENDLYARM目录,更新命令如下:
To update the kernel you need to use the Linux_Upgrade_Tool_1.27.rar utility. Refer to the aforementioned sections on how to use this utility.
+
<syntaxhighlight lang="bash">
 +
# for Lubuntu
 +
cp kernel.img resource.img /media/FRIENDLYARM/lubuntu/
 +
 
 +
# for FriendlyCore
 +
cp kernel.img resource.img /media/FRIENDLYARM/friendlycore-arm64/
 +
 
 +
# for FriendlyDesktop
 +
cp kernel.img resource.img /media/FRIENDLYARM/friendlydesktop-arm64/
 +
</syntaxhighlight>
 +
也可以用线刷工具来更新。
 +
 
 +
===编译 FriendlyCore/FriendlyDesktop/Lubuntu U-boot源代码===
 +
<syntaxhighlight lang="bash">
 +
git clone https://gitlab.com/friendlyelec/rk3399-nougat --depth 1 -b nanopc-t4-nougat
 +
cd rk3399-nougat/u-boot
 +
make CROSS_COMPILE=aarch64-linux- rk3399_defconfig
 +
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
 +
make CROSS_COMPILE=aarch64-linux-
 +
</syntaxhighlight>
 +
 
 +
编译完成后会生成 uboot.img、trust.img 和 rk3399_loader_v1.12.109.bin这3个文件,其中rk3399_loader_v1.12.109.bin需要重命名为MiniLoaderAll.bin,将其拷贝到eflasher系统的SD卡覆盖旧文件即可,假设SD卡的FRIENDLYARM分区挂载到FRIENDLYARM目录,更新命令如下:
 +
<syntaxhighlight lang="bash">
 +
# for Lubuntu
 +
cp uboot.img trust.img /media/FRIENDLYARM/lubuntu
 +
cp rk3399_loader_v1.12.109.bin /media/FRIENDLYARM/lubuntu/MiniLoaderAll.bin
 +
 
 +
# for FriendlyCore
 +
cp uboot.img trust.img /media/FRIENDLYARM/friendlycore-arm64
 +
cp rk3399_loader_v1.12.109.bin /media/FRIENDLYARM/friendlycore-arm64/MiniLoaderAll.bin
 +
 
 +
# for FriendlyDesktop
 +
cp uboot.img trust.img /media/FRIENDLYARM/friendlydesktop-arm64
 +
cp rk3399_loader_v1.12.109.bin /media/FRIENDLYARM/friendlydesktop-arm64/MiniLoaderAll.bin
 +
</syntaxhighlight>
 +
也可以用线刷工具来更新。
 +
 
 +
===制作用于量产的启动卡或者烧写文件===
 +
如果要自已做启动卡,或制作用于批量生产的img文件,可参考这个github仓库:[https://github.com/friendlyarm/sd-fuse_rk3399 sd-fuse_rk3399]<br />

Revision as of 10:20, 15 November 2018

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;
也可以使用Docker环境:friendlyelec-android-docker

1.2 安装交叉编译器

1.2.1 安装aarch64-linux-gcc 6.4

该编译器可用来编译Linux系统的内核和u-boot,用以下命令下载并安装:

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位的PC 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 编译Android8.1源代码

1.3.1 下载Android8.1源代码

{{{1}}} 源代码托管在 gitlab 上,使用以下命令进行下载:

git clone https://gitlab.com/friendlyelec/rk3399-android-8.1 --depth 1 -b master

1.3.2 编译并生成Image文件

使用以下命令编译 Android7:

cd rk3399-android-8.1
./build-nanopc-t4.sh -F -M

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

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

1.4 编译Android7源代码

1.4.1 下载Android7源代码

{{{1}}} 源代码托管在 gitlab 上,使用以下命令进行下载:

git clone https://gitlab.com/friendlyelec/rk3399-nougat --depth 1 -b nanopc-t4-nougat

1.4.2 编译并生成Image文件

使用以下命令编译 Android7:

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

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

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

1.5 编译 FriendlyCore/FriendlyDesktop/Lubuntu 内核源代码

git clone https://github.com/friendlyarm/kernel-rockchip --depth 1 -b nanopi4-linux-v4.4.y kernel-rockchip
cd kernel-rockchip
make ARCH=arm64 nanopi4_linux_defconfig
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
make ARCH=arm64 nanopi4-images

编译完成后会生成 kernel.img resource.img 这两个文件,将其拷贝到eflasher系统的SD卡覆盖旧文件即可, 假设SD卡的FRIENDLYARM分区挂载到FRIENDLYARM目录,更新命令如下:

# for Lubuntu
cp kernel.img resource.img /media/FRIENDLYARM/lubuntu/
 
# for FriendlyCore
cp kernel.img resource.img /media/FRIENDLYARM/friendlycore-arm64/
 
# for FriendlyDesktop
cp kernel.img resource.img /media/FRIENDLYARM/friendlydesktop-arm64/

也可以用线刷工具来更新。

1.6 编译 FriendlyCore/FriendlyDesktop/Lubuntu U-boot源代码

git clone https://gitlab.com/friendlyelec/rk3399-nougat --depth 1 -b nanopc-t4-nougat
cd rk3399-nougat/u-boot
make CROSS_COMPILE=aarch64-linux- rk3399_defconfig
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
make CROSS_COMPILE=aarch64-linux-

编译完成后会生成 uboot.img、trust.img 和 rk3399_loader_v1.12.109.bin这3个文件,其中rk3399_loader_v1.12.109.bin需要重命名为MiniLoaderAll.bin,将其拷贝到eflasher系统的SD卡覆盖旧文件即可,假设SD卡的FRIENDLYARM分区挂载到FRIENDLYARM目录,更新命令如下:

# for Lubuntu
cp uboot.img trust.img /media/FRIENDLYARM/lubuntu
cp rk3399_loader_v1.12.109.bin /media/FRIENDLYARM/lubuntu/MiniLoaderAll.bin
 
# for FriendlyCore
cp uboot.img trust.img /media/FRIENDLYARM/friendlycore-arm64
cp rk3399_loader_v1.12.109.bin /media/FRIENDLYARM/friendlycore-arm64/MiniLoaderAll.bin
 
# for FriendlyDesktop
cp uboot.img trust.img /media/FRIENDLYARM/friendlydesktop-arm64
cp rk3399_loader_v1.12.109.bin /media/FRIENDLYARM/friendlydesktop-arm64/MiniLoaderAll.bin

也可以用线刷工具来更新。

1.7 制作用于量产的启动卡或者烧写文件

如果要自已做启动卡,或制作用于批量生产的img文件,可参考这个github仓库:sd-fuse_rk3399