Template:RK3568-BuildFromSource
1 Build Openwrt/Friendlywrt
1.1 Download Code
Two versions are available, please choose as required:
1.1.1 FriendlyWrt 21.02
mkdir friendlywrt21-rk3568 cd friendlywrt21-rk3568 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 rk3568.xml --repo-url=https://github.com/friendlyarm/repo --no-clone-bundle tools/repo sync -c --no-clone-bundle
1.1.2 FriendlyWrt 22.03.2
mkdir friendlywrt22-rk3568 cd friendlywrt22-rk3568 git clone https://github.com/friendlyarm/repo --depth 1 tools tools/repo init -u https://github.com/friendlyarm/friendlywrt_manifests -b master-v22.03 \ -m rk3568.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 rk3568.mk # or rk3568-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 Other Linux
2.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 |
---|---|---|---|---|---|---|---|---|---|
buildroot | linux v5.10.y | u-boot v2017.09 |
11.3-aarch64 | GPT | sd-fuse | nanopi5-v5.10.y_opt | nanopi5_linux_defconfig | nanopi5-v2017.09 | rk3568_defconfig |
friendlycore-focal-arm64 | |||||||||
debian-bullseye-core-arm64 | |||||||||
debian-bullseye-desktop-arm64 | |||||||||
debian-bullseye-minimal-arm64 | |||||||||
debian-buster-desktop-arm64 | |||||||||
friendlywrt21 | nanopi5_linux_defconfig friendlywrt.config | ||||||||
friendlywrt21-docker | |||||||||
friendlywrt22 | |||||||||
friendlywrt22-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.
2.2 Build kernel linux-v5.10.y
Clone the repository to your local drive then build:
git clone https://github.com/friendlyarm/kernel-rockchip --single-branch --depth 1 -b nanopi5-v5.10.y_opt 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 nanopi5_linux_defconfig # Optionally, load configuration for FriendlyWrt # make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi5_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 nanopi5-images -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)
The generated files:
kernel.img | resource.img | |
The kernel modules are located in the out-modules directory |
Run your build:
Please refre to #Running the build
2.3 Build u-boot v2017.09
Clone the repository to your local drive then build:
git clone https://github.com/friendlyarm/rkbin --single-branch --depth 1 -b nanopi5 git clone https://github.com/friendlyarm/uboot-rockchip --single-branch --depth 1 -b nanopi5-v2017.09 export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH cd uboot-rockchip/ ./make.sh nanopi5
After the compilation, the following files will be generated:
uboot.img | rk356x_spl_loader_v1.15.112.bin (aka MiniLoaderAll.bin) |
Run your build:
Please refre to #Running the build
2.4 Running the build
2.4.1 Install to target board
RK3568 uses GPT partitions by default, 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
Use the 'parted' command to view the partition layout:
parted /dev/mmcblk2 print
Sample outputs:
Model: MMC A3A551 (sd/mmc) Disk /dev/mmcblk2: 31.0GB 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 misc 3 16.8MB 21.0MB 4194kB dtbo 4 21.0MB 37.7MB 16.8MB resource 5 37.7MB 79.7MB 41.9MB kernel 6 79.7MB 113MB 33.6MB boot 7 113MB 147MB 33.6MB recovery 8 147MB 31.0GB 30.9GB ext4 rootfs
as shown above, the resource partition is located at 4 and the kernel partition is located at 5. 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/mmcblk2p4 bs=1M dd if=kernel.img of=/dev/mmcblk2p5 bs=1M
If you want to update u-boot:
dd if=boot.img of=/dev/mmcblk2p1 bs=1M
To update new driver modules, copy the newly compiled driver modules to the appropriate directory under /lib/modules.
2.4.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 v5.10.y | sd-fuse_rk3568 |
2.4.3 USB flashing
2.4.3.1 Linux
To flash U-Boot and kernel using the "upgrade_tool" tool, please use the following command:
sudo upgrade_tool ul MiniLoaderAll.bin sudo upgrade_tool di -p parameter.txt sudo upgrade_tool di uboot uboot.img sudo upgrade_tool di resource resource.img sudo upgrade_tool di kernel kernel.img sudo upgrade_tool RD
Note: "upgrade_tool" is a command-line tool provided by Rockchip for Linux operating systems (Linux_Upgrade_Tool).
3 Build the code using scripts
3.1 Download scripts and image files
git clone https://github.com/friendlyarm/sd-fuse_rk3568.git --single-branch -b master cd sd-fuse_rk3568 tar xvzf /path/to/netdrive/03_Partition\ image\ files/friendlycore-focal-arm64-images.tgz
3.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 nanopi5-v5.10.y_opt kernel-rk3568 KERNEL_SRC=$PWD/kernel-rk3568 ./build-kernel.sh friendlycore-focal-arm64
3.3 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 nanopi5-v2017.09 UBOOT_SRC=$PWD/uboot-rockchip ./build-uboot.sh friendlycore-focal-arm64
3.4 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/rk3568-sd-friendlycore-focal-5.10-arm64-YYYYMMDD.img of=/dev/sdX bs=1M ===Building AOSP from source=== ====Download source from the netdrive==== Netdisk URL: [http://download.friendlyelec.com/{{#replace:{{#replace:{{BASEPAGENAME}}| |}}|/zh|}} Click here]<br /> File location on netdisk:"07_Source codes/rk35xx-android12-xxxxxxx-YYYYMMDD.tgz" (YYYYMMDD represents the date of the package, and xxxxxxx represents the final commit-id)<br /> Unzip and fetch updates: <syntaxhighlight lang="bash"> tar xzf '/path/to/netdisk/07_Source codes/rk35xx-android12-xxxxxxx-YYYYMMDD.tgz' cd rk35xx-android12 git pull
3.5 Tablet profile build
echo "ROCKCHIP_DEVICE_DIR := device/rockchip/rk356x/nanopi5" > .rockchip_device.mk # export INSTALL_GAPPS_FOR_TESTING=yes # include google apps . setenv.sh ./build.sh -FMu
3.6 TV profile build
echo "ROCKCHIP_DEVICE_DIR := device/rockchip/rk356x/nanopi5_box" > .rockchip_device.mk # export INSTALL_GAPPS_FOR_TESTING=yes # include google apps . setenv.sh ./build.sh -FMu
3.7 Running your AOSP build
After the Android compilation is completed, the image file will be stored in the rockdev/Image-aosp_nanopi3 subdirectory of the Android source code directory.
3.7.1 USB Flashing
Use the rockchip tool to flash the following file: rockdev/Image-aosp_nanopi3/update.img
3.7.2 SD-to-eMMC Flashing
Refer to the following steps:
1) Insert the SD card of the eflasher system into the host;
2) Copy the files in the rockdev/Image-aosp_nanopi3 directory to the android12 or androidtv directory in the FRIENDLYARM partition of the SD card:
sudo cp -af parameter.txt config.cfg MiniLoaderAll.bin uboot.img \ dtbo.img vbmeta.img boot.img recovery.img \ misc.img pcba_small_misc.img pcba_whole_misc.img \ baseparameter.img super.img /media/$USER/FriendlyARM/android12
3) Insert the SD card into {{{1}}} and re-flash;
3.8 Pack the new SD Image
git clone https://github.com/friendlyarm/sd-fuse_rk3568.git SDFUSE=$PWD/sd-fuse_rk3568 mkdir $SDFUSE/android12 cd /path/to/rk35xx-android12/rockdev/Image-aosp_nanopi3 cp -af parameter.txt config.cfg MiniLoaderAll.bin uboot.img \ dtbo.img vbmeta.img boot.img recovery.img \ misc.img pcba_small_misc.img pcba_whole_misc.img \ baseparameter.img super.img $SDFUSE/android12 cd $SDFUSE/ ./mk-sd-image.sh android12 tar xvzf /path/to/netdrive/03_Partition\ image\ files/emmc-flasher-images.tgz ./mk-emmc-image.sh android12
For more information, please refer to #Packaging and creating an SD image