2 Replies Latest reply on Sep 30, 2015 3:39 AM by f.fuga

    How to make permanent changes to configuration files via your own Yocto layer [answered]


      You set up some config files on your Galileo to match your preferences, like the credentials for your WLAN or you mounted one or more files as additional file systems on the SD card. How to keep them even if you create a new image?


      The answer is: don't store them only in your image on the SD card but also add the changes to your own Yocto layer.

      This text deals with:

      • Adding you own Yocto layer to the BSP
      • Create Recipes to use your customized config files instead of the default one




      You have installed the Galileo BSP and have successfully build your own image for the Galileo as described in Chapter 4 of the Intel® Quark BSP Build Guide

      Add your own Yocto layer


      Go to the directory, where the other layers of your BSP resides. These layers are directories and named meta-clanton-distro, meta-clanton-bsp etc.

      Create a directory for your layer. For example: meta-mylayer and go into it:

      mkdir meta-mylayer

      cd meta-mylayer


      Create the conf directory and go into it

      mkdir conf

      cd conf


      Create a file called layer.conf. It describes, how bitbake should handle our layer directory. It should be enough to copy&paste the following text and only change the directory references (also in the variable names!):

      BBPATH .= ":${LAYERDIR}"

      BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \


      BBFILE_COLLECTIONS += "meta-mylayer"

      BBFILE_PATTERN_meta-mylayer := "^${LAYERDIR}/"

      BBFILE_PRIORITY_meta-mylayer = "6"


      The first line adds your layer directory to the list of directories bitbake should walk through. The variable ${LAYERDIR} references our layer directory. The next assignment to BBFILES tells which files bitbake should handle, here: all files in the recipes-*-directories ending with .bb or .bbappend. In the third line we define the suffix for the next both variables. Just copy the fourth line as is. The fifth line set the layer priority, I will explain its meaning latter.


      If you edit this file or type the text above character by character take care of the different types of assignment operators used here: .= += :=


      Houston, we have a new Yocto layer! The last thing to do: Bitbake should use it. Go into the conf directory in your yocto_build directory. There you will find a file called bblayers.conf, open it.

      At the end of the file there is a list of layer directories – add your directory at the end of the BBLAYERS assignment. Take care to end the line with a backslash \ and to have a " in the last line.


      Now try to run bitbake. It should run without any problems. But the layer is still empty, so let's start with part 2...

      Create a recipe for a customized config file


      We want to make a recipe for a customized fstab file. It should contain an extra entry for file called data.ext3 on the SD card, that should be mounted as home directory for the root user. The additional line for fstab looks like this:


      /dev/mmcblk0p1/data.ext3 /home/root ext3 defaults 0 0


      I will not expand further what this line means or how to create the data.ext3 file in first place. Please use Google to get additional informations about fstab or how to create an ext3 filesystem in a regular file. You don't need this knowledge to follow the explanations about creating a recipe.

      The fstab file is included be default in the created image. So we know, there must be an existing recipe for the fstab file. But how to find it? There are two options: Search for a recipe with the term „fstab“ in its filename, or directly search for the file „fstab“. A third option would be to grep for the term in all *.bb and *.bbappend files, but this can lead to a lot of false positive results, so this is more some kind of last resort.


      Try it. Go to the directory, where all the layers reside and the do some grepping:

      find ./ -name 'fstab' | grep 'recipes'


      This will find all occurrences of fstab-related files that should relate to recipes. In Intels BSP only one line should show up:



      Touché! We have found the file. The related recipe is in the directory ./poky/meta/recipes-core/base-files/ and called base-files_3.0.14.bb, there is only this *.bb file in the directory. The numbers in the file name may differ, depending on the Galileo BSP version you use.


      If you open this file, you could be shocked, but calm down. Basically it just says: copy the files in the subdirectory base-files to predefined locations in the image.


      The easy fix for a permanent change of fstab would be to copy the additional line above directly into the fstab file here. But then, the change would be gone after a layer update.


      The more sophisticated solution is to create a corresponding recipe and a modified fstab in our layer.


      A corresponding recipe must have to same path like the original one:

      meta/recipes-core/base-files/ -> meta-mylayer/recipes-core/base-files


      Create a file named like the original recipe but use .bbappend as file suffix:

      base-files_3.0.14.bb -> base-files_3.0.14.bbappend


      This new file needs only a single line:



      The meaning of the variable ${THISDIR} should be clear. ${PN} refers to the name of the recipe (PN is short for Package Name). The name is extracted from the recipe file name without the version number. In our case it is base-files. The line says: add the directory base-files to the list of directories to use for the original recipe.


      Don't forget to create the directory base-files mentioned above, in the same directory where our recipe reside. In this directory put the modified version of fstab in there. Just copy the original fstab and insert the additional line from the beginning.


      The final paths should look like this:




      Build the image with bitbake and check /etc/fstab in the image. It should be the modified version.


      How does the magic work?


      Bitbake starts with collecting the recipes and „merging“ original and corresponding recipes together. So, if bitbake processes the base-files_3.0.14.bb recipe it will not only look in „its“ directories but also in the base-files directory of your layer. We told bitbake to do so because, we extended the list of directories in the .bbappend file.

      The original recipe makes bitbake to copy named files to specific location. One of them is fstab. But instead of the original one, it uses your modified fstab file. Bitbake selected the modified file, because the layer meta-mylayer has a higher priority value (priority: 6) then the poky-meta layer (priority: 5).