Difference between revisions of "APITestPage/zh"

From FriendlyELEC WiKi
Jump to: navigation, search
Line 1: Line 1:
===Linux系统编译===
+
===搭建编译环境===
====各个OS对应的内核与u-boot版本====
+
====使用Docker进行交叉编译====
{| class="wikitable"
+
请参考 [https://github.com/friendlyarm/docker-cross-compiler-novnc docker-cross-compiler-novnc]
|-
+
====本地搭建交叉编译环境====
! 操作系统
+
=====安装编译所需软件包=====
! 内核版本
+
建议使用'''64位'''的[http://mirrors.aliyun.com/ubuntu-releases/20.04/ Ubuntu 20.04系统],参考如下内容安装编译及打包所需要的软件包:
! uboot版本
+
! 交叉编译器
+
! 分区类型
+
! 构建脚本
+
! 内核代码分支
+
! 内核配置
+
! uboot代码分支
+
! uboot配置
+
|-
+
| buildroot
+
| rowspan="10" | linux v5.10.y
+
| rowspan="10" | u-boot <br />v2017.09
+
| rowspan="10" | 11.3-aarch64
+
| rowspan="10" | [https://github.com/friendlyarm/sd-fuse_rk3588/blob/master/prebuilt/parameter.template GPT]
+
| rowspan="10" | [https://github.com/friendlyarm/sd-fuse_rk3588/tree/master sd-fuse]
+
| rowspan="10" | [https://github.com/friendlyarm/kernel-rockchip/tree/nanopi5-v5.10.y_opt nanopi5-v5.10.y_opt]
+
| rowspan="6" | nanopi5_linux_defconfig
+
| rowspan="10" | [https://github.com/friendlyarm/uboot-rockchip/tree/nanopi5-v2017.09 nanopi5-v2017.09]
+
| rowspan="10" | rk3588_defconfig
+
|-
+
| friendlycore-focal-arm64
+
|-
+
| debian-bullseye-core-arm64
+
|-
+
| debian-bullseye-desktop-arm64
+
|-
+
| debian-bullseye-minimal-arm64
+
|-
+
| debian-buster-desktop-arm64
+
|-
+
| friendlywrt21
+
| rowspan="4" | nanopi5_linux_defconfig<br />friendlywrt.config
+
|-
+
| friendlywrt21-docker
+
|-
+
| friendlywrt22
+
|-
+
| friendlywrt22-docker
+
|}
+
* 内核源代码仓库地址:https://github.com/friendlyarm/kernel-rockchip
+
* u-boot源代码仓库地址:https://github.com/friendlyarm/uboot-rockchip
+
* 交叉编译工具链存放在如下路径: /opt/FriendlyARM/toolchain/,使用前需导出到PATH环境变量,例如需要使用11.3-aarch64版本的编译器,使用如下命令:
+
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
+
sudo apt-get -y update
 +
sudo apt-get install -y sudo curl
 +
sudo bash -c \
 +
  "$(curl -fsSL https://raw.githubusercontent.com/friendlyarm/build-env-on-ubuntu-bionic/master/install.sh)"
 
</syntaxhighlight>
 
</syntaxhighlight>
* [https://github.com/friendlyarm/sd-fuse_rk3588/tree/master sd-fuse]构建脚本可以用于快速编译kernel和uboot、重新打包sd卡固件与卡刷固件等
+
你的电脑上会安装好如下交叉编译器:
====编译内核linux-v5.10.y====
+
下载源代码并编译:
+
<syntaxhighlight lang="bash">
+
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
+
# 配置内核
+
# option1: 加载Linux系统配置
+
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi5_linux_defconfig
+
# option2: 加载FriendlyWrt系统配置
+
# make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi5_linux_defconfig friendlywrt.config
+
# 启动配置界面
+
# make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 menuconfig
+
# 编译内核
+
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi5-images -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)
+
</syntaxhighlight>
+
完成后会得到如下文件:
+
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
| kernel.img
+
! 版本
| resource.img
+
! 架构
| <del>boot.img (此img弃用)</del>
+
! 编译器路径
| 驱动模块位于out-modules目录
+
! 用途
|}
+
安装内核: <br>
+
请参考 [[#下载uboot与内核到目标板]]<br>
+
====编译u-boot v2017.09====
+
下载源代码并编译:
+
<syntaxhighlight lang="bash">
+
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
+
</syntaxhighlight>
+
编译完成后会生成如下文件:
+
{| class="wikitable"
+
 
|-
 
|-
| uboot.img
+
| 4.9.3
| rk356x_spl_loader_v1.15.112.bin (打包时改名为MiniLoaderAll.bin)
+
| armhf
|}
+
| /opt/FriendlyARM/toolchain/4.9.3
安装u-boot: <br />
+
| 用于编译32位的arm应用程序
请参考 [[#下载uboot与内核到目标板]]<br>
+
 
+
====应用新编译的uboot与内核====
+
=====安装到目标板=====
+
由于rk3588的OS默认均采用GPT分区, 可以用dd命令将image文件烧写至image对应的分区,SD卡与eMMC的设备节点如下:
+
* SD/TF Card设备节点为 /dev/mmcblk0 <br />
+
* eMMC设备节点为 /dev/mmcblk2 <br />
+
下面将演示如何将内核更新到eMMC:<br />
+
使用parted命令查看分区布局:
+
<syntaxhighlight lang="bash">
+
parted /dev/mmcblk2 print
+
</syntaxhighlight>
+
得到如下输出:
+
<syntaxhighlight lang="bash">
+
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
+
</syntaxhighlight>
+
resource分区的序号为4, kernel分区的序号为5,对应的设备节点为/dev/mmcblk2p4和/dev/mmcblk2p5,  dd命令如下:
+
<syntaxhighlight lang="bash">
+
dd if=resource.img of=/dev/mmcblk2p4 bs=1M
+
dd if=kernel.img of=/dev/mmcblk2p5 bs=1M
+
</syntaxhighlight>
+
如果要更新uboot:
+
<syntaxhighlight lang="bash">
+
dd if=boot.img of=/dev/mmcblk2p1 bs=1M
+
</syntaxhighlight>
+
如果要更新内核驱动模块,将新驱动模块目录上传并替换以下目录下的文件即可:/lib/modules。
+
 
+
=====打包新的SD Image=====
+
sd-fuse 提供一些工具和脚本, 用于制作SD卡固件, 具体用途如下:<br />
+
* 制作分区镜像文件, 例如将rootfs目录打包成rootfs.img<br />
+
* 将多个分区镜像文件打包成可直接写SD卡的单一镜像文件<br />
+
* 简化内核和uboot的编译, 一键编译内核、第三方驱动, 并更新rootfs.img中的内核模块<br />
+
请根据所用的内核版本点击对应的链接了解详细的使用方法:
+
{| class="wikitable"
+
 
|-
 
|-
! 内核版本
+
| 6.4
! 构建脚本
+
| aarch64
 +
| /opt/FriendlyARM/toolchain/6.4-aarch64
 +
| 用于交叉编译4.4内核
 
|-
 
|-
| linux v5.10.y
+
| 11.3
| [https://github.com/friendlyarm/sd-fuse_rk3588/tree/master sd-fuse_rk3588]
+
| aarch64
 +
| /opt/FriendlyARM/toolchain/11.3-aarch64
 +
| 用于交叉编译4.19及以上内核(含5.10,5.15)及uboot
 
|}
 
|}
=====线刷=====
+
=====设置交叉编译器=====
======Linux系统======
+
参考上一节的表格,选用合适版本的编译器,然后将编译器的路径加入到PATH中,例加要使用11.3的交叉编译器,用vi编辑~/.bashrc,在末尾加入以下内容:
用upgrade_tool工具烧写uboot与内核, 命令如下所示:
+
<syntaxhighlight lang="bash">
+
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
+
</syntaxhighlight>
+
注:upgrade_tool是Rockchip提供的Linux下的命令行工具(Linux_Upgrade_Tool)
+
===Android系统编译===
+
====从网盘下载Android源代码====
+
网盘地址:[http://download.friendlyelec.com/{{#replace:{{#replace:{{BASEPAGENAME}}| |}}|/zh|}} 点击进入]<br />
+
网盘路径:07_源代码/rk35xx-android12-xxxxxxx-YYYYMMDD.tgz (YYYYMMDD表示打包的日期, xxxxxxx表示最后的commit-id)<br />
+
使用如下命令解压并拉取更新:<br />
+
<syntaxhighlight lang="bash">
+
tar xzf /path/to/netdisk/07_源代码/rk35xx-android12-xxxxxxx-YYYYMMDD.tgz
+
cd rk35xx-android12
+
git pull
+
</syntaxhighlight>
+
====编译Android Table版本====
+
<syntaxhighlight lang="bash">
+
echo "ROCKCHIP_DEVICE_DIR := device/rockchip/rk356x/nanopi5" > .rockchip_device.mk
+
# export INSTALL_GAPPS_FOR_TESTING=yes  # 是否包含google apps
+
. setenv.sh
+
./build.sh -FMu
+
</syntaxhighlight>
+
====编译Android TV版本====
+
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
echo "ROCKCHIP_DEVICE_DIR := device/rockchip/rk356x/nanopi5_box" > .rockchip_device.mk
+
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin:$PATH
# export INSTALL_GAPPS_FOR_TESTING=yes  # 是否包含google apps
+
export GCC_COLORS=auto
. setenv.sh
+
./build.sh -FMu
+
 
</syntaxhighlight>
 
</syntaxhighlight>
====安装Android====
+
执行一下~/.bashrc脚本让设置立即在当前shell窗口中生效,注意"."后面有个空格:
Android编译完成后,image文件会存放在Android源代码目录的 rockdev/Image-aosp_nanopi3 子目录下。
+
=====USB线刷=====
+
用rockchip的工具刷入如下文件:rockdev/Image-aosp_nanopi3/update.img
+
=====SD卡烧写=====
+
参考以下步骤: <br />
+
1) 将安装了 eflasher 系统的SD卡插入电脑; <br />
+
2) 将 rockdev/Image-aosp_nanopi3 子目录下的文件更新到SD卡 FRIENDLYARM 分区里的android12或androidtv目录: <br />
+
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
sudo cp -af parameter.txt config.cfg MiniLoaderAll.bin uboot.img \
+
. ~/.bashrc
    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
+
 
</syntaxhighlight>
 
</syntaxhighlight>
3) 将SD卡插入{{{1}}},重新烧写Andorid系统即可; <br />
+
验证是否安装成功:
====打包成新的SD Image====
+
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://github.com/friendlyarm/sd-fuse_rk3588.git
+
$ aarch64-linux-gcc -v
SDFUSE=$PWD/sd-fuse_rk3588
+
Using built-in specs.
mkdir $SDFUSE/android12
+
COLLECT_GCC=aarch64-linux-gcc
 
+
COLLECT_LTO_WRAPPER=/opt/FriendlyARM/toolchain/11.3-aarch64/libexec/gcc/aarch64-cortexa53-linux-gnu/11.3.0/lto-wrapper
cd /path/to/rk35xx-android12/rockdev/Image-aosp_nanopi3
+
Target: aarch64-cortexa53-linux-gnu
cp -af parameter.txt config.cfg MiniLoaderAll.bin uboot.img \
+
Configured with: /home/cross/arm64/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/11.3-aarch64 --exec_prefix=/opt/FriendlyARM/toolchain/11.3-aarch64 --with-sysroot=/opt/FriendlyARM/toolchain/11.3-aarch64/aarch64-cortexa53-linux-gnu/sysroot --enable-languages=c,c++ --enable-fix-cortex-a53-843419 --with-arch=armv8-a+crypto+crc --with-cpu=cortex-a53 --with-pkgversion=ctng-1.25.0-119g-FA --with-bugurl=http://www.friendlyelec.com/ --enable-objc-gc --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --disable-libmpx --with-gmp=/home/cross/arm64/buildtools --with-mpfr=/home/cross/arm64/buildtools --with-mpc=/home/cross/arm64/buildtools --with-isl=/home/cross/arm64/buildtools --enable-lto --enable-threads=posix --disable-libstdcxx-pch --enable-clocale=gnu --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-indirect-function --enable-gnu-unique-object --enable-default-pie --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --enable-gold --with-libintl-prefix=/home/cross/arm64/buildtools --disable-multilib --with-local-prefix=/opt/FriendlyARM/toolchain/11.3-aarch64/aarch64-cortexa53-linux-gnu/sysroot --enable-long-long --enable-checking=release --enable-link-serialization=2
    dtbo.img vbmeta.img boot.img recovery.img \
+
Thread model: posix
    misc.img pcba_small_misc.img pcba_whole_misc.img \
+
Supported LTO compression algorithms: zlib
    baseparameter.img super.img $SDFUSE/android12
+
gcc version 11.3.0 (ctng-1.25.0-119g-FA)
 
+
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
+
 
</syntaxhighlight>
 
</syntaxhighlight>
更多信息,请参考 [[#打包新的SD Image]]<br>
 

Revision as of 02:50, 8 April 2023

1 搭建编译环境

1.1 使用Docker进行交叉编译

请参考 docker-cross-compiler-novnc

1.2 本地搭建交叉编译环境

1.2.1 安装编译所需软件包

建议使用64位Ubuntu 20.04系统,参考如下内容安装编译及打包所需要的软件包:

sudo apt-get -y update
sudo apt-get install -y sudo curl
sudo bash -c \
  "$(curl -fsSL https://raw.githubusercontent.com/friendlyarm/build-env-on-ubuntu-bionic/master/install.sh)"

你的电脑上会安装好如下交叉编译器:

版本 架构 编译器路径 用途
4.9.3 armhf /opt/FriendlyARM/toolchain/4.9.3 用于编译32位的arm应用程序
6.4 aarch64 /opt/FriendlyARM/toolchain/6.4-aarch64 用于交叉编译4.4内核
11.3 aarch64 /opt/FriendlyARM/toolchain/11.3-aarch64 用于交叉编译4.19及以上内核(含5.10,5.15)及uboot
1.2.2 设置交叉编译器

参考上一节的表格,选用合适版本的编译器,然后将编译器的路径加入到PATH中,例加要使用11.3的交叉编译器,用vi编辑~/.bashrc,在末尾加入以下内容:

export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin:$PATH
export GCC_COLORS=auto

执行一下~/.bashrc脚本让设置立即在当前shell窗口中生效,注意"."后面有个空格:

. ~/.bashrc

验证是否安装成功:

$ aarch64-linux-gcc -v
Using built-in specs.
COLLECT_GCC=aarch64-linux-gcc
COLLECT_LTO_WRAPPER=/opt/FriendlyARM/toolchain/11.3-aarch64/libexec/gcc/aarch64-cortexa53-linux-gnu/11.3.0/lto-wrapper
Target: aarch64-cortexa53-linux-gnu
Configured with: /home/cross/arm64/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/11.3-aarch64 --exec_prefix=/opt/FriendlyARM/toolchain/11.3-aarch64 --with-sysroot=/opt/FriendlyARM/toolchain/11.3-aarch64/aarch64-cortexa53-linux-gnu/sysroot --enable-languages=c,c++ --enable-fix-cortex-a53-843419 --with-arch=armv8-a+crypto+crc --with-cpu=cortex-a53 --with-pkgversion=ctng-1.25.0-119g-FA --with-bugurl=http://www.friendlyelec.com/ --enable-objc-gc --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --disable-libmpx --with-gmp=/home/cross/arm64/buildtools --with-mpfr=/home/cross/arm64/buildtools --with-mpc=/home/cross/arm64/buildtools --with-isl=/home/cross/arm64/buildtools --enable-lto --enable-threads=posix --disable-libstdcxx-pch --enable-clocale=gnu --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-indirect-function --enable-gnu-unique-object --enable-default-pie --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --enable-gold --with-libintl-prefix=/home/cross/arm64/buildtools --disable-multilib --with-local-prefix=/opt/FriendlyARM/toolchain/11.3-aarch64/aarch64-cortexa53-linux-gnu/sysroot --enable-long-long --enable-checking=release --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.3.0 (ctng-1.25.0-119g-FA)