Follow and star our public account, and access exciting content directly

ID: Technology Makes Dreams Greater
Source: Online Materials
Embedded Linux includes four major components: bootloader, kernel, driver programs, and root filesystem.1. BootloaderIt is a slightly complex bare-metal program. However, understanding and writing this bare-metal program is not easy at all. The useful tools under Windows have weakened our programming abilities. Many people start using ADS or KEIL when they play with embedded systems. Can you answer these questions?Q:When powered on, where does the CPU fetch instructions to execute?A:Generally from Flash memory.Q:But Flash is generally read-only and cannot be directly written; if global variables are used, where are these global variables?A:Global variables should be in memory.Q:So who puts the global variables into memory?A:Friends who have been using ADS or KEIL for a long time, can you answer this? This requires “relocation”. In ADS or KEIL, the relocation code is written by the companies that made these tools. Have you ever read it?Q:Memory is so large, how do I know which address to read the “original content from Flash” into memory?A:This address is determined by the “linker script”; there is a scatter file in ADS, and a similar file in KEIL. But, have you studied it?Q:You said relocation is copying the program from Flash to memory, but can this program read Flash?A:Yes, it must be able to operate Flash. Of course, there’s more than just this; there’s also setting the clock to make the system run faster, etc.Let’s stop here for self-questioning and answering. For the bootloader, there are actually three key points:① Hardware OperationTo operate the hardware, you need to look at the schematic and chip manual. This requires some hardware knowledge; it’s not required to design hardware, but at least you should be able to understand it. You don’t need to understand analog circuits, but you should understand digital circuits. This ability can be learned at school; Microcomputer Principles and Digital Circuits are sufficient. If you want to fast-track, just skip this part; if you don’t understand, GOOGLE it or post a question. Additionally, the chip manual must be read; don’t look for Chinese versions, just read the English ones. It starts off very painful, but later you will find that once you are familiar with the syntax and vocabulary, reading any chip manual becomes easy.② Understanding of ARM Architecture ProcessorsTo understand ARM architecture processors, you can refer to Du Chunlei’s ARM Architecture and Programming, which covers assembly instructions, exception modes, MMU, etc. These three areas need to be understood.③ Basic Concepts of Programs: Relocation, Stack, Code Segment, Data Segment, BSS Segment, etc.The basic concepts of programs; the best way is to read Compiler Principles. Unfortunately, this type of book is absolutely cryptic. Unless you are a super genius, it’s better not to read it. You can read Wei Dongshan’s Embedded Linux Application Development Complete Manual.For the bootloader, you can first read ARM Architecture and Programming, and then write programs to experiment with various hardware, such as GPIO, clock, SDRAM, UART, NAND. Once you understand them, it will be easy to understand u-boot.In summary, understanding hardware schematics and reading chip manuals require you to find the information yourself.2. KernelIf you want to fast-track, skip learning the kernel and directly learn how to write drivers.If you want to become an expert, you must have a deep understanding of the kernel. Note that it is understanding; you should understand the scheduling mechanism, memory management mechanism, file management mechanism, etc.Recommended Books:1. Read Linux Kernel Complete Annotations, please refer to the thinner version.2. Selectively read Linux Kernel Scenario Analysis; read the section you want to understand.3. DriversDrivers consist of two parts: the operation of the hardware itself and the framework of the driver program.Again, hardware; you still need to understand schematics and read chip manuals, practice more.① Operation of the Hardware ItselfRegarding the driver framework, there are some books that introduce it. LDD3, which is Linux Device Drivers, written by foreigners, introduces many concepts and is worth reading. However, its purpose is limited to introducing concepts. Before starting, you can use it to familiarize yourself with the concepts.② Framework of Driver ProgramsThe most comprehensive introduction to drivers should be Song Baohua’s Detailed Explanation of Linux Device Driver Development. If you want to delve into a specific area, Linux Kernel Scenario Analysis is absolutely a five-star recommendation. Don’t expect to finish it; it’s over 1800 pages, in two volumes. When you’re unclear about a certain part, just flip through it. Any part of this book can be elaborated on for 200-300 pages, very detailed. It analyzes the kernel source code with specific goals. It takes Linux 2.4 as an example, but the principles are applicable to other versions of Linux as well.Try writing a driver for all the hardware involved in your development board. If you encounter problems, first “think painfully”; during the thinking process, many unrelated pieces of knowledge will be connected, ultimately leading to understanding.4. Root FilesystemHave you ever thought about these two questions: Q:For products made with Linux, some are used for monitoring, some for mobile phones, and some for tablets. After the kernel starts, which application should be started after mounting the root filesystem?A:The kernel does not know or care which user program should be started. It only starts the init application, which corresponds to /sbin/init.Clearly, this application must read the configuration file and start the user program based on the configuration file (monitoring, manual interface, tablet interface, etc.). This question suggests that the contents of the filesystem have some conventions, such as needing /sbin/init and a configuration file.Q:Have you considered who implemented the printf used in your hello, world program?A:This function is not implemented by you; it is implemented by the library function. At runtime, it needs to find the library.This question suggests that the filesystem must also have libraries.To understand this simply, you can look at busybox’s init.c to see what the init process does.Of course, you can also refer to the chapter on building the root filesystem in Embedded Linux Application Development Complete Manual.
‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧ END ‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧
Scan the WeChat below, add the author’s WeChat to join the technical exchange group, please introduce yourself first.

Recommended Reading:
Embedded Programming Collection
Linux Learning Collection
C/C++ Programming Collection
Qt Advanced Learning Collection
Follow the public account "Technology Makes Dreams Greater" and reply "m" to see more content.
Long press to go to the public account contained in the image to follow.