5. Creating Your Own Layer with Yocto
You have successfully imported an existing layer in the previous tutorial Installing the Kivy layer in Yocto.
However, you might want to create your own layer now, add your own recipe, or modify an existing recipe using a bbappend file.
If that’s the case, you’re in the right place!
5.1. Creating a Layer
5.1.1. Why Create Your Own Layer?
Think of a Yocto layer as a collection of recipes and configurations that you can add to your Linux build. Creating your layer allows you to keep your customizations separate from the core Yocto setup. This separation helps you keep things organized, maintain compatibility with updates, and share your creations with others.
5.1.2. How to Create Your Layer
Creating a layer is a straightforward process. Follow these steps:
Navigate to your yocto folder and start bitbake with:
$ source sources/poky/oe-init-build-env`
Create and move your new layer inside the
sourcesfolder:
$ bitbake-layers create-layer <meta-mylayer> && mv <meta-mylayer> ../sources/
Add the new layer to the configuration file: Open
conf/bblayers.confand add the following line at the end:
BBLAYERS += "${BSPDIR}/sources/meta-mylayer"
Verify if the layer is added to your image using:
bitbake-layers show-layers.
5.2. Changing an Existing Recipe
Imagine you want to install Kivy, and the recipe to install it already exists. Incredible, right? However, after trying the recipe, you find it’s not working, and you need to make some changes. If you directly modify a recipe in a layer you do not own (like openembedded), you’ll run into problems.
That’s where the file with the extension bbappend comes into play. It allows you to extend the behavior of an existing recipe without modifying it directly.
To learn how to create and use bbappend, you can refer to the bbappend files in the sources folder.
5.3. How to Debug on Yocto?
You might encounter errors while creating your recipe. If that’s the case, you need to understand a little about how Yocto works and where to check for information.
5.3.1. How to Find Files
Yocto is a powerful parser that goes through update files and checks your cache. Many steps are done implicitly, which can sometimes lead to confusion. One of the best tools to use in Yocto are find, grep, and tree. They can show you useful information about the structure in the sources folder.
5.3.2. Don’t Forget the Cache !
The cache is quite useful. The first time you build your image, it might take a while. But the following builds are going to be much faster. That’s because of the cache !
However, the cache sometimes doesn’t reload something that has changed. That’s why a good practice is to clean the cache when a problem occurs. To do that, you can use the following command
bitbake -c cleanall <myrecipe>
5.3.3. Check Your Recipe in the Image
Because Yocto only compile a part of what is present in the sources folder, you sometimes have to check if what you added is really on the image. For that, you can use this tools:
Look into the
*.manifestfile in your image folder (where you obtain your final file you copy on the SD card).Look into the
work/tmpfolder in thebuilddirectory. You can find for each recipe a folder with all the files fetched by Yocto and the final result of the packaging inside theimagedirectory.Use the command
bitbake -e.
5.4. Conclusion
You now have a better understanding of how to create and use a layer in Yocto. You’re ready to customize your own version of Linux for your product. If you want to add a specific Python package to your board through Yocto, please check Install a Python Package in Yocto.