7

I want to know if there is an opportunity to create machine specific recipes just by file name in order that I have a similar layer structure like this:

\-> recipes-example
     \-> example
         \-> example_1.0.bb_machine1
         \-> example_1.0.bb_machine2

I have read almost the complete Yocto Documentation a while ago and thought I once stumbled over this opportunity to create machine specific recipes, but couldn't refind it.

Alternatives are also appreciated, however I know about the bash solutions like this example:

do_install() {
   case ${MACHINE} in
      < case statements [...] >
}
h0ch5tr4355
  • 2,092
  • 4
  • 28
  • 51

1 Answers1

16

No, there's no way to create machine-specific recipe just by their name.

Assuming there's only a few files / patches that differs, the most common way to do this would be to add the different files in a machine specific directory see e.g.:

\-> recipes-example
  \-> example
    \-> example
      \-> machine1
        \-> defconfig
        \-> mach1.patch
      \-> machine2
        \-> defconfig
    \-> defconfig

That would allow you to write things like: (Note that in my example, there's a generic defconfig file, and two machine specific ones. The correct one will automatically be chosen, due to MACHINEOVERRIDES)

SRC_URI += "file://defconfig"
SRC_URI_machine1 += "file://mach1.patch"

In this example, mach1.patch will only be applied for machine1.

If you need to do something special for a machine in e.g. the do_install, you could use:

do_install_append_machine1 () {
    do something here
}

UPDATE: (after graugans comment)

Yes, COMPATIBLE_MACHINE could also be used. One way would be to create example-mach1.bb, example-mach2.bb, and exampe-machs.bb Which would include a couple of lines such as:

PROVIDES += "virtual/example"
COMPATIBLE_MACHINE = "machine1"

and for `example-machs.bb"

PROVIDES += "virtual/example"
COMPATIBLE_MACHINE = "(machine3|machine4)"

In your image recipe, you then add IMAGE_INSTALL += "virtual/example".

Anders
  • 8,541
  • 1
  • 27
  • 34
  • Ok thanks for the answer, the last part helped me a lot, can I also do sth like `do_install_append_machine1_machine2` to use the same function for 2 machines, or do I have to create the function twice then? – h0ch5tr4355 Jan 20 '16 at 11:11
  • No, that's not possible. Though you could use something similar to SOC_FAMILY in http://git.openembedded.org/openembedded-core/tree/meta/conf/machine/include/soc-family.inc, to create a family of your machines. – Anders Jan 20 '16 at 11:49
  • Ok, but I can create several `do_install ()` methods for different machines in one recipe, can't I? `do_install ()`, `do_install_mach1 ()` and `do_install_mach2 ()` as example – h0ch5tr4355 Jan 20 '16 at 12:20
  • Ok thank you for your help, i think i can solve all my problems now with this method – h0ch5tr4355 Jan 20 '16 at 12:23
  • Just for the sake of completeness there is [COMPATIBLE_MACHINE](http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-COMPATIBLE_MACHINE) to restrict a package to special machine(s). – graugans Jan 25 '16 at 06:43
  • I was curious how this worked exactly (how yocto finds the file in the "machine1" subdirectory), and it took me a while to find out: SRC_URI searches for local files ("file://") in FILESPATH, which includes FILESOVERRIDES, which includes MACHINESOVERRIDES. It may be good to include this in the answer. – Étienne Jan 29 '18 at 13:04
  • By the way, should there really be 2 nested "examples" directories for this recipe? It seems there is one too much: \-> example \-> example – Étienne Jan 29 '18 at 13:05
  • Yes, that's quite common. It doesn't have to be called `${BPN}`, however. It can actually be any of `${BP}`, `${BPN}`, or `files`. – Anders Jan 29 '18 at 13:14
  • I have created 2 machines and I have added MACHINEOVERRIDES =. "new_silicon:" and MACHINEOVERRIDES =. "old_silicon:". Now I want to apply same patch for 2 machines in a single .bbappend file. SRC_URI_old_silicon += "file://flash-writer.patch" SRC_UR_new_silicon += "file://flash-writer.patch" But this is generating an error ERROR: An uncaught exception occurred in runqueue. – Meera Jan 25 '23 at 11:39