Difference between revisions of "Buildroot/zh"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
(updated by API)
 
(17 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
==Buildroot简介==
 
==Buildroot简介==
{{RK3399 Buildroot Intro/zh}}
+
{{RK3399 Buildroot Intro/zh|NanoPC-T4}}
  
 
==下载体验版固件==
 
==下载体验版固件==
访问[http://download.friendlyarm.com/nanopct4 此处的下载地址]下载:<br />
+
===Buildroot for RK3588===
 +
访问[http://download.friendlyelec.com/nanopct6 此处的下载地址]下载:<br />
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
 
   | colspan=2 | Image Files
 
   | colspan=2 | Image Files
 
|-
 
|-
   | rk3399-sd-buildroot-linux-4.4-arm64-YYYYMMDD.img.zip
+
   | rk3588-sd-buildroot-5.10-arm64-YYYYMMDD.img.gz
 
   | 从SD卡启动的固件
 
   | 从SD卡启动的固件
 
|-
 
|-
   | rk3399-eflasher-buildroot-YYYYMMDD.img.zip
+
  | rk3588-eflasher-buildroot-YYYYMMDD.img.gz
 +
  | 用于烧写到eMMC运行
 +
|}
 +
===Buildroot for RK3568===
 +
访问[http://download.friendlyelec.com/nanopir5s 此处的下载地址]下载:<br />
 +
{| class="wikitable"
 +
|-
 +
  | colspan=2 | Image Files
 +
|-
 +
  | rk3568-sd-buildroot-5.10-arm64-YYYYMMDD.img.gz
 +
  | 从SD卡启动的固件
 +
|-
 +
  | rk3568-eflasher-buildroot-YYYYMMDD.img.gz
 +
  | 用于烧写到eMMC运行
 +
|}
 +
===Buildroot for RK3399===
 +
访问[http://download.friendlyelec.com/nanopct4 此处的下载地址]下载:<br />
 +
{| class="wikitable"
 +
|-
 +
  | colspan=2 | Image Files
 +
|-
 +
  | rk3399-sd-buildroot-linux-4.19-arm64-YYYYMMDD.img.zip
 +
  | 从SD卡启动的固件
 +
|-
 +
   | rk3399-eflasher-buildroot-4.19-arm64-YYYYMMDD.img.gz
 +
  | 用于烧写到eMMC运行
 +
|}
 +
===Buildroot for RK3328===
 +
访问[http://download.friendlyelec.com/nanopir2cplus 此处的下载地址]下载:<br />
 +
{| class="wikitable"
 +
|-
 +
  | colspan=2 | Image Files
 +
|-
 +
  | rk3328-sd-buildroot-linux-4.19-arm64-YYYYMMDD.img.zip
 +
  | 从SD卡启动的固件
 +
|-
 +
  | rk3328-eflasher-buildroot-4.19-arm64-YYYYMMDD.img.gz
 
   | 用于烧写到eMMC运行
 
   | 用于烧写到eMMC运行
 
|}
 
|}
解压后用 dd 或者 win32image 烧写到 SD 卡。
 
  
 +
解压后用 dd 或者 win32image 烧写到 SD 卡。
 +
==帐户与密码==
 +
用户名: root<br />
 +
密码: rockchip<br />
 +
<br />
 +
密码可通过以下文件更改:
 +
<syntaxhighlight lang="bash">
 +
buildroot/configs/rockchip/network.config # branch: rockchip-kernel4.19
 +
buildroot/rockchip/base/common.config    # branch: rockchip-kernel5.10
 +
</syntaxhighlight>
 +
==连接WiFi==
 +
* 编辑 /etc/wpa_supplicant.conf, 在ssid与psk处填上要连接的WiFi信息
 +
* 使用如下命令启动wpa_supplicant进程
 +
<syntaxhighlight lang="bash">
 +
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
 +
</syntaxhighlight>
 +
* 没有错误的话, 用命令 ifconfig wlan0 可以查看ip地址
 
==获取项目源代码==
 
==获取项目源代码==
 
===安装 repo 工具===
 
===安装 repo 工具===
 
首先需要安装 repo 工具:
 
首先需要安装 repo 工具:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://github.com/friendlyarm/repo
+
git clone https://github.com/friendlyarm/repo --depth 1
cp repo/repo /usr/bin/
+
sudo cp repo/repo /usr/bin/
 
</syntaxhighlight>
 
</syntaxhighlight>
 
===下载项目源代码===
 
===下载项目源代码===
 
有以下两种途径获取项目源代码,中国大陆用户建议使用方法1的途径下载:
 
有以下两种途径获取项目源代码,中国大陆用户建议使用方法1的途径下载:
 
====方法一:使用网盘里的repo压缩包====
 
====方法一:使用网盘里的repo压缩包====
网盘下载地址: [http://download.friendlyarm.com/{{#replace:{{#replace:{{BASEPAGENAME}}| |}}|/zh|}} 点击进入]<br />
+
网盘下载地址: [http://download.friendlyelec.com/nanopct6 RK3588]  [http://download.friendlyelec.com/nanopir5s RK3568]  [http://download.friendlyelec.com/nanopct4 RK3399]  [http://download.friendlyelec.com/nanopir2cplus RK3328]<br />
文件位于网盘的以下路径:sources/linuxsdk-friendlyelec-YYYYMMDD.tar (YYYYMMDD表示打包的日期)<br />
+
文件位于网盘的以下路径:07_源代码/buildroot-rkXXXX-YYYYMMDD.tar (YYYYMMDD表示打包的日期)<br />
 
从网盘中获取的 repo 压缩包在解压之后,需要执行一下以下命令做一次解包动作:
 
从网盘中获取的 repo 压缩包在解压之后,需要执行一下以下命令做一次解包动作:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
tar xvf /path/to/netdisk/sources/linuxsdk-friendlyelec-YYYYMMDD.tar
+
tar xvf /path/to/netdrive/07_源代码/buildroot-rkXXXX-YYYYMMDD.tar
cd linuxsdk-friendlyelec
+
cd buildroot-rkXXXX
 
repo sync -l
 
repo sync -l
 
</syntaxhighlight>
 
</syntaxhighlight>
 
用此方法得到的源代码版本是repo打包时的版本,如果想拉取到官方最新的版本,可以去掉 -l 参数,执行一次 repo sync, 例如:
 
用此方法得到的源代码版本是repo打包时的版本,如果想拉取到官方最新的版本,可以去掉 -l 参数,执行一次 repo sync, 例如:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
cd linuxsdk-friendlyelec
+
cd buildroot-rkXXXX
repo sync
+
repo sync --no-clone-bundle
 
</syntaxhighlight>
 
</syntaxhighlight>
 
====方法二:从github下载====
 
====方法二:从github下载====
 +
=====Buildroot for RK3588=====
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
mkdir linuxsdk-friendlyelec
+
mkdir buildroot-rk3588
cd linuxsdk-friendlyelec
+
cd buildroot-rk3588
repo init -u https://github.com/friendlyarm/buildroot_manifests -b master -m rk3399_linux_release.xml --repo-url=https://github.com/rockchip-linux/repo
+
repo init -u https://github.com/friendlyarm/buildroot_manifests \
repo sync -c
+
    -b rockchip-kernel5.10 -m rk3588.xml --repo-url=https://github.com/friendlyarm/repo \
 +
    --no-clone-bundle
 +
repo sync -c --no-clone-bundle
 +
</syntaxhighlight>
 +
=====Buildroot for RK3568=====
 +
<syntaxhighlight lang="bash">
 +
mkdir buildroot-rk3568
 +
cd buildroot-rk3568
 +
repo init -u https://github.com/friendlyarm/buildroot_manifests \
 +
    -b rockchip-kernel5.10 -m rk3568.xml --repo-url=https://github.com/friendlyarm/repo \
 +
    --no-clone-bundle
 +
repo sync -c --no-clone-bundle
 +
</syntaxhighlight>
 +
=====Buildroot for RK3399=====
 +
<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>
 +
=====Buildroot for RK3328=====
 +
<syntaxhighlight lang="bash">
 +
mkdir buildroot-rk3328
 +
cd buildroot-rk3328
 +
repo init -u https://github.com/friendlyarm/buildroot_manifests \
 +
    -b rockchip-kernel4.19 -m rk3328.xml --repo-url=https://github.com/friendlyarm/repo \
 +
    --no-clone-bundle
 +
repo sync -c --no-clone-bundle
 
</syntaxhighlight>
 
</syntaxhighlight>
 
====同步项目到最新版本====
 
====同步项目到最新版本====
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
cd linuxsdk-friendlyelec
+
repo sync -c --no-clone-bundle
repo sync -c
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 
同步过程中,由于网络原因出现中断,可以使用下面脚本同步代码:
 
同步过程中,由于网络原因出现中断,可以使用下面脚本同步代码:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
#! /bin/bash
 
#! /bin/bash
repo sync -c
+
repo sync -c --no-clone-bundle
 
while [ $? -ne 0 ];  
 
while [ $? -ne 0 ];  
 
do   
 
do   
     repo sync -c
+
     repo sync -c --no-clone-bundle
 
done
 
done
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
==如何编译==
 
==如何编译==
 
===搭建编译环境===
 
===搭建编译环境===
在PC的Ubuntu系统下,执下以下命令安装所需的软件:
+
在PC的Ubuntu系统下 (建议使用版本20.04-64bit),执下以下命令安装所需的软件:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
sudo apt-get install repo git-core gitk git-gui gcc-arm-linux-gnueabihf u-boot-tools device-tree-
+
wget -O - https://raw.githubusercontent.com/friendlyarm/build-env-on-ubuntu-bionic/master/install.sh | bash
compiler gcc-aarch64-linux-gnu mtools parted libudev-dev libusb-1.0-0-dev python-linaro-image-
+
</syntaxhighlight>
tools linaro-image-tools autoconf autotools-dev libsigsegv2 m4 intltool libdrm-dev curl sed make
+
===在Docker容器里编译===
binutils build-essential gcc g++ bash patch gzip bzip2 perl tar cpio python unzip rsync file bc wget
+
请使用此链接提供的Docker映象, 具体方法可阅读此链接中的README:<br />
libncurses5 libqt4-dev libglib2.0-dev libgtk2.0-dev libglade2-dev cvs git mercurial rsync openssh-
+
[https://github.com/friendlyarm/docker-cross-compiler-novnc docker-cross-compiler-novnc]<br />
client subversion asciidoc w3m dblatex graphviz python-matplotlib libc6:i386 libssl-dev texinfo
+
 
liblz4-tool genext2fs lib32stdc++6
+
===查看帮助===
 +
不带参数执行 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>
 
</syntaxhighlight>
  
 
===全自动方式编译===
 
===全自动方式编译===
 +
初次编译,需要选择目标的硬件平台,以RK3399平台的R4S为例:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
./build.sh
+
./build.sh nanopi_r4s.mk
 
</syntaxhighlight>
 
</syntaxhighlight>
===部分编译===
+
执行上述命令,会自动编译所有组件,其中包括u-boot, kernel 和 buildroot,并生成sd启动的烧写镜像文件。
 +
 
 +
===编译单独的模块===
 
====kernel====
 
====kernel====
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 89: Line 198:
 
./build.sh uboot
 
./build.sh uboot
 
</syntaxhighlight>
 
</syntaxhighlight>
====rootfs====
+
====buildroot====
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
./build.sh rootfs
+
./build.sh buildroot
 
</syntaxhighlight>
 
</syntaxhighlight>
 
===生成sdcard固件===
 
===生成sdcard固件===
Line 97: Line 206:
 
sudo ./build.sh sd-img
 
sudo ./build.sh sd-img
 
</syntaxhighlight>
 
</syntaxhighlight>
或者直接将固件烧写到sd卡:
+
打包img成功后,终端会显示如下信息,可以参考下面的dd命令将img写入sd卡,注意/dev/sdX需要替换成真实的sd卡设备:<br />
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
./friendlyelec/rk3399/sd-fuse_rk3399/fusing.sh /dev/sdX buildroot
+
Run the following for sdcard install:
 +
    sudo dd if=out/Buildroot_20211213_NanoPi-R4S_arm64_sd.img bs=1M of=/dev/sdX
 
</syntaxhighlight>
 
</syntaxhighlight>
其中,/dev/sdX请替换为真实的SD卡设备文件名。
 
 
===生成emmc (eflasher) 固件===
 
===生成emmc (eflasher) 固件===
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
sudo ./build.sh emmc-img
 
sudo ./build.sh emmc-img
 
</syntaxhighlight>
 
</syntaxhighlight>
 
+
打包img成功后,终端会显示如下信息,可以参考下面的dd命令将img写入sd卡,注意/dev/sdX需要替换成真实的sd卡设备:<br />
===查看帮助===
+
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
# ./build.sh help
+
Run the following for sdcard install:
====USAGE: build.sh modules====
+
    sudo dd if=out/Buildroot_20211213_NanoPi-R4S_arm64_eflasher.img bs=1M of=/dev/sdX
uboot              -build uboot
+
kernel            -build kernel
+
rootfs            -build default rootfs, currently build buildroot as default
+
buildroot          -build buildroot rootfs
+
ramboot            -build ramboot image
+
yocto              -build yocto rootfs, currently build ros as default
+
ros                -build ros rootfs
+
debian            -build debian rootfs
+
pcba              -build pcba
+
recovery          -build recovery
+
all                -build uboot, kernel, rootfs, recovery image
+
cleanall          -clean uboot, kernel, rootfs, recovery
+
firmware          -pack all the image we need to boot up system
+
updateimg          -pack update image
+
sd-img            -pack sd-card image, used to create bootable SD card
+
emmc-img          -pack sd-card image, used to install buildroot to emmc
+
save              -save images, patches, commands used to debug
+
default            -build all module
+
 
</syntaxhighlight>
 
</syntaxhighlight>
重点参数说明:<br />
+
用此sd卡启动eflasher系统,执行eflasher命令,将系统写入emmc,之后就可以拨掉sd卡,从emmc启动buildroot了。
uboot              -单独编译uboot<br />
+
kernel            -单独编译kernel<br />
+
rootfs            -单独编译buildroot<br />
+
buildroot          -同上<br />
+
sdimg              -生成用于dd到sd卡的image文件,以及用于eFlasher工具使用的eMMC烧写文件<br />
+
<br />
+
  
 
==Buildroot定制与开发==
 
==Buildroot定制与开发==
 
===目录结构===
 
===目录结构===
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
├── linuxsdk-friendlyelec
+
├── buildroot-xxyyzz
│  ├── app
+
│  ├── buildroot -> buildroot源代码
  ├── buildroot buildroot根文件系统的编译目录
+
|   └── toolchain -> 交叉编译器,仅用于编译u-boot与kernel
│  ├── build.sh -> device/rockchip/common/build.sh 全自动编译脚本
+
│  ├── build.sh -> 编译脚本
│  ├── device 编译相关配置文件
+
│  ├── device/friendlyelec -> 用于适配友善电子开发板的相关文件
│  ├── distro debian根文件系统生成目录
+
│  ├── kernel -> 内核
│  ├── docs 文档
+
│  └── u-boot -> u-boot
│  ├── envsetup.sh -> buildroot/build/envsetup.sh
+
│  └── app -> rockchip的app
│  ├── external
+
│  └── external -> rockchip的buildroot软件包
│  ├── friendlyelec 用于适配友善电子RK3399开发板的文件
+
│  └── rkbin -> rockchip的引导程序
│  ├── kernel 内核
+
│  └── scripts -> 打包img的相关脚本
│  ├── Makefile -> buildroot/build/Makefile
+
│  ├── mkfirmware.sh -> device/rockchip/common/mkfirmware.sh rockdev链接更新脚本
+
│  ├── prebuilts
+
│  ├── rkbin  
+
│  ├── rkflash.sh -> device/rockchip/common/rkflash.sh 烧写脚本
+
│  ├── rootfs debian根文件系统编译目录
+
│  ├── tools 烧写、打包工具
+
│  └── u-boot u-boot
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 
====更改Buildroot配置====
 
====更改Buildroot配置====
 
* 列出当前可用的配置
 
* 列出当前可用的配置
Line 167: Line 244:
 
make list-defconfigs
 
make list-defconfigs
 
</syntaxhighlight>
 
</syntaxhighlight>
显示所下:<br />
+
适合FriendlyELEC RK3399的配置所下:<br />
rockchip_rk3399_defconfig           - Build for rockchip_rk3399<br />
+
friendlyelec_rk3399_defconfig           - Build for friendlyelec_rk3399<br />
 
* 使用menuconfig更改配置
 
* 使用menuconfig更改配置
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
make rockchip_rk3399_defconfig
+
make friendlyelec_rk3399_defconfig
 
make menuconfig
 
make menuconfig
 
make savedefconfig
 
make savedefconfig
diff .defconfig configs/rockchip_rk3399_defconfig
+
diff .defconfig configs/friendlyelec_rk3399_defconfig
cp .defconfig configs/rockchip_rk3399_defconfig
+
cp .defconfig configs/friendlyelec_rk3399_defconfig
 
</syntaxhighlight>
 
</syntaxhighlight>
 
* 重新编译
 
* 重新编译
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
cd ../
 
cd ../
./build.sh rootfs
+
./build.sh buildroot
 
</syntaxhighlight>
 
</syntaxhighlight>
 
===预装文件到文件系统===
 
===预装文件到文件系统===
将文件放在 friendlyelec/rk3399/fs-overlay-64,然后重新编译 rootfs。
+
将文件放在 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===
 
直接修改u-boot和kernel目录下的文件即可。
 
直接修改u-boot和kernel目录下的文件即可。
Line 203: Line 284:
 
==常见问题==
 
==常见问题==
 
===如何获取用于USB Type-C烧写的文件?===
 
===如何获取用于USB Type-C烧写的文件?===
执行 build.sh emmc-img 之后,在 friendlyelec/rk3399/sd-fuse_rk3399 下面会有一个 buildroot 目录,使用android_tools工具加载这个目录下的文件即可。
+
执行 build.sh emmc-img 之后,在 scripts/sd-fuse 下面会有一个 buildroot 目录,使用android_tools工具加载这个目录下的文件即可。
 +
==报告bug==
 +
欢迎发邮件到:techsupport@friendlyarm.com<br />
 +
==更新日志==
 +
===2023-08-15===
 +
* 增加rk3588的支持
 +
* 将buildroot更新至原厂新版本 linux-5.10-gen-rkr5.1
 +
===2022-07-20===
 +
* 增加rk3568的支持
 +
* 将buildroot更新至原厂新版本
 +
===2021-12-23===
 +
* 简化构建脚本, 并将buildroot更新至原厂新版本

Latest revision as of 11:26, 16 August 2023

English

1 Buildroot简介

Buildroot是Linux平台上一个构建嵌入式Linux系统的框架,由Makefile脚本和Kconfig配置文件构成,旨在简化系统制作步骤,可实现一站式生成可烧写的系统固件,最终的固件包含boot-loader、kernel和rootfs,以及rootfs中的各种库和应用程序 (例如qt, gstreamer, busybox等)。

由 FriendlyELEC 提供的 Buildroot 项目是基于Rockchip原厂的 linux-sdk 制作, 项目使用 git 管理,与原厂的linux sdk更新保持同步;


Buildroot for rockchip运行界面如下:

  • Rk3399-buildroot-home.jpg
  • Rk3399-buildroot-console.jpg

  • Rk3399-buildroot-camera.jpg
  • Rk3399-buildroot-player.jpg

2 下载体验版固件

2.1 Buildroot for RK3588

访问此处的下载地址下载:

Image Files
rk3588-sd-buildroot-5.10-arm64-YYYYMMDD.img.gz 从SD卡启动的固件
rk3588-eflasher-buildroot-YYYYMMDD.img.gz 用于烧写到eMMC运行

2.2 Buildroot for RK3568

访问此处的下载地址下载:

Image Files
rk3568-sd-buildroot-5.10-arm64-YYYYMMDD.img.gz 从SD卡启动的固件
rk3568-eflasher-buildroot-YYYYMMDD.img.gz 用于烧写到eMMC运行

2.3 Buildroot for RK3399

访问此处的下载地址下载:

Image Files
rk3399-sd-buildroot-linux-4.19-arm64-YYYYMMDD.img.zip 从SD卡启动的固件
rk3399-eflasher-buildroot-4.19-arm64-YYYYMMDD.img.gz 用于烧写到eMMC运行

2.4 Buildroot for RK3328

访问此处的下载地址下载:

Image Files
rk3328-sd-buildroot-linux-4.19-arm64-YYYYMMDD.img.zip 从SD卡启动的固件
rk3328-eflasher-buildroot-4.19-arm64-YYYYMMDD.img.gz 用于烧写到eMMC运行

解压后用 dd 或者 win32image 烧写到 SD 卡。

3 帐户与密码

用户名: root
密码: rockchip

密码可通过以下文件更改:

buildroot/configs/rockchip/network.config # branch: rockchip-kernel4.19
buildroot/rockchip/base/common.config     # branch: rockchip-kernel5.10

4 连接WiFi

  • 编辑 /etc/wpa_supplicant.conf, 在ssid与psk处填上要连接的WiFi信息
  • 使用如下命令启动wpa_supplicant进程
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
  • 没有错误的话, 用命令 ifconfig wlan0 可以查看ip地址

5 获取项目源代码

5.1 安装 repo 工具

首先需要安装 repo 工具:

git clone https://github.com/friendlyarm/repo --depth 1
sudo cp repo/repo /usr/bin/

5.2 下载项目源代码

有以下两种途径获取项目源代码,中国大陆用户建议使用方法1的途径下载:

5.2.1 方法一:使用网盘里的repo压缩包

网盘下载地址: RK3588 RK3568 RK3399 RK3328
文件位于网盘的以下路径:07_源代码/buildroot-rkXXXX-YYYYMMDD.tar (YYYYMMDD表示打包的日期)
从网盘中获取的 repo 压缩包在解压之后,需要执行一下以下命令做一次解包动作:

tar xvf /path/to/netdrive/07_源代码/buildroot-rkXXXX-YYYYMMDD.tar
cd buildroot-rkXXXX
repo sync -l

用此方法得到的源代码版本是repo打包时的版本,如果想拉取到官方最新的版本,可以去掉 -l 参数,执行一次 repo sync, 例如:

cd buildroot-rkXXXX
repo sync --no-clone-bundle

5.2.2 方法二:从github下载

5.2.2.1 Buildroot for RK3588
mkdir buildroot-rk3588
cd buildroot-rk3588
repo init -u https://github.com/friendlyarm/buildroot_manifests \
    -b rockchip-kernel5.10 -m rk3588.xml --repo-url=https://github.com/friendlyarm/repo \
    --no-clone-bundle
repo sync -c --no-clone-bundle
5.2.2.2 Buildroot for RK3568
mkdir buildroot-rk3568
cd buildroot-rk3568
repo init -u https://github.com/friendlyarm/buildroot_manifests \
    -b rockchip-kernel5.10 -m rk3568.xml --repo-url=https://github.com/friendlyarm/repo \
    --no-clone-bundle
repo sync -c --no-clone-bundle
5.2.2.3 Buildroot for RK3399
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
5.2.2.4 Buildroot for RK3328
mkdir buildroot-rk3328
cd buildroot-rk3328
repo init -u https://github.com/friendlyarm/buildroot_manifests \
    -b rockchip-kernel4.19 -m rk3328.xml --repo-url=https://github.com/friendlyarm/repo \
    --no-clone-bundle
repo sync -c --no-clone-bundle

5.2.3 同步项目到最新版本

repo sync -c --no-clone-bundle

同步过程中,由于网络原因出现中断,可以使用下面脚本同步代码:

#! /bin/bash
repo sync -c --no-clone-bundle
while [ $? -ne 0 ]; 
do  
    repo sync -c --no-clone-bundle
done

6 如何编译

6.1 搭建编译环境

在PC的Ubuntu系统下 (建议使用版本20.04-64bit),执下以下命令安装所需的软件:

wget -O - https://raw.githubusercontent.com/friendlyarm/build-env-on-ubuntu-bionic/master/install.sh | bash

6.2 在Docker容器里编译

请使用此链接提供的Docker映象, 具体方法可阅读此链接中的README:
docker-cross-compiler-novnc

6.3 查看帮助

不带参数执行 build.sh,默认是打印帮助信息:

./build.sh

显示的帮助信息如下 (以RK3399平台为例):

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

6.4 全自动方式编译

初次编译,需要选择目标的硬件平台,以RK3399平台的R4S为例:

./build.sh nanopi_r4s.mk

执行上述命令,会自动编译所有组件,其中包括u-boot, kernel 和 buildroot,并生成sd启动的烧写镜像文件。

6.5 编译单独的模块

6.5.1 kernel

./build.sh kernel

6.5.2 u-boot

./build.sh uboot

6.5.3 buildroot

./build.sh buildroot

6.6 生成sdcard固件

sudo ./build.sh sd-img

打包img成功后,终端会显示如下信息,可以参考下面的dd命令将img写入sd卡,注意/dev/sdX需要替换成真实的sd卡设备:

Run the following for sdcard install:
    sudo dd if=out/Buildroot_20211213_NanoPi-R4S_arm64_sd.img bs=1M of=/dev/sdX

6.7 生成emmc (eflasher) 固件

sudo ./build.sh emmc-img

打包img成功后,终端会显示如下信息,可以参考下面的dd命令将img写入sd卡,注意/dev/sdX需要替换成真实的sd卡设备:

Run the following for sdcard install:
    sudo dd if=out/Buildroot_20211213_NanoPi-R4S_arm64_eflasher.img bs=1M of=/dev/sdX

用此sd卡启动eflasher系统,执行eflasher命令,将系统写入emmc,之后就可以拨掉sd卡,从emmc启动buildroot了。

7 Buildroot定制与开发

7.1 目录结构

├── 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的相关脚本

7.1.1 更改Buildroot配置

  • 列出当前可用的配置
cd buildroot
make list-defconfigs

适合FriendlyELEC RK3399的配置所下:
friendlyelec_rk3399_defconfig - Build for friendlyelec_rk3399

  • 使用menuconfig更改配置
make friendlyelec_rk3399_defconfig
make menuconfig
make savedefconfig
diff .defconfig configs/friendlyelec_rk3399_defconfig 
cp .defconfig configs/friendlyelec_rk3399_defconfig
  • 重新编译
cd ../
./build.sh buildroot

7.2 预装文件到文件系统

将文件放在 device/friendlyelec/rk3399/common-files,然后重新打包img:

sudo ./build.sh sd-img
sudo ./build.sh emmc-img

7.3 修改u-boot和kernel

直接修改u-boot和kernel目录下的文件即可。

7.4 使用sdk里的交叉编译器

export PATH=$PWD/buildroot/output/rockchip_rk3399/host/bin/:$PATH
aarch64-buildroot-linux-gnu-g++ -v

显示版本如下:
gcc 版本 6.4.0 (Buildroot 2018.02-rc3-g4f000a0797)

7.5 交叉编译Qt程序

git clone https://github.com/friendlyarm/QtE-Demo.git
cd QtE-Demo
../buildroot/output/rockchip_rk3399/host/bin/qmake QtE-Demo.pro
make

要实现开机自动运行你的Qt程序,可将QtE-Demo拷贝到开发板上,然后修改 /etc/init.d/下的S50launcher,将/usr/local/QLauncher/QLauncher &这一行改为QtE-Demo的文件路径即可。

8 常见问题

8.1 如何获取用于USB Type-C烧写的文件?

执行 build.sh emmc-img 之后,在 scripts/sd-fuse 下面会有一个 buildroot 目录,使用android_tools工具加载这个目录下的文件即可。

9 报告bug

欢迎发邮件到:techsupport@friendlyarm.com

10 更新日志

10.1 2023-08-15

  • 增加rk3588的支持
  • 将buildroot更新至原厂新版本 linux-5.10-gen-rkr5.1

10.2 2022-07-20

  • 增加rk3568的支持
  • 将buildroot更新至原厂新版本

10.3 2021-12-23

  • 简化构建脚本, 并将buildroot更新至原厂新版本