|
|
Line 1: |
Line 1: |
− | [[Buildroot for RK3399|English]]
| + | {{H3-KernelHeaderFile/zh}} |
− | | + | {{H5-KernelHeaderFile/zh}} |
− | ==Buildroot简介==
| + | |
− | {{RK3399 Buildroot Intro/zh}} | + | |
− | | + | |
− | ==下载体验版固件==
| + | |
− | 访问[http://download.friendlyarm.com/nanopct4 此处的下载地址]下载:<br />
| + | |
− | {| class="wikitable" | + | |
− | |-
| + | |
− | | colspan=2 | Image Files
| + | |
− | |-
| + | |
− | | rk3399-sd-buildroot-linux-4.19-arm64-YYYYMMDD.img.zip
| + | |
− | | 从SD卡启动的固件
| + | |
− | |-
| + | |
− | | rk3399-eflasher-buildroot-YYYYMMDD.img.zip
| + | |
− | | 用于烧写到eMMC运行
| + | |
− | |}
| + | |
− | 解压后用 dd 或者 win32image 烧写到 SD 卡。
| + | |
− | ==帐户与密码==
| + | |
− | 用户名: root<br />
| + | |
− | 密码: rockchip<br />
| + | |
− | <br />
| + | |
− | 密码可通过以下文件更改:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | buildroot/configs/rockchip/network.config
| + | |
− | </syntaxhighlight>
| + | |
− | ==获取项目源代码==
| + | |
− | ===安装 repo 工具===
| + | |
− | 首先需要安装 repo 工具:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | git clone https://github.com/friendlyarm/repo --depth 1
| + | |
− | sudo cp repo/repo /usr/bin/
| + | |
− | </syntaxhighlight>
| + | |
− | ===下载项目源代码===
| + | |
− | 有以下两种途径获取项目源代码,中国大陆用户建议使用方法1的途径下载:
| + | |
− | ====方法一:使用网盘里的repo压缩包====
| + | |
− | 网盘下载地址: [http://download.friendlyarm.com/{{#replace:{{#replace:{{BASEPAGENAME}}| |}}|/zh|}} 点击进入]<br />
| + | |
− | 文件位于网盘的以下路径:sources/buildroot-rk3399-YYYYMMDD.tar (YYYYMMDD表示打包的日期)<br />
| + | |
− | 从网盘中获取的 repo 压缩包在解压之后,需要执行一下以下命令做一次解包动作:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | tar xvf /path/to/netdisk/sources/buildroot-rk3399-YYYYMMDD.tar
| + | |
− | cd buildroot-rk3399
| + | |
− | repo sync -l
| + | |
− | </syntaxhighlight>
| + | |
− | 用此方法得到的源代码版本是repo打包时的版本,如果想拉取到官方最新的版本,可以去掉 -l 参数,执行一次 repo sync, 例如:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | cd buildroot-rk3399
| + | |
− | repo sync --no-clone-bundle
| + | |
− | </syntaxhighlight>
| + | |
− | ====方法二:从github下载====
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | mkdir buildroot-rk3399
| + | |
− | cd buildroot-rk3399
| + | |
− | repo init -u https://github.com/friendlyarm/buildroot_manifests \
| + | |
− | -b rockchip-kernel4.19 -m rk3399.xml --repo-url=https://github.com/friendlyarm/repo \
| + | |
− | --no-clone-bundle
| + | |
− | repo sync -c --no-clone-bundle
| + | |
− | </syntaxhighlight>
| + | |
− | ====同步项目到最新版本====
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | cd buildroot-rk3399
| + | |
− | repo sync -c --no-clone-bundle
| + | |
− | </syntaxhighlight>
| + | |
− | 同步过程中,由于网络原因出现中断,可以使用下面脚本同步代码:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | #! /bin/bash
| + | |
− | repo sync -c --no-clone-bundle
| + | |
− | while [ $? -ne 0 ];
| + | |
− | do
| + | |
− | repo sync -c --no-clone-bundle
| + | |
− | done
| + | |
− | </syntaxhighlight>
| + | |
− | ==如何编译==
| + | |
− | ===搭建编译环境===
| + | |
− | 在PC的Ubuntu系统下 (建议使用版本18.04-64bit),执下以下命令安装所需的软件:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | wget -O - https://raw.githubusercontent.com/friendlyarm/build-env-on-ubuntu-bionic/master/install.sh | bash
| + | |
− | </syntaxhighlight>
| + | |
− | | + | |
− | ===在Docker容器里编译===
| + | |
− | 请使用此链接提供的Docker映象, 具体方法可阅读此链接中的README:<br />
| + | |
− | https://github.com/friendlyarm/friendlyelec-ubuntu18-docker<br />
| + | |
− | | + | |
− | ===查看帮助===
| + | |
− | 不带参数执行 build.sh,默认是打印帮助信息:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ./build.sh
| + | |
− | </syntaxhighlight>
| + | |
− | 显示的帮助信息如下 (以RK3399平台为例):
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | USAGE: ./build.sh <parameter>
| + | |
− | | + | |
− | # 选择目标的硬件平台:
| + | |
− | ./build.sh nanopc_t4.mk
| + | |
− | ./build.sh nanopi_m4.mk
| + | |
− | ./build.sh nanopi_neo4.mk
| + | |
− | ./build.sh nanopi_r4s.mk
| + | |
− | ./build.sh som-rk3399.mk
| + | |
− | | + | |
− | # 编译各个模块:
| + | |
− | ./build.sh all -编译所有组件
| + | |
− | ./build.sh uboot -单独编译uboot
| + | |
− | ./build.sh kernel -单独编译kernel
| + | |
− | ./build.sh buildroot -单独编译buildroot
| + | |
− | ./build.sh sd-img -生成sd启动的镜像文件
| + | |
− | ./build.sh emmc-img -生成用于安装到emmc的镜像文件 (镜像文件需要dd到sd卡,通过sd卡启动安装程序)
| + | |
− | # 清理:
| + | |
− | ./build.sh clean -remove old images
| + | |
− | ./build.sh cleanall
| + | |
− | </syntaxhighlight>
| + | |
− | | + | |
− | ===全自动方式编译===
| + | |
− | 初次编译,需要选择目标的硬件平台,以RK3399平台的R4S为例:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ./build.sh nanopi_r4s.mk
| + | |
− | </syntaxhighlight>
| + | |
− | 执行上述命令,会自动编译所有组件,其中包括u-boot, kernel 和 buildroot,并生成sd启动的烧写镜像文件。
| + | |
− | | + | |
− | ===编译单独的模块===
| + | |
− | ====kernel====
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ./build.sh kernel
| + | |
− | </syntaxhighlight>
| + | |
− | ====u-boot====
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ./build.sh uboot
| + | |
− | </syntaxhighlight>
| + | |
− | ====buildroot====
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ./build.sh buildroot
| + | |
− | </syntaxhighlight>
| + | |
− | ===生成sdcard固件===
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | sudo ./build.sh sd-img
| + | |
− | </syntaxhighlight>
| + | |
− | 打包img成功后,终端会显示如下信息,可以参考下面的dd命令将img写入sd卡,注意/dev/sdX需要替换成真实的sd卡设备:<br />
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | Run the following for sdcard install:
| + | |
− | sudo dd if=out/Buildroot_20211213_NanoPi-R4S_arm64_sd.img bs=1M of=/dev/sdX
| + | |
− | </syntaxhighlight>
| + | |
− | ===生成emmc (eflasher) 固件===
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | sudo ./build.sh emmc-img
| + | |
− | </syntaxhighlight>
| + | |
− | 打包img成功后,终端会显示如下信息,可以参考下面的dd命令将img写入sd卡,注意/dev/sdX需要替换成真实的sd卡设备:<br />
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | Run the following for sdcard install:
| + | |
− | sudo dd if=out/Buildroot_20211213_NanoPi-R4S_arm64_eflasher.img bs=1M of=/dev/sdX
| + | |
− | </syntaxhighlight>
| + | |
− | 用此sd卡启动eflasher系统,执行eflasher命令,将系统写入emmc,之后就可以拨掉sd卡,从emmc启动buildroot了。
| + | |
− | | + | |
− | ==Buildroot定制与开发==
| + | |
− | ===目录结构===
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ├── buildroot-xxyyzz
| + | |
− | │ ├── buildroot -> buildroot源代码
| + | |
− | | └── toolchain -> 交叉编译器,仅用于编译u-boot与kernel
| + | |
− | │ ├── build.sh -> 编译脚本
| + | |
− | │ ├── device/friendlyelec -> 用于适配友善电子开发板的相关文件
| + | |
− | │ ├── kernel -> 内核
| + | |
− | │ └── u-boot -> u-boot
| + | |
− | │ └── app -> rockchip的app
| + | |
− | │ └── external -> rockchip的buildroot软件包
| + | |
− | │ └── rkbin -> rockchip的引导程序
| + | |
− | │ └── scripts -> 打包img的相关脚本
| + | |
− | </syntaxhighlight>
| + | |
− | | + | |
− | ====更改Buildroot配置====
| + | |
− | * 列出当前可用的配置
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | cd buildroot
| + | |
− | make list-defconfigs
| + | |
− | </syntaxhighlight>
| + | |
− | 适合FriendlyELEC RK3399的配置所下:<br />
| + | |
− | friendlyelec_rk3399_defconfig - Build for friendlyelec_rk3399<br />
| + | |
− | * 使用menuconfig更改配置
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | make friendlyelec_rk3399_defconfig
| + | |
− | make menuconfig
| + | |
− | make savedefconfig
| + | |
− | diff .defconfig configs/friendlyelec_rk3399_defconfig
| + | |
− | cp .defconfig configs/friendlyelec_rk3399_defconfig
| + | |
− | </syntaxhighlight>
| + | |
− | * 重新编译
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | cd ../
| + | |
− | ./build.sh buildroot
| + | |
− | </syntaxhighlight>
| + | |
− | ===预装文件到文件系统===
| + | |
− | 将文件放在 device/friendlyelec/rk3399/common-files,然后重新打包img:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | sudo ./build.sh sd-img
| + | |
− | sudo ./build.sh emmc-img
| + | |
− | </syntaxhighlight>
| + | |
− | ===修改u-boot和kernel===
| + | |
− | 直接修改u-boot和kernel目录下的文件即可。
| + | |
− | ===使用sdk里的交叉编译器===
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | export PATH=$PWD/buildroot/output/rockchip_rk3399/host/bin/:$PATH
| + | |
− | aarch64-buildroot-linux-gnu-g++ -v
| + | |
− | </syntaxhighlight>
| + | |
− | 显示版本如下:<br />
| + | |
− | gcc 版本 6.4.0 (Buildroot 2018.02-rc3-g4f000a0797)
| + | |
− | ===交叉编译Qt程序===
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | git clone https://github.com/friendlyarm/QtE-Demo.git
| + | |
− | cd QtE-Demo
| + | |
− | ../buildroot/output/rockchip_rk3399/host/bin/qmake QtE-Demo.pro
| + | |
− | make
| + | |
− | </syntaxhighlight>
| + | |
− | 要实现开机自动运行你的Qt程序,可将QtE-Demo拷贝到开发板上,然后修改 /etc/init.d/下的S50launcher,将/usr/local/QLauncher/QLauncher &这一行改为QtE-Demo的文件路径即可。
| + | |
− | ==常见问题==
| + | |
− | ===如何获取用于USB Type-C烧写的文件?===
| + | |
− | 执行 build.sh emmc-img 之后,在 scripts/sd-fuse 下面会有一个 buildroot 目录,使用android_tools工具加载这个目录下的文件即可。
| + | |
− | ==报告bug==
| + | |
− | 欢迎发邮件到:techsupport@friendlyarm.com<br />
| + | |
− | ==更新日志==
| + | |
− | ===2021-12-23===
| + | |
− | * 简化构建脚本, 并将buildroot更新至原厂新版本
| + | |
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
$ cat /proc/version
Linux version 4.14.111 (root@ubuntu) (gcc version 4.9.3 (ctng-1.21.0-229g-FA)) #193 SMP Thu Jun 10 18:20:47 CST 2021
sudo apt-get update
sudo apt-get install dpkg-dev libarchive-tools
git clone https://github.com/friendlyarm/linux -b sunxi-4.14.y --depth 1 kernel-h3
cd kernel-h3
rm -rf .git
make distclean
touch .scmversion
make CROSS_COMPILE= ARCH=arm sunxi_defconfig
alias tar=bsdtar
make CROSS_COMPILE= ARCH=arm bindeb-pkg -j4
dpkg-deb: building package 'linux-headers-4.14.111' in '../linux-headers-4.14.111_4.14.111-1_armhf.deb'.
dpkg-deb: building package 'linux-libc-dev' in '../linux-libc-dev_4.14.111-1_armhf.deb'.
dpkg-deb: building package 'linux-image-4.14.111' in '../linux-image-4.14.111_4.14.111-1_armhf.deb'.
dpkg-genchanges: warning: substitution variable ${kernel:debarch} used, but is not defined
dpkg-genchanges: info: binary-only upload (no source code included)
sudo dpkg -i ../linux-headers-4.14.111_4.14.111-1_armhf.deb
git clone https://github.com/ntop/PF_RING.git
cd PF_RING/kernel/
make
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
$ cat /proc/version
Linux version 4.14.111 (root@ubuntu) (gcc version 6.3.1 20170109 (Linaro GCC 6.3-2017.02)) #192 SMP Thu Jun 10 15:47:26 CST 2021
sudo apt-get update
sudo apt-get install -y dpkg-dev libarchive-tools
git clone https://github.com/friendlyarm/linux -b sunxi-4.14.y --depth 1 kernel-h5
cd kernel-h5
rm -rf .git
make distclean
touch .scmversion
make CROSS_COMPILE= ARCH=arm64 sunxi_arm64_defconfig
alias tar=bsdtar
make CROSS_COMPILE= ARCH=arm64 bindeb-pkg -j4
dpkg-deb: building package 'linux-headers-4.14.111' in '../linux-headers-4.14.111_4.14.111-1_arm64.deb'.
dpkg-deb: building package 'linux-libc-dev' in '../linux-libc-dev_4.14.111-1_arm64.deb'.
dpkg-deb: building package 'linux-image-4.14.111' in '../linux-image-4.14.111_4.14.111-1_arm64.deb'.
dpkg-genchanges: warning: substitution variable ${kernel:debarch} used, but is not defined
dpkg-genchanges: info: binary-only upload (no source code included)
sudo dpkg -i ../linux-headers-4.14.111_4.14.111-1_arm64.deb
git clone https://github.com/ntop/PF_RING.git
cd PF_RING/kernel/
make