############ Review embedded Linux application ############
Embedded Linux applications:
I. Embedded summary, basic concepts:
1. GPL: The same as GPL for the database connected to it;
Lgpl: lgpl is required only when it is modified;
In general, GPL is more rigorous in protecting free software.
2. ARM Linux: refers to the Linux port version running on the ARM platform with MMU;
UClinux: A brand new Linux, instead of a Linux transplant version. Without MMU, uClinux does not protect the memory space. Multiple processes share one runtime space;
RT-Linux/rtal: supports hard real-time Linux releases. The basic idea is to use kernel as a real-time task with the lowest priority.
3. patch files:
Naming rules: patch-x.y.z-rmkn.gz -- x. y. Z is the Linux kernel version number, n is the patch version number;
Pre-patch-x.y.z-rmkn.gz -- Alpha or beta, usually unstable;
Diff-2.4.18-rmk7-pxa3.gz -- A look at the name of diff will know, is to patch the kernel and then patch, note, must first patch and then diff.
4. Hierarchical Operating System Model:
/*************************************** *****/
User Program and application Libraries
^
|
C libary
^
|
Kernel
/*************************************** *****/
5 GNU = GNU's not UNIX, which implements a new operating system.
Ii. Embedded Linux development tools:
1. GCC -- GNU Compiler collective. Compilation parameters:
-C: generate the. o file;
-D: add the macro name;
-E: only run the C pre-compiler CPP.
-I: the path of the header file that is followed by the header file.
-L: search path based on the function library.
-L: name of the library file to be connected during connection.
-O (n): optimization level;
-Mm: dependency of the output source file;
-FPIC: generates location-independent code, which is generally used when a shared library is generated.
-Shared: generates execution files that support dynamic shared libraries;
-Static: dynamically shared libraries are not supported. The library content is statically connected to the execution file (the executable file will be large ).
2. binutils-a set of binary tools to assist GCC.
AR: Create an archive file. E. g: used for static databases.
As: GNU assembler. It is mainly used to compile the assembly code generated by GCC-s, and then generate a binary code, which is stored in the object file.
Ld: connector, the last step of compilation. It is mainly to connect the target file and the archive file, then relocate the data, and connect to the reference to form an executable file.
NM: list the symbols of the target file.
Objcopy: copy the content of the target file to another target file and change the file type;
E. g: objcopy A. Out-O binary A. Bin
File a. Out -- elf, not stripped. Running on PC requires support from the operating system.
File a. Bin -- data. You can run it naked on the board.
Objdump-Assembler's favorites: display one or complex object file. You can use options to control the display information. E. g: objdump-s. out> a.txt: Read the assembly code of the ELF File. However,. out is already a LD file, so there may be a lot of assembly code, so I generally do this:
Gcc-c a. C
Objdump-s a. O> a.txt
Readelf: displays information about executable files, such as head information.
Strip: slimming command;
3. Cross-compiler -- Cross-Compiler
Arm-Linux-GCC: compiles elf files that can be run in Linux systems on arm;
Arm-elf-GCC: Compile the flat ELF File running on uClinux without MMU;
Tar xzvf arm-linux-gcc-2.95.3.tar.gz-C dir
Rpm-IVH... rpm
Uninstall: rpm-e arm-Linux-gcc
The installation directory is usually under/usr/local/bin or/usr/local/ARM-Linux/bin.
Check the installation status: Which arm-Linux-gcc
E. g:
Arm-elf-gcc-elf2flt main. C-o helloworld/* generate the flat elf Executable File */
ARMM-Linux-GCC main. C-o helloworld
Iii. startup code-bootloader
1. The first software program executed after the hardware is started is fixed in the ROM and powered on.
2. What is bootloader do?
1) initialize SDRAM, establish a stack environment, and prepare for the entry to C-language code.
2) initialize UART to establish communication between the target board and the debugging host.
3) implement a command interpreter based on serial port input and provide some basic user commands.
In fact, there are still many tasks for Bootloader initialization, but I think these three tasks are quite important.
Here, combined with the lumit4510 code, I provide a simplified bootloader (L-boot ),
Only startup. s and Main. C Programs are included. One is assembly code and the other is the C language entry.
We can intuitively see the necessary initialization steps before the system runs into the C language.
Resetentry
|
+++ Sys_rst_handler
|
+++ Initsystem
|
+++ Initmemory
|
++
|
++ Copy Rom to ram
|
++ Set up SVC Stack
|
+++ Remap memory
|
++ Goto main (in Main. c)
/* Initialize the hardware.
Load, execute, and Debug Programs and operating system kernels. */
3. Two Phases and main functions:
The first stage: code written by sink, dependent on the CPU architecture.
Initialize hardware;
Set the ram space and create a stack environment;
Copy stage2 to the ram space;
Jump to the C entry of stage2;
Stage 2: written in C, which can implement some complex functions and provide better code readability and portability.
1) initialize common hardware devices in this phase.
2) memory ing-MMAP;
3) read the kernel image file and the root file system image from flash to the ram space;
4) set startup parameters for the kernel;
5) Call the kernel;
Bootloader stops working and exits from the stage of history. Later, it will be the world of Kerner.
4. Why should we use the main function as the entry, because so many things will be done before calling Main:
1) Copies Ro and RW execution regions from their load addresses to their execution addresses.
2) zeroes BSS regions.
3) set up stack and heap.
4) initialize referenced library functions.
5) set up argc and agrv for main ().
6) callmain ()
4. Kernel configuration, compilation, cutting, and Transplantation
1. Directory is the directory where the kernel source file is located
Patch-P1-d directory <... patch
Or
Cat ../.. patch | patch-P1-d directory
2. Configure the Kerner:
Make menuconfig
Config. In -- add options in menu;
. Config -- after the menu is configured, save the configuration result here;
Autoconf. h -- finally, it is the only thing that is actually compiled.
3. What are the differences between uClinux kernel compilation and Linux kernel compilation:
1) make lib_only
2) Make user_only
3) make romfs. img
4. ELF file:
1) A common file format used by Linux system, supporting dynamic connection.
The file starts with header information, which describes information about each section. Including the connection address and execution address.
There are three types:
. O target file;
. So shared file;
. Elf executable file.
2) the executable segment of an elf file generally includes three sections:
. Text -- read-only code area;
. Data -- Data zone that can be read and written;
. BSS-in the memory space, the. Data section is adjacent to the non-initialized data zone that can be read and written;
Flat format:
Elf header information is simplified and generally used in uClinux.
Arm-Linux-gcc-elf2flt hello. c
Bin format:
A binary file that does not contain address location information;
Conclusion: Elf and flat are all elf and must be run on the operating system. Flat can be used on uClinux because uClinux does not have MMU.
5. uClinux:
1) kernel loading method:
It can be executed on flash, or decompress the kernel in ram, and supports location-independent code;
2) romfs as its root file system:
The code size is reduced.
Dynamic Block erasure is not supported. If the system needs to dynamically store the data, use Ram-disk + ext2 as the file system.
3) Elf files in flat format are used to save more space.
4) glibc and application libraries are simplified. Static connection is used for user programs, and the code can be solidified.
6. Description of the files under images/In the uClinux source code directory:
1) romfs. IMG -- is a romfs directory generated through tools/romfs-inst.sh and the files under it, and then packaged into a file romfs. IMG.
It can be stored in flash or SDRAM, but the address must be specified in Driver/block/blkmem. C during kernel compilation so that the kernel can find it.
2).txt .txt: The. Text Segment of the compiled kernel, which is generally stored in flash and read-only.
Linux. Data: The. Data segment in the kernel after compilation, generally in the SDRAM space, reads and writes.
3) image. Bin: the preceding three files are connected sequentially to generate =.txt .txt + linux. Data + romfs. IMG.
7. uClinux's image. Rom is a compressed kernel, which can be directly burned to flash. = Zimage generated by Linux.
Image. Ram -- extract image. Rom to the elf Linux kernel running in SDRAM.
Image. Rom = gunzip program + gzipped (image. Ram)
8. Two kernel images generated after ARM Linux compilation.
Vmlinux; no compressed original Linux kernel image; ELF format; PC;
Zimage; Compressed Linux kernel image; bin format; streaking;
5. root file system-rootfs
1. romfs File System:
1) space saving compared with ext2:
Fewer code is required for kernel to support romfs;
Romfs requires less space to create a file system superblock.
2) romfs is a read-only file system, so the system also needs a virtual disk (ramdisk) to support the storage of temporary files and data files.
Ram must use the ext2 file system.
2. jffs2 file system and yaffs File System:
1) jffs2:
It is mainly designed for norflash.
-- (Jounaling flash filesystem 2) log file system.
2) yaffs (yet another flash filesystem)
It is mainly designed for nandflash.
Suitable for large-capacity storage.
They are all file systems designed for embedded storage devices:
It supports loss balancing. When a small amount of data is modified, it is only appended, rather than overwriting the entire sector.
Provides better crash/power loss security protection.
3. NFS file system:
/Etc/init. d/nfs START | restart
Modprobe NFS //?????????
Mount-t nfs 192.168.0.33:/usr/src // mnt
4. initrd-specifies the smallest File System in Ram after romfs is cropped.
Production:
1) dd If =/dev/Zero of = initrd. img bs = 1024 COUNT = 500/* dd copies a file with a specified size block */
2) mke2fs-M0-F initrd. img/* format with ext2 */
3) mkdir Rom Ram
4) Mount initrd. img ram/-o loop
5) Mount romfs. img rom/-o loop
6) mkdir RAM/bin RAM/sbin RAM/dev RAM/etc RAM/var RAM/lib RAM/probe RAM/usr RAM/tmp
7) CP-a ROM/etc/* RAM/etc/
8) CP-a ROM/bin/* RAM/bin/
9) CP-a ROM/bin/init RAM/bin/init
10) mknod RAM/dev/ttys0 C 4 64/* serial device */
11) mknod RAM/dev/console C 5 1
12) umount Ram
Umount Rom
Busybox-Swiss Army Knife;
After creating a RAM disk, you can use ftp to download initrd. IMG to the Development Board. With the kernel, and now the file system, we have completed a uCLinux operating system. Haha.
5. kernel startup parameters:
Purpose: you do not need to re-compile the kernel and change the kernel behavior at startup.
For specific parameters, see: Documentation/kernel-parametes.txt
Common examples:
1) root =/dev/ram0 RW/* root = root file system device, RW-read/write mode to load root file system */
Init =/linuxrc/* the kernel will run at the end of initialization. The default value is/sbin/init */
Console = ttys0, 115200n8 console = tty0/* start information console */
Ramdisk_size = 8192
Cachepolicy = writethrough
2)
Root =/dev/nfs IP = BOOTP console = ttys0, 115200n8
6. Application Development-Applications
1. Arm-elf-GCC main. C-elf2flt
Arm-Linux-GCC main. c
2. Make-C subdir/* pass the make command to the respective subdir and execute their makefile */