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

3

5

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?

Hammerhead answered 13/3, 2018 at 20:48 Comment(0)
S
9
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

Sledge answered 13/3, 2018 at 21:31 Comment(1)
Okay. That makes since. I knew I was making it more complicated than I needed too. I'll try it tomorrow and mark it solved when it fixes it.Hammerhead
I
10

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")

Isobath answered 14/3, 2018 at 15:1 Comment(4)
Thanks for the additional info. I didn't see it prior to testing and posting the previous solution. I will play with your solution, too.Hammerhead
So looking at your comment more an in regards to machine/distro/arch specific files I have a questions. if I wanted to have specific files for a specific distro and a specific machine would the directory structure be: files/<distro>/<machine1>/asound.conf or files/<machine1>/<distro>/asound.conf Or does it matter?Hammerhead
@zonedar, unfortunately no. It is files/<distro>/asound.conf or files/<machine1>/asound.conf. The distro and machine path cannot be combined in the default configuration. But you can play with FILESEXTRAPATHS variable if you want such behaviour.Isobath
@Thomas: Got it. Thanks!Hammerhead
S
9
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

Sledge answered 13/3, 2018 at 21:31 Comment(1)
Okay. That makes since. I knew I was making it more complicated than I needed too. I'll try it tomorrow and mark it solved when it fixes it.Hammerhead
H
1

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!

Hammerhead answered 14/3, 2018 at 15:16 Comment(1)
IMHO the @tomas solution better follows yocto best-practicesJudaism

© 2022 - 2024 — McMap. All rights reserved.