Alla de möjligheter som Internet of Things skapar innebär att användningen av små inbyggda system och enheter ökar i snabb takt. Linux är ett av de populäraste operativsystemen för dessa inbyggda system, och det finns många olika Linux-distributioner att välja bland. I denna artikel, skriven på engelska, beskriver Martin Andersson hur du kan använda yocto för att skapa en anpassad och optimerad distribution för just dina behov.
Du kan även ladda ner artikeln som pdf här.
Create an embedded Linux distribution customized for your IoT device
by M Sc Martin Andersson, Software Consultant at Attentec AB
Embedded devices are making their way into our daily lives as well as into more and more companies’ business models. With Internet of Things (IoT), the use of embedded devices is expected to continue to grow fast. Linux is one of the most popular operating system to run on an embedded device today and there are many Linux distributions out there, but which one should you run? The existing ones usually mean some sort of compromise. With yocto you can easily create a custom Linux distribution to run on your embedded device which is optimized for your needs. Or why not create two? One with all the debugging tools you need and one optimized for production!
The yocto project is an open-source collaboration that supports a wide range of architectures. Many vendors on the market also supply BSPs and SDKs for their products which means that getting started is effortless. Arduino, raspberry Pi, Texas Instruments, Xilinx, Freescale and qemu, just to mention a few. There are also layers, as it is called in yocto, for Linux distributions and with support for a wide range of software. Have a look at OpenEmbedded’s webpage to see if they already have what you are looking for.
Before going into how you can work with yocto I want to present a little more detail about the workflow in yocto. The picture below contains more information than I will present here so let’s focus on what the different segments do.
An overview of the workflow in yocto.
There are different ways to configure your system as well as modifying existing sources or adding new ones (the black boxes on the left) but more about this later. One strength of yocto is that is very easy to mix local projects with existing sources, such as git repositories (grey boxes at the top). The build system (the blue box) essentially fetches the required sources, applies your patches and then compiles everything for you. The output is an image ready to be loaded onto your device and potentially an SDK to be used with it (the red boxes).
Yocto uses bitbake as build system, in which configuration and modifications are organized in layers. For each target you build you select which layers to include and thereby what the final image shall contain. Layers can complement or override previous ones making it simple to separate the layers. The table below gives an example on how layers can be used to organize and structure your projects.
In conclusion, yocto is a great way to create a custom embedded Linux distribution with support for many architectures. Furthermore, you can easily combine, organize and modify sources, internal as well as external. Why not try it out on your raspberry Pi? An example of how to make use of layers in yocto.
OpenEmbedded and poky are the two base layers used in all projects. Company wide policies, such as which GPL license to follow, can benefically be placed in a separate layer. To keep track of what changes you have made to the BSP from your chip vendor, simply put it in a separate layer. And finally, different features such as network support or a certain UI can be placed on top to configure the final image as needed.
Each layer defines, configures and/or modifies recipes. For example you might want to lock which revision of a certain git repository you are fetching or you might want to use your own internal source mirror so that you can build your project even if the git repository is no longer available online. If you want the cutting-edge then you can of course let yocto follow upstream changes to the repositories you are using.
Essentially the tasks within a recipe is fetch, patch, build and deploy. Creating a recipe from scratch is quickly done with the built-in tool. And if you want to modify existing tasks then you can either prepend or append to them or even inserting your own tasks in between the existing ones. Testing or debugging something is quick since you can tell yocto to only execute a certain task within a certain recipe and then yocto will perform just that task instead of the whole build chain. If a dependency has changed then yocto will of course perform the necessary tasks prior, in order to bring the system up-to-date.
Useful links with more information to get you started:
Thank you for your time and I hope you enjoyed the article!
Martin Andersson, Software Consultant at Attentec
About the author
Martin Andersson’s wide interest for IT and communication resulted in double masters of science, one within Communication Systems from Linköping University and one within Internet Technologies and Security from the University of Bristol.
In a recent consultancy assignment for one of Attentec´s major customers, Martin has successfully transferred an existing solution to yocto.