Yocto: How to assign variables with examples

  • = A hard assignment. The variable is assigned as soon as the statement is evaluated. If the assignment contains a reference to another variable then that reference will be included in the assignment rather that the value of the reference.
  • ?= Defines a variable only if it is undefined at the time of parsing.
  • ??= Assignment does not occur until the end of the parsing process.
  • := Immediate variable expansion
  • += Appending with spaces.
  • =+ Prepending with spaces.
  • .= Appending without spaces.
  • =. Prepending without spaces.

Assignment Using Overrides

Variables can be appended or prepended using the override style syntax. In the example below B becomes equal to “bval additional data” and C becomes equal to “additional data cval”. Note that no additional spaces are include over what is in the original variable definitions.

B = "bval"
B_append = " additional data"
C = "cval"
C_prepend = "additional data "

Removal of data can also be accomplished. In the following example FOO becomes equal to “ghi abcdef”. Note that surrounding spaces are also removed.

FOO = "abc def ghi abcdef abc def abc def"
FOO_remove = "abc def"

Examples

In the following example the value of A is set to “aval”. The value of B is set to “pre${A}post”. In other words the value of B becomes dependent on the value of A at the times it is referenced. If the value of A changes between references to B the value of B will be different at those times.

A = "aval"
B = "pre${A}post"

The following code includes some immediate variable assignment. The value of A becomes “test 123” as the values of A and B are unassigned at the time of As assignment.

T = "123"
A := "${B} ${A} test ${T}"

The following code uses a soft assignment. A is only assigned if the value is currently unassigned. The code therefore results in A being given the value of “one”

A ?= "one"
A ?= "two"

The following code uses weak assignment. A is not assigned until the end of the parsing process and is therefore given a value of “two”

A ??= "one"
A ??= "two"

Yocto: base_contains

The base_contains function is used to return a value based on a search of a named variable for a given value. The following line of code for example would search the DISTRO_FEATURES variable for the text bluetooth and if found it would return the text bluez5 otherwise we would get a blank.

"${@base_contains('DISTRO_FEATURES', 'bluetooth', 'bluez5', '', d)}"

Linux Commands: Alias

An alias is a shortcut to entering a command in Linux. You can create an alias as shown below.

$ alias ll='ls -l'

If you now enter the command ll, you will get the same output you would have got if you had entered the command ls -l. If you want to add further arguments or flags that is still possible. The command ll -a will for example produce the same output as typing ls -l -a.

To get a list of the current aliases you can enter the command

$ alias

at the command prompt.

Yocto: Setting the root password

To set the root password under a Yocto build you need to add the following code to the local.conf file located in the build/conf directory.

INHERIT += "extrausers"
EXTRA_USERS_PARAMS = "usermod -p Rbna8drt0yYLk root;"

Where the Rbna8drt0yYLk value is generated via the command

$ openssl passwd <password>