A Perspective on Embedded Linux from a Microcontroller Engineer

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 Perspective on Embedded Linux from a Microcontroller Engineer

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 Perspective on Embedded Linux from a Microcontroller Engineer

2. Understanding Embedded Linux

When learning Embedded Linux, we need to focus on the following major areas:

A Perspective on Embedded Linux from a Microcontroller Engineer

The three most important components of Embedded Linux software are Bootloader, Linux Kernel, and Root File System. 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 Perspective on Embedded Linux from a Microcontroller Engineer

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 Perspective on Embedded Linux from a Microcontroller Engineer

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 Unix-like operating system monolithic kernel. 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 Perspective on Embedded Linux from a Microcontroller Engineer

(3) Root File System

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

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

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

A Perspective on Embedded Linux from a Microcontroller Engineer

A Perspective on Embedded Linux from a Microcontroller Engineer

(Image source: Baiwen Network)

The root file system requires a specialized framework for its creation, such as BusyBox, Yocto, and Buildroot.

(4) Linux Drivers

Linux drivers should be the starting point and focus of our Embedded Linux learning. The three major 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 Perspective on Embedded Linux from a Microcontroller Engineer

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 the 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 (device files, etc.).

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, beginning with Linux drivers and applications is a better approach. Don’t jump straight into the three major components mentioned above, as it is easy to get discouraged.

Be prepared to endure hardships while learning this, as many issues may drive you crazy. 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 in resolving them.

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

A Perspective on Embedded Linux from a Microcontroller Engineer

The problem description indicated that something called lzop was missing. After installing it as prompted, another issue arose:

A Perspective on Embedded Linux from a Microcontroller Engineer

Then I had to search online for solutions, trying each method one by one until I finally resolved it:

A Perspective on Embedded Linux from a Microcontroller Engineer

A Perspective on Embedded Linux from a Microcontroller Engineer

My experimental method was the same as the tutorial, including the development environment provided by the tutorial. Even with identical operations, issues can still arise, let alone when you have to set up the environment yourself, which increases the likelihood of errors.

Regardless, do not give up easily.

Conclusion

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

Feel free to follow along for more notes. Join me in the journey from giving up to getting startedA Perspective on Embedded Linux from a Microcontroller Engineer~

If you find this article helpful, please share and give it a thumbs up, as it motivates us to continue updating.

You might also like:

[Linux Notes] PC, Development Board, Ubuntu Ping Experiment

What are Dynamic Linking and Static Linking?

[RT-Thread Notes] Object Container and Doubly Linked List

C Language, Embedded Key Knowledge: Callback FunctionsJob Seeking Matters for Fresh Graduates

A Perspective on Embedded Linux from a Microcontroller Engineer

Leave a Comment