Difference between revisions of "Template:RK3399-BuildFromSource"

From FriendlyELEC WiKi
Jump to: navigation, search
(如何编译系统)
(updated by API)
 
(39 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Make Your Own OS Image==
+
===Build Openwrt/Friendlywrt===
===Setup Development Environment===
+
====Download Code====
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:
+
Two versions are available, please choose as required:
 +
=====FriendlyWrt 21.02=====
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zip
+
mkdir friendlywrt21-rk3399
sudo apt-get install flex curl libncurses5-dev libssl-dev zlib1g-dev gawk minicom
+
cd friendlywrt21-rk3399
sudo apt-get install openjdk-8-jdk
+
git clone https://github.com/friendlyarm/repo --depth 1 tools
sudo apt-get install exfat-fuse exfat-utils device-tree-compiler liblz4-tool
+
tools/repo init -u https://github.com/friendlyarm/friendlywrt_manifests -b master-v21.02 \
 +
        -m rk3399.xml --repo-url=https://github.com/friendlyarm/repo  --no-clone-bundle
 +
tools/repo sync ---no-clone-bundle
 +
</syntaxhighlight>
 +
=====FriendlyWrt 23.05=====
 +
<syntaxhighlight lang="bash">
 +
mkdir friendlywrt23-rk3399
 +
cd friendlywrt23-rk3399
 +
git clone https://github.com/friendlyarm/repo --depth 1 tools
 +
tools/repo init -u https://github.com/friendlyarm/friendlywrt_manifests -b master-v23.05 \
 +
        -m rk3399.xml --repo-url=https://github.com/friendlyarm/repo  --no-clone-bundle
 +
tools/repo sync -c  --no-clone-bundle
 +
</syntaxhighlight>
 +
====First compilation step====
 +
<syntaxhighlight lang="bash">
 +
./build.sh rk3399.mk  # or rk3399-docker.mk
 +
</syntaxhighlight>
 +
All the components (including u-boot, kernel, and friendlywrt) are compiled and the sd card image will be generated, then execute the following command to generate the image file for installing the system into the emmc:
 +
<syntaxhighlight lang="bash">
 +
./build.sh emmc-img
 +
</syntaxhighlight>
 +
After making changes to the project, the sd card image needs to be repackaged by running the following command:
 +
<syntaxhighlight lang="bash">
 +
./build.sh sd-img
 +
</syntaxhighlight>
 +
====Secondary compilation steps====
 +
<syntaxhighlight lang="bash">
 +
cd friendlywrt
 +
make menuconfig
 +
rm -rf ./tmp
 +
make -j${nproc}
 +
cd ../
 +
./build.sh sd-img
 +
./build.sh emmc-img
 +
</syntaxhighlight>
 +
====Build u-boot only====
 +
<syntaxhighlight lang="bash">
 +
./build.sh uboot
 +
</syntaxhighlight>
 +
====Build kernel only====
 +
<syntaxhighlight lang="bash">
 +
./build.sh kernel
 +
</syntaxhighlight>
 +
====Build friendlywrt only====
 +
<syntaxhighlight lang="bash">
 +
./build.sh friendlywrt
 +
</syntaxhighlight>
 +
Or go to the friendlywrt directory and follow the standard openwrt commands. If you get an error with the above command, try using the following command to compile in a single thread:
 +
<syntaxhighlight lang="bash">
 +
cd friendlywrt
 +
make -j1 V=s
 
</syntaxhighlight>
 
</syntaxhighlight>
更多说明可查看 https://source.android.com/source/initializing.html; <br />
 
也可以使用Docker环境:[http://github.com/friendlyarm/friendlyelec-android-docker friendlyelec-android-docker]<br />
 
  
===安装交叉编译器===
+
===Build Buildroot===
====安装aarch64-linux-gcc 6.4====
+
please refer to: [[Buildroot|Buildroot]]
该编译器可用来编译Linux系统的内核和u-boot,用以下命令下载并安装:
+
 
 +
===Build Other Linux===
 +
====Kernel and u-boot versions====
 +
{| class="wikitable"
 +
|-
 +
! Operating System
 +
! Kernel Version
 +
! U-boot version
 +
! Cross-compiler
 +
! Partition type
 +
! Packaging Tool
 +
! Kernel branch
 +
! Kernel configuration
 +
! U-boot branch
 +
! U-boot configuration
 +
|-
 +
| lubuntu
 +
| rowspan="4" | linux v4.4.y
 +
| rowspan="4" | u-boot v2014.10
 +
| rowspan="4" | 6.4-aarch64<br />
 +
| rowspan="4" | [https://github.com/friendlyarm/sd-fuse_rk3399/blob/master/prebuilt/parameter.template MBR]
 +
| rowspan="4" | [https://github.com/friendlyarm/sd-fuse_rk3399/tree/master sd-fuse]
 +
| rowspan="4" | [https://github.com/friendlyarm/kernel-rockchip/tree/nanopi4-linux-v4.4.y nanopi4-linux-v4.4.y]
 +
| rowspan="4" | nanopi4_linux_defconfig
 +
| rowspan="4" | [https://github.com/friendlyarm/uboot-rockchip/tree/nanopi4-v2014.10_oreo nanopi4-v2014.10_oreo]
 +
| rowspan="4" | rk3399_defconfig<br /><br />
 +
|-
 +
| friendlycore-arm64
 +
|-
 +
| friendlydesktop-arm64
 +
|-
 +
| eflasher
 +
|-
 +
| buildroot
 +
| rowspan="7" | linux v4.19.y
 +
| rowspan="7" | u-boot <br />v2017.09
 +
| rowspan="7" | 11.3-aarch64
 +
| rowspan="7" | [https://github.com/friendlyarm/sd-fuse_rk3399/blob/kernel-4.19/prebuilt/parameter.template GPT]
 +
| rowspan="7" | [https://github.com/friendlyarm/sd-fuse_rk3399/tree/kernel-4.19 sd-fuse]
 +
| rowspan="7" | [https://github.com/friendlyarm/kernel-rockchip/tree/nanopi4-v4.19.y nanopi4-v4.19.y]
 +
| rowspan="7" | nanopi4_linux_defconfig
 +
| rowspan="12" | [https://github.com/friendlyarm/uboot-rockchip/tree/nanopi4-v2017.09 nanopi4-v2017.09]
 +
| rowspan="12" | nanopi4_defconfig
 +
|-
 +
| ubuntu-focal-desktop-arm64
 +
|-
 +
| debian-bullseye-desktop-arm64
 +
|-
 +
| debian-bullseye-minimal-arm64
 +
|-
 +
| friendlycore-focal-arm64
 +
|-
 +
| debian-bookworm-core-arm64
 +
|-
 +
| ubuntu-noble-core-arm64
 +
|-
 +
| openmediavault-arm64
 +
| rowspan="5" | linux v6.1.y
 +
| rowspan="5" | u-boot <br />v2017.09
 +
| rowspan="5" | 11.3-aarch64
 +
| [https://github.com/friendlyarm/sd-fuse_rk3399/blob/kernel-6.1.y/prebuilt/parameter-ext4.txt GPT]
 +
| rowspan="5" | [https://github.com/friendlyarm/sd-fuse_rk3399/tree/kernel-6.1.y<br /> sd-fuse]<br /><br /><br /><br />
 +
| rowspan="5" | [https://github.com/friendlyarm/kernel-rockchip/tree/nanopi-r2-v6.1.y nanopi-r2-v6.1.y]<br /><br /><br /><br />
 +
| nanopi4_linux_defconfig
 +
|-
 +
| friendlywrt21
 +
| rowspan="4" | [https://github.com/friendlyarm/sd-fuse_rk3399/blob/kernel-6.1.y/prebuilt/parameter.txt GPT]
 +
| rowspan="4" | nanopi4_linux_defconfig<br />+friendlywrt.config
 +
|-
 +
| friendlywrt21-docker
 +
|-
 +
| friendlywrt23
 +
|-
 +
| friendlywrt23-docker
 +
|}
 +
* Kernel git repo:https://github.com/friendlyarm/kernel-rockchip
 +
* U-boot git repo:https://github.com/friendlyarm/uboot-rockchip
 +
* The cross-compile toolchain is located in the path: /opt/FriendlyARM/toolchain/
 +
* The SD-Fuse is a  helper script to make bootable SD card image.
 +
* Click on MBR and GPT in the table to view the partition layout (configuration file) for each system.
 +
 
 +
====Build kernel linux-v4.4.y====
 +
This section applies to the following operating systems:
 +
{| class="wikitable"
 +
|-
 +
| lubuntu
 +
| eflasher
 +
| friendlydesktop-arm64
 +
| friendlycore-arm64
 +
|}
 +
Clone the repository to your local drive then build:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://github.com/friendlyarm/prebuilts.git
+
git clone https://github.com/friendlyarm/kernel-rockchip --single-branch --depth 1 -b nanopi4-linux-v4.4.y kernel-rockchip
sudo mkdir -p /opt/FriendlyARM/toolchain
+
cd kernel-rockchip
sudo tar xf prebuilts/gcc-x64/aarch64-cortexa53-linux-gnu-6.4.tar.xz -C /opt/FriendlyARM/toolchain/
+
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
 +
touch .scmversion
 +
# Load configuration
 +
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig
 +
# Optionally, if you want to change the default kernel config
 +
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- menuconfig 
 +
# Start building kernel
 +
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4-images -j$(nproc)
 +
# Start building kernel modules
 +
mkdir -p out-modules
 +
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- INSTALL_MOD_PATH="$PWD/out-modules" modules -j$(nproc)
 +
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- INSTALL_MOD_PATH="$PWD/out-modules" modules_install
 +
KERNEL_VER=$(make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 kernelrelease)
 +
rm -rf $PWD/out-modules/lib/modules/${KERNEL_VER}/kernel/drivers/gpu/arm/mali400/
 +
[ ! -f "$PWD/out-modules/lib/modules/${KERNEL_VER}/modules.dep" ] && depmod -b $PWD/out-modules -E Module.symvers -F System.map -w ${KERNEL_VER}
 +
(cd $PWD/out-modules && find . -name \*.ko | xargs aarch64-linux-strip --strip-unneeded)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
After the compilation, the following files will be generated:
 +
{| class="wikitable"
 +
|-
 +
| kernel.img
 +
| resource.img
 +
| The kernel modules are located in the out-modules directory
 +
|}
 +
Run your build: <br>
 +
Please refre to [[#Running the build]]<br>
  
然后将编译器的路径加入到PATH中,用vi编辑vi ~/.bashrc,在末尾加入以下内容:
+
====Build u-boot v2014.10====
 +
This section applies to the following operating systems:
 +
{| class="wikitable"
 +
|-
 +
| lubuntu
 +
| eflasher
 +
| friendlydesktop-arm64
 +
| friendlycore-arm64
 +
|}
 +
Clone the repository to your local drive then build:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin:$PATH
+
git clone https://github.com/friendlyarm/uboot-rockchip --single-branch --depth 1 -b nanopi4-v2014.10_oreo
export GCC_COLORS=auto
+
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-
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
After the compilation, the following files will be generated:
 +
{| class="wikitable"
 +
|-
 +
| uboot.img
 +
| trust.img
 +
| rk3399_loader_v1.22.119.bin (aka MiniLoaderAll.bin)
 +
|}
 +
Installing the u-boot: <br>
 +
Please refre to [[#Running the build]]<br>
  
执行一下~/.bashrc脚本让设置立即在当前shell窗口中生效,注意"."后面有个空格:
+
====Build kernel linux-v4.19.y====
 +
This section applies to the following operating systems:
 +
{| class="wikitable"  
 +
|-
 +
| ubuntu-focal-desktop-arm64
 +
| debian-bullseye-desktop-arm64
 +
| debian-bullseye-minimal-arm64
 +
| friendlycore-focal-arm64
 +
| ubuntu-noble-core-arm64
 +
| debian-bookworm-core-arm64
 +
| buildroot
 +
|}
 +
Clone the repository to your local drive then build:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
. ~/.bashrc
+
git clone https://github.com/friendlyarm/kernel-rockchip --single-branch --depth 1 -b nanopi4-v4.19.y kernel-rockchip
 +
cd kernel-rockchip
 +
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
 +
touch .scmversion
 +
# Configuring the Kernel
 +
# Load default configuration
 +
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig
 +
# Optionally, load configuration for FriendlyWrt
 +
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig friendlywrt.config
 +
# Optionally, if you want to change the default kernel config
 +
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- menuconfig
 +
# Start building kernel
 +
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4-images -j$(nproc)
 +
# Start building kernel modules
 +
mkdir -p out-modules
 +
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- INSTALL_MOD_PATH="$PWD/out-modules" modules -j$(nproc)
 +
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- INSTALL_MOD_PATH="$PWD/out-modules" modules_install
 +
KERNEL_VER=$(make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 kernelrelease)
 +
rm -rf $PWD/out-modules/lib/modules/${KERNEL_VER}/kernel/drivers/gpu/arm/mali400/
 +
[ ! -f "$PWD/out-modules/lib/modules/${KERNEL_VER}/modules.dep" ] && depmod -b $PWD/out-modules -E Module.symvers -F System.map -w ${KERNEL_VER}
 +
(cd $PWD/out-modules && find . -name \*.ko | xargs aarch64-linux-strip --strip-unneeded)
 +
</syntaxhighlight>
 +
After the compilation, the following files will be generated:
 +
{| class="wikitable"
 +
|-
 +
| kernel.img
 +
| resource.img
 +
| The kernel modules are located in the out-modules directory
 +
|}
 +
Run your build: <br>
 +
Please refre to [[#Running the build]]<br>
 +
====Build kernel linux-v6.1.y====
 +
This section applies to the following operating systems:
 +
{| class="wikitable"
 +
|-
 +
| friendlywrt21
 +
| friendlywrt21-docker
 +
| friendlywrt23
 +
| friendlywrt23-docker
 +
| openmediavault-arm64
 +
|}
 +
Clone the repository to your local drive then build:
 +
<syntaxhighlight lang="bash">
 +
git clone https://github.com/friendlyarm/kernel-rockchip --single-branch --depth 1 -b nanopi-r2-v6.1.y kernel-rockchip
 +
cd kernel-rockchip
 +
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
 +
touch .scmversion
 +
# Configuring the Kernel
 +
# Load default configuration
 +
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi4_linux_defconfig
 +
# Optionally, load configuration for FriendlyWrt
 +
# make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi4_linux_defconfig friendlywrt.config
 +
# Optionally, if you want to change the default kernel config
 +
# make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 menuconfig
 +
# Start building kernel
 +
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 -j$(nproc)
 +
# Start building kernel modules
 +
mkdir -p out-modules && rm -rf out-modules/*
 +
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 INSTALL_MOD_PATH="$PWD/out-modules" modules -j$(nproc)
 +
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 INSTALL_MOD_PATH="$PWD/out-modules" modules_install
 +
KERNEL_VER=$(make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 kernelrelease)
 +
[ ! -f "$PWD/out-modules/lib/modules/${KERNEL_VER}/modules.dep" ] && depmod -b $PWD/out-modules -E Module.symvers -F System.map -w ${KERNEL_VER}
 +
(cd $PWD/out-modules && find . -name \*.ko | xargs aarch64-linux-strip --strip-unneeded)
 +
</syntaxhighlight>
 +
Pack the kernel.img and resource.img:
 +
<syntaxhighlight lang="bash">
 +
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3399/kernel-6.1.y/tools/mkkrnlimg && chmod 755 mkkrnlimg
 +
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3399/kernel-6.1.y/tools/resource_tool && chmod 755 resource_tool
 +
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3399/kernel-6.1.y/prebuilt/boot/logo.bmp
 +
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3399/kernel-6.1.y/prebuilt/boot/logo_kernel.bmp
 +
./mkkrnlimg arch/arm64/boot/Image kernel.img
 +
mkdir kernel-dtbs
 +
cp -f arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4s.dtb kernel-dtbs/rk3399-nanopi4-rev09.dtb
 +
cp -f arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4s.dtb kernel-dtbs/rk3399-nanopi4-rev0a.dtb
 +
cp -f arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4se.dtb kernel-dtbs/rk3399-nanopi4-rev0b.dtb
 +
cp -f arch/arm64/boot/dts/rockchip/rk3399-nanopc-t4.dtb kernel-dtbs/rk3399-nanopi4-rev00.dtb
 +
./resource_tool --dtbname kernel-dtbs/*.dtb logo.bmp logo_kernel.bmp
 +
</syntaxhighlight>
 +
After the compilation, the following files will be generated:
 +
{| class="wikitable"
 +
|-
 +
| kernel.img
 +
| resource.img
 +
| The kernel modules are located in the out-modules directory
 +
|}
 +
Run your build: <br>
 +
Please refre to [[#Running the build]]<br>
 +
====Build u-boot v2017.09====
 +
This section applies to the following operating systems:
 +
{| class="wikitable"
 +
|-
 +
| ubuntu-focal-desktop-arm64
 +
| debian-bullseye-desktop-arm64
 +
| debian-bullseye-minimal-arm64
 +
| friendlycore-focal-arm64
 +
| ubuntu-noble-core-arm64
 +
| debian-bookworm-core-arm64
 +
| buildroot
 +
|}
 +
Clone the repository to your local drive then build:
 +
<syntaxhighlight lang="bash">
 +
git clone https://github.com/friendlyarm/rkbin --single-branch --depth 1 -b friendlyelec
 +
git clone https://github.com/friendlyarm/uboot-rockchip --single-branch --depth 1 -b nanopi4-v2017.09
 +
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
 +
cd uboot-rockchip/
 +
./make.sh nanopi4
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
After the compilation, the following files will be generated:
 +
{| class="wikitable"
 +
|-
 +
| uboot.img
 +
| trust.img
 +
| rk3399_loader_v1.24.126.bin (aka MiniLoaderAll.bin)
 +
|}
 +
Run your build: <br>
 +
Please refre to [[#Running the build]]<br>
  
这个编译器是64位的,不能在32位的PC Linux系统上运行,安装完成后,用以下命令可以验证是否安装成功:
+
====Running the build====
 +
=====Install to target board=====
 +
======MBR partition======
 +
This section applies to the following operating systems:
 +
{| class="wikitable"
 +
|-
 +
| lubuntu
 +
| eflasher
 +
| friendlydesktop-arm64
 +
| friendlycore-arm64
 +
|}
 +
The MBR partitioning is only used by the Linux v4.4 kernel. You can check the partition layout by clicking on this link: [https://github.com/friendlyarm/sd-fuse_rk3399/blob/master/prebuilt/parameter.template partmap]. To write an image file, you can use the dd command. For example, in the parameter.template file, "0x00014000@0x00014000(kernel)" specifies that the kernel partition starts at 0x00014000, which is equivalent to 81920 in decimal. Therefore, the dd command should be as follows:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
aarch64-linux-gcc -v
+
dd if=kernel.img of=/dev/mmcblk0 seek=81920
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)
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===编译Android8.1源代码===
+
======GPT partition======
====下载Android8.1源代码====
+
This section applies to the following operating systems:
{{{1}}} 源代码托管在 gitlab 上,使用以下命令进行下载:
+
{| class="wikitable"
 +
|-
 +
| ubuntu-focal-desktop-arm64
 +
| debian-bookworm-core-arm64
 +
| debian-bullseye-desktop-arm64
 +
| debian-bullseye-minimal-arm64
 +
|-
 +
| friendlycore-focal-arm64
 +
| ubuntu-noble-core-arm64
 +
| friendlywrt21-kernel4
 +
| buildroot
 +
|-
 +
| friendlywrt21
 +
| friendlywrt21-docker
 +
| friendlywrt23
 +
| friendlywrt23-docker
 +
|}
 +
The OS uses GPT partitions by default which is using the Linux v4.19 and Linux v5.15 kernel, you can use the dd command, but be careful to choose the right output device:
 +
* The SD/TF Card device node: /dev/mmcblk0 <br />
 +
* The eMMC device node: /dev/mmcblk2 <br />
 +
The following is an example of how to update the kernel to eMMC:<br />
 +
Use the 'parted' command to view the partition layout:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://gitlab.com/friendlyelec/rk3399-android-8.1 --depth 1 -b master
+
parted /dev/mmcblk2 print
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
Sample outputs:
 +
<syntaxhighlight lang="bash">
 +
Model: MMC BJTD4R (sd/mmc)
 +
Disk /dev/mmcblk2: 31.3GB
 +
Sector size (logical/physical): 512B/512B
 +
Partition Table: gpt
 +
Disk Flags:
  
====编译并生成Image文件====
+
Number  Start  End    Size    File system  Name      Flags
使用以下命令编译 Android7:
+
1      8389kB  12.6MB  4194kB              uboot
 +
2      12.6MB  16.8MB  4194kB              trust
 +
3      16.8MB  21.0MB  4194kB              misc
 +
4      21.0MB  25.2MB  4194kB              dtbo
 +
5      25.2MB  41.9MB  16.8MB              resource
 +
6      41.9MB  83.9MB  41.9MB              kernel
 +
7      83.9MB  134MB  50.3MB              boot
 +
8      134MB  2500MB  2366MB  ext4        rootfs
 +
9      2500MB  31.3GB  28.8GB  ext4        userdata
 +
</syntaxhighlight>
 +
as shown above, the resource partition is located at 5 and the kernel partition is located at 6. Use the dd command to write the resource.img and kernel.img files to these partitions, the commands are as follows:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
cd rk3399-android-8.1
+
dd if=resource.img of=/dev/mmcblk2p5 bs=1M
./build-nanopc-t4.sh -F -M
+
dd if=kernel.img of=/dev/mmcblk2p6 bs=1M
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
If you want to update u-boot:
 +
<syntaxhighlight lang="bash">
 +
dd if=uboot.img of=/dev/mmcblk2p1 bs=1M
 +
</syntaxhighlight>
 +
To update new driver modules, copy the newly compiled driver modules to the appropriate directory under /lib/modules.
  
====更新系统为自已编译的Image====
+
=====Packaging and creating an SD image=====
编译完成后,image文件会存放在Android8.1源代码目录的 rockdev/Image-nanopc_t4/ 子目录下,参考以下步骤更新到 {{{1}}}上: <br />
+
To create a new OS image file, you need to use the "sd-fuse" packaging tool.<br />
1) 将 EFlasher 启动SD卡 通过读卡器插入电脑,电脑上的Ubuntu系统会自动挂载 SD卡的分区; <br />
+
<br />
2) 我们需要将 rockdev/Image-nanopc_t4/ 子目录下的所有文件,拷贝并覆盖到 SD卡 FRIENDLYARM 分区里的 android8 目录; <br />
+
"sd-fuse" is a collection of scripts that can be used to create bootable SD card images for FriendlyElec boards. Its main features include:<br />
3) 将SD卡插入{{{1}}},重新烧写Andorid系统即可; <br />
+
* Creation of root filesystem images from a directory <br />
也可参考这个github仓库的方法来更新:[https://github.com/friendlyarm/sd-fuse_rk3399 sd-fuse_rk3399]<br />
+
* Building of bootable SD card images<br />
 
+
* Simple compilation of kernel, U-Boot, and third-party drivers<br />
===编译Android7源代码===
+
Please click on the following link to find out more:
====下载Android7源代码====
+
{| class="wikitable"
{{{1}}} 源代码托管在 gitlab 上,使用以下命令进行下载:
+
|-
 +
! Kernel version
 +
! Packaging Tool
 +
|-
 +
| linux v4.4.y
 +
| [https://github.com/friendlyarm/sd-fuse_rk3399/tree/master sd-fuse]
 +
|-
 +
| linux v4.19.y
 +
| [https://github.com/friendlyarm/sd-fuse_rk3399/tree/kernel-4.19<br /> sd-fuse_rk3399/kernel-4.19]
 +
|-
 +
| linux v6.1.y
 +
| [https://github.com/friendlyarm/sd-fuse_rk3399/tree/kernel-6.1.y<br /> sd-fuse_rk3399/kernel-6.1.y]
 +
|}
 +
=====USB flashing=====
 +
Note: kernel v4.4.y is not supported
 +
======Linux======
 +
Reboot the board and enter loader mode with the following command:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://gitlab.com/friendlyelec/rk3399-nougat --depth 1 -b nanopc-t4-nougat
+
sudo reboot loader
 +
</syntaxhighlight>
 +
To flash U-Boot and kernel using the "upgrade_tool_v2.17_for_linux" tool, please use the following command:
 +
<syntaxhighlight lang="bash">
 +
sudo upgrade_tool di -k kernel.img
 +
sudo upgrade_tool di -re resource.img
 +
sudo upgrade_tool di -u uboot.img
 +
sudo upgrade_tool RD
 +
</syntaxhighlight>
 +
Note: "upgrade_tool" is a command-line tool provided by Rockchip for Linux operating systems (Linux_Upgrade_Tool).
 +
===Build the code using scripts===
 +
====Download scripts and image files====
 +
<syntaxhighlight lang="bash">
 +
git clone https://github.com/friendlyarm/sd-fuse_rk3399.git -b kernel-4.19
 +
cd sd-fuse_rk3399
 +
wget http://112.124.9.243/dvdfiles/RK3399/images-for-eflasher/friendlycore-focal-arm64-images.tgz
 +
tar xvzf friendlycore-focal-arm64-images.tgz
 +
</syntaxhighlight>
 +
====Compile the kernel====
 +
Download the kernel source code and compile it. the relevant image files in the friendlycore-focal-arm64 directory will be automatically updated, including the kernel modules in the file system:
 +
<syntaxhighlight lang="bash">
 +
git clone https://github.com/friendlyarm/kernel-rockchip --depth 1 -b nanopi4-v4.19.y kernel-rk3399
 +
KERNEL_SRC=$PWD/kernel-rk3399 ./build-kernel.sh friendlycore-focal-arm64
 +
</syntaxhighlight>
 +
====Compile the kernel headers====
 +
<syntaxhighlight lang="bash">
 +
git clone https://github.com/friendlyarm/kernel-rockchip --depth 1 -b nanopi4-v4.19.y kernel-rk3399
 +
MK_HEADERS_DEB=1 BUILD_THIRD_PARTY_DRIVER=0 KERNEL_SRC=$PWD/kernel-rk3399 ./build-kernel.sh friendlycore-focal-arm64
 +
</syntaxhighlight>
 +
====Compile the uboot====
 +
Download the uboot source code and compile it. the relevant image files in the friendlycore-focal-arm64 directory will be automatically updated:
 +
<syntaxhighlight lang="bash">
 +
git clone https://github.com/friendlyarm/uboot-rockchip --depth 1 -b nanopi4-v2017.09
 +
UBOOT_SRC=$PWD/uboot-rockchip ./build-uboot.sh friendlycore-focal-arm64
 +
</syntaxhighlight>
 +
====Generate new image====
 +
Repackage the image file in the friendlycore-focal-arm64 directory into sd card image:
 +
<syntaxhighlight lang="bash">
 +
./mk-sd-image.sh friendlycore-focal-arm64
 +
</syntaxhighlight>
 +
After the command is completed, the image is in the out directory, you can use the dd command to make the SD boot card, for example:
 +
<syntaxhighlight lang="bash">
 +
dd if=out/rk3399-sd-friendlycore-focal-4.19-arm64-YYYYMMDD.img of=/dev/sdX bs=1M
 
</syntaxhighlight>
 
</syntaxhighlight>
  
====编译并生成Image文件====
+
===Building AOSP from source===
使用以下命令编译 Android7:
+
====Hardware and Software Requirements====
 +
* Your computer should have at least 16GB of RAM and 300GB of disk space. We recommend using a machine with 32GB of RAM and a large-capacity, high-speed SSD, and we do not recommend using virtual machines.
 +
* If you encounter compilation errors, they may be caused by problems with the compilation environment. We recommend using the following Docker container for compilation: [https://github.com/friendlyarm/docker-cross-compiler-novnc docker-cross-compiler-novnc].
 +
 
 +
====Compile Android10====
 +
=====Download Android10 Source Code=====
 +
There are two ways to download the source code:
 +
* '''repo archive file on netdisk'''
 +
Netdisk URL: [http://download.friendlyelec.com/{{#replace:{{#replace:{{BASEPAGENAME}}| |}}|/zh|}} Click here]<br />
 +
File location on netdisk:"07_Source codes/rk3399-android-10.git-YYYYMMDD.tar.xz" (YYYYMMDD means the date of packaging)<br />
 +
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:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
cd rk3399-nougat
+
tar xf "/path/to/netdisk/07_Source codes/rk3399-android-10.git-YYYYMMDD.tar.xz"
 +
cd rk3399-android-10
 +
./sync.sh
 +
</syntaxhighlight>
 +
* '''git clone from gitlab'''
 +
{{{1}}} source code is maintained in gitlab, You can download it by running the following command:
 +
<syntaxhighlight lang="bash">
 +
git clone --recursive https://gitlab.com/friendlyelec/rk3399-android-10.git -b main
 +
</syntaxhighlight>
 +
Note: If the following error "error: unknown option `recurse-submodules'" appears, please upgrade git to v2.0.0 or above.
 +
=====Generate Image File=====
 +
You can compile an Android source code and generate an image file (non-root user is recommended):
 +
<syntaxhighlight lang="bash">
 +
cd rk3399-android-10
 
./build-nanopc-t4.sh -F -M
 
./build-nanopc-t4.sh -F -M
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
If you need to include google apps, you need to set an environment variable and then compile, as shown below:
 +
<syntaxhighlight lang="bash">
 +
cd rk3399-android-10
 +
export INSTALL_GAPPS_FOR_TESTING=yes
 +
./build-nanopc-t4.sh -F -M
 +
</syntaxhighlight>
 +
 +
=====Make OTA Packages=====
 +
If you need the support of A/B (Seamless) System Updates, you need to do the following:<br />
 +
a) Build your own update server for http download of update files;<br />
 +
b) Customize the Updater application, the code is located in packages/apps/Updater, let it connect and download file from your server;<br />
 +
c) Use the quick compilation script parameter -O or --ota to compile OTA Packages, as shown below:
 +
<syntaxhighlight lang="bash">
 +
cd rk3399-android-10
 +
./build-nanopc-t4.sh -F -O -M
 +
</syntaxhighlight>
 +
After the compilation is successfully completed, the OTA update related packages are located in the directory: rockdev/otapackage/ ,Please do not delete this directory.<br />
 +
After you have made some changes, compiling again with the parameter -O will generate ota-update-XXXXXXXX.zip, which is an incremental update package.<br />
 +
OTA Packages decides whether to generate incremental update package according to BUILD_NUMBER, for details, please refer to build-nanopc-t4.sh.<br />
 +
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:<br />
 +
<syntaxhighlight lang="bash">
 +
BOARD_USES_AB_IMAGE := false
 +
</syntaxhighlight>
 +
<br />
  
====更新系统为自已编译的Image====
+
=====Update System with New Image=====
编译完成后,image文件会存放在Android7源代码目录的 rockdev/Image-nanopc_t4/ 子目录下,参考以下步骤更新到 {{{1}}}上: <br />
+
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}}}:<br />
1) EFlasher 启动SD卡 通过读卡器插入电脑,电脑上的Ubuntu系统会自动挂载 SD卡的分区; <br />
+
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; <br />
2) 我们需要将 rockdev/Image-nanopc_t4/ 子目录下的所有文件,拷贝并覆盖到 SD卡 FRIENDLYARM 分区里的  nougat 目录; <br />
+
2) Copy all the files under the "rockdev/Image-nanopc_t4/" directory to the SD card's android10 directory in the "FRIENDLYARM" partition;<br />
3) 将SD卡插入{{{1}}},重新烧写Andorid系统即可; <br />
+
3) Insert this SD card to {{{1}}} and reflash Android<br />
也可参考这个github仓库的方法来更新:[https://github.com/friendlyarm/sd-fuse_rk3399 sd-fuse_rk3399]<br />
+
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.
  
===编译 FriendlyCore/FriendlyDesktop/Lubuntu 内核源代码===
+
====Compile Android8.1====
 +
=====Download Android8.1 Source Code=====
 +
There are two ways to download the source code:
 +
* '''repo archive file on netdisk'''
 +
Netdisk URL: [http://download.friendlyelec.com/{{#replace:{{#replace:{{BASEPAGENAME}}| |}}|/zh|}} Click here]<br />
 +
File location on netdisk:sources/rk3399-android-8.1.git-YYYYMMDD.tgz (YYYYMMDD means the date of packaging)<br />
 +
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:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://github.com/friendlyarm/kernel-rockchip --depth 1 -b nanopi4-linux-v4.4.y kernel-rockchip
+
tar xvzf /path/to/netdisk/sources/rk3399-android-8.1.git-YYYYMMDD.tgz
cd kernel-rockchip
+
cd rk3399-android-8.1
make ARCH=arm64 nanopi4_linux_defconfig
+
./sync.sh
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
+
</syntaxhighlight>
make ARCH=arm64 nanopi4-images
+
* '''git clone from gitlab'''
 +
{{{1}}} source code is maintained in gitlab, You can download it by running the following command:
 +
<syntaxhighlight lang="bash">
 +
git clone https://gitlab.com/friendlyelec/rk3399-android-8.1 --depth 1 -b master
 
</syntaxhighlight>
 
</syntaxhighlight>
  
编译完成后会生成 kernel.img resource.img 这两个文件,将其拷贝到eflasher系统的SD卡覆盖旧文件即可, 假设SD卡的FRIENDLYARM分区挂载到FRIENDLYARM目录,更新命令如下:
+
=====Generate Image File=====
 +
You can compile an Android source code and generate an image file:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
# for Lubuntu
+
cd rk3399-android-8.1
cp kernel.img resource.img /media/FRIENDLYARM/lubuntu/
+
./build-nanopc-t4.sh -F -M
 +
</syntaxhighlight>
  
# for FriendlyCore
+
=====Update System with New Image=====
cp kernel.img resource.img /media/FRIENDLYARM/friendlycore-arm64/
+
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}}}:<br />
 +
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; <br />
 +
2) Copy all the files under the "rockdev/Image-nanopc_t4/" directory to the SD card's android8 directory in the "FRIENDLYARM" partition;<br />
 +
3) Insert this SD card to {{{1}}} and reflash Android<br />
 +
Here is an alternative guide to update OS: [https://github.com/friendlyarm/sd-fuse_rk3399 sd-fuse_rk3399]<br />
  
# for FriendlyDesktop
+
====Compile Android7====
cp kernel.img resource.img /media/FRIENDLYARM/friendlydesktop-arm64/
+
=====Download Android7 Source Code=====
 +
There are two ways to download the source code:
 +
* '''repo archive file on netdisk'''
 +
Netdisk URL: [http://download.friendlyelec.com/{{#replace:{{#replace:{{BASEPAGENAME}}| |}}|/zh|}} Click here]<br />
 +
File location on netdisk:sources/rk3399-android-7.git-YYYYMMDD.tgz (YYYYMMDD means the date of packaging)<br />
 +
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:
 +
<syntaxhighlight lang="bash">
 +
tar xvzf /path/to/netdisk/sources/rk3399-android-7.git-YYYYMMDD.tgz
 +
cd rk3399-nougat
 +
./sync.sh
 
</syntaxhighlight>
 
</syntaxhighlight>
也可以用线刷工具来更新。
+
* '''git clone from gitlab'''
 
+
{{{1}}} source code is maintained in gitlab, You can download it by running the following command:
===编译 FriendlyCore/FriendlyDesktop/Lubuntu U-boot源代码===
+
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git clone https://gitlab.com/friendlyelec/rk3399-nougat --depth 1 -b nanopc-t4-nougat
 
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>
 
</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目录,更新命令如下:
+
=====Generate Image File=====
 +
You can compile an Android7 source code and generate an image file:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
# for Lubuntu
+
cd rk3399-nougat
cp uboot.img trust.img /media/FRIENDLYARM/lubuntu
+
./build-nanopc-t4.sh -F -M
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>
 
</syntaxhighlight>
也可以用线刷工具来更新。
 
  
===制作用于量产的启动卡或者烧写文件===
+
=====Update System with New Image=====
如果要自已做启动卡,或制作用于批量生产的img文件,可参考这个github仓库:[https://github.com/friendlyarm/sd-fuse_rk3399 sd-fuse_rk3399]<br />
+
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}}}:<br />
 +
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; <br />
 +
2) Copy all the files under the "rockdev/Image-nanopc_t4/" directory to the SD card's android8 directory in the "FRIENDLYARM" partition;<br />
 +
3) Insert this SD card to {{{1}}} and reflash Android<br />
 +
Here is an alternative guide to update OS: [https://github.com/friendlyarm/sd-fuse_rk3399 sd-fuse_rk3399]<br />

Latest revision as of 08:18, 1 July 2024

1 Build Openwrt/Friendlywrt

1.1 Download Code

Two versions are available, please choose as required:

1.1.1 FriendlyWrt 21.02
mkdir friendlywrt21-rk3399
cd friendlywrt21-rk3399
git clone https://github.com/friendlyarm/repo --depth 1 tools
tools/repo init -u https://github.com/friendlyarm/friendlywrt_manifests -b master-v21.02 \
        -m rk3399.xml --repo-url=https://github.com/friendlyarm/repo  --no-clone-bundle
tools/repo sync -c  --no-clone-bundle
1.1.2 FriendlyWrt 23.05
mkdir friendlywrt23-rk3399
cd friendlywrt23-rk3399
git clone https://github.com/friendlyarm/repo --depth 1 tools
tools/repo init -u https://github.com/friendlyarm/friendlywrt_manifests -b master-v23.05 \
        -m rk3399.xml --repo-url=https://github.com/friendlyarm/repo  --no-clone-bundle
tools/repo sync -c  --no-clone-bundle

1.2 First compilation step

./build.sh rk3399.mk  # or rk3399-docker.mk

All the components (including u-boot, kernel, and friendlywrt) are compiled and the sd card image will be generated, then execute the following command to generate the image file for installing the system into the emmc:

./build.sh emmc-img

After making changes to the project, the sd card image needs to be repackaged by running the following command:

./build.sh sd-img

1.3 Secondary compilation steps

cd friendlywrt
make menuconfig
rm -rf ./tmp
make -j${nproc}
cd ../
./build.sh sd-img
./build.sh emmc-img

1.4 Build u-boot only

./build.sh uboot

1.5 Build kernel only

./build.sh kernel

1.6 Build friendlywrt only

./build.sh friendlywrt

Or go to the friendlywrt directory and follow the standard openwrt commands. If you get an error with the above command, try using the following command to compile in a single thread:

cd friendlywrt
make -j1 V=s

2 Build Buildroot

please refer to: Buildroot

3 Build Other Linux

3.1 Kernel and u-boot versions

Operating System Kernel Version U-boot version Cross-compiler Partition type Packaging Tool Kernel branch Kernel configuration U-boot branch U-boot configuration
lubuntu linux v4.4.y u-boot v2014.10 6.4-aarch64
MBR sd-fuse nanopi4-linux-v4.4.y nanopi4_linux_defconfig nanopi4-v2014.10_oreo rk3399_defconfig

friendlycore-arm64
friendlydesktop-arm64
eflasher
buildroot linux v4.19.y u-boot
v2017.09
11.3-aarch64 GPT sd-fuse nanopi4-v4.19.y nanopi4_linux_defconfig nanopi4-v2017.09 nanopi4_defconfig
ubuntu-focal-desktop-arm64
debian-bullseye-desktop-arm64
debian-bullseye-minimal-arm64
friendlycore-focal-arm64
debian-bookworm-core-arm64
ubuntu-noble-core-arm64
openmediavault-arm64 linux v6.1.y u-boot
v2017.09
11.3-aarch64 GPT
sd-fuse




nanopi-r2-v6.1.y



nanopi4_linux_defconfig
friendlywrt21 GPT nanopi4_linux_defconfig
+friendlywrt.config
friendlywrt21-docker
friendlywrt23
friendlywrt23-docker

3.2 Build kernel linux-v4.4.y

This section applies to the following operating systems:

lubuntu eflasher friendlydesktop-arm64 friendlycore-arm64

Clone the repository to your local drive then build:

git clone https://github.com/friendlyarm/kernel-rockchip --single-branch --depth 1 -b nanopi4-linux-v4.4.y kernel-rockchip
cd kernel-rockchip
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
touch .scmversion
# Load configuration
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig
# Optionally, if you want to change the default kernel config
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- menuconfig  
# Start building kernel
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4-images -j$(nproc)
# Start building kernel modules
mkdir -p out-modules
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- INSTALL_MOD_PATH="$PWD/out-modules" modules -j$(nproc)
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- INSTALL_MOD_PATH="$PWD/out-modules" modules_install
KERNEL_VER=$(make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 kernelrelease)
rm -rf $PWD/out-modules/lib/modules/${KERNEL_VER}/kernel/drivers/gpu/arm/mali400/
[ ! -f "$PWD/out-modules/lib/modules/${KERNEL_VER}/modules.dep" ] && depmod -b $PWD/out-modules -E Module.symvers -F System.map -w ${KERNEL_VER}
(cd $PWD/out-modules && find . -name \*.ko | xargs aarch64-linux-strip --strip-unneeded)

After the compilation, the following files will be generated:

kernel.img resource.img The kernel modules are located in the out-modules directory

Run your build:
Please refre to #Running the build

3.3 Build u-boot v2014.10

This section applies to the following operating systems:

lubuntu eflasher friendlydesktop-arm64 friendlycore-arm64

Clone the repository to your local drive then build:

git clone https://github.com/friendlyarm/uboot-rockchip --single-branch --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 the compilation, the following files will be generated:

uboot.img trust.img rk3399_loader_v1.22.119.bin (aka MiniLoaderAll.bin)

Installing the u-boot:
Please refre to #Running the build

3.4 Build kernel linux-v4.19.y

This section applies to the following operating systems:

ubuntu-focal-desktop-arm64 debian-bullseye-desktop-arm64 debian-bullseye-minimal-arm64 friendlycore-focal-arm64 ubuntu-noble-core-arm64 debian-bookworm-core-arm64 buildroot

Clone the repository to your local drive then build:

git clone https://github.com/friendlyarm/kernel-rockchip --single-branch --depth 1 -b nanopi4-v4.19.y kernel-rockchip
cd kernel-rockchip
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
touch .scmversion
# Configuring the Kernel
# Load default configuration
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig
# Optionally, load configuration for FriendlyWrt
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig friendlywrt.config
# Optionally, if you want to change the default kernel config
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- menuconfig
# Start building kernel
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4-images -j$(nproc)
# Start building kernel modules
mkdir -p out-modules
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- INSTALL_MOD_PATH="$PWD/out-modules" modules -j$(nproc)
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- INSTALL_MOD_PATH="$PWD/out-modules" modules_install
KERNEL_VER=$(make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 kernelrelease)
rm -rf $PWD/out-modules/lib/modules/${KERNEL_VER}/kernel/drivers/gpu/arm/mali400/
[ ! -f "$PWD/out-modules/lib/modules/${KERNEL_VER}/modules.dep" ] && depmod -b $PWD/out-modules -E Module.symvers -F System.map -w ${KERNEL_VER}
(cd $PWD/out-modules && find . -name \*.ko | xargs aarch64-linux-strip --strip-unneeded)

After the compilation, the following files will be generated:

kernel.img resource.img The kernel modules are located in the out-modules directory

Run your build:
Please refre to #Running the build

3.5 Build kernel linux-v6.1.y

This section applies to the following operating systems:

friendlywrt21 friendlywrt21-docker friendlywrt23 friendlywrt23-docker openmediavault-arm64

Clone the repository to your local drive then build:

git clone https://github.com/friendlyarm/kernel-rockchip --single-branch --depth 1 -b nanopi-r2-v6.1.y kernel-rockchip
cd kernel-rockchip
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
touch .scmversion
# Configuring the Kernel
# Load default configuration
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi4_linux_defconfig
# Optionally, load configuration for FriendlyWrt
# make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi4_linux_defconfig friendlywrt.config
# Optionally, if you want to change the default kernel config
# make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 menuconfig
# Start building kernel
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 -j$(nproc)
# Start building kernel modules
mkdir -p out-modules && rm -rf out-modules/*
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 INSTALL_MOD_PATH="$PWD/out-modules" modules -j$(nproc)
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 INSTALL_MOD_PATH="$PWD/out-modules" modules_install
KERNEL_VER=$(make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 kernelrelease)
[ ! -f "$PWD/out-modules/lib/modules/${KERNEL_VER}/modules.dep" ] && depmod -b $PWD/out-modules -E Module.symvers -F System.map -w ${KERNEL_VER}
(cd $PWD/out-modules && find . -name \*.ko | xargs aarch64-linux-strip --strip-unneeded)

Pack the kernel.img and resource.img:

wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3399/kernel-6.1.y/tools/mkkrnlimg && chmod 755 mkkrnlimg
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3399/kernel-6.1.y/tools/resource_tool && chmod 755 resource_tool
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3399/kernel-6.1.y/prebuilt/boot/logo.bmp
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3399/kernel-6.1.y/prebuilt/boot/logo_kernel.bmp
./mkkrnlimg arch/arm64/boot/Image kernel.img
mkdir kernel-dtbs
cp -f arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4s.dtb kernel-dtbs/rk3399-nanopi4-rev09.dtb
cp -f arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4s.dtb kernel-dtbs/rk3399-nanopi4-rev0a.dtb
cp -f arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4se.dtb kernel-dtbs/rk3399-nanopi4-rev0b.dtb
cp -f arch/arm64/boot/dts/rockchip/rk3399-nanopc-t4.dtb kernel-dtbs/rk3399-nanopi4-rev00.dtb
./resource_tool --dtbname kernel-dtbs/*.dtb logo.bmp logo_kernel.bmp

After the compilation, the following files will be generated:

kernel.img resource.img The kernel modules are located in the out-modules directory

Run your build:
Please refre to #Running the build

3.6 Build u-boot v2017.09

This section applies to the following operating systems:

ubuntu-focal-desktop-arm64 debian-bullseye-desktop-arm64 debian-bullseye-minimal-arm64 friendlycore-focal-arm64 ubuntu-noble-core-arm64 debian-bookworm-core-arm64 buildroot

Clone the repository to your local drive then build:

git clone https://github.com/friendlyarm/rkbin --single-branch --depth 1 -b friendlyelec
git clone https://github.com/friendlyarm/uboot-rockchip --single-branch --depth 1 -b nanopi4-v2017.09
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
cd uboot-rockchip/
./make.sh nanopi4

After the compilation, the following files will be generated:

uboot.img trust.img rk3399_loader_v1.24.126.bin (aka MiniLoaderAll.bin)

Run your build:
Please refre to #Running the build

3.7 Running the build

3.7.1 Install to target board
3.7.1.1 MBR partition

This section applies to the following operating systems:

lubuntu eflasher friendlydesktop-arm64 friendlycore-arm64

The MBR partitioning is only used by the Linux v4.4 kernel. You can check the partition layout by clicking on this link: partmap. To write an image file, you can use the dd command. For example, in the parameter.template file, "0x00014000@0x00014000(kernel)" specifies that the kernel partition starts at 0x00014000, which is equivalent to 81920 in decimal. Therefore, the dd command should be as follows:

dd if=kernel.img of=/dev/mmcblk0 seek=81920
3.7.1.2 GPT partition

This section applies to the following operating systems:

ubuntu-focal-desktop-arm64 debian-bookworm-core-arm64 debian-bullseye-desktop-arm64 debian-bullseye-minimal-arm64
friendlycore-focal-arm64 ubuntu-noble-core-arm64 friendlywrt21-kernel4 buildroot
friendlywrt21 friendlywrt21-docker friendlywrt23 friendlywrt23-docker

The OS uses GPT partitions by default which is using the Linux v4.19 and Linux v5.15 kernel, you can use the dd command, but be careful to choose the right output device:

  • The SD/TF Card device node: /dev/mmcblk0
  • The eMMC device node: /dev/mmcblk2

The following is an example of how to update the kernel to eMMC:
Use the 'parted' command to view the partition layout:

parted /dev/mmcblk2 print

Sample outputs:

Model: MMC BJTD4R (sd/mmc)
Disk /dev/mmcblk2: 31.3GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
 
Number  Start   End     Size    File system  Name      Flags
 1      8389kB  12.6MB  4194kB               uboot
 2      12.6MB  16.8MB  4194kB               trust
 3      16.8MB  21.0MB  4194kB               misc
 4      21.0MB  25.2MB  4194kB               dtbo
 5      25.2MB  41.9MB  16.8MB               resource
 6      41.9MB  83.9MB  41.9MB               kernel
 7      83.9MB  134MB   50.3MB               boot
 8      134MB   2500MB  2366MB  ext4         rootfs
 9      2500MB  31.3GB  28.8GB  ext4         userdata

as shown above, the resource partition is located at 5 and the kernel partition is located at 6. Use the dd command to write the resource.img and kernel.img files to these partitions, the commands are as follows:

dd if=resource.img of=/dev/mmcblk2p5 bs=1M
dd if=kernel.img of=/dev/mmcblk2p6 bs=1M

If you want to update u-boot:

dd if=uboot.img of=/dev/mmcblk2p1 bs=1M

To update new driver modules, copy the newly compiled driver modules to the appropriate directory under /lib/modules.

3.7.2 Packaging and creating an SD image

To create a new OS image file, you need to use the "sd-fuse" packaging tool.

"sd-fuse" is a collection of scripts that can be used to create bootable SD card images for FriendlyElec boards. Its main features include:

  • Creation of root filesystem images from a directory
  • Building of bootable SD card images
  • Simple compilation of kernel, U-Boot, and third-party drivers

Please click on the following link to find out more:

Kernel version Packaging Tool
linux v4.4.y sd-fuse
linux v4.19.y
sd-fuse_rk3399/kernel-4.19
linux v6.1.y
sd-fuse_rk3399/kernel-6.1.y
3.7.3 USB flashing

Note: kernel v4.4.y is not supported

3.7.3.1 Linux

Reboot the board and enter loader mode with the following command:

sudo reboot loader

To flash U-Boot and kernel using the "upgrade_tool_v2.17_for_linux" tool, please use the following command:

sudo upgrade_tool di -k kernel.img
sudo upgrade_tool di -re resource.img
sudo upgrade_tool di -u uboot.img
sudo upgrade_tool RD

Note: "upgrade_tool" is a command-line tool provided by Rockchip for Linux operating systems (Linux_Upgrade_Tool).

4 Build the code using scripts

4.1 Download scripts and image files

git clone https://github.com/friendlyarm/sd-fuse_rk3399.git -b kernel-4.19
cd sd-fuse_rk3399
wget http://112.124.9.243/dvdfiles/RK3399/images-for-eflasher/friendlycore-focal-arm64-images.tgz
tar xvzf friendlycore-focal-arm64-images.tgz

4.2 Compile the kernel

Download the kernel source code and compile it. the relevant image files in the friendlycore-focal-arm64 directory will be automatically updated, including the kernel modules in the file system:

git clone https://github.com/friendlyarm/kernel-rockchip --depth 1 -b nanopi4-v4.19.y kernel-rk3399
KERNEL_SRC=$PWD/kernel-rk3399 ./build-kernel.sh friendlycore-focal-arm64

4.3 Compile the kernel headers

git clone https://github.com/friendlyarm/kernel-rockchip --depth 1 -b nanopi4-v4.19.y kernel-rk3399
MK_HEADERS_DEB=1 BUILD_THIRD_PARTY_DRIVER=0 KERNEL_SRC=$PWD/kernel-rk3399 ./build-kernel.sh friendlycore-focal-arm64

4.4 Compile the uboot

Download the uboot source code and compile it. the relevant image files in the friendlycore-focal-arm64 directory will be automatically updated:

git clone https://github.com/friendlyarm/uboot-rockchip --depth 1 -b nanopi4-v2017.09
UBOOT_SRC=$PWD/uboot-rockchip ./build-uboot.sh friendlycore-focal-arm64

4.5 Generate new image

Repackage the image file in the friendlycore-focal-arm64 directory into sd card image:

./mk-sd-image.sh friendlycore-focal-arm64

After the command is completed, the image is in the out directory, you can use the dd command to make the SD boot card, for example:

dd if=out/rk3399-sd-friendlycore-focal-4.19-arm64-YYYYMMDD.img of=/dev/sdX bs=1M

5 Building AOSP from source

5.1 Hardware and Software Requirements

  • Your computer should have at least 16GB of RAM and 300GB of disk space. We recommend using a machine with 32GB of RAM and a large-capacity, high-speed SSD, and we do not recommend using virtual machines.
  • If you encounter compilation errors, they may be caused by problems with the compilation environment. We recommend using the following Docker container for compilation: docker-cross-compiler-novnc.

5.2 Compile Android10

5.2.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:"07_Source codes/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/07_Source codes/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.

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


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

5.3 Compile Android8.1

5.3.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
5.3.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
5.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 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

5.4 Compile Android7

5.4.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
5.4.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
5.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 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