Search code examples
yoctobitbake

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


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?


Solution

  • 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