|
|
(177 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | [[Buildroot for RK3399/zh|查看中文]]
| |
| | | |
− | ==Buildroot简介==
| + | {{BurnLinuxToExtDrive-Rockchip/zh|NanoPC-T4}} |
− | Buildroot是Linux平台上一个构建嵌入式Linux系统的框架,由Makefile脚本和Kconfig配置文件构成,旨在简化系统制作步骤,可实现一站式生成可烧写的系统固件,最终的固件包含boot-loader、kernel和rootfs,以及rootfs中的各种库和应用程序 (例如qt, gstreamer, busybox等)。<br />
| + | {{BurnLinuxToExtDrive-Rockchip|NanoPC-T4}} |
− | <br />
| + | |
− | 由 FriendlyELEC 提供的 Buildroot 项目是基于Rockchip原厂的 linux-sdk 制作, 项目使用 git 管理,与原厂的linux sdk更新保持同步;
| + | |
− | <br />
| + | |
− | * Rockchip原厂Buildroot项目: https://github.com/rockchip-linux/buildroot<br />
| + | |
− | * Buildroot官网: https://buildroot.org<br />
| + | |
− | <br />
| + | |
− | Buildroot for RK3399运行界面如下:
| + | |
− | <div><ul>
| + | |
− | <li style="display: inline-block;">[[File:rk3399-buildroot-home.jpg|500px]]</li>
| + | |
− | <li style="display: inline-block;">[[File:rk3399-buildroot-console.jpg|500px]] </li>
| + | |
− | </ul></div><br />
| + | |
− | <div><ul>
| + | |
− | <li style="display: inline-block;">[[File:rk3399-buildroot-camera.jpg|500px]]</li>
| + | |
− | <li style="display: inline-block;">[[File:rk3399-buildroot-player.jpg|500px]] </li>
| + | |
− | </ul></div>
| + | |
− | | + | |
− | ==下载体验版固件==
| + | |
− | 访问[http://download.friendlyarm.com/nanopct4 此处的下载地址]下载:<br />
| + | |
− | {| class="wikitable" | + | |
− | |-
| + | |
− | | colspan=2 | Image Files
| + | |
− | |- | + | |
− | | rk3399-sd-buildroot-linux-4.4-arm64-YYYYMMDD.img.zip
| + | |
− | | 从SD卡启动的固件
| + | |
− | |-
| + | |
− | | rk3399-eflasher-buildroot-YYYYMMDD.img.zip
| + | |
− | | 用于烧写到eMMC运行
| + | |
− | |}
| + | |
− | 解压后用 dd 或者 win32image 烧写到 SD 卡。
| + | |
− | | + | |
− | ==获取项目源代码==
| + | |
− | ===安装 repo 工具===
| + | |
− | 首先需要安装 repo 工具:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | git clone https://github.com/friendlyarm/repo
| + | |
− | cp repo/repo /usr/bin/
| + | |
− | </syntaxhighlight>
| + | |
− | ===下载项目源代码===
| + | |
− | 有以下两种途径获取项目源代码,中国大陆用户建议使用方法1的途径下载:
| + | |
− | ====方法一:使用网盘里的repo压缩包====
| + | |
− | 网盘下载地址: [http://download.friendlyarm.com/{{#replace:{{#replace:{{BASEPAGENAME}}| |}}|/zh|}} 点击进入]<br />
| + | |
− | 文件位于网盘的以下路径:sources/linuxsdk-friendlyelec-YYYYMMDD.tar (YYYYMMDD表示打包的日期)<br />
| + | |
− | 从网盘中获取的 repo 压缩包在解压之后,需要执行一下以下命令做一次解包动作:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | tar xvf /path/to/netdisk/sources/linuxsdk-friendlyelec-YYYYMMDD.tar
| + | |
− | cd linuxsdk-friendlyelec
| + | |
− | repo sync -l
| + | |
− | </syntaxhighlight>
| + | |
− | 用此方法得到的源代码版本是repo打包时的版本,如果想拉取到官方最新的版本,可以去掉 -l 参数,执行一次 repo sync, 例如:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | cd linuxsdk-friendlyelec
| + | |
− | repo sync
| + | |
− | </syntaxhighlight>
| + | |
− | ====方法二:从github下载====
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | 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
| + | |
− | </syntaxhighlight>
| + | |
− | ====同步项目到最新版本====
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | cd linuxsdk-friendlyelec
| + | |
− | repo sync -c
| + | |
− | </syntaxhighlight>
| + | |
− | 同步过程中,由于网络原因出现中断,可以使用下面脚本同步代码:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | #! /bin/bash
| + | |
− | repo sync -c
| + | |
− | while [ $? -ne 0 ];
| + | |
− | do
| + | |
− | repo sync -c
| + | |
− | done
| + | |
− | </syntaxhighlight>
| + | |
− | | + | |
− | ==如何编译==
| + | |
− | ===搭建编译环境===
| + | |
− | 在PC的Ubuntu系统下,执下以下命令安装所需的软件:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | 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
| + | |
− | </syntaxhighlight>
| + | |
− | | + | |
− | ===全自动方式编译===
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ./build.sh
| + | |
− | </syntaxhighlight>
| + | |
− | ===部分编译===
| + | |
− | ====kernel====
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ./build.sh kernel
| + | |
− | </syntaxhighlight>
| + | |
− | ====u-boot====
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ./build.sh uboot
| + | |
− | </syntaxhighlight>
| + | |
− | ====rootfs====
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ./build.sh rootfs
| + | |
− | </syntaxhighlight>
| + | |
− | ===生成sdcard固件===
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ./build.sh sd-img
| + | |
− | </syntaxhighlight>
| + | |
− | 或者直接将固件烧写到sd卡:
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ./friendlyelec/rk3399/sd-fuse_rk3399/fusing.sh /dev/sdX buildroot
| + | |
− | </syntaxhighlight>
| + | |
− | 其中,/dev/sdX请替换为真实的SD卡设备文件名。
| + | |
− | ===生成emmc (eflasher) 固件===
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ./build.sh emmc-img
| + | |
− | </syntaxhighlight>
| + | |
− | | + | |
− | ===查看帮助===
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | # ./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 -build sd-card image
| + | |
− | emmc-img -build sd-card image
| + | |
− | save -save images, patches, commands used to debug
| + | |
− | default -build all module
| + | |
− | </syntaxhighlight>
| + | |
− | 重点参数说明:<br />
| + | |
− | uboot -单独编译uboot<br />
| + | |
− | kernel -单独编译kernel<br />
| + | |
− | rootfs -单独编译buildroot<br />
| + | |
− | buildroot -同上<br />
| + | |
− | sdimg -生成用于dd到sd卡的image文件,以及用于eFlasher工具使用的eMMC烧写文件<br />
| + | |
− | <br />
| + | |
− | | + | |
− | ==Buildroot定制与开发==
| + | |
− | ===目录结构===
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | ├── 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
| + | |
− | </syntaxhighlight>
| + | |
− | ====更改Buildroot配置====
| + | |
− | * 列出当前可用的配置
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | cd buildroot
| + | |
− | make list-defconfigs
| + | |
− | </syntaxhighlight>
| + | |
− | 显示所下:<br />
| + | |
− | rockchip_rk3399_defconfig - Build for rockchip_rk3399<br />
| + | |
− | * 使用menuconfig更改配置
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | make rockchip_rk3399_defconfig
| + | |
− | make menuconfig
| + | |
− | make savedefconfig
| + | |
− | diff .defconfig configs/rockchip_rk3399_defconfig
| + | |
− | cp .defconfig configs/rockchip_rk3399_defconfig
| + | |
− | </syntaxhighlight>
| + | |
− | * 重新编译
| + | |
− | <syntaxhighlight lang="bash">
| + | |
− | cd ../
| + | |
− | ./build.sh rootfs
| + | |
− | </syntaxhighlight>
| + | |
− | ===预装文件到文件系统===
| + | |
− | 将文件放在 friendlyelec/rk3399/fs-overlay-64,然后重新编译 rootfs。
| + | |
− | ===修改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的文件路径即可。
| + | |
可以通过使用TF卡启动eFlasher系统,将引导和系统分别安装到不同存储设备,但是由于CPU不支持直接从M.2和USB设备引导,所以虽然系统可以安装到M.2和USB设备,但是引导仍然需要安装到eMMC或者TF卡。
操作步骤如下:
You can use a TF card to boot the eFlasher system, allowing the boot and system to be installed on different storage devices. However, since the CPU doesn’t support booting directly from M.2 and USB devices, the system can be installed on M.2 and USB devices, but the boot must still be installed on eMMC or a TF card.
Steps are as follows: