Difference between revisions of "APITestPage"

From FriendlyELEC WiKi
Jump to: navigation, search
Line 1: Line 1:
===How to compile custom kernel and u-boot===
+
===Linux系统编译===
====Kernel and u-boot versions for each OS====
+
====各个OS对应的内核与u-boot版本====
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
! Operating System
+
! 操作系统
! Kernel Version
+
! 内核版本
! U-boot version
+
! uboot版本
! Cross-compiler
+
! 交叉编译器
! Partition type
+
! 分区类型
! Build toolset
+
! 构建工具集
! Kernel code branch
+
! 内核代码分支
! Kernel configuration
+
! 内核配置
! U-boot code branch
+
! uboot代码分支
! u-boot configuration
+
! uboot配置
|-
+
| 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
+
|-
+
| friendlycore-arm64
+
|-
+
| friendlydesktop-arm64
+
|-
+
| eflasher
+
 
|-
 
|-
 
| buildroot
 
| buildroot
| rowspan="8" | linux v4.19.y
+
| rowspan="2" | linux v4.19.y
| rowspan="8" | u-boot <br />v2017.09
+
| rowspan="7" | u-boot <br />v2017.09
| rowspan="8" | 11.3-aarch64
+
| rowspan="7" | 11.3-aarch64
| rowspan="8" | [https://github.com/friendlyarm/sd-fuse_rk3399/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="8" | [https://github.com/friendlyarm/sd-fuse_rk3399/tree/kernel-4.19 sd-fuse]
+
| rowspan="2" | [https://github.com/friendlyarm/sd-fuse_rk3328/tree/kernel-4.19 sd-fuse]
| rowspan="8" | [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="7" | nanopi4_linux_defconfig
+
| rowspan="2" | nanopi4_linux_defconfig
| rowspan="8" | [https://github.com/friendlyarm/uboot-rockchip/tree/nanopi4-v2017.09 nanopi4-v2017.09]
+
| rowspan="7" | [https://github.com/friendlyarm/uboot-rockchip/tree/nanopi4-v2017.09 nanopi4-v2017.09]
| rowspan="8" | rk3399_defconfig
+
| rowspan="7" | rk3288_defconfig
|-
+
| debian-buster-desktop-arm64
+
|-
+
| debian-bullseye-core-arm64
+
|-
+
| debian-bullseye-desktop-arm64
+
|-
+
| debian-bullseye-minimal-arm64
+
 
|-
 
|-
 
| friendlycore-focal-arm64
 
| friendlycore-focal-arm64
 
|-
 
|-
| friendlycore-lite-focal-kernel4-arm64
+
| friendlycore-lite-focal-arm64
|-
+
| friendlywrt21-kernel4
+
| nanopi4_linux_defconfig<br />+friendlywrt.config
+
|-
+
| friendlycore-lite-focal-kernel5-arm64
+
 
| rowspan="5" | linux v5.15.y
 
| rowspan="5" | linux v5.15.y
| rowspan="5" | u-boot <br />v2017.09
+
| rowspan="5" | [https://github.com/friendlyarm/sd-fuse_rk3328/blob/kernel-5.15.y/prebuilt/parameter.template GPT]
| rowspan="5" | 11.3-aarch64
+
| rowspan="5" | [https://github.com/friendlyarm/sd-fuse_rk3328/tree/kernel-5.15.y<br /> sd-fuse]
| rowspan="5" | [https://github.com/friendlyarm/sd-fuse_rk3399/blob/kernel-5.15.y/prebuilt/parameter.template GPT]
+
| rowspan="5" | [https://github.com/friendlyarm/sd-fuse_rk3399/tree/kernel-5.15.y<br /> sd-fuse]
+
 
| rowspan="5" | [https://github.com/friendlyarm/kernel-rockchip/tree/nanopi-r2-v5.15.y nanopi-r2-v5.15.y]
 
| rowspan="5" | [https://github.com/friendlyarm/kernel-rockchip/tree/nanopi-r2-v5.15.y nanopi-r2-v5.15.y]
| nanopi4_linux_defconfig
+
| nanopi-r2_linux_defconfig
| rowspan="5" | [https://github.com/friendlyarm/uboot-rockchip/tree/nanopi4-v2017.09<br /> nanopi4-v2017.09]
+
| rowspan="5" | rk3399_defconfig
+
 
|-
 
|-
 
| friendlywrt21
 
| friendlywrt21
| rowspan="4" | nanopi4_linux_defconfig<br />+friendlywrt.config
+
| rowspan="4" | nanopi-r2_linux_defconfig<br />+friendlywrt.config
 
|-
 
|-
 
| friendlywrt21-docker
 
| friendlywrt21-docker
Line 77: Line 43:
 
| friendlywrt22-docker
 
| friendlywrt22-docker
 
|}
 
|}
* Kernel source code repository:https://github.com/friendlyarm/kernel-rockchip
+
* 内核源代码仓库地址:https://github.com/friendlyarm/kernel-rockchip
* u-boot source code repository:https://github.com/friendlyarm/uboot-rockchip
+
* u-boot源代码仓库地址:https://github.com/friendlyarm/uboot-rockchip
* The cross-compile toolchain is stored in the following path: /opt/FriendlyARM/toolchain/. Before using it, it needs to be exported to the PATH environment variable. For example, if you need to use version 11.3-aarch64 of the compiler, use the following command:
+
* 交叉编译工具链存放在如下路径: /opt/FriendlyARM/toolchain/,使用前需导出到PATH环境变量,例如需要使用11.3-aarch64版本的编译器,使用如下命令:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
 
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
 
</syntaxhighlight>
 
</syntaxhighlight>
* The SD-Fuse build toolset can be used to quickly compile the kernel and u-boot, as well as repackaging SD card image and SD-to-eMMC image.
+
* sd-fuse构建工具集可以用于快速编译kernel和uboot、重新打包sd卡固件与卡刷固件等
* Click on MBR and GPT in the table to view the partition layout (configuration file) for each system.
+
* 点击表格中的MBR与GPT可查看各系统的分区布局(配置文件)
  
====Compile kernel linux-v4.4.y====
+
====编译内核linux-v4.4.y====
This section applies to the following operating systems:
+
本节内容适用于如下OS:
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
Line 95: Line 61:
 
| friendlycore-arm64
 
| friendlycore-arm64
 
|}
 
|}
Download the source code and compile as follows:
+
下载源代码并编译:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git clone https://github.com/friendlyarm/kernel-rockchip --single-branch --depth 1 -b nanopi4-linux-v4.4.y kernel-rockchip
 
git clone https://github.com/friendlyarm/kernel-rockchip --single-branch --depth 1 -b nanopi4-linux-v4.4.y kernel-rockchip
Line 101: Line 67:
 
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
 
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
 
touch .scmversion
 
touch .scmversion
# Compile the kernel
+
# 编译内核
 
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig
 
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- menuconfig  # Modifying the configuration
+
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- menuconfig  # 启动配置界面
 
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4-images -j$(nproc)
 
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4-images -j$(nproc)
# Compile the kernel modules
+
# 编译驱动模块
 
mkdir -p out-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 -j$(nproc)
Line 114: Line 80:
 
(cd $PWD/out-modules && find . -name \*.ko | xargs aarch64-linux-strip --strip-unneeded)
 
(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"  
 
{| class="wikitable"  
 
|-
 
|-
 
| kernel.img
 
| kernel.img
 
| resource.img
 
| resource.img
| The kernel modules are located in the out-modules directory
+
| 驱动模块位于out-modules目录
 
|}
 
|}
Installing the kernel: <br>
+
安装内核: <br>
Please click on [[#Download u-boot and the kernel to the target board]]<br>
+
请参考 [[#下载uboot与内核到目标板]]<br>
  
====Compile u-boot v2014.10====
+
====编译u-boot v2014.10====
This section applies to the following operating systems:
+
本节内容适用于如下OS:
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
Line 133: Line 99:
 
| friendlycore-arm64
 
| friendlycore-arm64
 
|}
 
|}
Download the source code and compile as follows:
+
下载源代码并编译:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git clone https://github.com/friendlyarm/uboot-rockchip --single-branch --depth 1 -b nanopi4-v2014.10_oreo
 
git clone https://github.com/friendlyarm/uboot-rockchip --single-branch --depth 1 -b nanopi4-v2014.10_oreo
Line 141: Line 107:
 
make CROSS_COMPILE=aarch64-linux-
 
make CROSS_COMPILE=aarch64-linux-
 
</syntaxhighlight>
 
</syntaxhighlight>
After the compilation, the following files will be generated:
+
编译完成后会生成如下文件:
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
Line 148: Line 114:
 
| rk3399_loader_v1.22.119.bin
 
| rk3399_loader_v1.22.119.bin
 
|}
 
|}
Installing the u-boot: <br>
+
安装u-boot: <br />
Please click on [[#Download u-boot and the kernel to the target board]]<br>
+
请参考 [[#下载uboot与内核到目标板]]<br>
  
====Compile kernel linux-v4.19.y====
+
====编译内核linux-v4.19.y====
This section applies to the following operating systems:
+
本节内容适用于如下OS:
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
Line 165: Line 131:
 
| buildroot
 
| buildroot
 
|}
 
|}
Download the source code and compile as follows:
+
下载源代码并编译:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git clone https://github.com/friendlyarm/kernel-rockchip --single-branch --depth 1 -b nanopi4-v4.19.y kernel-rockchip
 
git clone https://github.com/friendlyarm/kernel-rockchip --single-branch --depth 1 -b nanopi4-v4.19.y kernel-rockchip
Line 171: Line 137:
 
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
+
# 编译内核
 
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig
 
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- menuconfig  # Modifying the configuration
+
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- menuconfig  # 启动配置界面
 
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4-images -j$(nproc)
 
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4-images -j$(nproc)
# Compile the kernel modules
+
# 编译驱动模块
 
mkdir -p out-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 -j$(nproc)
Line 184: Line 150:
 
(cd $PWD/out-modules && find . -name \*.ko | xargs aarch64-linux-strip --strip-unneeded)
 
(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"  
 
{| class="wikitable"  
 
|-
 
|-
 
| kernel.img
 
| kernel.img
 
| resource.img
 
| resource.img
| The kernel modules are located in the out-modules directory
+
| 驱动模块位于out-modules目录
 
|}
 
|}
Installing the kernel: <br>
+
安装内核: <br>
Please click on [[#Download u-boot and the kernel to the target board]]<br>
+
请参考 [[#下载uboot与内核到目标板]]<br>
====Compile kernel linux-v5.15.y====
+
====编译内核linux-v5.15.y====
This section applies to the following operating systems:
+
本节内容适用于如下OS:
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
Line 203: Line 169:
 
| friendlycore-lite-focal-kernel5-arm64
 
| friendlycore-lite-focal-kernel5-arm64
 
|}
 
|}
Download the source code and compile as follows:
+
下载源代码并编译:
 
<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-v5.15.y kernel-rockchip
Line 209: Line 175:
 
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
+
# 编译内核
 
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi4_linux_defconfig
 
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi4_linux_defconfig
# make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 menuconfig  # Modifying the configuration
+
# make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 menuconfig  # 启动配置界面
 
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 -j$(nproc)
 
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 -j$(nproc)
# Compile the 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 235: Line 201:
 
./resource_tool --dtbname kernel-dtbs/*.dtb logo.bmp logo_kernel.bmp
 
./resource_tool --dtbname kernel-dtbs/*.dtb logo.bmp logo_kernel.bmp
 
</syntaxhighlight>
 
</syntaxhighlight>
After the compilation, the following files will be generated:
+
完成后会得到如下文件:
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
 
| kernel.img
 
| kernel.img
 
| resource.img
 
| resource.img
| The kernel modules are located in the out-modules directory
+
| 驱动模块位于out-modules目录
 
|}
 
|}
Installing the kernel: <br>
+
安装内核: <br>
Please click on [[#Download u-boot and the kernel to the target board]]<br>
+
请参考 [[#下载uboot与内核到目标板]]<br>
====Compile u-boot v2017.09====
+
====编译u-boot v2017.09====
This section applies to the following operating systems:
+
本节内容适用于如下OS:
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
Line 258: Line 224:
 
| buildroot
 
| buildroot
 
|}
 
|}
Download the source code and compile as follows:
+
下载源代码并编译:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git clone https://github.com/friendlyarm/rkbin --single-branch --depth 1 -b friendlyelec
 
git clone https://github.com/friendlyarm/rkbin --single-branch --depth 1 -b friendlyelec
Line 266: Line 232:
 
./make.sh nanopi4
 
./make.sh nanopi4
 
</syntaxhighlight>
 
</syntaxhighlight>
After the compilation, the following files will be generated:
+
编译完成后会生成如下文件:
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
Line 273: Line 239:
 
| rk3399_loader_v1.24.126.bin
 
| rk3399_loader_v1.24.126.bin
 
|}
 
|}
Installing the u-boot: <br>
+
安装u-boot: <br />
Please click on [[#Download u-boot and the kernel to the target board]]<br>
+
请参考 [[#下载uboot与内核到目标板]]<br>
  
====Download u-boot and the kernel to the target board====
+
====下载uboot与内核到目标板====
=====Download to the installed system=====
+
=====下载至已安装的系统=====
======MBR partition======
+
======MBR分区======
This section applies to the following operating systems:
+
本节内容适用于如下OS:
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
Line 287: Line 253:
 
| friendlycore-arm64
 
| friendlycore-arm64
 
|}
 
|}
Currently, only the Linux v4.4 kernel uses MBR partitioning. Please refer to the partmap file in this link: [https://github.com/friendlyarm/sd-fuse_rk3399/blob/kernel-4.19/prebuilt/parameter.template partmap],calculate the offset addresses of each partition, and use the dd command to write them. For example, in the contents of the parameter.template file, "0x00014000@0x00014000(kernel)" indicates that the position of kernel.img is at 0x00014000, which converted to decimal is 81920, so the dd command would be as follows:
+
目前只有linux v4.4内核使用mbr分区,需要参考此链接的[https://github.com/friendlyarm/sd-fuse_rk3399/blob/kernel-4.19/prebuilt/parameter.template partmap文件],计算各分区的偏移地址,用dd命令进行写入,例如parameter.template文件内容中"0x00014000@0x00014000(kernel)"表示kernel.img的位置位于0x00014000,转换成10进制就是81920, 所以dd命令如下:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
dd if=kernel.img of=/dev/mmcblk0 seek=81920
 
dd if=kernel.img of=/dev/mmcblk0 seek=81920
 
</syntaxhighlight>
 
</syntaxhighlight>
  
======GPT partition======
+
======GPT分区======
This section applies to the following operating systems:
+
本节内容适用于如下OS:
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
Line 311: Line 277:
 
| friendlywrt22-docker
 
| friendlywrt22-docker
 
|}
 
|}
Systems using the Linux v4.19 and Linux v5.15 kernels use GPT partitioning by default. Just use the dd command to write the image file to the corresponding partition.
+
linux v4.19内核和linux v5.15内核的系统默认使用GPT分区, 更新GPT分区比较简单,直接dd image文件至相应的分区即可(注意image的大小不要越界),在操作时需要注意存储设备的节点:
* The SD/TF Card device node: /dev/mmcblk0 <br />
+
* SD/TF Card设备节点为 /dev/mmcblk0 <br />
* The eMMC device node: /dev/mmcblk2 <br />
+
* eMMC设备节点为 /dev/mmcblk2 <br />
The following is an example of how to update the kernel to eMMC:<br />
+
下面将演示如何将内核更新到eMMC:<br />
Use the 'parted' command to view the partition layout:
+
使用parted命令查看分区布局:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
parted /dev/mmcblk2 print
 
parted /dev/mmcblk2 print
 
</syntaxhighlight>
 
</syntaxhighlight>
You should get output similar to the following:
+
得到如下输出:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
Model: MMC A3A551 (sd/mmc)
 
Model: MMC A3A551 (sd/mmc)
Line 337: Line 303:
 
  8      147MB  31.0GB  30.9GB  ext4        rootfs
 
  8      147MB  31.0GB  30.9GB  ext4        rootfs
 
</syntaxhighlight>
 
</syntaxhighlight>
s 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, respectively. The commands are as follows:
+
可以看到resource分区位置为4, kernel分区位置为5,用dd命令分别写入resource.img与kernel.img到这两个分区即可, 命令如下:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
dd if=resource.img of=/dev/mmcblk2p4 bs=1M
 
dd if=resource.img of=/dev/mmcblk2p4 bs=1M
 
dd if=kernel.img of=/dev/mmcblk2p5 bs=1M
 
dd if=kernel.img of=/dev/mmcblk2p5 bs=1M
 
</syntaxhighlight>
 
</syntaxhighlight>
If you want to update u-boot, the command is:
+
如果要更新uboot,则命令为:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
dd if=boot.img of=/dev/mmcblk2p1 bs=1M
 
dd if=boot.img of=/dev/mmcblk2p1 bs=1M
 
</syntaxhighlight>
 
</syntaxhighlight>
To update the kernel driver modules, simply upload and replace the files in the following directory with the new driver module directory: /lib/modules.
+
如果要更新内核驱动模块,将新驱动模块目录上传并替换以下目录下的文件即可:/lib/modules。
  
=====To package a new SD card image or an SD-to-eMMC image=====
+
=====打包新的SD卡启动固件或者SD-to-eMMC卡刷固件=====
The sd-fuse is a bunch of scripts to build bootable SD card images for FriendlyElec boards, the main features are as follows:<br />
+
sd-fuse 提供一些工具和脚本, 用于制作SD卡固件, 具体用途如下:<br />
* Create root filesystem image from a directory<br />
+
* 制作分区镜像文件, 例如将rootfs目录打包成rootfs.img<br />
* Build bootable SD card image<br />
+
* 将多个分区镜像文件打包成可直接写SD卡的单一镜像文件<br />
* Easy way to compile kernel、uboot and third-party driver<br />
+
* 简化内核和uboot的编译, 一键编译内核、第三方驱动, 并更新rootfs.img中的内核模块<br />
Please click on the corresponding link to learn more:
+
请根据所用的内核版本点击对应的链接了解详细的使用方法:
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
! Kernel version
+
! 内核版本
! Build toolset
+
! 构建工具集
 
|-
 
|-
 
| linux v4.4.y
 
| linux v4.4.y
Line 368: Line 334:
 
| [https://github.com/friendlyarm/sd-fuse_rk3399/tree/kernel-5.15.y<br /> sd-fuse]
 
| [https://github.com/friendlyarm/sd-fuse_rk3399/tree/kernel-5.15.y<br /> sd-fuse]
 
|}
 
|}
=====USB flashing=====
+
=====线刷=====
You can directly flash the compiled files. It's important to note that the rk3399_loader generated by u-boot needs to be renamed to MiniLoaderAll.bin. The following command demonstrates how to flash u-boot and the kernel. You need to load parameter.txt first before flashing other files:
+
不擦除flash的情况下只刷入编译生成的文件即可,需要注意的是uboot编译生成的rk3399_loader需要改名为MiniLoaderAll.bin,如下命令演示刷入uboot与内核,需要先加载parameter.txt,再刷入其他文件:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
sudo upgrade_tool ul MiniLoaderAll.bin
 
sudo upgrade_tool ul MiniLoaderAll.bin
Line 379: Line 345:
 
sudo upgrade_tool RD
 
sudo upgrade_tool RD
 
</syntaxhighlight>
 
</syntaxhighlight>
Note: upgrade_tool is a command-line tool provided by Rockchip for Linux (Linux_Upgrade_Tool).
+
注:upgrade_tool是Rockchip提供的Linux下的命令行工具(Linux_Upgrade_Tool)
===Compile Android===
+
====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">
+
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
+
</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 />
+
 
+
=====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}}}:<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 android10 directory in the "FRIENDLYARM" partition;<br />
+
3) Insert this SD card to {{{1}}} and reflash Android<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.
+
 
+
====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">
+
tar xvzf /path/to/netdisk/sources/rk3399-android-8.1.git-YYYYMMDD.tgz
+
cd rk3399-android-8.1
+
./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 https://gitlab.com/friendlyelec/rk3399-android-8.1 --depth 1 -b master
+
</syntaxhighlight>
+
 
+
=====Generate Image File=====
+
You can compile an Android source code and generate an image file:
+
<syntaxhighlight lang="bash">
+
cd rk3399-android-8.1
+
./build-nanopc-t4.sh -F -M
+
</syntaxhighlight>
+
 
+
=====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}}}:<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 />
+
 
+
====Compile Android7====
+
=====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>
+
* '''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-nougat --depth 1 -b nanopc-t4-nougat
+
</syntaxhighlight>
+
 
+
=====Generate Image File=====
+
You can compile an Android7 source code and generate an image file:
+
<syntaxhighlight lang="bash">
+
cd rk3399-nougat
+
./build-nanopc-t4.sh -F -M
+
</syntaxhighlight>
+
 
+
=====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}}}:<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 />
+

Revision as of 14:42, 26 March 2023

1 Linux系统编译

1.1 各个OS对应的内核与u-boot版本

操作系统 内核版本 uboot版本 交叉编译器 分区类型 构建工具集 内核代码分支 内核配置 uboot代码分支 uboot配置
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
friendlycore-lite-focal-arm64 linux v5.15.y GPT
sd-fuse
nanopi-r2-v5.15.y nanopi-r2_linux_defconfig
friendlywrt21 nanopi-r2_linux_defconfig
+friendlywrt.config
friendlywrt21-docker
friendlywrt22
friendlywrt22-docker
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
  • sd-fuse构建工具集可以用于快速编译kernel和uboot、重新打包sd卡固件与卡刷固件等
  • 点击表格中的MBR与GPT可查看各系统的分区布局(配置文件)

1.2 编译内核linux-v4.4.y

本节内容适用于如下OS:

lubuntu eflasher friendlydesktop-arm64 friendlycore-arm64

下载源代码并编译:

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
# 编译内核
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- menuconfig  # 启动配置界面
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4-images -j$(nproc)
# 编译驱动模块
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)

编译完会生成如下文件:

kernel.img resource.img 驱动模块位于out-modules目录

安装内核:
请参考 #下载uboot与内核到目标板

1.3 编译u-boot v2014.10

本节内容适用于如下OS:

lubuntu eflasher friendlydesktop-arm64 friendlycore-arm64

下载源代码并编译:

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-

编译完成后会生成如下文件:

uboot.img trust.img rk3399_loader_v1.22.119.bin

安装u-boot:
请参考 #下载uboot与内核到目标板

1.4 编译内核linux-v4.19.y

本节内容适用于如下OS:

debian-buster-desktop-arm64 debian-bullseye-core-arm64 debian-bullseye-desktop-arm64 debian-bullseye-minimal-arm64
friendlycore-focal-arm64 friendlycore-lite-focal-kernel4-arm64 friendlywrt21-kernel4 buildroot

下载源代码并编译:

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
# 编译内核
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- menuconfig  # 启动配置界面
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4-images -j$(nproc)
# 编译驱动模块
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)

编译完会生成如下文件:

kernel.img resource.img 驱动模块位于out-modules目录

安装内核:
请参考 #下载uboot与内核到目标板

1.5 编译内核linux-v5.15.y

本节内容适用于如下OS:

friendlywrt21 friendlywrt21-docker friendlywrt22 friendlywrt22-docker friendlycore-lite-focal-kernel5-arm64

下载源代码并编译:

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
# 编译内核
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi4_linux_defconfig
# make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 menuconfig  # 启动配置界面
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 -j$(nproc)
# 编译驱动模块
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)

打包kernel.img与resource.img:

wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3399/kernel-5.15.y/tools/mkkrnlimg && chmod 755 mkkrnlimg
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3399/kernel-5.15.y/tools/resource_tool && chmod 755 resource_tool
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3399/kernel-5.15.y/prebuilt/boot/logo.bmp
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_rk3399/kernel-5.15.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

完成后会得到如下文件:

kernel.img resource.img 驱动模块位于out-modules目录

安装内核:
请参考 #下载uboot与内核到目标板

1.6 编译u-boot v2017.09

本节内容适用于如下OS:

debian-buster-desktop-arm64 debian-bullseye-core-arm64 debian-bullseye-desktop-arm64 debian-bullseye-minimal-arm64
friendlycore-focal-arm64 friendlycore-lite-focal-kernel4-arm64 friendlywrt21-kernel4 buildroot

下载源代码并编译:

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 -j$(nproc)
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
cd uboot-rockchip/
./make.sh nanopi4

编译完成后会生成如下文件:

uboot.img trust.img rk3399_loader_v1.24.126.bin

安装u-boot:
请参考 #下载uboot与内核到目标板

1.7 下载uboot与内核到目标板

1.7.1 下载至已安装的系统
1.7.1.1 MBR分区

本节内容适用于如下OS:

lubuntu eflasher friendlydesktop-arm64 friendlycore-arm64

目前只有linux v4.4内核使用mbr分区,需要参考此链接的partmap文件,计算各分区的偏移地址,用dd命令进行写入,例如parameter.template文件内容中"0x00014000@0x00014000(kernel)"表示kernel.img的位置位于0x00014000,转换成10进制就是81920, 所以dd命令如下:

dd if=kernel.img of=/dev/mmcblk0 seek=81920
1.7.1.2 GPT分区

本节内容适用于如下OS:

debian-buster-desktop-arm64 debian-bullseye-core-arm64 debian-bullseye-desktop-arm64 debian-bullseye-minimal-arm64
friendlycore-focal-arm64 friendlycore-lite-focal-kernel4-arm64 friendlywrt21-kernel4 buildroot
friendlywrt21 friendlywrt21-docker friendlywrt22 friendlywrt22-docker

linux v4.19内核和linux v5.15内核的系统默认使用GPT分区, 更新GPT分区比较简单,直接dd image文件至相应的分区即可(注意image的大小不要越界),在操作时需要注意存储设备的节点:

  • SD/TF Card设备节点为 /dev/mmcblk0
  • eMMC设备节点为 /dev/mmcblk2

下面将演示如何将内核更新到eMMC:
使用parted命令查看分区布局:

parted /dev/mmcblk2 print

得到如下输出:

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

可以看到resource分区位置为4, kernel分区位置为5,用dd命令分别写入resource.img与kernel.img到这两个分区即可, 命令如下:

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

如果要更新uboot,则命令为:

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

如果要更新内核驱动模块,将新驱动模块目录上传并替换以下目录下的文件即可:/lib/modules。

1.7.2 打包新的SD卡启动固件或者SD-to-eMMC卡刷固件

sd-fuse 提供一些工具和脚本, 用于制作SD卡固件, 具体用途如下:

  • 制作分区镜像文件, 例如将rootfs目录打包成rootfs.img
  • 将多个分区镜像文件打包成可直接写SD卡的单一镜像文件
  • 简化内核和uboot的编译, 一键编译内核、第三方驱动, 并更新rootfs.img中的内核模块

请根据所用的内核版本点击对应的链接了解详细的使用方法:

内核版本 构建工具集
linux v4.4.y sd-fuse
linux v4.19.y
sd-fuse
linux v5.15.y
sd-fuse
1.7.3 线刷

不擦除flash的情况下只刷入编译生成的文件即可,需要注意的是uboot编译生成的rk3399_loader需要改名为MiniLoaderAll.bin,如下命令演示刷入uboot与内核,需要先加载parameter.txt,再刷入其他文件:

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

注:upgrade_tool是Rockchip提供的Linux下的命令行工具(Linux_Upgrade_Tool)