You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在自定义Yocto层中让Linux 6.1.21内核Recipe被识别构建?

问题描述

在Yocto构建树莓派镜像时,当前可正常编译Linux 5.15内核,尝试在自定义层meta-mylayer中添加linux-raspberrypi_6.1.bb recipe(基于官方层的5.15版本修改,仅调整版本参数),并在local.conf中设置PREFERRED_VERSION_linux-raspberrypi = "6.1.21",但Yocto提示无法找到对应版本的recipe(尽管可用版本列表包含该版本)。将该recipe移入meta-raspberrypi层的对应目录则可正常构建,需要解决如何在自定义层中保留该recipe并让Yocto识别使用。

目录结构如下:

sources/meta-raspberrypi/recipes-kernel/linux
 + linux-raspberrypi_5.15.bb

sources/meta-mylayer/recipes-kernel/linux
 + linux-raspberrypi_6.1.bb

自定义recipe内容:

LINUX_VERSION ?= "6.1.21"
LINUX_RPI_BRANCH ?= "rpi-6.1.y"
LINUX_RPI_KMETA_BRANCH ?= "yocto-6.1"

SRCREV_machine = "${AUTOREV}"
SRCREV_meta = "${AUTOREV}"

KMETA = "kernel-meta"

SRC_URI = " \
    git://github.com/raspberrypi/linux.git;name=machine;branch=${LINUX_RPI_BRANCH};protocol=https \
    git://git.yoctoproject.org/yocto-kernel-cache;type=kmeta;name=meta;branch=${LINUX_RPI_KMETA_BRANCH};destsuffix=${KMETA} \
    file://powersave.cfg \
    file://android-drivers.cfg \
    "

require linux-raspberrypi.inc

KERNEL_DTC_FLAGS += "-@ -H epapr"

local.conf配置:

# KERNEL_VERSION_SANITY_SKIP="1"
PREFERRED_VERSION_linux-raspberrypi = "6.1.21"
解决方案

1. 提升自定义层的优先级

Yocto会优先选择层优先级更高的recipe,修改meta-mylayer/conf/layer.conf:

  • 设置更高的BBFILE_PRIORITY,确保数值大于meta-raspberrypi的默认优先级(通常为5):
    BBFILE_PRIORITY_mymeta = "6"
    
  • 确认BBFILES已正确包含自定义层的recipe路径:
    BBFILES += "${LAYERDIR}/recipes-kernel/linux/*.bb ${LAYERDIR}/recipes-kernel/linux/*.bbappend"
    

2. 匹配recipe文件名与指定版本

Yocto默认从recipe文件名提取版本号(PV变量),当前自定义recipe名为linux-raspberrypi_6.1.bb,提取的PV为6.1,与local.conf中指定的6.1.21不匹配,导致识别失败。可通过两种方式解决:

  • 将recipe文件名改为linux-raspberrypi_6.1.21.bb;
  • 或在自定义recipe中显式指定PV变量:
    PV = "${LINUX_VERSION}"
    

3. 确认自定义层已正确启用

检查bblayers.conf,确保meta-mylayer已被添加且未被注释:

BBLAYERS ?= " \
  ...
  ${BSPDIR}/sources/meta-mylayer \
  ...
"

4. 清理构建缓存后重新构建

旧的构建缓存可能干扰版本识别,执行以下命令清理后重新编译:

bitbake -c cleansstate linux-raspberrypi
bitbake -c clean linux-raspberrypi
rm -rf tmp/cache/
bitbake <your-image-name>

内容的提问来源于stack exchange,提问作者rosewater

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 10:05:29