Transitioning from Microcontrollers to Linux: A Guide

Follow+Star Public Account, never miss exciting content

Transitioning from Microcontrollers to Linux: A Guide

Author | ZhengN

Source | Embedded Miscellaneous

Many microcontroller engineers transition to Linux, but not everyone can smoothly “transition”. There are many who give up before even starting.

As for how difficult it is to transition to Linux, it varies from person to person. Here, I share some basic knowledge you need to master when advancing from microcontrollers to Linux, hoping to help you in your transition.

What to Learn in Embedded Linux

1. Understanding Linux

Transitioning from Microcontrollers to Linux: A Guide
Friends who study microcontrollers may already have some basic knowledge of Linux, but there are also many who have never used Linux, and some beginners may not have even heard of Linux. To accommodate these friends, let’s briefly understand Linux:
Transitioning from Microcontrollers to Linux: A Guide

2. Understanding Embedded Linux

When learning embedded Linux, we need to focus on the following major areas:
Transitioning from Microcontrollers to Linux: A Guide
The three most important parts of embedded Linux software are<span>Bootloader, Linux Kernel, Root Filesystem</span>. With these three parts, we have a minimal, complete, and runnable embedded system.

(1) BootLoader

<span>BootLoader</span> is a piece of code that runs before the operating system, used to<span>boot the operating system</span>. There are many open-source<span>BootLoaders</span>, such as RedBoot, U-Boot, etc., among which<span>U-Boot</span> is the most commonly used. The source code of U-Boot is quite large:
Transitioning from Microcontrollers to Linux: A Guide
Our focus is on learning how to modify the U-Boot that has been ported by the chip manufacturer to adapt it to our board:
Transitioning from Microcontrollers to Linux: A Guide
What we usually refer to as<span>U-Boot porting</span> usually means the process of modifying the U-Boot that has been ported by the chip manufacturer to adapt it to our board.

(2) Linux Kernel

The Linux kernel is an open-source Unix-like operating system<span>monolithic kernel</span>. The Linux kernel we need to learn to port is also the kernel package that has been ported by the chip manufacturer. The kernel source code directory is as follows:
Transitioning from Microcontrollers to Linux: A Guide

(3) Root Filesystem

The root filesystem is the first filesystem mounted when the kernel starts, and the kernel code image file is stored in the root filesystem.
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 like the system disk of our computer; with this system disk, we can install our system. The root filesystem has a root directory<span>/</span>, and there are many subdirectories under the root directory:
Transitioning from Microcontrollers to Linux: A Guide
Transitioning from Microcontrollers to Linux: A Guide
(Image source: Baiwen Network)
The root filesystem needs a dedicated framework to create it, such as: BusyBox, Yocto, Buildroot, etc.

(4) Linux Drivers

Linux drivers should be the starting point and focus of our learning embedded Linux. The above three major parts have already created a complete embedded Linux environment for us.
With such an environment, our Linux drivers can be installed on it. Linux drivers:
Transitioning from Microcontrollers to Linux: A Guide
There are three main types of drivers in Linux: character device drivers, block device drivers, and network device drivers.
Device Tree: The DTS file describes the board-level devices in a tree structure, such as the number of CPUs, memory base address, 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 are opening, reading, writing, 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 much more difficult than learning microcontrollers, not only because there is more content to learn, but also because just getting familiar with the development environment (Linux environment, cross-compiler, Makefile, etc.) is quite a lot of content.
In terms of depth, it is also much deeper than microcontrollers. For example, learning STM32 before was IDE compilation, while embedded Linux is compiled directly using the compiler or using a compilation script.
From my experience of starting from scratch to giving up, starting with Linux drivers and applications is a good approach; don’t jump straight into the three giants above, or it’s easy to give up after starting…
Be prepared to endure hardships while learning this; many problems may drive you crazy. For example, if you follow the tutorial, the final result may be different, and many issues may arise, which is completely normal.
Sometimes, a seemingly small problem can lead to other issues, so patience is required to resolve them.
For example, when I compiled the Linux kernel before, I encountered the following problem:
Transitioning from Microcontrollers to Linux: A Guide
According to the problem description: something called<span>lzop</span> was missing, so I installed it as prompted, but then another problem arose:
Transitioning from Microcontrollers to Linux: A Guide
Then I had to search for solutions online, trying one method after another until I finally resolved it:
Transitioning from Microcontrollers to Linux: A Guide
Transitioning from Microcontrollers to Linux: A Guide
My experimental method was the same as the tutorial, including the development environment provided by the tutorial. If issues arise even with identical operations as the tutorial, the chances of errors will be even greater when setting up the environment yourself.
In any case, do not give up easily.

———— END ————

Transitioning from Microcontrollers to Linux: A Guide

● Column “Embedded Tools”

● Column “Embedded Development”

● Column “Keil Tutorial”

● Selected Tutorials from Embedded Column

Follow the public account and reply “Add Group” to join the technical exchange group, reply “1024” to see more content.

Transitioning from Microcontrollers to Linux: A Guide

Transitioning from Microcontrollers to Linux: A Guide

Click “Read Original” to see more shares.

Leave a Comment