[TOC]
一、IMX8创建yocto编译环境 Link to heading
Ubuntu 18.04编译主机需要事先执行以下命令安装编译所需包:
1sudo apt-get update
2sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat libsdl1.2-dev
3sudo apt-get install libsdl1.2-dev xterm sed cvs subversion coreutils texi2html docbook-utils python-pysqlite2 help2man
4sudo apt-get install make gcc g++ desktop-file-utils libgl1-mesa-dev libglu1-mesa-dev mercurial autoconf automake groff curl lzop asciidoc
5sudo apt-get install u-boot-tools
6
7git config --global user.name xxx
8git config --global user.email xxx@xxx.com
9git config –list
5.4.24 BSP需要python3支持,所以需要用ubuntu18.04(16.04和14.04不支持python3);
根据文档 imx-yocto-L5.4.24_2.1.0\i.MX_Yocto_Project_User's_Guide.pdf
创建 yocto 编译环境时,需要注意以下几点:
安装repo
工具
Link to heading
1mkdir bin
2cd bin
3curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
4chmod a+x repo
5export PATH=~/bin:$PATH
下载yocto环境 Link to heading
1mkdir imx-yocto-bsp
2cd imx-yocto-bsp
3repo init -u https://source.codeaurora.org/external/imx/imx-manifest -b imx-linux-zeus -m imx-5.4.24-2.1.0.xml
4--repo-url=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo
5repo sync
配置yocto环境 Link to heading
1DISTRO=<distro name> MACHINE= imx8qxpc0mek source imx-setup-release.sh -b imx8qxpc0mek_"distro name"
2
3DISTRO=fsl-imx-xwayland MACHINE=imx8qxpc0mek source imx-setup-release.sh -b build_xwayland_imx8qxpc0mek
4DISTRO=fsl-imx-xwayland MACHINE=imx8qxpc0mek source imx-setup-release.sh -b imx8qxpc0mek_xwayland
bitbake配置文件为:imx-yocto-bsp/build-xwayland/conf/local.conf
1INHERIT += "rm_work" # 清除中间文件,节约硬盘空间
2BB_NUMBER_THREADS = '4' # 设置编译的线程数目
3PARALLEL_MAKE = '-j 4'
bitbake显示所有的编译操作: Link to heading
1ubuntu@ubuntu:~/imx8-yocto-bsp-5.4.24/imx8qxpc0mek_xwayland$ bitbake imx-image-full -c listtasks
2Loading cache: 100% |##########################################################################################################| Time: 0:00:00
3Loaded 4671 entries from dependency cache.
4Parsing recipes: 100% |########################################################################################################| Time: 0:00:00
5Parsing of 3213 .bb files complete (3211 cached, 2 parsed). 4671 targets, 238 skipped, 2 masked, 0 errors.
6NOTE: Resolving any missing task queue dependencies
7Build Configuration:
8BB_VERSION = "1.44.0"
9BUILD_SYS = "x86_64-linux"
10NATIVELSBSTRING = "ubuntu-18.04"
11TARGET_SYS = "aarch64-poky-linux"
12MACHINE = "imx8qxpc0mek"
13DISTRO = "fsl-imx-xwayland"
14DISTRO_VERSION = "5.4-zeus"
15TUNE_FEATURES = "aarch64 cortexa35 crc crypto"
16TARGET_FPU = ""
17meta
18meta-poky = "HEAD:cba967414370e195d109353e51510bd829aa86c3"
19meta-oe
20meta-multimedia
21meta-python = "HEAD:9e60d30669a2ad0598e9abf0cd15ee06b523986b"
22meta-freescale = "HEAD:c2a0d924f6200eea1fb1d1b61e7420ea5da2f8fb"
23meta-freescale-3rdparty = "HEAD:dbcc686f52c3c84db8cb86aa8973a4e373651b98"
24meta-freescale-distro = "HEAD:ca27d12e4964d1336e662bcc60184bbff526c857"
25meta-bsp
26meta-sdk
27meta-ml = "HEAD:a083ffbbc3f4d1c02b1542746784d7f641a75b60"
28meta-browser = "HEAD:5f365ef0f842ba4651efe88787cf9c63bc8b6cb3"
29meta-rust = "HEAD:a012a1027defe28495f06ed522a7a82bdd59a610"
30meta-gnome
31meta-networking
32meta-filesystems = "HEAD:9e60d30669a2ad0598e9abf0cd15ee06b523986b"
33meta-qt5 = "HEAD:b8bcf8cb576d072f435a0177375e54424f67d1c9"
34meta-python2 = "HEAD:231c3d74cfcf734c3415e86ea8dd97f73ddced9d"
35
36Initialising tasks: 100% |#####################################################################################################| Time: 0:00:02
37Sstate summary: Wanted 0 Found 0 Missed 0 Current 0 (0% match, 0% complete)
38NOTE: No setscene tasks
39NOTE: Executing Tasks
40do_build Default task for a recipe - depends on all other normal tasks required to 'build' a recipe
41do_checkuri Validates the SRC_URI value
42do_clean Removes all output files for a target
43do_cleanall Removes all output files, shared state cache, and downloaded source files for a target
44do_cleansstate Removes all output files and shared state cache for a target
45do_compile Compiles the source in the compilation directory
46do_configure Configures the source by enabling and disabling any build-time and configuration options for the software being built
47do_devpyshell Starts an interactive Python shell for development/debugging
48do_devshell Starts a shell with the environment set up for development/debugging
49do_fetch Fetches the source code
50do_image
51do_image_complete
52do_image_complete_setscene (setscene version)
53do_image_create_sdcard_symlink
54do_image_qa
55do_image_qa_setscene (setscene version)
56do_image_tar
57do_image_wic
58do_install Copies files from the compilation directory to a holding area
59do_listtasks Lists all defined tasks for a target
60do_package Analyzes the content of the holding area and splits it into subsets based on available packages and files
61do_package_qa_setscene Runs QA checks on packaged files (setscene version)
62do_package_setscene Analyzes the content of the holding area and splits it into subsets based on available packages and files (setscene version)
63do_package_write_deb_setscene Creates the actual DEB packages and places them in the Package Feed area (setscene version)
64do_packagedata Creates package metadata used by the build system to generate the final packages
65do_packagedata_setscene Creates package metadata used by the build system to generate the final packages (setscene version)
66do_patch Locates patch files and applies them to the source code
67do_populate_lic Writes license information for the recipe that is collected later when the image is constructed
68do_populate_lic_deploy
69do_populate_lic_setscene Writes license information for the recipe that is collected later when the image is constructed (setscene version)
70do_populate_sdk Creates the file and directory structure for an installable SDK
71do_populate_sdk_ext
72do_populate_sysroot_setscene Copies a subset of files installed by do_install into the sysroot in order to make them available to other recipes (setscene version)
73do_prepare_recipe_sysroot
74do_rootfs Creates the root filesystem (file and directory structure) for an image
75do_rootfs_wicenv
76do_sdk_depends
77do_unpack Unpacks the source code into a working directory
78do_write_wks_template
79NOTE: Tasks Summary: Attempted 1 tasks of which 0 didn't need to be rerun and all succeeded.
yocto编译过程中会出现多次bitbake错误,可以使用 ./bitbake_imx-image-full.sh
脚本在出现错误自动重新编译,脚本如下:
1#!/bin/bash
2
3if [ $# = 1 ]; then
4# do_task="-c $1"
5 do_task="$1"
6fi
7
8echo "================ bitbake imx-image-full ${do_task} ================"
9echo "do_task:" ${do_task}
10#cp conf/bblayers_default.conf conf/bblayers.conf
11
12bitbake imx-image-full ${do_task}
13
14while [ $? == 1 ]; do
15 echo "================ bitbake imx-image-full failed, re-bitbake again ================"
16 echo "do_task:" ${do_task}
17 sleep 10
18 bitbake imx-image-full ${do_task}
19done
1# 编译 imx-image-full 的 yocto 环境
2./bitbake_imx-image-full.sh
3
4# 编译 imx-image-full 的 yocto 环境的SDK支持包
5./bitbake_imx-image-full.sh -c do_populate_sdk
测试发现:编译 do_populate_sdk 的有些关于QT的包不会下载;
1# 直接获取 imx-image-full 支持包,不编译
2bitbake imx-image-full --runall=fetch # yocto 只下载指令
3./bitbake_imx-image-full.sh --runall=fetch
中断后重新编译命令:
1source setup-environment <build-dir>
二、编译过程中问题记录与解决办法 Link to heading
1、源码包fetch失败: Link to heading
1遇到有些包fetch失败的情况,可以找到该包的bb文件,查看链接与版本,自行下载后移动到yocto目录下的download目录;
以下列出编译过程中fetch失败的一些源码包的配置文件及下载链接;
kernel 源码: Link to heading
1KERNEL_SRC ?= "git://source.codeaurora.org/external/imx/linux-imx.git;protocol=https"
2#KERNEL_SRC ?= "git:///home/ubuntu/fsl-downloads/linux-imx;protocol=file"
3git clone https://source.codeaurora.org/external/imx/linux-imx.git -b imx_5.4.24_2.1.0
uboot 源码: Link to heading
1UBOOT_SRC ?= "git://source.codeaurora.org/external/imx/uboot-imx.git;protocol=https"
2SRCBRANCH = "imx_v2020.04_5.4.24_2.1.0"
3git clone https://source.codeaurora.org/external/imx/uboot-imx.git -b imx_v2020.04_5.4.24_2.1.0
opencv 源码: Link to heading
1https://source.codeaurora.org/external/imx/opencv-imx/log/?h=4.2.0_imx
2git clone https://source.codeaurora.org/external/imx/opencv-imx -b 4.2.0_imx
arm-computelibrary-imx 源码: Link to heading
1ARM_COMPUTELIBRARY_SRC ?= "git://source.codeaurora.org/external/imx/arm-computelibrary-imx.git;protocol=https"
2SRCBRANCH = "imx_19.08"
3git clone https://source.codeaurora.org/external/imx/arm-computelibrary-imx.git -b imx_19.08
tensorflow 与 armnn 源码: Link to heading
1SRC_URI = " \
2 git://github.com/tensorflow/tensorflow.git;name=tensorflow;branch=r2.0 \
3 git://github.com/ARM-software/armnn.git;name=armnn;subdir=${WORKDIR}/armnn;destsuffix=armnn \
4"
5
6# 修改bb文件,从文件获取源码:
7SRC_URI = " \
8 git:///home/ubuntu/fsl-downloads/tensorflow;protocol=file;name=tensorflow;branch=r2.0 \
9 git:///home/ubuntu/fsl-downloads/armnn;protocol=file;name=armnn;subdir=${WORKDIR}/armnn;destsuffix=armnn \
10"
11
12# 源码目录:
13github.com.tensorflow.tensorflow.git
14github.com.ARM-software.armnn.git
15
16# Git下载源码:
17git clone git://github.com/tensorflow/tensorflow.git -b r2.0
18git clone git://github.com/ARM-software/armnn.git
其它bin
文件的源码:
Link to heading
除了以上方法,可以根据文档《i.MX_Linux_Release_Notes.pdf》,执行以下指令快速下载安装包。
1wget https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/<package file name>
如imx-gpu-viv-6.4.0.p2.4-aarch64.bin
源码,可以执行命令快速下载 gpu 安装包。
1wget https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/imx-gpu-viv-6.4.0.p2.4-aarch64.bin
2、编译内核出错: Link to heading
1 CHK include/generated/compile.h
2 LD vmlinux.o
3 MODPOST vmlinux.o
4 MODINFO modules.builtin.modinfo
5 LD .tmp_vmlinux1
6Killed
7/home/ubuntu/imx8-yocto-bsp-5.4.24/build_xwayland_imx8qxpc0mek/tmp/work-shared/imx8qxpc0mek/kernel-source/Makefile:1076: recipe for target 'vmlinux' failed
8make[1]: *** [vmlinux] Error 137
9/home/ubuntu/imx8-yocto-bsp-5.4.24/build_xwayland_imx8qxpc0mek/tmp/work-shared/imx8qxpc0mek/kernel-source/Makefile:179: recipe for target 'sub-make' failed
10make: *** [sub-make] Error 2
11WARNING: exit code 1 from a shell command.
问题原因:在编译过程中,内存不够了;
解决方法:
大致思路就是新建虚拟内存,具体步骤如下:
1free -m # 先查看交换区
2swapoff /swapfile # 关闭交换分区
3dd if=/dev/zero of=/swapfile bs=1k count=2048000 # 添加 swap 文件,大小设置为2G;
4mkswap /swapfile # 创建 swap 文件
5swapon /swapfile # 激活 swap 文件
3、编译qtbase出错: Link to heading
1| Makefile:47: recipe for target 'sub-auto-make_first' failed
2| make[1]: *** [sub-auto-make_first] Error 2
3| make[1]: Leaving directory '/home/ubuntu/imx8-yocto-bsp-5.4.24/build_xwayland_imx8qxpc0mek/tmp/work/aarch64-mx8-poky-linux/qtbase/5.14.99+5.15-beta3+gitAUTOINC+12fc3f5751-r0/build/tests'
4| Makefile💯 recipe for target 'sub-tests-make_first' failed
5| make: *** [sub-tests-make_first] Error 2
6| WARNING: exit code 1 from a shell command.
解决办法:
clean之后使用一个线程编译“-j1”
4、编译opencv出错: Link to heading
1{standard input}: Assembler messages:
2{standard input}:1359645: Warning: end of file not at end of a line; newline inserted
3{standard input}: Error: open CFI at the end of file; missing .cfi_endproc directive
4aarch64-poky-linux-g++: fatal error: Killed signal terminated program cc1plus
5compilation terminated.
解决办法:
虚拟机分配的内存小了,我之前分配的是2G,我将虚拟机的内存设置为4G后就make成功了!!! 发现是内存溢出(out of memory)造成的g++不能正常工作。扩大内存或者增大swap,或者取消MAKEOPTS="-j5"就可以解决。 同上;
5、编译opencv警告: Link to heading
1WARNING: opencv-4.2.0.imx-r0 do_patch: Fuzz detected:
2
3Applying patch download.patch
4patching file cmake/OpenCVDownload.cmake
5Hunk #2 succeeded at 157 with fuzz 2 (offset 3 lines).
6
7The context lines in the patches can be updated with devtool:
8
9 devtool modify opencv
10 devtool finish --force-patch-refresh opencv <layer_path>
11
12Don't forget to review changes done by devtool!
13
14WARNING: opencv-4.2.0.imx-r0 do_patch: QA Issue: Patch log indicates that patches do not apply cleanly. [patch-fuzz]
15
16devtool reset opencv
解决办法:
按照上面的方法尝试会产生新的问题;这个问题不影响,可以直接跳过;
6、编译qt3d出错: Link to heading
1{standard input}: Assembler messages:
2{standard input}:548692: Warning: end of file in string; '"' inserted
3aarch64-poky-linux-g++: fatal error: Killed signal terminated program cc1plus
4compilation terminated.
5ninja: build stopped: subcommand failed.
解决方法:
应该是内存不够,ubuntu的make命令好像比较吃内存,同上;
7、编译imx-gpu-sdk报错: Link to heading
1ERROR: When reparsing /home/ubuntu/imx8-yocto-bsp-5.4.24/sources/meta-imx/meta-sdk/recipes-graphics/imx-gpu-sdk/imx-gpu-sdk_5.5.3.bb:do_compile, the basehash value changed from 0424c5417143b3e6a25badb42c42823030d925f7820f56aa17d67ae58a2a26a0 to 2e539f474364aa01666787fb400c8117169e8b9deb4cef1419ac525fd4a29e19. The metadata is not deterministic and this needs to be fixed.
2ERROR: The following commands may help:
3ERROR: $ bitbake imx-gpu-sdk -c do_compile -Snone
4ERROR: Then:
5ERROR: $ bitbake imx-gpu-sdk -c do_compile -Sprintdiff
解决办法:
这个问题不影响,可以直接跳过;
8、nn-imx模块clean的时候出错: Link to heading
1DEBUG: Executing shell function do_configure
2NOTE: make SDKTARGETSYSROOT=/work2/NXP/imx8-yocto-bsp-5.4.24/build_xwayland_imx8qxpc0mek-sysvinit/tmp/work/aarch64-poky-linux/nn-imx/1.0.4-r0/recipe-sysroot AQROOT=/work2/NXP/imx8-yocto-bsp-5.4.24/build_xwayland_imx8qxpc0mek-sysvinit/tmp/work/aarch64-poky-linux/nn-imx/1.0.4-r0/git clean
3remove *.so and *.o
4rm: cannot remove '*.so': No such file or directory
5makefile:20: recipe for target 'clean' failed
6make: *** [clean] Error 1
7ERROR: oe_runmake failed
8WARNING: exit code 1 from a shell command.
9ERROR: Execution of '/work2/NXP/imx8-yocto-bsp-5.4.24/build_xwayland_imx8qxpc0mek-sysvinit/tmp/work/aarch64-poky-linux/nn-imx/1.0.4-r0/temp/run.do_configure.5748' failed with exit code 1:
10remove *.so and *.o
11rm: cannot remove '*.so': No such file or directory
12makefile:20: recipe for target 'clean' failed
13make: *** [clean] Error 1
14WARNING: exit code 1 from a shell command.
makefile文件如下:
1
2NNRT := $(shell pwd)/nn_runtime/nnrt
3NNAPI_DELEGATE := $(shell pwd)/nn_runtime/nnapi_delegate
4...
5clean:
6 @echo "remove *.so and *.o"
7 @rm *.so
8 @cd $(NNRT);rm *.o
9 @cd $(NNAPI_DELEGATE);rm *.o
解决方法:
1tmp/work/aarch64-poky-linux/nn-imx/1.0.4-r0/git
2./nn_runtime/nnrt
3./nn_runtime/nnapi_delegate
直接在上述文件夹下面创建a.so,a.o文件供make clean的时候删除即可;
三、修改systemd 与 sysvinit 支持 Link to heading
支持用例文件:poky/meta-poky/conf/local.conf.sample.extended
1#
2# Use busybox/mdev for system initialization
3#
4VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
5VIRTUAL-RUNTIME_login_manager = "busybox"
6VIRTUAL-RUNTIME_init_manager = "busybox"
7VIRTUAL-RUNTIME_initscripts = "initscripts"
8VIRTUAL-RUNTIME_keymaps = "keymaps"
9DISTRO_FEATURES_BACKFILL_CONSIDERED += "sysvinit"
10
11#
12# Use systemd for system initialization
13#
14DISTRO_FEATURES_append = " systemd"
15DISTRO_FEATURES_BACKFILL_CONSIDERED += "sysvinit"
16VIRTUAL-RUNTIME_login_manager = "shadow-base"
17VIRTUAL-RUNTIME_init_manager = "systemd"
18VIRTUAL-RUNTIME_initscripts = "systemd-compat-units"
根据 local.conf.sample.extended 用例来修改build目录下 conf/local.conf 中关于 sysvinit 的支持。
配置文件:meta-imx/meta-sdk/conf/distro/fsl-imx-xwayland.conf
meta-imx/meta-sdk/conf/distro/include/fsl-imx-preferred-env.inc
1# Use systemd as default init manager
2#VIRTUAL-RUNTIME_init_manager = "systemd"
3#PREFERRED_PROVIDER_udev = "systemd"
4#PREFERRED_PROVIDER_udev-utils = "systemd"
5#DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
6#POKY_DEFAULT_DISTRO_FEATURES += " systemd"
7
8VIRTUAL-RUNTIME_init_manager = "busybox"
9PREFERRED_PROVIDER_udev = "sysvinit"
10PREFERRED_PROVIDER_udev-utils = "sysvinit"
11DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
12POKY_DEFAULT_DISTRO_FEATURES += " sysvinit"
配置文件:meta-freescale-distro/conf/distro/fsl-xwayland.conf
1# Remove conflicting backends
2
3DISTRO_FEATURES_remove = "directfb"
4DISTRO_FEATURES_append = " x11 wayland pam systemd"
5#VIRTUAL-RUNTIME_init_manager = "systemd"
6#VIRTUAL-RUNTIME_init_manager = "sysvinit"
7VIRTUAL-RUNTIME_init_manager = "busybox"
目前sysvinit启动方式测试是不正常的,是否支持需要继续验证。
编译sysvinit启动方式失败: Link to heading
尝试1: Link to heading
将 local.conf
中把以下去掉,看看能不能成功。
1IMAGE_INSTALL_remove += "hostapd"
尝试2: Link to heading
将local.conf
中加上以下,参考
1PACKAGE_EXCLUDE = “hostapd”
这个配置选项好像生效了,但是编译还是报错,从LOG信息看好像是很多package依赖于“hostapd”。
这个“hostapd”模块是不是不能去掉?但是不去掉编译又过去不。
FAE建议:
看log 是packagegroup-fsl-tools-testapps 依赖 hostapd, 那把这个也去掉试试。
或者需要客户研究一下hostapd 能否和systemv 兼容。
Because which is Yocto project issue and our AE suggest you can refer Yocto community for it, Sorry for that.
支持sysvinit启动方式的尝试还需继续验证。