Difference between revisions of "Buildroot/zh"
(→同步项目到最新版本) |
(updated by API) |
||
Line 48: | Line 48: | ||
mkdir linuxsdk-friendlyelec | mkdir linuxsdk-friendlyelec | ||
cd linuxsdk-friendlyelec | cd linuxsdk-friendlyelec | ||
− | repo init -u https://github.com/friendlyarm/buildroot_manifests -b | + | repo init -u https://github.com/friendlyarm/buildroot_manifests -b friendlyelec -m rk3399_linux_release.xml --repo-url=https://github.com/rockchip-linux/repo --no-clone-bundle |
repo sync -c --no-clone-bundle | repo sync -c --no-clone-bundle | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 77: | Line 77: | ||
==如何编译== | ==如何编译== | ||
===搭建编译环境=== | ===搭建编译环境=== | ||
− | + | 在PC的Ubuntu (推荐版本:18.04 64bit) 系统下,执下以下命令安装所需的软件: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | sudo apt-get install | + | sudo apt-get update |
− | + | sudo apt-get -y install git time aria2 wget make lsb-release openssh-client vim tree exfat-fuse exfat-utils u-boot-tools mediainfo \ | |
− | + | libasound2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libxcb-xinerama0 libxcb-xinerama0-dev \ | |
− | + | libopenal-dev libalut-dev libpulse-dev libuv1-dev libmicrohttpd-dev libssl-dev bridge-utils ifplugd \ | |
− | + | libbluetooth3-dev libjpeg8 libjpeg8-dev libjpeg-turbo8 libjpeg-turbo8-dev libvpx-dev \ | |
− | + | libgtk2.0-dev libnss3 libgconf-2-4 gconf2 gconf2-common libx11-dev libxext-dev libxtst-dev \ | |
− | + | libxrender-dev libxmu-dev libxmuu-dev libxfixes-dev libxfixes3 libpangocairo-1.0-0 \ | |
+ | libpangoft2-1.0-0 libdbus-1-dev libdbus-1-3 libusb-0.1-4 libusb-dev \ | ||
+ | bison build-essential gperf flex ruby python libasound2-dev libbz2-dev libcap-dev \ | ||
+ | libcups2-dev libdrm-dev libegl1-mesa-dev libgcrypt11-dev libnss3-dev libpci-dev libpulse-dev libudev-dev \ | ||
+ | libxtst-dev gyp ninja-build \ | ||
+ | libssl-dev libxcursor-dev libxcomposite-dev libxdamage-dev libxrandr-dev \ | ||
+ | libfontconfig1-dev libxss-dev libsrtp0-dev libwebp-dev libjsoncpp-dev libopus-dev libminizip-dev \ | ||
+ | libavutil-dev libavformat-dev libavcodec-dev libevent-dev libcups2-dev libpapi-dev \ | ||
+ | gcc-aarch64-linux-gnu g++-aarch64-linux-gnu gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf \ | ||
+ | qemu-user-static debootstrap whiptail bsdtar bc device-tree-compiler \ | ||
+ | swig python-dev python3-dev liblz4-tool | ||
+ | sudo apt-get -y install kmod cpio rsync patchelf | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 03:18, 27 September 2021
1 Buildroot简介
Buildroot是Linux平台上一个构建嵌入式Linux系统的框架,由Makefile脚本和Kconfig配置文件构成,旨在简化系统制作步骤,可实现一站式生成可烧写的系统固件,最终的固件包含boot-loader、kernel和rootfs,以及rootfs中的各种库和应用程序 (例如qt, gstreamer, busybox等)。
由 FriendlyELEC 提供的 Buildroot 项目是基于Rockchip原厂的 linux-sdk 制作, 项目使用 git 管理,与原厂的linux sdk更新保持同步;
- Rockchip原厂Buildroot项目: https://github.com/rockchip-linux/buildroot
- Buildroot官网: https://buildroot.org
2 下载体验版固件
访问此处的下载地址下载:
Image Files | |
rk3399-sd-buildroot-linux-4.4-arm64-YYYYMMDD.img.zip | 从SD卡启动的固件 |
rk3399-eflasher-buildroot-YYYYMMDD.img.zip | 用于烧写到eMMC运行 |
解压后用 dd 或者 win32image 烧写到 SD 卡。
3 帐户与密码
用户名: root
密码: rockchip
4 获取项目源代码
4.1 安装 repo 工具
首先需要安装 repo 工具:
git clone https://github.com/friendlyarm/repo cp repo/repo /usr/bin/
4.2 下载项目源代码
有以下两种途径获取项目源代码,中国大陆用户建议使用方法1的途径下载:
4.2.1 方法一:使用网盘里的repo压缩包
网盘下载地址: 点击进入
文件位于网盘的以下路径:sources/linuxsdk-friendlyelec-YYYYMMDD.tar (YYYYMMDD表示打包的日期)
从网盘中获取的 repo 压缩包在解压之后,需要执行一下以下命令做一次解包动作:
tar xvf /path/to/netdisk/sources/linuxsdk-friendlyelec-YYYYMMDD.tar cd linuxsdk-friendlyelec repo sync -l
用此方法得到的源代码版本是repo打包时的版本,如果想拉取到官方最新的版本,可以去掉 -l 参数,执行一次 repo sync, 例如:
cd linuxsdk-friendlyelec repo sync --no-clone-bundle
4.2.2 方法二:从github下载
mkdir linuxsdk-friendlyelec cd linuxsdk-friendlyelec repo init -u https://github.com/friendlyarm/buildroot_manifests -b friendlyelec -m rk3399_linux_release.xml --repo-url=https://github.com/rockchip-linux/repo --no-clone-bundle repo sync -c --no-clone-bundle
4.2.3 同步项目到最新版本
4.2.3.1 仅同步友善电子的部分仓库
repo sync kernel repo sync u-boot repo sync buildroot-device-custom_rk3399 repo sync buildroot-scripts_rk3399 repo sync sd-fuse_rk3399
4.2.3.2 同步所有
cd linuxsdk-friendlyelec 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
5 如何编译
5.1 搭建编译环境
在PC的Ubuntu (推荐版本:18.04 64bit) 系统下,执下以下命令安装所需的软件:
sudo apt-get update sudo apt-get -y install git time aria2 wget make lsb-release openssh-client vim tree exfat-fuse exfat-utils u-boot-tools mediainfo \ libasound2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libxcb-xinerama0 libxcb-xinerama0-dev \ libopenal-dev libalut-dev libpulse-dev libuv1-dev libmicrohttpd-dev libssl-dev bridge-utils ifplugd \ libbluetooth3-dev libjpeg8 libjpeg8-dev libjpeg-turbo8 libjpeg-turbo8-dev libvpx-dev \ libgtk2.0-dev libnss3 libgconf-2-4 gconf2 gconf2-common libx11-dev libxext-dev libxtst-dev \ libxrender-dev libxmu-dev libxmuu-dev libxfixes-dev libxfixes3 libpangocairo-1.0-0 \ libpangoft2-1.0-0 libdbus-1-dev libdbus-1-3 libusb-0.1-4 libusb-dev \ bison build-essential gperf flex ruby python libasound2-dev libbz2-dev libcap-dev \ libcups2-dev libdrm-dev libegl1-mesa-dev libgcrypt11-dev libnss3-dev libpci-dev libpulse-dev libudev-dev \ libxtst-dev gyp ninja-build \ libssl-dev libxcursor-dev libxcomposite-dev libxdamage-dev libxrandr-dev \ libfontconfig1-dev libxss-dev libsrtp0-dev libwebp-dev libjsoncpp-dev libopus-dev libminizip-dev \ libavutil-dev libavformat-dev libavcodec-dev libevent-dev libcups2-dev libpapi-dev \ gcc-aarch64-linux-gnu g++-aarch64-linux-gnu gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf \ qemu-user-static debootstrap whiptail bsdtar bc device-tree-compiler \ swig python-dev python3-dev liblz4-tool sudo apt-get -y install kmod cpio rsync patchelf
5.2 全自动方式编译
./build.sh
5.3 部分编译
5.3.1 kernel
./build.sh kernel
5.3.2 u-boot
./build.sh uboot
5.3.3 rootfs
./build.sh rootfs
5.4 生成sdcard固件
sudo ./build.sh sd-img
或者直接将固件烧写到sd卡:
./friendlyelec/rk3399/sd-fuse_rk3399/fusing.sh /dev/sdX buildroot
其中,/dev/sdX请替换为真实的SD卡设备文件名。
5.5 生成emmc (eflasher) 固件
sudo ./build.sh emmc-img
5.6 查看帮助
# ./build.sh help ====USAGE: build.sh modules==== 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
重点参数说明:
uboot -单独编译uboot
kernel -单独编译kernel
rootfs -单独编译buildroot
buildroot -同上
sdimg -生成用于dd到sd卡的image文件,以及用于eFlasher工具使用的eMMC烧写文件
6 Buildroot定制与开发
6.1 目录结构
├── linuxsdk-friendlyelec │ ├── app │ ├── buildroot buildroot根文件系统的编译目录 │ ├── build.sh -> device/rockchip/common/build.sh 全自动编译脚本 │ ├── device 编译相关配置文件 │ ├── distro debian根文件系统生成目录 │ ├── docs 文档 │ ├── envsetup.sh -> buildroot/build/envsetup.sh │ ├── external │ ├── friendlyelec 用于适配友善电子RK3399开发板的文件 │ ├── kernel 内核 │ ├── 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
6.1.1 更改Buildroot配置
- 列出当前可用的配置
cd buildroot make list-defconfigs
显示所下:
rockchip_rk3399_defconfig - Build for rockchip_rk3399
- 使用menuconfig更改配置
make rockchip_rk3399_defconfig make menuconfig make savedefconfig diff .defconfig configs/rockchip_rk3399_defconfig cp .defconfig configs/rockchip_rk3399_defconfig
- 重新编译
cd ../ ./build.sh rootfs
6.2 预装文件到文件系统
将文件放在 friendlyelec/rk3399/fs-overlay-64,然后重新编译 rootfs。
6.3 修改u-boot和kernel
直接修改u-boot和kernel目录下的文件即可。
6.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)
6.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的文件路径即可。
7 常见问题
7.1 如何获取用于USB Type-C烧写的文件?
执行 build.sh emmc-img 之后,在 friendlyelec/rk3399/sd-fuse_rk3399 下面会有一个 buildroot 目录,使用android_tools工具加载这个目录下的文件即可。