Share this

Detailed Explanation of Basic Knowledge Points in Embedded Linux C

2026-04-06 05:42:26 · · #1

Embedded systems is a comprehensive discipline that integrates computer hardware technology, computer software technology, and electronic circuit technology. It covers a wide range of topics and knowledge, including: digital circuits, analog circuits, computer organization principles, microcontroller fundamentals, C language fundamentals, operating systems, data structures, compiler principles, computer control, and computer networks.

Before truly learning embedded development, it's essential to build a solid foundation. The most important courses are C programming fundamentals, digital circuits, and computer organization. Below, we'll discuss the basic knowledge points of embedded Linux C.

I. Basic Development Environment

C language development environment under Linux

Tools used: GCC (program generation tool), GDB (program debugging tool), and make and Makefile (project management tools). Development process: C source files are written using an editor, then compiled to generate a binary executable program primarily composed of machine code. Compilation process: The C code is compiled, assembled, and linked to finally generate an executable program. The executable program consists of two parts: a program header and a program body.

Embedded C language development environment

The generation of a program typically uses compilation tools from x86 to the target machine. The program development tool is an executable program that runs on the x86 machine, while the target generated by the development tool is an image file or executable program with the target machine code as its entity. This process is called "cross compilation".

Compared to developing in a regular Linux environment, there are a few more points that need to be mastered:

*Library functions and system calls*Advanced C language applications*Special C language syntax in embedded systems (endianness, memory alignment, etc.)*Resource performance considerations (running efficiency and storage space)

II. Basic Development Tools

Linux Text Editing Tool VI

The main focus is on mastering the switching between VI's three modes: command mode, text input mode, and last-line mode, as well as the various commands and operations of the VI editor. Learn how to use VIM, edit the vimrc file, and modify features (such as displaying line numbers, highlighting colors, etc.) using gedit~ . /vimrc.

GCC Program Development Tools

GCC can convert source files from C, C++, Objective-C, etc., into target code that runs on specific CPU hardware. For general-purpose computers, GCC is generally used to generate x86 executable code; for embedded development systems, a cross-compilation version of GCC is used to generate programs that can run on the target machine.

The process of generating an application using GCC/G++ can be divided into the following four steps: (1) Preprocessing: generating .i files (preprocessor cpp) (2) Compilation: converting the preprocessed files into assembly language and generating .s files (compiler gcc) (3) Assembly: generating target code, i.e. machine code, from the assembly code and generating .o files (assembler as) (4) Linking: generating an executable program from the target code of each file (linker ld). Another point of knowledge involved here is the generation of static link libraries and dynamic link libraries.

Make project management tool

A Makefile is a text file that determines how a project should be compiled, and it follows certain writing rules. When a project is updated, the GNU make tool is used to selectively compile the project based on the current Makefile.

Tools that automatically generate Makefiles include autoconf and automake. Other similar tools include cMake.

GDB debugging tool

Before using GDB, you need to add the -g compilation option to the source program. The compiled program will contain the information that needs to be debugged, which can then be used for debugging with GDB. The main commands used are run (start running the program), break (set a breakpoint), next (execute a line without entering a function), step (enter a function), and continue (continue running the program).

Debugging is divided into local GDB debugging and remote GDB debugging. Remote GDB is more suitable for debugging embedded systems, using a GDB server on the target machine and a GDB debugger on the host machine to complete the debugging work.

III. Basic Learning Functions

C language standard library functions

(1) Standard input/output functions: scanf, printf, put, charget, char, putc, getc, putsung, etc. (2) Character processing and conversion functions: isdigit, isalpha, sprint, strn, cat, stnc, pystr, lenstr, chrstr, strstr, rev, memset, memmov, ememcpy, memcpy, etc. (3) Mathematical calculation functions: divacos/asin, pow, exp, log, ceilabs, floor, fmod, etc. (4) Data structure and algorithm functions: bsearch, lfind, lsearch, qsort, rand, srand, etc. (5) File I/O operation functions: fopen, fclose, fget, cfputs, fseek, fwrite, fush, etc. (6) Time and date functions: clocktime, gmttime, mktime, asctime, etc. (7) Error handling and utility functions: clearer, feof, perrorer, rno, assert, set, jmp, long, jmp, etc.

C language extension library functions in LinuxC

(1) File I/O operation functions: open, close, read, write, lseek, oct, lfcnt, lm, map, dup, create, etc. (2) File permission related functions: access, chownch, modu, time, umask, link, stat, unlink, etc. (3) User operation functions: getgid/setgid, getegid/setegid, geteuid/seteuid, etc. (4) Signal and process functions: kill, raise, alarm, signal, getpid, forks, sleep, execute, _exit, etc.

IV. Advanced C Programming

The memory used during C language execution is generally divided into two types: static storage area and dynamic storage area.

Static storage area

In C programs, static data storage is divided into three categories: Read-Only Memory (RO), Initialized Read-Write Data Area (RWData), and Uninitialized Read-Write Data Area (BSS). RWData is allocated during the program's initialization phase and remains unchanged during runtime (its size and location are fixed). It is reclaimed by the system when the program exits.

Dynamic storage area

Dynamic memory is divided into two categories: heap and stack. It is dynamically allocated during program execution (its location and size change dynamically). Common dynamic memory management methods involve allocating stack memory from high to low memory addresses, and heap memory from low to high memory addresses. Generally, the heap is implemented using a linked list, while the stack uses linear storage. In C programs, stack space is managed by the compiler. Examples of stack space usage include parameter passing, return value usage, and automatic variable space. Generally, stack space grows from high to low memory addresses.

The order in which parameters are pushed onto the stack is: later parameters are at higher memory addresses, and earlier parameters are at lower memory addresses.

Automatic variables reside in the stack space. Earlier variables are placed at higher addresses on the stack, and later automatic variables are placed at lower addresses.

The contents of the function stack are released when the function exits. Therefore, the address of an automatic variable cannot be used as a function return value.

In C, heap memory allocation and deallocation are accomplished through library functions: malloc, calloc, realloc, and free. These four functions handle heap memory allocation, deallocation, and management. Remember to manually free allocated memory; otherwise, the resources will not be reclaimed by the system, leading to memory leaks. Also, after a pointer is freed, it should be set to NULL to avoid dangling pointers. In summary, stack memory is allocated and deallocated by the compiler, while heap memory is allocated and deallocated by the program.

Use of function pointers

A function pointer is a pointer to a function (essentially an address of a code segment), and the function itself represents an algorithm. In this case, the C language algorithm can be used like a regular variable through the pointer. A function pointer can be a member of a structure, passed as an argument to other functions, and also used as a function's return value.

Read next

CATDOLL 139CM Luisa Silicone Doll

Height: 139 Silicone Weight: 25kg Shoulder Width: 33cm Bust/Waist/Hip: 61/56/69cm Oral Depth: N/A Vaginal Depth: 3-15cm...

Articles 2026-02-22