Embedded Linux System Miniaturization Technology

I. Overview

Embedded Linux generally refers to a dedicated Linux operating system that is suitable for specific embedded applications after miniaturization and clipping of standard Linux distributions. Embedded systems are usually resource-constrained systems, which are "small" in terms of processor computing power or RAM or other memory capacity. Therefore, how to create a miniaturized Linux as an operating system development becomes the first question to be considered. Three-layer structure is commonly used in embedded Linux systems: the core layer is mainly the Linux kernel and modules; the call interface layer is a system library based on the glibc library; and the application layer is an application program designed according to user requirements. In order to achieve high utilization of resources, the last two layers are in the form of ELF files, and external function codes are dynamically loaded during operation.

In general, establishing a cross-platform development environment is the first step in the development of embedded software. The heterogeneous nature of the hardware platform between the host and the target (processor architecture) is the root cause of cross-development. In addition, due to limited resources, it is inconvenient or even impossible to develop software directly on the hardware platform of the embedded system. Therefore, the Host/Target development mode is usually used, as shown in Table 1.

Host (Host)

Target (Target)


PC or workstation where x86 CPU dominates

Embedded system hardware, processor diversity (x86, ARM, PowerPC, MIPS, 68K, etc.)


Windows, Linux and other desktop operating systems, rich integrated development environment (such as TorRiver's Tornado)

Limited software resources, usually downloaded from the host during development

Table 1 Characteristics of Cross-platform Development Environment

Cross-platform development environments include cross compilers, cross debuggers, and system simulators, such as the GNU toolchain often used for embedded Linux development. The developer needs to select the appropriate GNU cross compiler based on the target platform, and then recompile the kernel and other software on the host machine so that the target code obtained can get the target machine running. This process is quite tedious and error-prone. Host and target computers are generally connected via Ethernet or serial ports. At present, hundreds of embedded Linux development plans and distributions have appeared in the world, such as ETLinux, LPR, μC-Linux, ThinLinux and other development source code projects, as shown in Table 2.




Designed to run on small industrial computers, especially foot PC/104 modules




LPR's goal is to use networked devices such as routers, access servers, thin servers, and embedded systems, which can be installed on a floppy disk. Similar items are Linux On A Floppy (LOAF)

μ C-Linux

Linux running on system L without MMU. Supports Motorola DragonBall (M68EZ328), M68328, M68EN322, ColdFire, QUICC, ARM7TDMI, MC68EN302, Axis ETRAX, Intei i960, PRISMA, Atari 68k, etc.


A Linux distribution for embedded and specific applications running on Intel and PC compatible hardware

Table 2 Several Open Source Embedded Linux Distributions

In addition, there are distributions for commercial companies such as Coventive XLinux, LineoEmbedix, LynuxWorks BlueCat, and MontaVista Linux. At the same time, RT-Linux, RTAI, and other real-time extensions are available for real-time environments. In recent years, more and more target systems have selected x86 processors and mature PC architectures as cost performance hardware platforms. According to a survey conducted by LinuxDevices.com, the percentage of embedded system developers who chose x86 processors as target platforms in the past two years and the next two years was 31% and 35% respectively, ranking first.

For developers of both host and target PC compatible platforms, in addition to the above models, there is a simpler way to create a miniaturized Linux system: based on a regular Linux distribution, compile the kernel, copy The required files and the initial file system (initrd: INITial Ram Disk) mechanism to create the root file system can quickly implement a miniaturized Linux system.

Second, miniaturization technology

Linux has become more and more widely used in various embedded devices. However, general Linux distributions are very large and difficult to use for embedded devices with limited storage space. So we must cut the Linux system. Linux systems generally have the following four main cutting technologies. Using these technologies can effectively reduce the size of the system without affecting the performance of the system.

1 Delete redundant files. The general Linux distribution contains many help files, auxiliary programs, configuration files, and data templates. These files are unnecessary in the embedded system and can be deleted completely. Even a large number of comments in the configuration file can be removed.

2 Shared library clipping. The application of the embedded system is limited, there may be many redundant codes that can never be used in the shared library, and these codes can be deleted.

3 Use an alternative software package that has the same functionality. There are many software packages with similar functions on Linux. You can choose packages that occupy less storage space and migrate them to embedded devices to replace those that originally occupied larger space.

4 modify the source code. Including reconfigure, compile the software package, remove the unnecessary function; Increase the modularity of the software, thus help to improve cutting efficiency; Reconfigure the kernel, remove unnecessary driver and module.

1, streamlining the kernel

Different from the microkernel architecture of the traditional embedded operating system, the Linux kernel uses a monolithic structure. The entire kernel is a single, very large program. Its advantage is that it can directly communicate with each part of the system, effectively shorten the switching time between tasks and improve the system response speed. The shortcomings are also obvious, that is, the kernel size is relatively large, because the Linux kernel not only includes basic operating system functions such as task scheduling, memory management, and interrupt handling, but also includes functions such as file system, network protocol, and missing driver.

The Linux kernel is highly modular, configurable, and configures the kernel to have different functions to reduce the size of the kernel. For example, Linux supports a wide variety of file systems, including ext2, ext3, FAT, Reiserfs, JFS, and others. The desired file system can be selected according to the actual situation, such as just compiling the ext2 file system into the kernel. The main steps to compile the kernel are as follows ("#" stands for command prompt):

# cd/usr/src/1inux-2.4

# make menuconfig

# make dep;make clean;make bzlmage

The compiled kernel file is arch/i386/boot/bzlmage. The specific method refers to the README file in the kernel source code package. In order to further increase flexibility and reduce the size of the kernel, Linux also provides a loadable kernel module mechanism. Many functions in the kernel can be compiled into modules that are dynamically loaded during kernel runtime instead of being compiled directly into the kernel. However, embedded Linux systems tend to compile a separate kernel as needed, and use less of a module mechanism. The resulting kernel is usually in the order of a few hundred kB or even 1 MB, which is relatively large compared to traditional embedded operating system kernels (for example, the VxWorks kernel containing file system and network support is about 250 kB). In the kernel configuration, the developer needs to understand the dependencies between the various functional modules, otherwise it may cause the compilation to fail. In the VxWorks kernel configuration process, if the dependency is broken, there is a clear indication to avoid this error.

2, shared library cutting

In the miniaturization technology, the shared library cropping is easy to implement with software, and an automatic cutting tool is made. The effect is most obvious. The following focuses on the technology of miniaturization of shared libraries. The basic idea of ​​the miniaturization of shared libraries is to extract and analyze the dependencies of object files and symbols in the system libraries, and to perform relational calculations on these dependency-construction relation models, based on the symbol information in the application program. , Minimize the system library at the level of the library object file. The implementation is divided into four steps: a. Determine the set of to-be-adjusted functions. Inside the ELF file, there is a symbol table of the Elf32-Sym array structure, which is used for internal symbol definition and external symbol reference. By analyzing this symbol table, the to-be-adjusted symbols (system functions) in the ELF application program can be extracted. Create a many-to-many relationship for the application-pending function symbol. b. Determine the correspondence between system library functions and target files. The system library is logically divided into three levels: library, object file, and symbol. The library and object files are in ELF format. The library is obtained by analyzing the library image file *_pic.a and the symbol table in each object file. The definition of the target file relationship, the target file - symbol definition relationship and the target file - symbol call relationship. c. Determine the interdependencies between system library object files. The complete dependency of the target file-object file is obtained by calculating the relationship between the related relations in step b. d. Generate a miniaturized system library. By calculating the relationship between the application program-to-be-tuned symbol table and the target file-object file dependent table, a set of target files on which the function to be tuned depends can be obtained, and they can be re-linked to obtain a minimized library file.

2.1 Principle of Shared Library Cutting Technology

The shared library stores pre-compiled object code, which is commonly used by applications repeatedly. In Linux systems, applications and libraries can be statically linked or dynamically linked. When statically linked, the linker picks the code needed by the application from the library and then copies it into the generated executable file. Obviously, when a static library is used by multiple programs, there are multiple redundant copies on disk and in memory. When linking dynamically, the linker does not actually copy the library code into an executable file; the loader only checks if the library has been loaded into memory by another executable file if the executable file is running, if the memory does not exist Only load the library from disk. This allows multiple applications to share the same copy of the code in the library, saving storage space. This is the main reason why embedded Linux systems use shared libraries.

When using a statically linked library, the linker automatically links only the modules used in the library to the executable. However, this method is not used in shared libraries, mainly because the linker does not know which parts of the library are used by the application before the application is executed. Therefore, to cut the shared library must first analyze the principle of dynamic linking.

Shared libraries and executables have several symbol tables, which define some external symbols, which are divided into export and import symbols. Export symbol is a symbol defined in the file but can be used by other files. It is generally a function that can be called by other files. Import symbol is a symbol that is used by the file but is not defined. It is generally called by the file. The function, and the import symbol generally indicates the shared library that defines the symbol. Before the loader loads an executable file or a shared library, it first traverses each of its import symbols to check whether the symbol's associated code is already in memory. Otherwise, the loader first searches for and loads the shared library that defines the symbol. Since the applications and shared libraries in the embedded Linux system are generally determined, there may be export symbols in the shared library that are never called by other files, and the corresponding code of these symbols will not be deleted from the shared library. Affects the normal operation of the system.

The existing cutting technology is implemented on the above principle. The following is a detailed analysis of its implementation.

2.2, ELF file symbol extraction

The ELF format was developed and published by UNIX Labs as an application binary interface. ELF is a file format widely used in Linux systems.

2.2.1, ELF file process image loading

The beginning of the ELF file is an ELF header structure, which contains two pointers, which point to two array structures: Program header table and Section header table. The array elements in the Program header table locate the executable code segments inside the file; The array element in the header table holds the relevant relocation and dynamic link information. The loader controls the loading of process images by controlling these two types of arrays.

2.2.2, ELF file symbol table and relocation process

The Section header table of the ELF file has a section of type SHT_DYNSYM, which records all the symbols needed to create the process image.

a. Symbol value determination and symbol positioning. The string (.shstrtab) in the ELF file is used to save all the strings. The ELF header stores the section index of the section header string table (.shstrtab) through the e-_shstrndx field. The symbol name field value in the ELF file is a character index of the .shstrtab section: The St_name in the Syrnbol structure corresponds to the corresponding string table. An index corresponds to its symbol value in the corresponding string table. The St_value corresponds to two different addresses: Internally defined symbol, internal relative address of the file corresponding to the content of the symbol; for externally invoked symbols, corresponding to the address of the to-be-adjusted symbol (analyzed) or an entry in the relocation table (unresolved). St_info holds the type of symbol and the corresponding attribute.

b. Repositioned by the sign. In the symbol table, the STT-SEC-TION corresponds to the relocation entry information table. The relocation entry exists in an ELF file as an array, where R_offset holds the address applied to the relocation action, and R_addend corresponds to an offset used to calculate the value to be stored in the relocation field. The index of the symbol affected by the relocation and the type of relocation application are given in R_info. For example: When the type is R_386_JMP_SLOT, the symbol value corresponds to the position of a .plt (process connection table) entry.

c, external symbol loading. For the loading of external symbol code, the loader loads the external symbol code into the process image by means of lazy MODE loading: The first call to the external symbol is via the load code in PLT[0] and the push parameters in PLT[1]. The code is loaded into the .got table; later calls to this to-be-adjusted symbol are transferred through the corresponding .got table entry.

2.2.3, ELF file symbol extraction

For each shared target file that participates in dynamic linking, its Program header table has an entry element of type PT_DYNAMIC. The section.dynamic section pointed to by the entry is an array of Elf32_Dyn structures. The Elf32_Dyn structure has an attribute flag d_tag ​​and a union structure d_un. The d_tag ​​controls the interpretation in d_un. The entry in the array subscripted DT_SYMTAB points to the symbol table. By analyzing the related control structures of the symbol table, relocation table, process connection table and global process table, the separation of the file definition symbol and the to-be-adjusted symbol is completed. The algorithm is as follows:

Symtab=.dynamic[DT_SYMTAB]->d_un. d->ptr

找到 Find the address of the symbol table based on DT_SYMTAB

For(int i=0;symtab[i]!=NULL;i++)

∥ scan all entries in the symbol table

{swith((symtab[i] ->st_info)>>4) Operate according to symbol type



Case STB_GLOBOL:/* for global and weak symbols can be used for external file calls */

If (corresponding to the entrance to the process connection table entry) / * if it points to the address. The plt entry needs to be relocated when creating the process image */

Loadrequest(symtab[i]->st_name);/* Relocate and find the name of the symbol in the character table Relocate(symtab[i]->st_value) Corresponding value, and put its name in the corresponding relation table * /


Loadprovide(symtab[i]->st_name);/* If internally defined, then this symbolic name is for other applications to call */

... }}

The defined symbol and the to-be-adjusted symbol in the ELF file are distinguished by the object whose st_value indicates: the to-be-adjusted symbol corresponding to the .plt table needs to be relocated; corresponds to the internal symbol, if it is weakly typed (WEAK) or global type (GL0BOL) It is used for other file calls. Through the extraction of the to-be-adjusted symbols in the ELF format, the dependencies of applications and symbols are established.

2.3. Miniaturization and Analysis of Embedded Systems

Connect each table to get a set of object files that the application depends on. The target file in the collection is not duplicated and reconnected to get a minimal library. See Table 3 for the comparison of the data before and after the library. After miniaturization, the components in the system library have been significantly reduced, and the library has been reduced by nearly 50%. For an increasingly large number of applications in embedded systems, based on the internal dependencies of the library files, the application program is optimized and reduced based on the library files. For general applications, the system library can be reduced by 40% to 50%.

Before miniaturization

After miniaturization

Target file (s)



Symbols ()



Explicit dependence (Article)



Indirect dependence (Article)



Library size



Table 3 Before and after system library miniaturization

Third, the conclusion

In recent years, embedded Linux technology has developed rapidly. Various commercial and open source Linux distributions provide multiple choices for different hardware platforms and different application environments. Linux's file system is in fact very large. Constructing an embedded Linux file system is a complex process. How to make the file system compact and run more efficiently on the premise of ensuring security is a subject that needs further exploration. In particular, the shared library cropping technique can cut out most of the redundant code in the library, but requires the source code of the library to be relatively standardized, and different architectures require different processing. However, after all, the field of library cropping has only recently developed, and it is still not very mature. After a long period of testing of the technology, I believe we can make up for its deficiencies, making it widely used in the embedded Linux field. Through the above method, we constructed a streamlined embedded version of the Linux file system, which allows the kernel to run with the system as streamlined as possible. And meet the requirements of all aspects of products and systems.

The Neon Led Strip is the latest and most popular LED breakthrough product, it put Led flexible light strip inside the tube,Put the strips into the led tube to make the light soft. widely used in home decoration, shopping malls showcases, shelves and other auxiliary lighting. it  replaces the traditional glass neon tube With the fiber, let the city shine.

Neon LED Strip

Neon LED Strip,Magic Color LED Strip,LED Flexible Tube Lights,LED Neon Rope Light

SHEN ZHEN SEL LIGHTING CO.,LTD , https://www.sel-lighting.com