Buildroot

From FriendlyELEC WiKi
Revision as of 03:18, 27 September 2021 by Tzs (Talk | contribs) (updated by API)

Jump to: navigation, search

查看中文

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;


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 --no-clone-bundle

If you want to get the latest official source code you can run the following commands:

cd linuxsdk-friendlyelec
repo sync --no-clone-bundle

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 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 Get Latest Version with Sync

cd linuxsdk-friendlyelec
repo sync -c --no-clone-bundle

If your network connection is broken during sync you can run the following script to do it:

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

5 Compile Source Code

5.1 Setup Compilation Environment

Under Ubuntu (Recommended: 18.04 64bit) on a host PC run the following command:

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 Auto Compilation

./build.sh

5.3 Compile Partial Code

5.3.1 kernel

./build.sh kernel

5.3.2 u-boot

./build.sh uboot

5.3.3 rootfs

./build.sh rootfs

5.4 Generate Image for SD Card

sudo ./build.sh sd-img

Flash an image to an SD card:

./friendlyelec/rk3399/sd-fuse_rk3399/fusing.sh /dev/sdX buildroot

The "/dev/sdX" needs to be replaced with your actual SD card device name.

5.5 Generate Image for EMMC(Eflasher)

sudo ./build.sh emmc-img

5.6 Check Help Info

# ./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

Comments on popular parameters:
uboot -compile uboot only
kernel -compile kernel only
rootfs -compile buildroot only
buildroot -compile buildroot only
sdimg -generate an image which can be flashed to an SD card with the "dd" command and to eMMC with eFlasher

6 Customize Buildroot

6.1 Structure of Directories

├── linuxsdk-friendlyelec
│   ├── app
│   ├── buildroot buildroot's root directory
│   ├── build.sh -> device/rockchip/common/build.sh script for auto-compilation
│   ├── device configuration files
│   ├── distro debian's root directory
│   ├── docs documents
│   ├── envsetup.sh -> buildroot/build/envsetup.sh
│   ├── external
│   ├── friendlyelec configuration files for FriendlyElec's RK3399 
│   ├── kernel kernel
│   ├── Makefile -> buildroot/build/Makefile
│   ├── mkfirmware.sh -> device/rockchip/common/mkfirmware.sh script to update rockdev 
│   ├── prebuilts
│   ├── rkbin 
│   ├── rkflash.sh -> device/rockchip/common/rkflash.sh flashing script
│   ├── rootfs directory of debian's root file system
│   ├── tools tools and utilities for flashing and packaging
│   └── u-boot u-boot

6.1.1 Update Buildroot Configurations

  • List Available Configurations
cd buildroot
make list-defconfigs

Here is what you would get:
rockchip_rk3399_defconfig - Build for rockchip_rk3399

  • Update Configurations Using menuconfig
make rockchip_rk3399_defconfig
make menuconfig
make savedefconfig
diff .defconfig configs/rockchip_rk3399_defconfig 
cp .defconfig configs/rockchip_rk3399_defconfig
  • Recompile
cd ../
./build.sh rootfs

6.2 Customize File System

Put your files in the friendlyelec/rk3399/fs-overlay-64 directory and recompile "rootfs"

6.3 Update U-boot and Kernel

You can do it by directly updating the files in the u-boot and kernel directories.

6.4 Use Cross Compiler in SDK

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

Version information:
gcc version 6.4.0 (Buildroot 2018.02-rc3-g4f000a0797)

6.5 Cross Compile Qt Program

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

You can auto-run your Qt program on system boot. For example you want to auto-run a QtE-Demo program. Firstly you can copy the QtE-Demo to your board, open and edit the S50launcher file under the "/etc/init.d/" directory, replace "/usr/local/QLauncher/QLauncher &" with the full path of your QtE-Demo program.

7 Q&A

7.1 Generate Image File for Flashing with USB Type-C

After you run the "build.sh emmc-img" command a "buildroot" directory will be generated under the "friendlyelec/rk3399/sd-fuse_rk3399" directory. You can use the android_tools to load all the files under this "buildroot" directory.

8 Update Log

8.1 May-16-2019

  • Released English version