一、LSDK中使用yocto
yocto rootfs编译命令
# flex-builder -i mkrfs -r yocto:tiny -m ls1046ardb
生成文件: ./flexbuild_lsdk2108/build/images/rootfs_lsdk2108_yocto_tiny_arm64.tgz
注意:不要使用root用户编译,即使修改脚本跳过校验后面还会有很多难以修复的故障。
脚本第一步会下载yocto-poky到lexbuild_lsdk2108/components/rfs,这里如果是离线下载拷贝进来也要用普通用户解压,否则亦会出错;
pathname: flexbuild_lsdk2108/tools/distro_yocto
## yocto编译脚本 FBDIR=flexbuild_lsdk2108路径
build_distro_rfs_yocto() {
[ $username = root ] && fbprint_w "Please build yocto as non-root account" && exit ## root用户编译直接退出
[ -f $PACKAGES_PATH/rfs/yocto-poky/meta-poky/recipes-core/tiny-init/files/init ] || \
git clone $repo_yocto_poky_url $PACKAGES_PATH/rfs/yocto-poky -b $repo_yocto_poky_tag ## clone代码
yoctorfs=rootfs_${DISTRIB_VERSION}_yocto_${DISTROSCALE}_${DESTARCH} ## DISTRIB_VERSION=lsdk2108 DISTROSCALE=tiny DESTARCH=arm64
. $PACKAGES_PATH/rfs/yocto-poky/oe-init-build-env $FBOUTDIR/rfs/$yoctorfs ## components/rfs/yocto-poky/oe-init-build-env 为yocto环境设置环境变量
$FBDIR/configs/yocto/reconfig.sh fixcfg ## configs/yocto/reconfig.sh --> 按照deconfig修改配置
cp -f $FBDIR/configs/yocto/local_${DESTARCH}_${DISTROSCALE}.conf $FBOUTDIR/rfs/$yoctorfs/conf/local.conf
export.UTF-8
[ $DESTARCH = arm64 ] && export MACHINE=qemuarm64 || export MACHINE=qemuarm
bitbake $yoctoimgtype
[ $DESTARCH = arm64 -a $DISTROSCALE = devel ] && $FBDIR/configs/yocto/reconfig.sh fixlib $RFSDIR/usr/lib/libc.so
[ -L $FBOUTDIR/rfs/$yoctorfs/target ] || ln -s $RFSDIR $FBOUTDIR/rfs/$yoctorfs/target ## FBOUTDIR=build yoctorfs=rootfs_lsdk2108_yocto_tiny_arm64
# RFSDIR=/home/[username]/yoctobuild/tmp/work/qemuarm64-poky-linux/core-image-minimal/1.0-r0/rootfs
# setup app components (restool, aiop_tool, tsntool, fmc, etc) in yocto userland
echo Building and installing app components for $DISTROTYPE $DISTROSCALE
flex-builder -c apps -r yocto:$DISTROSCALE -a ${DESTARCH} -f $CFGLISTYML ## 编译DISTROSCALE范围的apps
if [ $DISTROSCALE = tiny ]; then ## 将生成文件塞进文件系统
[ -f $DESTDIR/usr/local/bin/restool ] && sudo cp -f $DESTDIR/usr/local/bin/{ls-*,restool} $RFSDIR/usr/bin
[ -f $DESTDIR/usr/bin/aiop_tool ] && sudo cp -f $DESTDIR/usr/bin/aiop_tool $RFSDIR/usr/bin
[ -f $DESTDIR/lib/libfm-arm.a ] && sudo cp -f $DESTDIR/lib/libfm-arm.a $RFSDIR/lib
[ -f $DESTDIR/usr/local/bin/fmc ] && sudo cp -f $DESTDIR/usr/local/bin/fmc $RFSDIR/usr/bin && \
sudo cp -Prf --preserve=mode,timestamps $DESTDIR/etc/fmc $RFSDIR/etc && sudo cp -f $DESTDIR/usr/local/lib/*/libfmc.a $RFSDIR/usr/lib
[ -f $DESTDIR/usr/local/bin/tsntool ] && sudo cp -f $DESTDIR/usr/local/bin/tsntool $RFSDIR/usr/bin && \
sudo cp -f $DESTDIR/usr/lib/libtsn.so $RFSDIR/usr/lib
sudo mkdir -p $RFSDIR/usr/local/bin && [ -f $DESTDIR/usr/local/bin/ccsr ] && sudo cp -f $DESTDIR/usr/local/bin/ccsr $RFSDIR/usr/local/bin/
sudo rm -rf $RFSDIR/usr/include/* $RFSDIR/usr/lib/aarch64-poky-linux $RFSDIR/usr/share/libtool $RFSDIR/usr/share/aclocal
sudo echo TinyLinux | sudo tee $RFSDIR/etc/hostname 1>/dev/null ## 将主机名写入/etc/hostname
sudo cp -f $FBDIR/packages/rfs/misc/mount-modules $RFSDIR/usr/local/bin ## mount-modules 启动方式不同挂载的目录也不同
elif [ $DISTROSCALE = devel ]; then ## another scale
sudo cp -Prf --preserve=mode,timestamps $DESTDIR/* $RFSDIR/
sudo mkdir -p $RFSDIR/etc/systemd/system && sudo cp -f $FBDIR/packages/rfs/misc/boot.mount $RFSDIR/etc/systemd/system/
sudo echo DevelLinux | sudo tee $RFSDIR/etc/hostname 1>/dev/null
fi
distroinfo="$DISTRIB_NAME $DISTROSCALE ${DISTRIB_VERSION:4:4} (based on Yocto)"
echo $distroinfo | sudo tee $RFSDIR/etc/issue 1>/dev/null
echo $distroinfo | sudo tee $RFSDIR/etc/buildinfo 1>/dev/null
distrostamp="Build: `date +'%Y-%m-%d %H:%M:%S'`"
echo "$distrostamp" | sudo tee -a $RFSDIR/etc/buildinfo 1>/dev/null ## 信息写入
sudo cp -f $FBDIR/tools/flex-installer $RFSDIR/usr/bin ## flex-installer拷入bin目录
$FBDIR/configs/yocto/reconfig.sh fixsys $RFSDIR
cd $RFSDIR && sudo chown -h -R 0:0 * && \
sudo find . | sudo cpio --quiet -o -H newc | gzip > $FBOUTDIR/images/$yoctorfs.cpio.gz && fbprint_d $FBOUTDIR/images/$yoctorfs.cpio.gz
cp -f $yoctotmpdir/deploy/images/$MACHINE/${yoctoimgtype}-${MACHINE}.manifest $FBOUTDIR/rfs/$yoctorfs/$yoctorfs.packages.manifest
[ $DISTROSCALE = tiny ] && cp -f $yoctotmpdir/deploy/images/$MACHINE/${yoctoimgtype}-${MACHINE}.ubifs $FBOUTDIR/images/$yoctorfs.ubifs && \
cp -f $yoctotmpdir/deploy/images/$MACHINE/${yoctoimgtype}-${MACHINE}.squashfs $FBOUTDIR/images/$yoctorfs.squashfs
flex-builder -i packrfs -r yocto:$DISTROSCALE -a $DESTARCH -f $CFGLISTYML ## 打包
ls -goh $FBOUTDIR/images/$yoctorfs*
}
编译日志:
xxx@xxx:/disk2/code/flexbuild_lsdk2108$ flex-builder -i mkrfs -r yocto:tiny -m ls1046ardb
DISTRO TYPE: yocto
DISTRO SCALE: tiny
MACHINE: ls1046ardb
You had no conf/local.conf file. This configuration file has therefore been
created for you with some default values. You may wish to edit it to, for
example, select a different MACHINE (target hardware). See conf/local.conf
for more information as common configuration options are commented.
You had no conf/bblayers.conf file. This configuration file has therefore been
created for you with some default values. To add additional metadata layers
into your configuration please add entries to conf/bblayers.conf.
The Yocto Project has extensive documentation about OE including a reference
manual which can be found at:
http://yoctoproject.org/documentation
For more information about OpenEmbedded see their website:
http://www.openembedded.org/
### Shell environment set up for builds. ###
You can now run 'bitbake <target>'
Common targets are:
core-image-minimal
core-image-full-cmdline
core-image-sato
core-image-weston
meta-toolchain
meta-ide-support
You can also run generated qemu images with a command like 'runqemu qemux86'
Other commonly useful commands are:
- 'devtool' and 'recipetool' handle common recipe tasks
- 'bitbake-layers' handles common layer tasks
- 'oe-pkgdata-util' handles common target package tasks
Loading cache: 100% | | ETA: --:--:--
Loaded 0 entries from dependency cache.
Parsing recipes: 100% |###########################################################################| Time: 0:00:16
Parsing of 818 .bb files complete (0 cached, 818 parsed). 1443 targets, 56 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
Build Configuration:
BB_VERSION = "1.50.0"
BUILD_SYS = "x86_64-linux"
NATIVELSBSTRING = "ubuntu-20.04"
TARGET_SYS = "aarch64-poky-linux"
MACHINE = "qemuarm64"
DISTRO = "poky"
DISTRO_VERSION = "3.3.1"
TUNE_FEATURES = "aarch64 armv8a crc cortexa57"
TARGET_FPU = ""
meta
meta-poky
meta-yocto-bsp = "master:7cf369c910ddc43b61d86a88a1fb771b9d6d4549"
Initialising tasks: 100% |########################################################################| Time: 0:00:03
Sstate summary: Wanted 1190 Local 1187 Network 0 Missed 3 Current 0 (99% match, 0% complete)
NOTE: Executing Tasks
NOTE: Tasks Summary: Attempted 3277 tasks of which 3014 didn't need to be rerun and all succeeded.
Building and installing app components for yocto tiny
以下内容来自 YOCTO编译环境的搭建_masterbee的博客-CSDN博客_yocto环境搭建
二、常规yocto环境搭建
用户磁盘预留至少80G硬盘空间
1、apt-get update
2、apt-get install wget git-core unzip make gcc g++ build-essentialsubversion sed autoconf automake texi2html texinfo coreutils diffstatpython-pysqlite2 docbook-utils libsdl1.2-dev libxml-parser-perl libgl1-mesa-devlibglu1-mesa-dev xsltproc desktop-file-utils chrpath groff libtool xterm gawkfop
3、clone poky 的 morty 稳定分支:
git clone -b mortygit://git.yoctoproject.org/poky.git
4、进入poky目录,然后运行下面的命令为 Yocto 开发环境设置(设置/导出)一些环境变量:
source oe-init-build-env
5、若正常,会自动进入build目录
6、修改build/conf/local.conf文件,如提供的local.conf文件所示。
7、编译:
bitbake core-image-minimal
编译过程会下载很多东西,编译持续时间较久。
8、编译完成后
runqemu qemux86-64为运行新的基于 Yocto 的 Linux 发行版的 qemu 打开一个新屏幕,则表示安装完成。
三、YOCTO BSP编译:
1、 下载repo:
mkdir ~/bin (this step may not be needed if the bin folder already exists)
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
2、设置搜索路径:
export PATH=~/bin:$PATH
3、设置用户名和邮箱
gitconfig --global user.name "Your Name"
gitconfig --global user.email "Your Email"
gitconfig –list
4、获取linux BSP:
mkdir fsl-release-bsp
cd fsl-release-bsp
repo init -ugit://git.freescale.com/imx/fsl-arm-yocto-bsp.git -b imx-3.14.52-1.1.0_ga
repo sync
说明:
reposync 将会是一个漫长的等待过程,中间可能会出错。如果出错了就重新repo sync,直到成功为止。另外有的时候可能会很长时间不动了,看下载的流量也一直是0,也可以ctrl+C终止,然后重新repo sync。
注意在yocto下,我们下载BSP实际上只是一些配置文件,实际编译的时候边编译边下载的,所以在我们下载的BSP里面是找不到代码的。
5、编译BSP前的准备工作:
格式:
DISTRO=<distro name>MACHINE=<machine name> source fsl-setup-release.sh -b <build dir>
distro name有下面4个值
fsl-imx-x11 说明只支持X11 graphics
fsl-imx-wayland 说明只支持Wayland weston graphics
fsl-imx-xwayland 说明支持 Wayland graphics 和 X11.
fsl-imx-fb 说明只支持Frame Buffer graphics 不支持 X11 和 Wayland
machine name 对应我们的开发板的类型,有下面的值
imx6qpsabreauto 、 imx6qpsabresd、 imx6ulevk 、imx6dlsabreauto
imx6dlsabresd 、 imx6qsabreauto 、 imx6qsabresd 、 imx6slevk 、 imx6solosabreauto
imx6solosabresd 、 imx6sxsabresd 、 imx6sxsabreauto 、 imx7dsabresd
build dir 是编译的目录,我们可以任意指定一个目录名,编译的时候将在当前目录下新建这个目录。
例如我是这样设置的
MACHINE=imx6qsabresd DISTRO=fsl-imx-x11 source ./fsl-setup-release.sh -bimx6q-x11
首次运行这个命令的时候会提示时候遵循EULA协议,我们选y就好了。
6、编译BSP:
设置好后开始编译。
我们用bitbake来编译的。
格式是 bitbake <project name>
project name有下面的选项
core-image-minimal 这个是构建一个能启动的最小的系统
core-image-base 这个是构建一个只有命令行的系统
core-image-sato 这个是一个支持X11图形界面的系统
fsl-image-machine-test 这个imx内核的只有命令行的系统
fsl-image-gui 这个是IMX内核的不支持qt的图形界面的系统
fsl-image-qt5 这个是支持qt5的图形界面的系统
例如我运行的命令是
bitbake fsl-image-qt5
7、
编译过程中,有可能会产生错误,产生错误的时候先尝试再次编译,如果还有相同的错误,再解决。
编译完成后,在fsl-release-bsp/imx6q-x11/tmp/deploy/images/imx6qsabresd目录下会产生uboot,zImage,rootfs等映象文件。
三、工具链的制作:
1、 GCC工具链安装包的制作:
bitbakemeta-toolchain
编译完成后,在imx6q-x11/tmp/deploy/sdk/目录下生成一个可执行的sh文件。在别的PC上安装即可。
2、 QT工具链安装包的制作:
bitbakemeta-toolchain-qt5