epteck logo white
Embedded Linux Boot Process in Resource Constrained Systems

Embedded Linux Boot Process in Resource Constrained Systems

If you are working in embedded linux, you must know the embedded linux boot process. Besides, you should also know the role of each component involved in embedded linux booting sequence. In this way, you will be able to effectively analyze and debug the problems in linux. In this tutorial, we will try our best to explain the linux boot process in the simplest possible way.

The booting process of almost all the linux distros are same. A bootloader loads the kernel into the ram. The Kernel is responsible for scheduling and managing the applications running in your system such as your browser where you are reading this article, your text editor and other software.

In this tutorial, we will discuss the whole linux booting process in embedded systems. Besides, we will also give reason for each step to clear all your queries.

Embedded Linux Boot Process Sequence:

Here are all the components involved in the linux booting process. If you don’t know about any of the above component, don’t worry. We will cover everything here for you!

  • ROM Code
  • Boot Loader
  • Kernel
  • Root File System (Root File System)

1- Rom Code:

Every microprocessor or microcontroller board that provides linux support has a piece of code in read only memory (also known as ROM code).

Role of Rom Code:

This code is usually very minimal. It is responsible for initializing very basic components of your hardware such as power management IC (PMIC) and other critical components required for hardware specific purposes.

How Rom Code Works?

Whenever, we press the power on button, it start running the ROM code. You might be thinking that rom is only readable. How can you run the code there? If you are thinking this, you are right. Every board has a static ram (usually few Kilobytes). So, ROM code is loaded into static ram and starts running there. We are telling this here as it will help us understand other concepts later in this tutorial.

So, whenever you press the power button of your pc (having linux) or any other embedded linux board, it straightly goes to ROM code and load it to the static ram. Then it do its duties such as initializing pmic etc and then move the pointer towards the bootloader.

The way how it locate the ROM code is a completely different story and go beyond the scope of this article. As here, we only aim to describe the clear role of each stage. We will discuss it in detail somewhere soon.

2- Bootloader or U-boot:

Before reading its purpose, you must know that bootloader is not a part of linux. It means that linux systems can run even without bootloader. Many people confuse it thats why we are telling you here. You must be thinking that if bootloader is not a part of linux, why we are using it in embedded linux boot process. Don’t you? Don’t worry, we will discuss all you queries about bootloaders in this section.

Basically, linux uses kernel to manage all the applications running in your system. The purpose of bootloader is to load the kernel in the ram. So you might be thinking that why we can’t load the kernel into the ram directly without using bootloader. Isn’t it? Yes, you can load the kernel directly into ram by doing some modifications and it will work fine too. But bootloader gives many flexibilities that’s why all the embedded linux systems uses bootloader.

Role of Bootloader in Embedded Linux Boot Process:

So, lets discuss the role of bootloader now. When your PC starts, only static ram is initialized and we have already discussed that static ram is very minimal. However, our kernel usually has a very big footprint (Hundreds of MegaBytes in normal case). We can’t load that big kernel code into static ram. So, embedded linux systems usually uses some external ram such as DDR for bigger code processing. Bootloader initializes the external Ram and load the kernel there.

Thats not the sole purpose of bootloaders. It also gives us the flexibility to load kernel from multiple storage sources such as sd cards, USB sticks, NOR Flash, Nand Flash as well as from network. Yes, bootloaders also allow us to load kernel from internet too using techniques like NFS server etc. So, using a bootloader, you can load kernel from multiple storage and network sources for your projects.

How Bootloaders Work?

We hope that you know the responsibility of bootloader very well. Its purpose is to load kernel from multiple sources and multiple techniques easily. So, lets discuss some detail of bootloader now.

Usually bootloaders have two parts. The first part is a primary bootloader also known as SPL and second part is the main bootloader. Primary bootloader is usually a very little piece of code that loads into the static ram and initializes the exeternal ram. Then, this primary bootloader loads the main bootloader into the external ram.

The main bootloader then initializes hardware components required for loading kernel. For example, if you want to load the kernel from the network, if will initialize the ethernet or wifi drivers necessary for networking. Then, it will try to load the kernel from the network using parameters and configurations given in .cfg file in bootloader.

Once the kernel come, it will override all the uboot binaries in the external ram. Now kernel will be responsible for managing all the applications running in linux. The role of bootloader is finished now. Thats why we already said that bootloader is not a component of linux. It is just a utility to load the linux in a customized way.

Preferred Bootloader for Embedded Systems

Multiple bootloaders are available in different linux systems such as uboot, barebox and grub. If you are using ubuntu on some x86 architecture PC, you must be using grub as bootloader. Grub is a very nice bootloader with a very nice menu. If you start pressing F10 button on your pc after power on button, it gives different options for booting. Its very good but we don’t use them in embedded system.

Embedded linux systems are very resource constrained and don’t use very hefty software. Therefore, most of the embedded systems use uboot as bootloader. Its footprint is very minimal and gives us a lot of useful options to customize embedded linux boot process. The best thing about uboot is thats its open source and has a code like kernel. So, its very easier for embedded linux developers to modify and patch it for their desired results. It also allow us to modify boot sequence from command line as well as changing configuration file quickly.

3- Linux Kernel and Root File System:

By now, we know that bootloader has loaded the kernel. Now, the kernel will be responsible for managing all the applications. Lets discuss some indepth stories of kernel here. Our linux system has a user space and kernel space. The kernel space has the access rights to modify the external hardware. The user space don’t pocess this ability to interact with hardware components directly.

The kernel space contains the drivers that provides API’s to applications running in linux to interact with external hardware. These applications reside in user space.

For example, you have a linux application that displays camera video on screen. The camera application written in some framework like opencv or QT. This camera application resides in user space and can’t open camera directly as user space don’t have permission to interact with camera directly. Your kernel space have a device driver for your camera and provides API’s to interact with camera. You use these API’s to interact with camera in your application. In this way, the kernel and userspace concepts makes the whole linux architcture secure and reasonable for working. Learn more about device drivers, kernel space and user space in linux here.

Apart from that, kernel is also responsible for scheduling and managing different applications in your system. For example, you might be running browser, a vscode terminal and other applications in your simultaneously. Kernel is responsible for managing all these applications working at real time. Although linux kernel is not real time, but we will discuss it somewhere else.

How Kernel Works?

So, if you have reached here, you must know the duties of kernel and rootfile system. So, when a bootloader load the kernel in ram, it initializes all the drivers of external components such as your keyboard, camera, LCD, mouse etc. Then, it loads the applications like display server on your system and the command line shell. Other applications like browser, text editor and camera application can be run after logging into the linux system.

Some applications run by default in linux such as your display. The display comes at default in linux which is a userspace application. These by default applications are used by systemd or sysvinit manager.

Final Words

We hope that you have enjoyed this tutorial on embedded linux boot process. If you have any other query, feel free to contact us in the comment sections. Bye Bye for today, we will see you in some other blog post hopefully. Stay connected and keep learning the advanced embedded linux concepts.

Get in touch with us Today!