Difference between revisions of "Template:RK3328-BuildFromSource"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
(updated by API)
 
(12 intermediate revisions by the same user not shown)
Line 11: Line 11:
 
tools/repo sync -c  --no-clone-bundle
 
tools/repo sync -c  --no-clone-bundle
 
</syntaxhighlight>
 
</syntaxhighlight>
=====FriendlyWrt 22.03.2=====
+
=====FriendlyWrt 23.05=====
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
mkdir friendlywrt22-rk3328
+
mkdir friendlywrt23-rk3328
cd friendlywrt22-rk3328
+
cd friendlywrt23-rk3328
 
git clone https://github.com/friendlyarm/repo --depth 1 tools
 
git clone https://github.com/friendlyarm/repo --depth 1 tools
tools/repo init -u https://github.com/friendlyarm/friendlywrt_manifests -b master-v22.03 \
+
tools/repo init -u https://github.com/friendlyarm/friendlywrt_manifests -b master-v23.05 \
 
         -m rk3328.xml --repo-url=https://github.com/friendlyarm/repo  --no-clone-bundle
 
         -m rk3328.xml --repo-url=https://github.com/friendlyarm/repo  --no-clone-bundle
 
tools/repo sync -c  --no-clone-bundle
 
tools/repo sync -c  --no-clone-bundle
Line 42: Line 42:
 
./build.sh emmc-img
 
./build.sh emmc-img
 
</syntaxhighlight>
 
</syntaxhighlight>
===Build u-boot only===
+
====Build u-boot only====
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
./build.sh uboot
 
./build.sh uboot
 
</syntaxhighlight>
 
</syntaxhighlight>
===Build kernel only===
+
====Build kernel only====
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
./build.sh kernel
 
./build.sh kernel
 
</syntaxhighlight>
 
</syntaxhighlight>
===Build friendlywrt only===
+
====Build friendlywrt only====
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
./build.sh friendlywrt
 
./build.sh friendlywrt
Line 60: Line 60:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===Build buildroot===
+
===Build Buildroot===
 
please refer to: [[Buildroot|Buildroot]]
 
please refer to: [[Buildroot|Buildroot]]
  
Line 80: Line 80:
 
| buildroot
 
| buildroot
 
| rowspan="2" | linux v4.19.y
 
| rowspan="2" | linux v4.19.y
| u-boot <br />v2017.09
+
| rowspan="9" | u-boot <br />v2017.09
| 11.3-aarch64
+
| rowspan="9" | 11.3-aarch64
 
| rowspan="2" | [https://github.com/friendlyarm/sd-fuse_rk3328/blob/kernel-4.19/prebuilt/parameter.template GPT]
 
| rowspan="2" | [https://github.com/friendlyarm/sd-fuse_rk3328/blob/kernel-4.19/prebuilt/parameter.template GPT]
 
| rowspan="2" | [https://github.com/friendlyarm/sd-fuse_rk3328/tree/kernel-4.19 sd-fuse]
 
| rowspan="2" | [https://github.com/friendlyarm/sd-fuse_rk3328/tree/kernel-4.19 sd-fuse]
 
| rowspan="2" | [https://github.com/friendlyarm/kernel-rockchip/tree/nanopi4-v4.19.y nanopi4-v4.19.y]
 
| rowspan="2" | [https://github.com/friendlyarm/kernel-rockchip/tree/nanopi4-v4.19.y nanopi4-v4.19.y]
 
| rowspan="2" | nanopi4_linux_defconfig
 
| rowspan="2" | nanopi4_linux_defconfig
| rowspan="8" | [https://github.com/friendlyarm/uboot-rockchip/tree/nanopi4-v2017.09 nanopi4-v2017.09]
+
| rowspan="9" | [https://github.com/friendlyarm/uboot-rockchip/tree/nanopi4-v2017.09 nanopi4-v2017.09]
| rowspan="8" | rk3288_defconfig
+
| rowspan="9" | nanopi_r2_defconfig
 
|-
 
|-
 
| friendlycore-focal-arm64
 
| friendlycore-focal-arm64
| u-boot <br />v2017.09
 
| 11.3-aarch64
 
 
|-
 
|-
| friendlycore-lite-focal-arm64
+
| openmediavault-arm64
| rowspan="6" | linux v5.15.y
+
| rowspan="7" | linux v6.1.y
| rowspan="6" | u-boot <br />v2017.09
+
| [https://github.com/friendlyarm/sd-fuse_rk3328/blob/kernel-6.1.y/prebuilt/parameter-ext4.txt GPT]
| rowspan="6" | 11.3-aarch64
+
| rowspan="7" | [https://github.com/friendlyarm/sd-fuse_rk3328/tree/kernel-6.1.y<br /> sd-fuse]
| rowspan="6" | [https://github.com/friendlyarm/sd-fuse_rk3328/blob/kernel-5.15.y/prebuilt/parameter.template GPT]
+
| rowspan="7" | [https://github.com/friendlyarm/kernel-rockchip/tree/nanopi-r2-v6.1.y nanopi-r2-v6.1.y]
| rowspan="6" | [https://github.com/friendlyarm/sd-fuse_rk3328/tree/kernel-5.15.y<br /> sd-fuse]
+
| rowspan="3" | nanopi-r2_linux_defconfig
| rowspan="6" | [https://github.com/friendlyarm/kernel-rockchip/tree/nanopi-r2-v5.15.y nanopi-r2-v5.15.y]
+
| rowspan="2" | nanopi-r2_linux_defconfig
+
 
|-
 
|-
| debian-bullseye-core-arm64
+
| ubuntu-noble-core-arm64
 +
| rowspan="6" | [https://github.com/friendlyarm/sd-fuse_rk3328/blob/kernel-6.1.y/prebuilt/parameter.template GPT]
 +
|-
 +
| debian-bookworm-core-arm64
 
|-
 
|-
 
| friendlywrt21
 
| friendlywrt21
| rowspan="4" | nanopi-r2_linux_defconfig<br /> friendlywrt.config
+
| rowspan="4" | nanopi-r2_linux_defconfig<br />+friendlywrt.config
 
|-
 
|-
 
| friendlywrt21-docker
 
| friendlywrt21-docker
 
|-
 
|-
| friendlywrt22
+
| friendlywrt23
 
|-
 
|-
| friendlywrt22-docker
+
| friendlywrt23-docker
 
|}
 
|}
 
* Kernel git repo:https://github.com/friendlyarm/kernel-rockchip
 
* Kernel git repo:https://github.com/friendlyarm/kernel-rockchip
Line 157: Line 156:
 
Run your build: <br>
 
Run your build: <br>
 
Please refre to [[#Running the build]]<br>
 
Please refre to [[#Running the build]]<br>
====Build kernel linux-v5.15.y====
+
====Build kernel linux-v6.1.y====
 
This section applies to the following operating systems:
 
This section applies to the following operating systems:
 
{| class="wikitable"  
 
{| class="wikitable"  
Line 163: Line 162:
 
| friendlywrt21
 
| friendlywrt21
 
| friendlywrt21-docker
 
| friendlywrt21-docker
| friendlywrt22
+
| friendlywrt23
| friendlywrt22-docker
+
| friendlywrt23-docker
| friendlycore-lite-focal-arm64
+
| ubuntu-noble-core-arm64
| debian-bullseye-core-arm64
+
| openmediavault-arm64
 +
| debian-bookworm-core-arm64
 
|}
 
|}
 
Clone the repository to your local drive then build:
 
Clone the repository to your local drive then build:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://github.com/friendlyarm/kernel-rockchip --single-branch --depth 1 -b nanopi-r2-v5.15.y kernel-rockchip
+
git clone https://github.com/friendlyarm/kernel-rockchip --single-branch --depth 1 -b nanopi-r2-v6.1.y kernel-rockchip
 
cd kernel-rockchip
 
cd kernel-rockchip
 
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
 
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
 
touch .scmversion
 
touch .scmversion
# Compile the kernel
+
# Configuring the Kernel
 +
# Load default configuration
 
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi-r2_linux_defconfig
 
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi-r2_linux_defconfig
# make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 menuconfig  # Modifying the configuration
+
# Optionally, load configuration for FriendlyWrt
 +
# make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi-r2_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)
 
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 -j$(nproc)
# Compile the kernel modules
+
# Start building kernel modules
 
mkdir -p out-modules && rm -rf out-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 -j$(nproc)
Line 188: Line 193:
 
Pack the kernel.img and resource.img:
 
Pack the kernel.img and resource.img:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
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-6.1.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-6.1.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-6.1.y/prebuilt/boot/logo.bmp
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3328/kernel-5.15.y/prebuilt/boot/logo_kernel.bmp
+
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3328/kernel-6.1.y/prebuilt/boot/logo_kernel.bmp
 
./mkkrnlimg arch/arm64/boot/Image kernel.img
 
./mkkrnlimg arch/arm64/boot/Image kernel.img
 
./resource_tool --dtbname arch/arm64/boot/dts/rockchip/rk3328-nanopi*-rev*.dtb logo.bmp logo_kernel.bmp
 
./resource_tool --dtbname arch/arm64/boot/dts/rockchip/rk3328-nanopi*-rev*.dtb logo.bmp logo_kernel.bmp
Line 212: Line 217:
 
| friendlywrt21
 
| friendlywrt21
 
| friendlywrt21-docker
 
| friendlywrt21-docker
| friendlywrt22
+
| friendlywrt23
| friendlywrt22-docker
+
| friendlywrt23-docker
| friendlycore-lite-focal-arm64
+
| ubuntu-noble-core-arm64
| debian-bullseye-core-arm64
+
| openmediavault-arm64
 +
| debian-bookworm-core-arm64
 
|}
 
|}
 
Clone the repository to your local drive then build:
 
Clone the repository to your local drive then build:
Line 235: Line 241:
 
Please refre to [[#Running the build]]<br>
 
Please refre to [[#Running the build]]<br>
  
====Running the build===
+
====Running the build====
 
=====Install to target board=====
 
=====Install to target board=====
======GPT partition======
 
 
This section applies to the following operating systems:
 
This section applies to the following operating systems:
 
{| class="wikitable"  
 
{| class="wikitable"  
Line 245: Line 250:
 
| friendlywrt21
 
| friendlywrt21
 
| friendlywrt21-docker
 
| friendlywrt21-docker
| friendlywrt22
+
| friendlywrt23
| friendlywrt22-docker
+
| friendlywrt23-docker
| friendlycore-lite-focal-arm64
+
| ubuntu-noble-core-arm64
| debian-bullseye-core-arm64
+
| openmediavault-arm64
 +
| debian-bookworm-core-arm64
 
|}
 
|}
 
RK3328 uses GPT partitions by default, you can use the dd command, but be careful to choose the right output device:
 
RK3328 uses GPT partitions by default, you can use the dd command, but be careful to choose the right output device:
Line 284: Line 290:
 
If you want to update u-boot:
 
If you want to update u-boot:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
dd if=boot.img of=/dev/mmcblk2p1 bs=1M
+
dd if=uboot.img of=/dev/mmcblk2p1 bs=1M
 
</syntaxhighlight>
 
</syntaxhighlight>
 
To update new driver modules, copy the newly compiled driver modules to the appropriate directory under /lib/modules.
 
To update new driver modules, copy the newly compiled driver modules to the appropriate directory under /lib/modules.
Line 304: Line 310:
 
| [https://github.com/friendlyarm/sd-fuse_rk3328/tree/kernel-4.19 sd-fuse_rk3328/kernel-4.19]
 
| [https://github.com/friendlyarm/sd-fuse_rk3328/tree/kernel-4.19 sd-fuse_rk3328/kernel-4.19]
 
|-
 
|-
| linux v5.15.y
+
| linux v6.1.y
| [https://github.com/friendlyarm/sd-fuse_rk3328/tree/kernel-5.15.y sd-fuse_rk3328/kernel-5.15.y]
+
| [https://github.com/friendlyarm/sd-fuse_rk3328/tree/kernel-6.1.y sd-fuse_rk3328/kernel-6.1.y]
 
|}
 
|}
 
=====USB flashing=====
 
=====USB flashing=====
 
======Linux======
 
======Linux======
To flash U-Boot and kernel using the "upgrade_tool" tool, please use the following command:
+
Reboot the board and enter loader mode with the following command:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
sudo upgrade_tool ul MiniLoaderAll.bin
+
sudo reboot loader
sudo upgrade_tool di -p parameter.txt
+
</syntaxhighlight>
sudo upgrade_tool di uboot uboot.img
+
To flash U-Boot and kernel using the "upgrade_tool_v2.17_for_linux" tool, please use the following command:
sudo upgrade_tool di trust trust.img
+
<syntaxhighlight lang="bash">
sudo upgrade_tool di resource resource.img
+
sudo upgrade_tool di -k kernel.img
sudo upgrade_tool di kernel kernel.img
+
sudo upgrade_tool di -re resource.img
 +
sudo upgrade_tool di -u uboot.img
 
sudo upgrade_tool RD
 
sudo upgrade_tool RD
 
</syntaxhighlight>
 
</syntaxhighlight>
 
Note: "upgrade_tool" is a command-line tool provided by Rockchip for Linux operating systems (Linux_Upgrade_Tool).
 
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_rk3328.git -b kernel-4.19
 +
cd sd-fuse_rk3328
 +
wget http://112.124.9.243/dvdfiles/rk3328/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-rk3328
 +
KERNEL_SRC=$PWD/kernel-rk3328 ./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-rk3328
 +
MK_HEADERS_DEB=1 BUILD_THIRD_PARTY_DRIVER=0 KERNEL_SRC=$PWD/kernel-rk3328 ./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/rk3328-sd-friendlycore-focal-4.19-arm64-YYYYMMDD.img of=/dev/sdX bs=1M
 +
</syntaxhighlight>

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-rk3328
cd friendlywrt21-rk3328
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 rk3328.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-rk3328
cd friendlywrt23-rk3328
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 rk3328.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 rk3328.mk  # or rk3328-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
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 nanopi_r2_defconfig
friendlycore-focal-arm64
openmediavault-arm64 linux v6.1.y GPT
sd-fuse
nanopi-r2-v6.1.y nanopi-r2_linux_defconfig
ubuntu-noble-core-arm64 GPT
debian-bookworm-core-arm64
friendlywrt21 nanopi-r2_linux_defconfig
+friendlywrt.config
friendlywrt21-docker
friendlywrt23
friendlywrt23-docker

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

3.3 Build kernel linux-v6.1.y

This section applies to the following operating systems:

friendlywrt21 friendlywrt21-docker friendlywrt23 friendlywrt23-docker ubuntu-noble-core-arm64 openmediavault-arm64 debian-bookworm-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-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 nanopi-r2_linux_defconfig
# Optionally, load configuration for FriendlyWrt
# make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi-r2_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_rk3328/kernel-6.1.y/tools/mkkrnlimg && chmod 755 mkkrnlimg
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3328/kernel-6.1.y/tools/resource_tool && chmod 755 resource_tool
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3328/kernel-6.1.y/prebuilt/boot/logo.bmp
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3328/kernel-6.1.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

3.4 Build u-boot v2017.09

This section applies to the following operating systems:

buildroot friendlycore-focal-arm64 friendlywrt21 friendlywrt21-docker friendlywrt23 friendlywrt23-docker ubuntu-noble-core-arm64 openmediavault-arm64 debian-bookworm-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

3.5 Running the build

3.5.1 Install to target board

This section applies to the following operating systems:

buildroot friendlycore-focal-arm64 friendlywrt21 friendlywrt21-docker friendlywrt23 friendlywrt23-docker ubuntu-noble-core-arm64 openmediavault-arm64 debian-bookworm-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=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.5.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 v6.1.y sd-fuse_rk3328/kernel-6.1.y
3.5.3 USB flashing
3.5.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_rk3328.git -b kernel-4.19
cd sd-fuse_rk3328
wget http://112.124.9.243/dvdfiles/rk3328/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-rk3328
KERNEL_SRC=$PWD/kernel-rk3328 ./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-rk3328
MK_HEADERS_DEB=1 BUILD_THIRD_PARTY_DRIVER=0 KERNEL_SRC=$PWD/kernel-rk3328 ./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/rk3328-sd-friendlycore-focal-4.19-arm64-YYYYMMDD.img of=/dev/sdX bs=1M