A Microcontroller Engineer’s Perspective on Embedded Linux

Introduction

This article provides a brief overview of some knowledge related to Embedded Linux, serving as a reference for those who, like me, wish to advance from microcontroller programming to Embedded Linux.

With the increasing number of tutorials on Embedded Linux, I believe many friends studying microcontrollers have started to explore this area.

What to Learn in Embedded Linux

1. Understanding Linux

A Microcontroller Engineer's Perspective on Embedded Linux

Some friends who study microcontrollers may already have a basic understanding of Linux, but there are also those who have never used Linux, and some beginners may not have even heard of it. To accommodate these friends, let’s briefly introduce Linux:

A Microcontroller Engineer's Perspective on Embedded Linux

2. Understanding Embedded Linux

When learning Embedded Linux, we need to focus on several key areas:

A Microcontroller Engineer's Perspective on Embedded Linux

The three most important components of Embedded Linux software are Bootloader, Linux kernel, and root filesystem. With these three components, we have a minimal, complete, and operational embedded system.

(1) BootLoader

BootLoader is a piece of code that runs before the operating system starts, used to boot the operating system. There are many open-source Bootloaders, such as RedBoot and U-Boot, with U-Boot being the most widely used. The source code for U-Boot is quite extensive:

A Microcontroller Engineer's Perspective on Embedded Linux

Our focus in learning is to understand how to modify the U-Boot provided by the chip manufacturer to adapt it to our board:

A Microcontroller Engineer's Perspective on Embedded Linux

When we talk about U-Boot porting, we usually refer to the process of modifying the U-Boot provided by the chip manufacturer to fit our board.

(2) Linux Kernel

The Linux kernel is an open-source monolithic kernel of a Unix-like operating system. The Linux kernel we need to learn to port is also the one provided by the chip manufacturer. The kernel source directory is as follows:

A Microcontroller Engineer's Perspective on Embedded Linux

(3) Root Filesystem

The root filesystem (rootfs) is the first filesystem mounted when the kernel starts, where the kernel image file is stored.

The system boot program will load some basic initialization scripts and services into memory to run after the root filesystem is mounted.

The importance of the root filesystem is akin to the system disk on our computer; without it, we cannot install our system. The root filesystem has a root directory /, which contains many subdirectories:

A Microcontroller Engineer's Perspective on Embedded Linux

A Microcontroller Engineer's Perspective on Embedded Linux

(Image source: Baiwen Network)

The root filesystem requires a specialized framework for creation, such as BusyBox, Yocto, Buildroot, etc.

(4) Linux Drivers

Linux drivers should be the starting point and focus of our Embedded Linux learning. The three components mentioned above have already created a complete Embedded Linux environment for us.

With such an environment, our Linux drivers can be installed on top of it. Linux drivers:

A Microcontroller Engineer's Perspective on Embedded Linux

There are three main types of drivers in Linux: character device drivers, block device drivers, and network device drivers.

Device Tree: A file that describes the device tree. This DTS file uses a tree structure to describe board-level devices, such as the number of CPUs, memory base addresses, devices connected to the IIC interface, devices connected to the SPI interface, etc.

(5) Linux Applications

In Linux, everything is a file. In C programming, we know that file operations involve opening files, reading and writing files, and closing files.

In Embedded Linux application programming, our focus is also on how to operate (open, close, read, write, etc.) these files (such as device files).

3. Some Experience

Learning Embedded Linux is significantly more challenging than learning microcontrollers, as there is much more content to learn. Just getting familiar with the development environment (Linux environment, cross-compiler, Makefile, etc.) involves a lot of material.

In terms of depth, it is also much deeper than microcontrollers. For example, when learning STM32, we used an IDE for compilation, while in Embedded Linux, we compile directly using a compiler or compilation scripts.

From my experience of starting and then giving up, I recommend starting with Linux drivers and applications. Don’t jump straight into the three major components mentioned above, as it’s easy to get discouraged.

Be prepared to endure hardships while learning; many issues may frustrate you. For instance, you might follow a tutorial, but the final result may differ, and many problems may arise, which is completely normal.

Sometimes, a seemingly simple problem can lead to other issues, so patience is essential for resolution.

For example, when I compiled the Linux kernel previously, I encountered the following issue:

A Microcontroller Engineer's Perspective on Embedded Linux

According to the problem description, I was missing something called lzop, so I installed it as prompted, but then another issue arose:

A Microcontroller Engineer's Perspective on Embedded Linux

Then I had to search online for solutions, trying various methods until I finally resolved it:

A Microcontroller Engineer's Perspective on Embedded Linux

A Microcontroller Engineer's Perspective on Embedded Linux

My experimental method was identical to the tutorial, including the development environment provided by the tutorial. Even with identical operations, issues can still arise, and the probability of errors increases when you have to set up your own environment.

Regardless, do not give up easily.

Conclusion

The knowledge of Embedded Linux is not limited to what has been mentioned above, but it covers the main content we need to learn. The concepts discussed are just a surface-level understanding, and we will continue to learn and share more in-depth and detailed knowledge together.

Leave a Comment