7 min. reading time

Overview

Embedded Linux is a subset of the Linux kernel that is optimized for embedded applications. Embedded Linux is a clear choice when your code base increases the superloop and you have to take care of several ISRs (Interrupt Service Routines) spreading all over the processes and the most of developers time is wasted into taking care of scheduling and managing different tasks, instead of implementing the tasks itself. Turning to bare metal kernels RTOS can be a choice but it has its own drawback. The memory management and protection which Linux kernel provides outperforms that of the bare metal operating systems for microcontrollers. Linux is a good choice for networking applications with a ton of support in the shape of different libraries that can handle asynchronous networking seamlessly. Likewise dynamic memory allocation is safer and physical memory is not exposed to memory bugs because the kernel kills the app running in virtual memory if it contains memory bugs. You can still start the app again from a shell script without restarting the entire system.

One more advantage that embedded Linux has over bare metal programming is the use of databases and filesystems. We can run databases on embedded Linux as we can in our desktop applications just by adding the right software already written by the open source community. We can develop, redistribute Linux applications under MIT license. So getting started with embedded Linux is very light on the pocket. 

Limitations

Embedded Linux is not suitable for every embedded application. There are some overheads and drawbacks in certain applications. We cannot use embedded Linux for hard responsive real time applications, for that purpose we have to use the Real Time version of Linux (RTLinux or better we use a combination of Linux and RTOS as a dual processor solution.) The other problem with embedded Linux is its boot time, which is far larger than the microcontroller's application program. As an open source operating system and a lot of functionality added, embedded Linux programmers should be careful about security and should disable the features that are not used in the particular application so that attackers have less chance to penetrate the system.

Architecture of microcontroller vs microprocessor

The architecture of microcontrollers contains Processor, RAM, ROM and different peripherals on chip. So you just need to add the driver circuit around the microcontroller and install the proper IDE from the vendor and start programming your first application. 
Whereas the architecture of Linux based processors are a bit different. You have to add external Storage and sometimes RAM as well. So first the small built-in boot ROM in the processor will load the bootloader which is typically responsible for loading the Linux. After this point, Linux will be loaded by the bootloader which can configure all the peripherals and applications. As a developer you have to take care of memory i.e. RAM and storage i.e. ROM. There are several development boards where you find RAM already embedded on PCB and you also can attach Storage in the form of SD Memory card (though SD memory cards are not reliable so you have to be careful in selecting proper storage for industrial applications).

Building embedded Linux from scratch  

If we want to build an embedded Linux image for your new project from scratch then you have to go through a few steps: The first thing is building a cross toolchain. This is required because you will be building a software image for an architecture different from your host machine. Then you have to take care of U-Boot, this is a universal boot software required to initialize main memory  so that the Linux kernel can be loaded. The Linux kernel is required to initialize a set of peripherals and device drivers. Embedded Linux needs to know about the addresses of hardware connected to microprocessors who’s information is stored in the device tree. After the Linux kernel initializes itself then we need to take care of the userspace program which is stored in “init” . We need a lot of shell scripts and softwares to run user programs. Thankfully “Busy box” can be used for this purpose, it gathers light weight programs necessary for start-up and adds the configuration similar to device tree Kconfig.

Automated Build system Yocto

As you see, building a Linux image from scratch seems a tedious task, that's why build systems come in. One of the most popular build systems for developers is Yocto. It is used to compile all the toolchain: fetch U-Boot, Linux kernel, userspace programs and many important packages automatically into target filesystem which is ready to be shipped to target hardware. Yocto is a giant industry project to deploy custom Linux images reliably. The Yocto project has many branches, poky and OpenEmbedded branches are specific for embedded Linux applications which includes base packages only. 
Yocto already supports many industrial development boards, so most of the time you can select target architectures and the target image is ready to be deployed on these boards. Yocto project allows you to build or rebuild packages so that you can save time to rebuild the entire Linux distribution from start. Yocto is not only a Linux image building tool but also a Linux distribution building tool.
If you want to get Yocto running for a new custom hardware then there is a steep learning curve as a coder. Recipe is the file containing all the information about source code and libraries. It also contains information about dependencies on different libraries and other recipes which are stored in layers. Layers are collections of related recipes. You can consolidate related recipes into one layer for clean practice. Layers are hierarchical and can override the older specifications. A Python based build system is used in Yocto, named BitBake, which parses recipe files to execute tasks. It is an execution engine which creates a dependency tree to schedule compilation of code.   

For getting an image using Yocto, first of all the developer needs to specify architecture policies, configuration and patches, to tell which components you need to be present in the target image. Build system will download and fetch the source code from the specified address or repository. After downloading the source code into the working directory, patches are applied and then software will be compiled. The build system will hand over the custom Linux image in the target folder.

Competency at itemis

At itemis we are updated and ready to develop custom Linux images according to different applications. Our dedicated team of expert embedded Linux developers have hands -on experience developing embedded Linux projects, which helps us develop fast to market products. If you need assistance in developing embedded Linux projects then feel free to contact us. 

Comments