1. 概述

本文档介绍如何使用 Yocto Project 为 RockChip 平台快速构建板级映像。 主要描述 meta-rochip layer 和 Yocto Project 基本构建方法。

Yocto Project 是一个专注于嵌入式 Linux® 操作系统开发的开源协作项目,它提供灵活的工具集和开发环境,允许全球的嵌入式设备开发人员通过共享技术,软件堆栈,配置和用于创建这些定制的Linux映像的最佳实践进行协作。有关 Yocto 项目的更多信息,请参阅 Yocto Project 官网:www.yoctoproject.org/。 Yocto Project 官网上有 Yocto Project Reference ManualYocto Project Overview 等相关文档详细描述了如何构建系统。

firefly 提供的 Yocer Project 支持情况如下表:

版本 板级支持情况 维护情况
2.7.4 (warrior) RK3399 不再维护
3.4 (honister) RK3588 RK3588S RK3399 RK3399PRO RK356X PX30 维护

2. Yocto Project Release layer 介绍

layer 路径 优先级(数字越大优先级越高) 描述
meta-oe meta-openembedded/meta-oe 6 contains a large amount of additional recipes
meta-python meta-openembedded/meta-python 7 Provide Python recipes
meta-qt5 meta-qt5 7 Provides QT5 recipes
meta-clang meta-clang 7 clang compiler
meta-rockchip meta-rockchip 9 Rockchip board level support available
meta meta 5 Contains the OpenEmbedded-Core metadata
meta-poky meta-poky 5 Holds the configuration for the Poky reference distribution
meta-yocto-bsp meta-yocto-bsp 5 Configuration for the Yocto Project reference hardware board support package.
meta-chromium meta-chromium 7 Provide chromium browser recipe

3. 获取SDK

repo init --no-clone-bundle --repo-url https://gitlab.com/firefly-linux/git-repo.git -u https://gitlab.com/firefly-linux/manifests.git -b master -m yocto_release.xml
.repo/repo/repo sync -c

4. 编译

4.1. 选择 core-image-minimal 映像

Yocto 项目提供了一些可用于不 layer 的映像。下表列出目前支持构建的映像和相关配方。

映像名字 描述 提供的layer
core-image-minimal A small image that only allows a device to boot Poky

4.2. 选择板级配置文件

yocto_sdk/build/conf下有许多板级配置文件,通过产生local.conf软连接选择相应的配置文件。

以firefly-rk3399板子为例:

    # 进入到yocto SDK
    cd build/conf

    # 选择配置文件,找到firefly-rk3399板子所对应配置文件 firefly-rk3399.conf进行软连接
    ln -fs rk3399/firefly-rk3399.conf local.conf

注意:不同板子对应的配置文件不同,以上仅仅仅供参考

4.3. 编译映像文件

使用 bitbake 命令构建的过程需要保证网络连接正常,如果是中国内陆客户需要保证能 ping 通外网

  • 进入目录<path/to/yocto>,按顺序执行如下命令

      # Install the required environment packages
      # sudo apt install zstd
      source oe-init-build-env
      bitbake core-image-minimal
    
  • 以上命令是编译完整 core-image-minimal recipes,如果想单独编译部分 recipes 可以参考以下内容:

      # kernel
      bitbake linux-rockchip
    
      # u-boot
      bitbake u-boot
    
      # rkmpp
      bitbake rockchip-mpp
    
      # rockchip-librga
      bitbake rockchip-librga
    
      # 参看更多编译对象
      bitbake -s
    

4.4. 更多 bitbake 选项

从根本上说,BitBake 是一个通用任务执行引擎,它允许 shell 和 Python 任务高效并行运行,同时在复杂的任务间依赖约束下工作。 BitBake 的主要用户之一,OpenEmbedded,利用这个核心并使用面向任务的方法构建嵌入式 Linux 软件堆栈。更多详细使用方法请查看《bitbake-user-manual》

    bitbake <target> <paramater>
    # e.g
    bitbake u-boot -c clean
    bitbake u-boot
Bitbake paramater 描述
-c fetch 拉取目标所需要的代码
-c clean 清除目标的输出文件
-c cleanall 删除目标所有输出文件、共享高速缓存(shared state cache)和源代码
-c compile -f 使用此选项可在部署映像后强制重新编译,但不建议使用,除非 Yocto Project 不知道目标代码已经发生改变
-c listtasks 列出目标定义的所有 target

5. 烧写映像

编译生成的固件位于目录<path/to/yocto>/build/tmp/deploy/<board>/,待下载的文件为.wic与update.img,进入loader模式后执行如下命令:

$ sudo upgrade_tool wl 0 <IMAGE NAME>.wic
$ sudo upgrade_tool uf update.img

# core-image-minimal 的默认登录账号密码为: root

如果客户在 Windows PC 上开发,也可以使用 RKdevtool 直接烧录 update.img