编译环境 Memo

Yocto & Poky & bitbake

1. Why not just call this project Poky? What has changed between Poky and the Yocto Project?

The Yocto Project is an umbrella project. Accordingly, it includes a
number of projects and resources specifically intended for
facilitating development with Linux on embedded devices, and it is an
appropriate place for larger organizations to collaborate on the
development of build infrastructure for embedded Linux. Poky is one of
the the largest components of the Yocto Project, and Poky continues as
an independent, open source project developing the build system used
by the Yocto Project, as well as by other open source projects.

Poky is a reference system for the Yocto Project, showing how the
tools work together. It includes BitBake, openembedded-core, and
several other components that anyone can use to start developing with
embedded Linux. Poky as a build system is tested by the Yocto Project
teams before each release. When you download and use the Yocto Project
build system, you are actually downloading Poky and using it to create
a distribution that by default is also named Poky. (You can, of
course, name your distribution anything you like.)

2. What is the difference between OpenEmbedded and the Yocto Project?

The Yocto Project and OpenEmbedded share a core collection of metadata
called openembedded-core. However, the two organizations remain
separate, each with its own focus. OpenEmbedded provides a
comprehensive set of metadata for a wide variety of architectures,
features, and applications. The Yocto Project focuses on providing
powerful, easy-to-use, interoperable, well-tested tools, metadata, and
board support packages (BSPs) for a core set of architectures and
specific boards.

  • 这系列training文档对了解yocto的流程很不错

https://community.nxp.com/docs/DOC-94849

  • 公司使用的嵌入式linux基于pokypoky是基于Yocto Project 的一个具体实现方案,包括bibake系统OpenEmbeded Core
  • 解压后(应该有压缩包解出来的):
ubuntu@ubuntu:/home/samba/sda3$ tree -F -L 5 --filelimit 13  freescale/  
freescale/  
└── 3.14.52/        
    └── yocto-L3.14.52/                 #yocto 根目录  
        ├── bin_export.sh*  
        ├── curl.sh*  
        ├── downloads/ [2260 entries exceeds filelimit, not opening dir]    #bitbake下载的源码包/依赖等等  
        ├── fb/  
        │   ├── bitbake.lock  
        │   ├── cache/  
        │   │   ├── bb_codeparser.dat  
        │   │   ├── bb_persist_data.sqlite3  
        │   │   └── local_file_checksum_cache.dat  
        │   ├── conf/  
        │   │   ├── bblayers.conf  
        │   │   ├── bblayers.conf.org  
        │   │   ├── local.conf          #默认平台在这里指定  
        │   │   ├── local.conf.org  
        │   │   ├── local.conf.sample  
        │   │   ├── sanity_info  
        │   │   └── templateconf.cfg  
        │   ├── imx_build_note.c*  
        │   ├── sstate-cache/ [252 entries exceeds filelimit, not opening dir]  
        │   ├── test/ [14 entries exceeds filelimit, not opening dir]  
        │   └── tmp/                    #看起来叫tmp,其实build过程中所有生成的文件全部都在这个目录下  
        │       ├── abi_version  
        │       ├── buildstats/  
        │       ├── cache/  
        │       ├── deploy/             #可供部署的整合包,do_populate_sdk后会在 deploy/sdk下生成打包好的安装脚本  
        │       ├── log/  
        │       ├── qa.log  
        │       ├── saved_tmpdir  
        │       ├── sstate-control/  
        │       ├── stamps/  
        │       ├── sysroots/  
        │       ├── work/               #make过程中的work目录,成品到这里找  
        │       └── work-shared/  
        ├── fsl-setup-release.sh*       #另一个setup-environment,一般不用  
        ├── git_config.sh*  
        ├── README  
        ├── README-IMXBSP  
        ├── repo_init.sh*  
        ├── setup-environment*          #开始使用前source这个脚本设置环境,然后才能开始使用bitbake  
        └── sources/                    #存放targets的源码,注意是bitbake目标的源码,bitbake解析这之中的源码进行build  
            ├── base/  
            │   ├── conf/  
            │   ├── README  
            │   └── setup-environment*  
            ├── meta-browser/  
            │   ├── classes/  
            │   ├── conf/  
            │   ├── COPYING.MIT  
            │   ├── README  
            │   ├── recipes-browser/  
            │   ├── recipes-devtools/  
            │   ├── recipes-gnome/  
            │   ├── recipes-mozilla/  
            │   └── scripts/  
            ├── meta-fsl-arm/ [19 entries exceeds filelimit, not opening dir]  
            ├── meta-fsl-arm-extra/  
            │   ├── conf/  
            │   ├── README  
            │   ├── recipes-bsp/  
            │   ├── recipes-core/  
            │   └── recipes-kernel/  
            ├── meta-fsl-bsp-release/  
            │   └── imx/  
            ├── meta-fsl-demos/  
            │   ├── conf/  
            │   ├── README  
            │   ├── recipes-fsl/  
            │   ├── recipes-graphics/  
            │   ├── recipes-multimedia/  
            │   └── recipes-qt/  
            ├── meta-openembedded/ [18 entries exceeds filelimit, not opening dir]  
            ├── meta-qt5/  
            │   ├── classes/  
            │   ├── conf/  
            │   ├── COPYING.MIT  
            │   ├── licenses/  
            │   ├── README  
            │   ├── recipes-devtools/  
            │   └── recipes-qt/  
            └── poky/ [14 entries exceeds filelimit, not opening dir]  

52 directories, 31 files
  • Yocto Project 采用bitbake进行build管理
    • bitbake可以视为一个带有包管理和task功能的make,可以自动解决编译过程中的依赖问题,并自动下载所需源码,每个_target_可分为不同功能模块(tasks),各_task_可分立单独执行
    • 每个_target_下都有一份**recipe**(食谱),包含若干.bb文件,这些指导bitbake应该怎样 b(m)ake (挺有趣的)
      • *python写的
    • 使用bitbake时必须处于**yocto**的 build目录(fb) 下
    • 全自动 build 目标:bitbake target
    • 列出所有目标: bitbake -s| grep xxx
    • 列出 available tasksbitbake target -c listtasks
    • 执行某项taskbitbake target -c task
      • 具体task以python脚本里某个do_xxx函数实现
      • 执行task时只需 -c xxx
  • 从freescale下载repo后,在yocto的根目录下查看**README-IMXBSP**
    • 整个yocto包括从本机交叉编译工具链到BSP(板级支持包)的所有构建目标 ,包括嵌入式图形化界面的各种解决方案
    • 图形化界面有采用QT / 不采用QT两种方案,分别是fsl-image-guifsl-image-qt5
    • 除开图形库,两种方案又可分别构建为 基于不同后端实现版本
      1. fb:采用framebuffer
      2. x11:通用x协议
      3. wayland
      4. XWayland
    • 不同后端实现需要完全不同的build目录,如 build-fb,build-x11,公司工程采用framebuffer后端,build目录就叫fb

自动配置交叉编译环境:

  • bitbake上游target仓库中有meta-toolchain-qt5fsl-image-qt5两项 fsl-image-qt5`包含完整的采用qt作为gui库的 全套系统 recipes
  • fsl-image-qt5实际上包含了从头到脚需要的所有交叉编译器qt库开发sdk板上文件系统等等一系列东西,其中也包括meta-toolchain-qt5这个子目标
  • fsl-image-qt5meta-toolchain-qt5 两者独立
  • 前者专门build qt 开发工具链,后者则编译整个qt 后者 编译出cross-toolchain,但交叉编译工具链中不含有qmake等qt构建工具
  • fsl-image-qt5中有一项_task_叫 populate_sdk,通过它也可以生成整个toolchain,所以其实不需要meta-toolchain-qt5。从meta-前缀可以猜测该_target_不会产生目标平台相关的image,纯粹是交叉编译所需的 meta tools
  • 未经bitbake meta-toolchain-qt5bitbake fsl-image-qt5 -c populate_sdk生成的SDK 不含有 _qmake_等构建工具,build过meta-toolchain-qt5后才会有
  • I have found the solution (perhaps its was clear for you :-) ) To add the QT toolchain in your global toolchain, in your image file (eg image_types_yourimage.bbclass), add this “inherit populate_sdk_qt5”

    https://stackoverflow.com/questions/33808081/yocto-dora-qt5-on-imx6-where-is-qmake


  • meta-toolchain-qt5
    1. bitbake meta-toolchain-qt5
    2. Run the new installer that has been generated in yocto/build/tmp/deploy/sdk
      /home/samba/sda3/freescale/3.14.52/yocto-L3.14.52/fb/tmp/deploy/sdk
    3. source /opt/fsl-imx-fb/3.14.52-1.1.1/
      environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
    4. qmake和cross-gcc可直接使用
  • fsl-image-qt5
    1. 编辑sources/meta-fsl-bsp-release/imx/meta-sdk/recipes-fsl/images/fsl-image-qt5.bb
    2. inherit distro_features_check 后的下一行加入 inherit populate_sdk_qt
    3. bitbake fsl-image-qt5 build整个qt库
    4. bitbake fsl-image-qt5 -c populate_sdk 生成sdk安装包
    5. 同上,运行deploy/sdk下的sdk安装包
    6. 同上,source   /opt/fsl-imx-fb/3.14.52-1.1.1/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
    7. qmake / gcc

关于cross-gcc

  • populate_sdk生成的sdk包含完整cross-gcc toolchain,执行environment-setup-xxxx后当前shell环境自动配好了path

    • $cat /opt/fsl-imx-fb/3.14.52-1.1.1/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
    export SDKTARGETSYSROOT=/opt/fsl-imx-fb/3.14.52-1.1.1/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi  
    export PATH=/opt/fsl-imx-fb/3.14.52-1.1.1/sysroots/i686-pokysdk-linux/usr/bin:/opt/fsl-imx-fb/3.14.52-1.1.1/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi:$PATH  
    export CCACHE_PATH=/opt/fsl-imx-fb/3.14.52-1.1.1/sysroots/i686-pokysdk-linux/usr/bin:/opt/fsl-imx-fb/3.14.52-1.1.1/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi:$CCACHE_PATH  
    export PKG_CONFIG_SYSROOT_DIR=$SDKTARGETSYSROOT  
    export PKG_CONFIG_PATH=$SDKTARGETSYSROOT/usr/lib/pkgconfig  
    export CONFIG_SITE=/opt/fsl-imx-fb/3.14.52-1.1.1/site-config-cortexa9hf-vfp-neon-poky-linux-gnueabi  
    export OECORE_NATIVE_SYSROOT="/opt/fsl-imx-fb/3.14.52-1.1.1/sysroots/i686-pokysdk-linux"  
    export OECORE_TARGET_SYSROOT="$SDKTARGETSYSROOT"  
    export OECORE_ACLOCAL_OPTS="-I /opt/fsl-imx-fb/3.14.52-1.1.1/sysroots/i686-pokysdk-linux/usr/share/aclocal"  
    export PYTHONHOME=/opt/fsl-imx-fb/3.14.52-1.1.1/sysroots/i686-pokysdk-linux/usr  
    export CC="arm-poky-linux-gnueabi-gcc  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=$SDKTARGETSYSROOT"  
    export CXX="arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=$SDKTARGETSYSROOT"  
    export CPP="arm-poky-linux-gnueabi-gcc -E  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=$SDKTARGETSYSROOT"  
    export AS="arm-poky-linux-gnueabi-as "  
    export LD="arm-poky-linux-gnueabi-ld  --sysroot=$SDKTARGETSYSROOT"  
    export GDB=arm-poky-linux-gnueabi-gdb  
    export STRIP=arm-poky-linux-gnueabi-strip  
    export RANLIB=arm-poky-linux-gnueabi-ranlib  
    export OBJCOPY=arm-poky-linux-gnueabi-objcopy  
    export OBJDUMP=arm-poky-linux-gnueabi-objdump  
    export AR=arm-poky-linux-gnueabi-ar  
    export NM=arm-poky-linux-gnueabi-nm  
    export M4=m4  
    export TARGET_PREFIX=arm-poky-linux-gnueabi-  
    export CONFIGURE_FLAGS="--target=arm-poky-linux-gnueabi --host=arm-poky-linux-gnueabi --build=i686-linux --with-libtool-sysroot=$SDKTARGETSYSROOT"  
    export CFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types"  
    export CXXFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types"  
    export LDFLAGS="-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed"  
    export CPPFLAGS=""  
    export KCFLAGS="--sysroot=$SDKTARGETSYSROOT"  
    export OECORE_DISTRO_VERSION="3.14.52-1.1.1"  
    export OECORE_SDK_VERSION="3.14.52-1.1.1"  
    export ARCH=arm  
    export CROSS_COMPILE=arm-poky-linux-gnueabi-  
    
    # Append environment subscripts  
    if [ -d "$OECORE_TARGET_SYSROOT/environment-setup.d" ]; then  
        for envfile in $OECORE_TARGET_SYSROOT/environment-setup.d/*.sh; do  
          source $envfile  
        done  
    fi  
    if [ -d "$OECORE_NATIVE_SYSROOT/environment-setup.d" ]; then  
        for envfile in $OECORE_NATIVE_SYSROOT/environment-setup.d/*.sh; do  
          source $envfile  
        done  
    fi
  • 编译器选项-march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=xxxx必须随gcc命令完整携带,否则会出现_找不到包含文件_以及_链接失败_的现象(不需要-I指定包含目录,如果是_populate_sdk_出来的gcc,指定的--sysroot下会包含完整的包含文件/库目录树),-mfloat-abi=hard指定平台所使用的abi,_bitbake_出来的gcc只使用这一种abi模式,如换成其它,需要链接不同的.o文件,而这些文件不会随_populate_sdk_生成,于是产生链接错误。