Development boards from microcontroller manufacturers, along with their software project examples, can greatly assist engineers when starting a new design. However, after the project design reaches its early stages, the software provided by manufacturers may lead to some issues during further design.
Designs that use a real-time operating system as the application code platform also face many challenges, such as how to allocate functions to different parallel tasks, how to design reliable inter-process communication, and how to test the entire software package on hardware.
More and more OEM manufacturers find that the best way to avoid the above two problems is to start new designs using Linux, an open-source, proven, scalable operating system that can run on different hardware platforms. In terms of the number of operating systems that have been ported to various computer hardware platforms, Linux is second to none.
Linux derivatives have run on a very wide range of embedded systems, including: network routers, mobile phones, building automation controls, televisions, and video game consoles.
Although Linux is successfully used, it does not mean it is easy to use. Linux contains over a million lines of code, and its operation carries a distinct Linux methodology flavor, which beginners may find difficult to grasp quickly.
Therefore, the purpose of this article is to provide a guide for starting a new design project using the embedded operating system version of Linux—μClinux. This guide is divided into five steps. To illustrate this guide, the article presents a μClinux project implementation on STMicroelectronics’ STM32F429 microcontroller (ARM Cortex-M4 core, up to 180MHz), using Emcraft’s STM32F429 Discovery Linux Board Support Package (BSP).
Step 1: Linux Tools and Project Layout
Every embedded software design starts with selecting the right tools.
The toolchain is a set of software development tools that are connected (or linked) together, containing components such as the GNU Compiler Collection (GCC), binutils (a set of development tools including linkers, assemblers, and other tools for object files and archives), and glibc (the C library providing system calls and basic functions); in some cases, it may also include other tools such as compilers and debuggers.
The toolchain used for embedded development is a cross-toolchain, more commonly referred to as a cross-compiler.
GNU Binutils is the first component of the embedded Linux toolchain. GNU Binutils includes two important tools:
● “as”, the assembler, converts assembly code (generated by GCC) into binary code
● “ld”, the linker, connects discrete object code segments to libraries or forms executable files
The compiler is the second important component of the toolchain. In embedded Linux, it is known as GCC and supports many types of microcontrollers and processor architectures.
Next is the C library. It implements Linux’s traditional POSIX application programming interface (API), which can be used to develop user-space applications. It interfaces with the kernel through system calls and provides higher-level services.
Engineers have several C library options:
● glibc is the available C library provided by the open-source GNU project. This library is fully functional and portable, compliant with Linux standards.
● Embedded GLIBC (EGLIBC) is a derivative optimized for embedded systems. Its code is streamlined, supporting cross-compilation and cross-testing, and its source and binary code are compatible with GLIBC.
● uClibc is another C library that can be used when flash space is limited and/or memory usage must be minimized.
Debuggers are often part of the toolchain since a cross-debugger is needed to debug application runtime on the target machine. In the embedded Linux field, GDB is a commonly used debugger.
The tools mentioned above are so indispensable, but when they work independently, it takes too long to compile the Linux source code and integrate it into the final image. Fortunately, Buildroot (a tool that automatically generates cross-compilation tools) automates the process of building a complete embedded system and simplifies cross-compilation by producing any or all of the following tasks:
● Cross-compilation toolchain
● Root filesystem
● Kernel image
● Boot image
For embedded system designers, a utility that aggregates tools, such as BusyBox, can also be conveniently used. This tool integrates miniature versions of many commonly used UNIX tools into a small executable file. According to BusyBox’s information page, “it provides alternatives to most of the tools you would typically see in GNU fileutils and shellutils. The tools in BusyBox usually have fewer options than their full-featured GNU counterparts; however, the expected functionality and behavior provided by the included options are nearly indistinguishable from those provided by GNU. The environment provided by BusyBox is quite complete for any small or embedded system.”
The last important tool is a BSP, specifically designed for the motherboard that hosts the project target MCU or processor.
A BSP includes pre-configured tools and a bootloader to load the operating system onto the motherboard. It also provides source code for the kernel and device drivers (see Figure 1).
Step 2: Boot Sequence, Clock System, Memory, and Serial Interface
A typical embedded Linux boot sequence executes as follows:
1) The bootloader firmware (U-Boot in the example project) runs in the target MCU’s built-in flash (no external memory required) and performs all necessary initialization tasks upon power-up/reset, including setting up the serial port and the memory controller for accessing external memory (RAM).
2) U-Boot can transfer the Linux image from external Flash to external RAM and hand over control to the kernel entry point in RAM. The compressed Linux image saves flash space at the cost of decompression time during boot.
3) Linux boots and installs a RAM-based filesystem (initramfs) as the root filesystem. During project build, Initramfs is populated with the required files and directories, and then simply linked to the kernel.
4) Under the Linux kernel, /sbin/init is executed. The /sbin/init program initializes the system according to the configuration files described in /etc/inittab.
5) Once the initialization process has completed running the runlevel execution and commands in /sbin/init, it starts a login process.
6) The execution of the shell initialization file /etc/profile marks the completion of the boot process.
Enabling Execute In Place (XIP) can significantly shorten boot time and improve overall performance; XIP is a method of executing code from flash. Typically, Linux code is loaded from flash into external memory and then executed from there. By executing from flash, this step of copying is eliminated, requiring less memory, and the read-only memory no longer occupies program space.
If you want to master more embedded Linux knowledge, you might want to check out this course—”Introduction to Embedded Linux Basics.”
Scan the QR code below
Limited-time free access👇
Course Introduction
The ultimate goal is to serve projects and practical applications. The course extracts essential knowledge points, allowing students to have a clear understanding of embedded Linux after completion, enabling them to proficiently operate the software, commands, and techniques needed in Linux, making it easy to get started.
Course Features
1. In-depth and easy-to-understand explanation of related basic concepts in the embedded industry
2. Hands-on teaching of Linux operations
3. Comprehensive coverage of basic and advanced knowledge, allowing for more systematic learning
Instructor Introduction – Sun Guorui
Instructor of embedded training at Jicheng Training Network, embedded engineer.
With years of front-line embedded development teaching experience, he has in-depth research on C/C++ related languages, embedded Linux application layer development, Linux driver layer development, the three major components of Linux system porting, GUI development, and the Harmony LiteOS-A kernel framework. Currently, he is committed to integrating embedded systems with industry and developing the Industrial Internet of Things to align with Industry 4.0. His current leading projects include industrial vision development projects, industrial gateway development projects, servo motor driver projects, and more.
Target Audience
1. Graduates from related majors such as Electrical Engineering, Machine Automation, Applied Electronics Technology, Communication Engineering, Electronic Information Engineering, Computer Applications, Internet of Things Engineering, Automation Technology, Software Engineering, Intelligent Science and Technology, Optoelectronic Information Science and Engineering, Electronic Science and Technology, Computer Science and Technology, Software Engineering, and Intelligent Science and Technology.
2. Proficient in using computers
3. Engineers with experience in software testing, software maintenance, and preparing to transition to embedded software development
4. Engineers with a certain foundation in C/C++ language, preparing to engage in embedded Linux application development
5. Engineers with a certain foundation in embedded development, aspiring to develop towards ARM high-performance processors and embedded Linux operating systems.
Course Outline
Scan the QR code below to learn more about embedded Linux knowledge together!
Scan the QR code below
Limited-time free access👇