Is it possible to pass in command line variables to a bitbake build?

17,976

Solution 1

bitbake -Dfoo=bar oe-myimage

-D flag is not recognized by bitbake. So, using above method will not work. Instead you could specify flags from command line using following steps -

Say you want to export variable foo and expect it be recognized by bitbake.

export foo="foobar"

You will need to export this and inform bitbake via BB_ENV_EXTRAWHITE variable after sourcing oe-init-build-env. This means

. oe-init-build-env
export foo="foobar"
export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE foo"      

This whitelists variable 'foo' for bitbake and thus makes it visible to any recipe and subprocess during the build.

After this you can invoke any bitbake operations using variable foo within bitbake via expressions like -

${foo}

Solution 2

While there is nothing wrong with the other answers bitbake does accept a --postread argument as documented here. That means that you can write as many bitbake variables as you want to some temporary configuration file and have it read after bitbake.conf by specifying the name of the file on the command-line. For example:

bitbake --postread=./extra.conf

I personally find this more convenient than dealing with environment variables.

Solution 3

There's also a convenient command-line way to do this, that's described in the bitbake manual using BB_ORIGENV:

Sometimes, it is useful to be able to obtain information from the original execution environment. Bitbake saves a copy of the original environment into a special variable named BB_ORIGENV.

To do so, you could read a variable exactly as they suggest (from a Python function):

 origenv = d.getVar("BB_ORIGENV", False)
 bar = origenv.getVar("BAR", False)

Then, the way to pass that from the command line is simply:

BAR=somevalue bitbake myimage

Solution 4

you can do:

export foo="bar"
export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE foo"
bitbake oe-myimage

Solution 5

No, I don't believe such a mechanism exists. But you could do something like

"echo "foo = \"bar\"" >local.conf

Not sure that will solve your particular problem or not. Also, there is a mechanism for local site-wide variables: if you have a 'site.conf' file in your home directory under a directory called .oe, bitbake will read that and apply those variables to the global environment for every build. Maybe that would help? You didn't specify exactly what problem you are trying to solve, there might be better ways.

Share:
17,976

Related videos on Youtube

Mike
Author by

Mike

Have a BS in computer science from SIUE Worked @ Motorola for 6 years as an embedded systems software engineer Currently reside in OH working for Emerson as a software engineer

Updated on October 12, 2020

Comments

  • Mike
    Mike over 3 years

    I have an OpenEmbedded environment using bitbake to do some builds. I wanted to get something "interactive" going on where bitbake would pause and ask for input then continue with the build but I've found out that's not possible.

    Since I can't do that I'm looking for some way to pass in extra flags for the build. Is there any way to pass in flags to a bitbake build sort of like gcc's -D option?

    ie:

    bitbake -Dfoo=bar oe-myimage
    

    Thus during the build process of oe-myimage the variable foo will be set to bar.

  • GAlexMES
    GAlexMES over 5 years
    Is it possible to add the extra variable permanent? In some configuration files or so? Or do I need to export the BB_ENV_EXTRAWHITE after each system reboot?
  • fabatera
    fabatera about 4 years
    Yes. You only need to set the variable wherever is more convenient for you. e.g. add the 2 export lines above mentioned to oe-init-build-env.
  • Vitalii Blagodir
    Vitalii Blagodir about 2 years
    One-line variant: BAR = "${@d.getVar('BB_ORIGENV').getVar('BAR')}"