Yocto: Install different config files based on MAC

2020-03-31 03:59发布

问题:

I've got a couple of HW platforms (same cpu, etc.) that require different asound.conf files.

The way that I'm controlling the target platform is via the MACHINE variable and target image (i.e., MACHINE=machine_1 nice bitbake machine-1-bringup-image)

Normally, if just replacing the conf file I'd just create an alsa-state.bbappend and create a do_install_append function to replace it.

However since the different HW platforms require differ conf files I'm unsure how to handle it.

I've tried putting some logic into the append file do_install_append function but it's not working out. It's not always picking up the correct file (like it thinks that nothing has changed so that it uses the previous cached conf?)

Here's an example of one of the append files that I've tried:

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

}

I can see the correct echoes in the logs per the logic.

At any rate I don't think that the path I'm going down is the best way to deal with this.

Is there a 'standard' way to have different files installed based on either the target image or MACHINE variable?

回答1:

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
}

The value of MACHINE is automatically added to OVERRIDES, which can be used at the end of a function append to have a MACHINE-specific addition to a function.

Maybe useful: https://www.yoctoproject.org/docs/2.4/mega-manual/mega-manual.html#var-OVERRIDES



回答2:

You can have configuration files in machine specific directories in your particular case (just a specific configuration file for each machine). OpenEmbedded will fetch the most specific one. The directory structure in your recipe directory will look like:

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

And your alsa-state.bbappend will contain just one line (you don't need to change do_install because alsa-state.bb already installs asound.conf):

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

BTW: We are using that setup to have specific asound.state file per machine in our project.

Moreover, OpenEmbedded will detect that SRC_URI contains machine specific file and change the PACKAGE_ARCH accordingly, see: https://www.yoctoproject.org/docs/2.5/mega-manual/mega-manual.html#var-SRC_URI_OVERRIDES_PACKAGE_ARCH

Few more words on machine, distro or arch specific files: OE is trying to fetch the most specific file in file:// fetcher. It searches also in the directories named by distro (e.g files/<distro>/asound.conf) and architecture (e.g. armv7a, arm). It might be useful if you want to have file specific for some set of devices. More information: 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 (section "Place Machine-Specific Files in Machine-Specific Locations")



回答3:

The above answer by clsulliv worked better than advertised. For future reference below is the append file I used:

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
}

Thanks for the help!



标签: yocto bitbake