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
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:
2. Understanding Embedded Linux
When learning Embedded Linux, we need to focus on the following major areas:
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 of U-Boot is quite large:
Our focus in learning is to understand how to modify the U-Boot provided by the chip manufacturer to adapt it to our board:
The term U-Boot porting
usually refers 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:
(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:
(Image source: Baiwen Network)
The root file system requires a dedicated 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 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:
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 (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 giants mentioned above, as it’s easy to go from beginner to giving up…
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 for resolution.
For example, when I compiled the Linux kernel previously, I encountered the following issue:
According to the problem description, I was missing something called lzop
, so I installed it as prompted, but then another issue arose:
Then I had to search online for solutions, trying one method after another until I finally resolved it:
My experimental method was the same as the tutorial, including the development environment provided by the tutorial. Even with identical operations to the tutorial, issues can still arise, let alone when you have to set up your own environment, 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 basically covers our main learning content. The concepts mentioned above are just some surface-level knowledge, and we will learn and share more in-depth and detailed knowledge together in the future.
Recommended Reading:Collection | Summary of Linux ArticlesCollection | Programming LifeCollection | C Language
Embedded LinuxScan the QR code to follow my public account