Template:RK3399-BuildFromSource

From FriendlyELEC WiKi
Revision as of 07:19, 21 February 2022 by Tzs (Talk | contribs) (updated by API)

Jump to: navigation, search

1 Compile Android10 Source Code

1.1 Download Android10 Source Code

There are two ways to download the source code:

  • repo archive file on netdisk

Netdisk URL: Click here
File location on netdisk:rk3399-android-10.git-YYYYMMDD.tar.xz (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 xf /path/to/netdisk/sources/rk3399-android-10.git-YYYYMMDD.tar.xz
cd rk3399-android-10
./sync.sh
  • git clone from gitlab

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

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

Note: If the following error "error: unknown option `recurse-submodules'" appears, please upgrade git to v2.0.0 or above.

1.2 Generate Image File

You can compile an Android source code and generate an image file (non-root user is recommended):

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

If you need to include google apps, you need to set an environment variable and then compile, as shown below:

cd rk3399-android-10
export INSTALL_GAPPS_FOR_TESTING=yes
./build-nanopc-t4.sh -F -M

1.3 Make OTA Packages

If you need the support of A/B (Seamless) System Updates, you need to do the following:
a) Build your own update server for http download of update files;
b) Customize the Updater application, the code is located in packages/apps/Updater, let it connect and download file from your server;
c) Use the quick compilation script parameter -O or --ota to compile OTA Packages, as shown below:

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

After the compilation is successfully completed, the OTA update related packages are located in the directory: rockdev/otapackage/ ,Please do not delete this directory.
After you have made some changes, compiling again with the parameter -O will generate ota-update-XXXXXXXX.zip, which is an incremental update package.
OTA Packages decides whether to generate incremental update package according to BUILD_NUMBER, for details, please refer to build-nanopc-t4.sh.
To disable the A/B feature, you can refer to the following to modify device/rockchip/rk3399/nanopc-t4/BoardConfig.mk, and then recompile uboot and android:

BOARD_USES_AB_IMAGE := false


1.4 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 10'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 android10 directory in the "FRIENDLYARM" partition;
3) Insert this SD card to {{{1}}} and reflash Android
When flashing Android 10, EFlasher requires v1.3 or above. When flashing with Type-C, please use the tool AndroidTool v2.71 or Linux_Upgrade_Tool v1.49 provided by Rockchip.

2 Compile Android8.1 Source Code

2.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

2.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

2.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

3 Compile Android7 Source Code

3.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

3.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

3.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

4 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 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- 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.

5 Compile U-boot v2014.10 for FriendlyCore/FriendlyDesktop/Lubuntu/EFlasher

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.

6 Compile U-boot v2017.09 for FriendlyCore-focal

git clone https://github.com/friendlyarm/rkbin -b friendlyelec
git clone https://github.com/friendlyarm/uboot-rockchip -b nanopi4-v2017.09
cd uboot-rockchip/
./make.sh nanopi4

3 files will be generated after compilation: uboot.img, trust.img and rk3399_loader_v1.24.126.bin, rk3399_loader_v1.24.126.bin needs to be renamed to MiniLoaderAll.bin, then copy it to the SD card of the eflasher system and replace the old file .

7 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