Difference between revisions of "Template:RK3328-BuildFromSource/zh"
(updated by API) |
(updated by API) |
||
Line 1: | Line 1: | ||
− | === | + | ===编译 Openwrt/Friendlywrt === |
+ | ====下载源代码==== | ||
+ | FriendlyWrt有两个版本, 请根据需要进行选择. | ||
+ | =====版本FriendlyWrt 21.02===== | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | 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 | ||
+ | </syntaxhighlight> | ||
+ | =====版本FriendlyWrt 22.03.2===== | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | mkdir friendlywrt22-rk3328 | ||
+ | cd friendlywrt22-rk3328 | ||
+ | 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 rk3328.xml --repo-url=https://github.com/friendlyarm/repo --no-clone-bundle | ||
+ | tools/repo sync -c --no-clone-bundle | ||
+ | </syntaxhighlight> | ||
+ | ====首次编译==== | ||
+ | 下面的命令是编译不带docker的版本, 如需要编译带docker的版本, 请将'''rk3328.mk'''替换为'''rk3328-docker.mk''': | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | ./build.sh rk3328.mk | ||
+ | </syntaxhighlight> | ||
+ | 会编译所有组件(包含u-boot, kernel 和 friendlywrt)并生成sd卡镜像文件,再执行以下命令,可生成用于安装系统到emmc运行的镜像文件(eflahser固件): | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | ./build.sh emmc-img | ||
+ | </syntaxhighlight> | ||
+ | 对项目进行过修改后, 需要重新打包sd卡镜像, 可执行如下命令: | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | ./build.sh sd-img | ||
+ | </syntaxhighlight> | ||
+ | ====二次编译==== | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | cd friendlywrt | ||
+ | make menuconfig #改动FriendlyWrt的配置 | ||
+ | rm -rf ./tmp | ||
+ | make -j${nproc} | ||
+ | cd ../ | ||
+ | ./build.sh sd-img | ||
+ | ./build.sh emmc-img | ||
+ | </syntaxhighlight> | ||
+ | ===单独编译u-boot=== | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | ./build.sh uboot | ||
+ | </syntaxhighlight> | ||
+ | ===单独编译kernel=== | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | ./build.sh kernel | ||
+ | </syntaxhighlight> | ||
+ | ===单独编译friendlywrt=== | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | ./build.sh friendlywrt | ||
+ | </syntaxhighlight> | ||
+ | 或者进入friendlywrt目录, 按标准openwrt的命令操作, 上面的命令出现错误时, 可尝试使用以下命令单线程编译: | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | cd friendlywrt | ||
+ | make -j1 V=s | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ===编译buildroot=== | ||
+ | 请参考: [[Buildroot/zh|Buildroot]] | ||
+ | |||
+ | ===其他Linux系统编译=== | ||
====各个OS对应的内核与u-boot版本==== | ====各个OS对应的内核与u-boot版本==== | ||
{| class="wikitable" | {| class="wikitable" |
Revision as of 06:25, 11 April 2023
Contents
1 编译 Openwrt/Friendlywrt
1.1 下载源代码
FriendlyWrt有两个版本, 请根据需要进行选择.
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 22.03.2
mkdir friendlywrt22-rk3328 cd friendlywrt22-rk3328 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 rk3328.xml --repo-url=https://github.com/friendlyarm/repo --no-clone-bundle tools/repo sync -c --no-clone-bundle
1.2 首次编译
下面的命令是编译不带docker的版本, 如需要编译带docker的版本, 请将rk3328.mk替换为rk3328-docker.mk:
./build.sh rk3328.mk
会编译所有组件(包含u-boot, kernel 和 friendlywrt)并生成sd卡镜像文件,再执行以下命令,可生成用于安装系统到emmc运行的镜像文件(eflahser固件):
./build.sh emmc-img
对项目进行过修改后, 需要重新打包sd卡镜像, 可执行如下命令:
./build.sh sd-img
1.3 二次编译
cd friendlywrt make menuconfig #改动FriendlyWrt的配置 rm -rf ./tmp make -j${nproc} cd ../ ./build.sh sd-img ./build.sh emmc-img
2 单独编译u-boot
./build.sh uboot
3 单独编译kernel
./build.sh kernel
4 单独编译friendlywrt
./build.sh friendlywrt
或者进入friendlywrt目录, 按标准openwrt的命令操作, 上面的命令出现错误时, 可尝试使用以下命令单线程编译:
cd friendlywrt make -j1 V=s
5 编译buildroot
请参考: Buildroot
6 其他Linux系统编译
6.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 | 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 |
- 内核源代码仓库地址:https://github.com/friendlyarm/kernel-rockchip
- u-boot源代码仓库地址:https://github.com/friendlyarm/uboot-rockchip
- 交叉编译工具链存放在如下路径: /opt/FriendlyARM/toolchain/,使用前需导出到PATH环境变量,例如需要使用11.3-aarch64版本的编译器,使用如下命令:
export PATH=/opt/FriendlyARM/toolchain/11.3-aarch64/bin/:$PATH
- sd-fuse构建脚本可以用于快速编译kernel和uboot、重新打包sd卡固件与卡刷固件等
6.2 编译内核linux-v4.19.y
本节内容适用于如下OS:
buildroot | friendlycore-focal-arm64 |
下载源代码并编译:
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 # 配置内核 # option1: 加载Linux系统配置 make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig # option2: 加载FriendlyWrt系统配置 # make ARCH=arm64 CROSS_COMPILE=aarch64-linux- nanopi4_linux_defconfig friendlywrt.config # 启动配置界面 # 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与内核到目标板
6.3 编译内核linux-v5.15.y
本节内容适用于如下OS:
friendlywrt21 | friendlywrt21-docker | friendlywrt22 | friendlywrt22-docker | friendlycore-lite-focal-arm64 | debian-bullseye-core-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 # 配置内核 # option1: 加载Linux系统配置 make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi-r2_linux_defconfig # option2: 加载FriendlyWrt系统配置 # make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 nanopi-r2_linux_defconfig friendlywrt.config # 启动配置界面 # 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_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
完成后会得到如下文件:
kernel.img | resource.img | 驱动模块位于out-modules目录 |
安装内核:
请参考 #下载uboot与内核到目标板
6.4 编译u-boot v2017.09
本节内容适用于如下OS:
buildroot | friendlycore-focal-arm64 | friendlywrt21 | friendlywrt21-docker | friendlywrt22 | friendlywrt22-docker | friendlycore-lite-focal-arm64 | debian-bullseye-core-arm64 |
下载源代码并编译:
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
编译完成后会生成如下文件:
uboot.img | trust.img | rk3328_loader_v1.16.250.bin (打包时改名为MiniLoaderAll.bin) |
安装u-boot:
请参考 #下载uboot与内核到目标板
6.5 应用新编译的uboot与内核
6.5.1 安装到目标板
本节内容适用于如下OS:
buildroot | friendlycore-focal-arm64 | friendlywrt21 | friendlywrt21-docker | friendlywrt22 | friendlywrt22-docker | friendlycore-lite-focal-arm64 | debian-bullseye-core-arm64 |
由于RK3328的OS默认均采用GPT分区, 可以用dd命令将image文件烧写至image对应的分区,SD卡与eMMC的设备节点如下:
- SD/TF Card设备节点为 /dev/mmcblk0
- eMMC设备节点为 /dev/mmcblk2
下面将演示如何将内核更新到eMMC:
使用parted命令查看分区布局:
parted /dev/mmcblk2 print
得到如下输出:
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
resource分区的序号为5, kernel分区的序号为6,对应的设备节点为/dev/mmcblk2p5和/dev/mmcblk2p6, dd命令如下:
dd if=resource.img of=/dev/mmcblk2p5 bs=1M dd if=kernel.img of=/dev/mmcblk2p6 bs=1M
如果要更新uboot:
dd if=boot.img of=/dev/mmcblk2p1 bs=1M
如果要更新内核驱动模块,将新驱动模块目录上传并替换以下目录下的文件即可:/lib/modules。
6.5.2 打包新的SD Image
sd-fuse 提供一些工具和脚本, 用于制作SD卡固件, 具体用途如下:
- 制作分区镜像文件, 例如将rootfs目录打包成rootfs.img
- 将多个分区镜像文件打包成可直接写SD卡的单一镜像文件
- 简化内核和uboot的编译, 一键编译内核、第三方驱动, 并更新rootfs.img中的内核模块
请根据所用的内核版本点击对应的链接了解详细的使用方法:
内核版本 | 构建脚本 |
---|---|
linux v4.19.y | sd-fuse_rk3328/kernel-4.19 |
linux v5.15.y | sd-fuse_rk3328/kernel-5.15.y |
6.5.3 线刷
6.5.3.1 Linux系统
用upgrade_tool工具烧写uboot与内核, 命令如下所示:
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)