Difference between revisions of "Template:RK3399-BuildFromSource"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
(updated by API)
Line 46: Line 46:
 
gcc version 6.4.0 (ctng-1.23.0-150g-FA)
 
gcc version 6.4.0 (ctng-1.23.0-150g-FA)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
===编译Android10源代码===
 +
====下载Android10源代码====
 +
有以下两种途径获取 Android10 的源代码,都需要联网:
 +
* '''使用网盘里的git repo压缩包'''
 +
网盘下载地址: [http://download.friendlyarm.com/{{#replace:{{#replace:{{BASEPAGENAME}}| |}}|/zh|}} 点击进入]<br />
 +
文件位于网盘的以下路径:sources/rk3399-android-10.git-YYYYMMDD.tar.xz (YYYYMMDD表示打包的日期)<br />
 +
从网盘中获取的压缩包在解压之后,需要执行一下 sync.sh 脚本,会从gitlab上拉取最新的代码:
 +
<syntaxhighlight lang="bash">
 +
tar xf /path/to/netdisk/sources/rk3399-android-10.git-YYYYMMDD.tar.xz
 +
cd rk3399-android-10
 +
</syntaxhighlight>
 +
* '''直接克隆git仓库'''
 +
{{{1}}} 源代码托管在 gitlab 上,使用以下命令进行下载:
 +
<syntaxhighlight lang="bash">
 +
git clone --recursive https://gitlab.com/friendlyelec/rk3399-android-10.git -b main
 +
</syntaxhighlight>
 +
 +
====编译并生成Image文件====
 +
编译Android 10建议使用普通用户登录,运行以下命令编译:
 +
<syntaxhighlight lang="bash">
 +
cd rk3399-android-10
 +
./build-nanopc-t4.sh -F -M
 +
</syntaxhighlight>
 +
 +
====更新系统为自已编译的Image====
 +
编译完成后,image文件会存放在Android10源代码目录的 rockdev/Image-nanopc_t4/ 子目录下,参考以下步骤更新到 {{{1}}}上: <br />
 +
1) 将 EFlasher 启动SD卡 通过读卡器插入电脑,电脑上的Ubuntu系统会自动挂载 SD卡的分区; <br />
 +
2) 我们需要将 rockdev/Image-nanopc_t4/ 子目录下的所有文件,拷贝并覆盖到 SD卡 FRIENDLYARM 分区里的 android10 目录; <br />
 +
3) 将SD卡插入{{{1}}},重新烧写Andorid系统即可; <br />
 +
也可参考这个github仓库的方法来更新:[https://github.com/friendlyarm/sd-fuse_rk3399 sd-fuse_rk3399]<br />
 +
烧写Android 10时EFlasher 需要 v1.3 或以上版本,通过Type-C烧写时请使用rockchip提供的工具AndroidTool v2.71 或Linux_Upgrade_Tool v1.49 。
  
 
===Compile Android8.1 Source Code===
 
===Compile Android8.1 Source Code===

Revision as of 02:30, 20 August 2020

1 Make Your Own OS Image

1.1 Setup Development Environment

In order to compile an Android image we suggest you do it on a 64 bit Ubuntu 16.04 system and install the following packages:

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

For more details refer to https://source.android.com/source/initializing.html;
Or you can do it in Docker: friendlyelec-android-docker

1.2 Install Cross Compiler

1.2.1 Install aarch64-linux-gcc 6.4

This compiler can be used to compile a Linux kernel and u-boot. You can do it by running the following commands:

git clone https://github.com/friendlyarm/prebuilts.git -b master --depth 1
cd prebuilts/gcc-x64
cat toolchain-6.4-aarch64.tar.gz* | sudo tar xz -C /

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

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

Run the ~/.bashrc script to make it effective in the current commandline. Note: there is a space after ".":

. ~/.bashrc

This is a 64 bit compiler and cannot work on a 32 bit Linux system. You can test if your compiler is installed correctly by running the following commands:

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 编译Android10源代码

1.3.1 下载Android10源代码

有以下两种途径获取 Android10 的源代码,都需要联网:

  • 使用网盘里的git repo压缩包

网盘下载地址: 点击进入
文件位于网盘的以下路径:sources/rk3399-android-10.git-YYYYMMDD.tar.xz (YYYYMMDD表示打包的日期)
从网盘中获取的压缩包在解压之后,需要执行一下 sync.sh 脚本,会从gitlab上拉取最新的代码:

tar xf /path/to/netdisk/sources/rk3399-android-10.git-YYYYMMDD.tar.xz
cd rk3399-android-10
  • 直接克隆git仓库

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

git clone --recursive https://gitlab.com/friendlyelec/rk3399-android-10.git -b main

1.3.2 编译并生成Image文件

编译Android 10建议使用普通用户登录,运行以下命令编译:

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

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

编译完成后,image文件会存放在Android10源代码目录的 rockdev/Image-nanopc_t4/ 子目录下,参考以下步骤更新到 {{{1}}}上:
1) 将 EFlasher 启动SD卡 通过读卡器插入电脑,电脑上的Ubuntu系统会自动挂载 SD卡的分区;
2) 我们需要将 rockdev/Image-nanopc_t4/ 子目录下的所有文件,拷贝并覆盖到 SD卡 FRIENDLYARM 分区里的 android10 目录;
3) 将SD卡插入{{{1}}},重新烧写Andorid系统即可;
也可参考这个github仓库的方法来更新:sd-fuse_rk3399
烧写Android 10时EFlasher 需要 v1.3 或以上版本,通过Type-C烧写时请使用rockchip提供的工具AndroidTool v2.71 或Linux_Upgrade_Tool v1.49 。

1.4 Compile Android8.1 Source Code

1.4.1 Download Android8.1 Source Code

There are two ways to download the source code:

  • repo archive file on netdisk

Netdisk URL: Click here
File location on netdisk:sources/rk3399-android-8.1.git-YYYYMMDD.tgz (YYYYMMDD means the date of packaging)
After extracting the repo package from the network disk, you need to execute the sync.sh script, which will pull the latest code from gitlab:

tar xvzf /path/to/netdisk/sources/rk3399-android-8.1.git-YYYYMMDD.tgz
cd rk3399-android-8.1
./sync.sh
  • git clone from gitlab

{{{1}}} source code is maintained in gitlab, You can download it by running the following command:

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

1.4.2 Generate Image File

You can compile an Android source code and generate an image file:

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

1.4.3 Update System with New Image

After compilation is done a new image file will be generated in the "rockdev/Image-nanopc_t4/" directory under Android 8.1's source code directory. You can follow the steps below to update the OS in {{{1}}}:
1) Insert an SD card which is processed with EFlasher to an SD card reader and insert this reader to a PC running Ubuntu. The SD card's partitions will be automatically mounted;
2) Copy all the files under the "rockdev/Image-nanopc_t4/" directory to the SD card's android8 directory in the "FRIENDLYARM" partition;
3) Insert this SD card to {{{1}}} and reflash Android
Here is an alternative guide to update OS: sd-fuse_rk3399

1.5 Compile Android7 Source Code

1.5.1 Download Android7 Source Code

There are two ways to download the source code:

  • repo archive file on netdisk

Netdisk URL: Click here
File location on netdisk:sources/rk3399-android-7.git-YYYYMMDD.tgz (YYYYMMDD means the date of packaging)
After extracting the repo package from the network disk, you need to execute the sync.sh script, which will pull the latest code from gitlab:

tar xvzf /path/to/netdisk/sources/rk3399-android-7.git-YYYYMMDD.tgz
cd rk3399-nougat
./sync.sh
  • git clone from gitlab

{{{1}}} source code is maintained in gitlab, You can download it by running the following command:

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

1.5.2 Generate Image File

You can compile an Android7 source code and generate an image file:

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

1.5.3 Update System with New Image

After compilation is done a new image file will be generated in the "rockdev/Image-nanopc_t4/" directory under Android7's source code directory. You can follow the steps below to update the OS in {{{1}}}:
1) Insert an SD card which is processed with EFlasher to an SD card reader and insert this reader to a PC running Ubuntu. The SD card's partitions will be automatically mounted;
2) Copy all the files under the "rockdev/Image-nanopc_t4/" directory to the SD card's android8 directory in the "FRIENDLYARM" partition;
3) Insert this SD card to {{{1}}} and reflash Android
Here is an alternative guide to update OS: sd-fuse_rk3399

1.6 Compile FriendlyCore/FriendlyDesktop/Lubuntu/EFlasher Kernel Source Code

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

After compilation is done a kernel.img and a resource.img will be generated. You can simply copy them to replace the existing files in your eflasher SD card. We assume your SD card's FRIENDLYARM partition is mounted at the FRIENDLYARM directory and you can run the following commands to update system:

# 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/

Or you can use a USB Type-C cable and the Linux_Upgrade_Tool utility to update system.

1.7 Compile FriendlyCore/FriendlyDesktop/Lubuntu/EFlasher U-boot Source Code

git clone https://github.com/friendlyarm/uboot-rockchip --depth 1 -b nanopi4-v2014.10_oreo
cd uboot-rockchip
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
make CROSS_COMPILE=aarch64-linux- rk3399_defconfig
make CROSS_COMPILE=aarch64-linux-

After compilation is done a uboot.img, a trust.img and a rk3399_loader_v1.22.119.bin will be generated. You need to rename the rk3399_loader_v1.22.119.bin to "MiniLoaderAll.bin" and copy it to replace the existing file in your eflasher SD card. We assume your SD card's FRIENDLYARM partition is mounted at the FRIENDLYARM directory. You can run the following commands to update system:

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

Or you can use a USB Type-C cable and the Linux_Upgrade_Tool utility to update system.

1.8 Make Bootable SD Card for Mass Production

If you need to make a bootable SD card for mass production you can refer to this github link:sd-fuse_rk3399