Template:RK3328-BuildFromSource
Contents
1 Build u-boot and kernel
1.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 v4.19.y | u-boot v2017.09 |
11.3-aarch64 | GPT | sd-fuse | nanopi4-v4.19.y | nanopi4_linux_defconfig | nanopi4-v2017.09 | rk3288_defconfig |
friendlycore-focal-arm64 | u-boot v2017.09 |
11.3-aarch64 | |||||||
friendlycore-lite-focal-arm64 | linux v5.15.y | u-boot v2017.09 |
11.3-aarch64 | GPT | sd-fuse |
nanopi-r2-v5.15.y | nanopi-r2_linux_defconfig | ||
debian-bullseye-core-arm64 | |||||||||
friendlywrt21 | nanopi-r2_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.
1.2 Build kernel linux-v4.19.y
This section applies to the following operating systems:
buildroot | friendlycore-focal-arm64 |
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
1.3 Build kernel linux-v5.15.y
This section applies to the following operating systems:
friendlywrt21 | friendlywrt21-docker | friendlywrt22 | friendlywrt22-docker | friendlycore-lite-focal-arm64 | debian-bullseye-core-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-v5.15.y kernel-rockchip cd kernel-rockchip export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH touch .scmversion # Compile the kernel make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi-r2_linux_defconfig # make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 menuconfig # Modifying the configuration make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 -j$(nproc) # Compile the 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_rk3328/kernel-5.15.y/tools/mkkrnlimg && chmod 755 mkkrnlimg wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3328/kernel-5.15.y/tools/resource_tool && chmod 755 resource_tool wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3328/kernel-5.15.y/prebuilt/boot/logo.bmp wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3328/kernel-5.15.y/prebuilt/boot/logo_kernel.bmp ./mkkrnlimg arch/arm64/boot/Image kernel.img ./resource_tool --dtbname arch/arm64/boot/dts/rockchip/rk3328-nanopi*-rev*.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
1.4 Build u-boot v2017.09
This section applies to the following operating systems:
buildroot | friendlycore-focal-arm64 | friendlywrt21 | friendlywrt21-docker | friendlywrt22 | friendlywrt22-docker | friendlycore-lite-focal-arm64 | debian-bullseye-core-arm64 |
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 nanopi_r2
After the compilation, the following files will be generated:
uboot.img | trust.img | rk3328_loader_v1.16.250.bin (aka MiniLoaderAll.bin) |
Run your build:
Please refre to #Running the build
2 =Running the build
2.1 Install to target board
2.1.1 GPT partition
This section applies to the following operating systems:
buildroot | friendlycore-focal-arm64 | friendlywrt21 | friendlywrt21-docker | friendlywrt22 | friendlywrt22-docker | friendlycore-lite-focal-arm64 | debian-bullseye-core-arm64 |
RK3328 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
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=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.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.19.y | sd-fuse_rk3328/kernel-4.19 |
linux v5.15.y | sd-fuse_rk3328/kernel-5.15.y |
2.3 USB flashing
2.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 trust trust.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).