Yocto:根据机器类型或目标图像安装不同的配置文件

Yocto: Install different config files based on MACHINE type or target image

我有几个硬件平台(相同的 cpu,等等)需要不同的 asound.conf 文件。

我控制目标平台的方式是通过 MACHINE 变量和目标图像(即 MACHINE=machine_1 nice bitbake machine-1-bringup-image)

通常,如果只是替换 conf 文件,我会创建一个 alsa-state.bbappend 并创建一个 do_install_append 函数来替换它。

然而,由于不同的硬件平台需要不同的 conf 文件,我不确定如何处理它。

我尝试将一些逻辑放入追加文件 do_install_append 函数中,但没有成功。它并不总是选择正确的文件(好像它认为什么都没有改变所以它使用以前缓存的 conf?)

这是我尝试过的附加文件之一的示例:

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

SRC_URI += " \ file://asound_MACHINE1.conf \ 
               file://asound_MACHINE2.conf \ "

do_install_append() {

echo "    alsa-state.bbappend MACHINE: ${MACHINE}"
if [ "${MACHINE}" = "machine_1" ]; then
    echo "    machine_1"
    echo "    installing ${WORKDIR}/asound_MACHINE1.conf to ${D}${sysconfdir}/asound.conf"

    install -m 644 ${WORKDIR}/asound_MACHINE1.conf {D}${sysconfdir}/asound.conf

else
    echo "    installing ${WORKDIR}/asound_MACHINE2.conf to ${D}${sysconfdir}/asound.conf"
    install -m 644 ${WORKDIR}/asound_MACHINE2.conf ${D}${sysconfdir}/asound.conf

fi

}

我可以根据逻辑在日志中看到正确的回声。

无论如何我不认为我正在走的路是处理这个问题的最好方法。

有没有 'standard' 方法可以根据目标映像或 MACHINE 变量安装不同的文件?

do_install_append () {
    // install common things here
}

do_install_append_machine-1 () {
    // install machine-1 specific things here
}

do_install_append_machine-2 () {
    // install machine-2 specific things here
}

MACHINE 的值会自动添加到 OVERRIDES 中,它可以用在函数的末尾追加以对函数进行 MACHINE-specific 添加。

可能有用:https://www.yoctoproject.org/docs/2.4/mega-manual/mega-manual.html#var-OVERRIDES

在您的特定情况下,您可以在特定于机器的目录中拥有配置文件(每台机器只有一个特定的配置文件)。 OpenEmbedded 将获取最具体的一个。食谱目录中的目录结构如下所示:

files/<machine1>/asound.conf
files/<machine2>/asound.conf

而你的 alsa-state.bbappend 将只包含一行(你不需要更改 do_install 因为 alsa-state.bb 已经安装了 asound.conf):

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

顺便说一句:我们正在使用该设置在我们的项目中为每台机器提供特定的 asound.state 文件。

此外,OpenEmbedded 将检测到 SRC_URI 包含机器特定文件并相应地更改 PACKAGE_ARCH,请参阅:https://www.yoctoproject.org/docs/2.5/mega-manual/mega-manual.html#var-SRC_URI_OVERRIDES_PACKAGE_ARCH

关于机器、发行版或 arch 特定文件的更多信息:OE 正在尝试在 file:// 提取器中提取最特定的文件。它还在发行版(例如 files/<distro>/asound.conf)和体系结构(例如 armv7a、arm)命名的目录中搜索。如果您想要特定于某些设备集的文件,这可能很有用。更多信息:https://www.yoctoproject.org/docs/2.5/mega-manual/mega-manual.html#var-FILESOVERRIDES and also https://www.yoctoproject.org/docs/2.5/mega-manual/mega-manual.html#best-practices-to-follow-when-creating-layers(部分 "Place Machine-Specific Files in Machine-Specific Locations")

clsulliv 的上述回答比宣传的要好。为了将来参考,下面是我使用的附加文件:

FILESEXTRAPATHS_prepend:= "${THISDIR}/${PN}:"

SRC_URI += " \
   file://machine1_asound.conf \
   file://machine2_asound.conf \
   "


do_install_append_machine1() {

    echo "    machine1"
    echo "    installing ${WORKDIR}/machine1_asound.conf to ${D}${sysconfdir}/asound.conf"
    install -m 644 ${WORKDIR}/machine1_asound.conf ${D}${sysconfdir}/asound.conf
}


do_install_append_machine2() {

    echo "    machine2"
    echo "    installing ${WORKDIR}/machine2_asound.conf to ${D}${sysconfdir}/asound.conf"
    install -m 644 ${WORKDIR}/machine2_asound.conf ${D}${sysconfdir}/asound.conf
}

感谢您的帮助!