Buildroot
Contents
1 Introduction to Buildroot
Buildroot is a simple, efficient and easy-to-use tool to generate embedded Linux systems through cross-compilation. It contains a boot-loader, kernel, rootfs, various libraries and utilities(e.g. qt, gstreamer, busybox etc).
FriendlyELEC's Buildroot is based on Rockchip's version which is made with linux-sdk and maintained with git. FriendlyELEC's version is synced with Rockchip's version;
- Rockchip's Buildroot: https://github.com/rockchip-linux/buildroot
- Buildroot's official site: https://buildroot.org
2 Download Images of Trial Version
Visit Download LinkDownload:
Image Files | |
rk3399-sd-buildroot-linux-4.4-arm64-YYYYMMDD.img.zip | OS image booting from SD card |
rk3399-eflasher-buildroot-YYYYMMDD.img.zip | Image used to flash to eMMC |
After extract the file you can use either dd or the win32image utility to flash the image to an SD card.
3 User Name and Password
User name: root
Password: rockchip
4 Obtain Source Code
4.1 Install repo Utility
Install the repo utility:
git clone https://github.com/friendlyarm/repo cp repo/repo /usr/bin/
4.2 Download Source Code
You can retrieve a project's source code in either of the following two ways. The first works better with Mainland Chinese users:
4.2.1 1: Retrieve Repo Package from Cloud Storage
Download link: Click to enter
File location: sources/linuxsdk-friendlyelec-YYYYMMDD.tar (YYYYMMDD stands for the data when the package is generated)
After you get a tar package, untar it and run the following command to extract it:
tar xvf /path/to/netdisk/sources/linuxsdk-friendlyelec-YYYYMMDD.tar cd linuxsdk-friendlyelec repo sync -l
If you want to get the latest official source code you can run the following commands:
cd linuxsdk-friendlyelec repo sync
4.2.2 2: Retrive Repo Package from Github
mkdir linuxsdk-friendlyelec cd linuxsdk-friendlyelec 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 sync -c
4.2.3 Get Latest Version with Sync
cd linuxsdk-friendlyelec repo sync -c
If your network connection is broken during sync you can run the following script to do it:
#! /bin/bash repo sync -c while [ $? -ne 0 ]; do repo sync -c done
5 如何编译
5.1 搭建编译环境
在PC的Ubuntu系统下,执下以下命令安装所需的软件:
sudo apt-get install repo git-core gitk git-gui gcc-arm-linux-gnueabihf u-boot-tools device-tree- compiler gcc-aarch64-linux-gnu mtools parted libudev-dev libusb-1.0-0-dev python-linaro-image- tools linaro-image-tools autoconf autotools-dev libsigsegv2 m4 intltool libdrm-dev curl sed make binutils build-essential gcc g++ bash patch gzip bzip2 perl tar cpio python unzip rsync file bc wget libncurses5 libqt4-dev libglib2.0-dev libgtk2.0-dev libglade2-dev cvs git mercurial rsync openssh- client subversion asciidoc w3m dblatex graphviz python-matplotlib libc6:i386 libssl-dev texinfo liblz4-tool genext2fs lib32stdc++6
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工具加载这个目录下的文件即可。