news 2026/5/12 4:43:04

Yocto开发流程参考

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Yocto开发流程参考
  1. 环境搭建

1.1 系统要求

  • 操作系统:Ubuntu 20.04/22.04 LTS(推荐)
  • 内存:至少8GB RAM,推荐16GB以上
  • 硬盘空间:至少100GB可用空间
  • 网络:稳定的互联网连接

1.2 安装依赖包

sudo apt update sudo apt upgrade sudo apt install -y gawk wget git-core diffstat unzip texinfo gcc-multilib \ build-essential chrpath socat cpio python3 python3-pip python3-pexpect \ xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa \ libsdl1.2-dev pylint3 xterm python3-subunit mesa-common-dev \ zstd liblz4-tool

1.3 配置Git

git config --global user.name "Your Name" git config --global user.email "your.email@example.com"

1.4 下载Yocto项目

# 创建工作目录 mkdir -p ~/yocto/workspace cd ~/yocto/workspace # 克隆poky(Yocto核心) git clone git://git.yoctoproject.org/poky -b kirkstone # 克隆meta-openembedded(额外的层) git clone git://git.openembedded.org/meta-openembedded -b kirkstone # 克隆meta-qt6(如果需要Qt支持) git clone https://github.com/meta-qt6/meta-qt6.git -b kirkstone

1.5 初始化构建环境

cd ~/yocto/workspace/poky # 初始化环境 source oe-init-build-env

1.6 配置构建环境

编辑conf/local.conf文件:

# 设置目标机器 MACHINE ?= "qemux86-64" # 设置并行编译 BB_NUMBER_THREADS = "8" PARALLEL_MAKE = "-j 8" # 启用镜像压缩 IMAGE_FSTYPES += "tar.bz2" # 设置包管理器 PACKAGE_CLASSES ?= "package_rpm" # 启用本地镜像缓存 DL_DIR ?= "${TOPDIR}/downloads" SSTATE_DIR ?= "${TOPDIR}/sstate-cache"

2. 系统镜像编译

2.1 选择镜像类型

Yocto提供多种预定义镜像类型:

镜像类型描述大小
core-image-minimal最小系统镜像~50MB
core-image-base基础系统镜像~100MB
core-image-sato带GUI的镜像~500MB
core-image-full-cmdline完整命令行镜像~200MB

2.2 编译镜像

# 编译最小镜像 bitbake core-image-minimal # 编译带GUI的镜像 bitbake core-image-sato # 编译完整命令行镜像 bitbake core-image-full-cmdline

2.3 编译过程监控

# 查看编译进度 bitbake -e | grep ^PARALLEL_MAKE # 查看任务状态 bitbake -g core-image-minimal && cat pn-buildlist | grep -v "native" # 查看错误日志 bitbake -v core-image-minimal 2>&1 | tee build.log

2.4 验证编译结果

# 查看生成的镜像 ls -la tmp/deploy/images/qemux86-64/ # 运行QEMU模拟器 runqemu qemux86-64 core-image-minimal

3. 添加Recipe

3.1 Recipe基本结构

# myapp_1.0.bb SUMMARY = "My Application" DESCRIPTION = "A simple example application" HOMEPAGE = "https://example.com" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://LICENSE;md5=xxxxxxx" SRC_URI = "git://github.com/user/myapp.git;branch=main;protocol=https" SRCREV = "v1.0" S = "${WORKDIR}/git" inherit cmake DEPENDS = "boost openssl" do_install() { install -d ${D}${bindir} install -m 0755 ${B}/myapp ${D}${bindir}/ }

3.2 创建自定义层

# 创建层结构 mkdir -p meta-mylayer/recipes-myapp/myapp cd meta-mylayer # 创建层配置文件 cat > conf/layer.conf << EOF # We have a conf and classes directory, add to BBPATH BBPATH .= ":${LAYERDIR}" # We have recipes-* directories, add to BBFILES BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ ${LAYERDIR}/recipes-*/*/*.bbappend" BBFILE_COLLECTIONS += "mylayer" BBFILE_PATTERN_mylayer = "^${LAYERDIR}/" BBFILE_PRIORITY_mylayer = "10" LAYERDEPENDS_mylayer = "core" EOF

3.3 添加层到构建配置

# 在build/conf/bblayers.conf中添加 BBLAYERS ?= " \ /path/to/poky/meta \ /path/to/poky/meta-poky \ /path/to/meta-openembedded/meta-oe \ /path/to/meta-mylayer \ "

3.4 常见Recipe类型

3.4.1 CMake项目
inherit cmake EXTRA_OECMAKE = "-DCMAKE_BUILD_TYPE=Release"
3.4.2 Autotools项目
inherit autotools
3.4.3 Python项目
inherit setuptools3
3.4.4 内核模块
inherit module

4.5 调试Recipe

# 清理recipe bitbake -c clean myapp # 重新下载源码 bitbake -c fetch -f myapp # 解压源码 bitbake -c unpack myapp # 打补丁 bitbake -c patch myapp # 配置 bitbake -c configure myapp # 编译 bitbake -c compile myapp # 安装 bitbake -c install myapp

4. 常见问题与解决方案

4.1 编译错误

问题:依赖包缺失

# 解决方案 bitbake -c cleanall <recipe-name> bitbake <recipe-name>

问题:网络连接问题

# 解决方案:设置代理 export http_proxy=http://proxy.example.com:8080 export https_proxy=http://proxy.example.com:8080 # 或在local.conf中添加 PREMIRRORS ??= "\ bzr://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \n \ cvs://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \n \ git://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \n \ gitsm://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \n \ hg://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \n \ osc://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \n \ p4://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \n \ svk://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \n \ svn://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \n"

4.2 性能优化

# 在local.conf中添加 # 启用ccache INHERIT += "ccache" CCACHE_DIR = "${TMPDIR}/ccache" # 设置磁盘缓存 BB_DISKMON_DIRS ??= "\ STOPTASKS,${TMPDIR},1G,100K \ STOPTASKS,${DL_DIR},1G,100K \ STOPTASKS,${SSTATE_DIR},1G,100K \ STOPTASKS,/tmp,100M,100K \ ABORT,${TMPDIR},100M,1K \ ABORT,${DL_DIR},100M,1K \ ABORT,${SSTATE_DIR},100M,1K \ ABORT,/tmp,10M,1K"

4.3 镜像定制

# 添加自定义包到镜像 IMAGE_INSTALL_append = " myapp myutils" # 移除默认包 IMAGE_FEATURES_remove = "x11-base" # 设置root密码 INHERIT += "extrausers" EXTRA_USERS_PARAMS = "usermod -P root root;"

4.4 调试技巧

# 查看recipe变量 bitbake -e <recipe-name> | grep VAR_NAME # 查看依赖关系 bitbake -g <recipe-name> cat pn-depends.dot | grep -v "native" # 查看文件路径 bitbake -c listtasks <recipe-name>

总结

Yocto Project是一个强大的嵌入式Linux构建系统,通过本文档的介绍,您应该能够:

  1. 成功搭建Yocto开发环境
  2. 编译系统镜像
  3. 使用开发工具提高效率
  4. 创建和管理自定义Recipe

随着经验的积累,您可以进一步探索Yocto的高级特性,如:

  • 多配置构建
  • SDK生成
  • 自动化测试
  • 持续集成

更多资源:

  • Yocto Project官方文档
  • Yocto Project邮件列表
  • Yocto Project Wiki
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/9 16:38:53

小龙虾牵手Ollama!本地模型+云端服务双模式,Windows/Ubuntu保姆级配置指南(附避坑代码)

摘要 OpenClaw(小龙虾)作为AI智能体开发平台,与Ollama的深度集成实现了本地大模型私有化部署和云端模型零成本调用的双重能力。本文详细拆解本地模型和Ollama Cloud云模型两种核心连接方式,全面覆盖Windows和Ubuntu两大主流操作系统,每一步操作均配套可直接复制的代码块,帮…

作者头像 李华
网站建设 2026/4/9 16:36:56

如何快速部署智能视频分析工具:3步搞定完整指南

如何快速部署智能视频分析工具&#xff1a;3步搞定完整指南 【免费下载链接】video-analyzer Analyze videos using LLMs, Computer Vision and Automatic Speech Recognition 项目地址: https://gitcode.com/gh_mirrors/vi/video-analyzer 你是否曾经面对长达数小时的会…

作者头像 李华
网站建设 2026/4/9 16:33:30

OpenClaw安全风险纵深剖析与平台级防护实践

引言 OpenClaw作为开源AI代理与自动化平台&#xff0c;通过将大语言模型与本地环境、即时通讯渠道深度集成&#xff0c;实现了从“被动问答”到“主动执行”的跨越。然而&#xff0c;这种强大的系统访问和自主决策能力也引入了全新的攻击面——不安全的网络暴露、提示词注入、供…

作者头像 李华
网站建设 2026/4/9 16:29:18

如何理解 Rust 没有运行时(No Runtime)

文章目录0.前言1. 运行时&#xff08;Runtime&#xff09;通常指什么&#xff1f;2. Rust 的“无运行时”到底指什么&#xff1f;3. 一个简单的对比4. Rust 真的“零运行时”吗&#xff1f;5.总结参考文献0.前言 Rust 核心卖点之一高性能的描述如下&#xff1a; Rust is blazi…

作者头像 李华
网站建设 2026/4/9 16:28:18

@Transcational

Transcational 是 Spring 中声明式事务管理的注解通俗来讲就是用了 Transcational 当 sql 语句每条执行后&#xff0c;遇到错误不会回滚&#xff0c;但是用了这个歌注解之后 sql 会回滚一般用法Service public class OrderService {Autowiredprivate OrderMapper orderMapper;A…

作者头像 李华