Yihui brothers learn to embed Linux notes and experience
For everyone to learn, I put this article from the foundation version. The things inside are full, you can try it! The following is the notes and experience I first study embedded Linux, making the floppy disk Minicom application, and the floppy disk Linux is also clear, and the busybox actually creates the Linux system on the floppy disk. I hope to help some help and inspire for novices, and also ask the masters to criticize. Yihui, Eazi@163.com February 12, 2004 A typical desktop Linux system consists of three main software layers --- Linux kernel, C library, and application code. The kernel is the only layer that can fully control the hardware, the kernel driver represents a session between the application and the hardware. The kernel is the C library, which is responsible for converting the POSIX API to the kernel to identify the form, then call the kernel, pass the parameters from the application to the kernel. The application relies on the drive kernel to complete specific tasks. When designing embedded applications, you may not follow this level, the application crosses the C library directly and the kernel session, or bundles the application and core, and even write the application as a thread of the kernel, run in the kernel, Although this has brought difficulties in transplantation, it is completely feasible to consider the characteristics of the embedded system to be small in size. However, we use the three-story software structure to learn embedded Linux will be clearer, simple and feasible and make the application flexible. Quick Start, the simplest way to build embedded Linux applications are from our desktop Linux, install a favorite version, and put our application as part of the initialization, the framework is completed. Of course, embedded Linux applications are simpler than our desktop version, which may be a terminal that is used for footprints, or a digital audio player that only needs a serial port in addition to using embedded CPUs. A small amount of input output interface such as the network port can complete their specific application. On the software, it can consist of a two-layer concept consisting of a kernel loader, a custom kernel, and a small-specific application for a particular task design. The use of static connection applications is because the storage space you want a small amount of static connection program is smaller than the same number of dynamic connections, this balance requires us to get in actual development. Maybe you are designing a PDA, which is more applications, then you are likely to use a dynamic connection program to reduce storage space. In your / bin or / sbin directory, use the factory list to see Bash, IFConfig, Vi ..., maybe just dozens of K, when you run LDD / Bash, you will see them and several Library files are connected. Ok, this seems that we have to imagine the PC into an embedded hardware platform, re-create an embedded Linux of a specific function. Before making practical operations, first figure a few basic knowledge. The kernel loader loader, its role is to move the kernel from the external memory to the memory. It only makes this matter, once completed the job that is transferred to the kernel, the Loader jumps to the kernel position to start execution. Different architectures have different Loaders, on the X86 structure's PC, usually used LILO, GRUB, SYSLINUX, SYSLINUX works in embedded Linux. Other non-x86 architectural applications, you must use a special Loader, or write loader yourself to load the kernel. There are also situations that do not use Loader. After the system is powered up, the kernel is directly executed directly from the Flash of the burning map. The kernel, once the kernel starts, it will initialize all hardware by the driver, which can be seen from the output of our PC monitor, and each driver prints some information about it.
After the initialization is completed, the computer is ready to run embedded applications. Perhaps one, perhaps multiple applications constitute an embedded application, but usually call INIT (incoming init = / program to the core through Loader). In the desktop Linux, init will read the / etc / inittab file to determine the execution level and which scripts and commands. In embedded applications, you can decide whether to use standard Init execution according to the actual situation, perhaps this init is a static program, which can complete our embedded application specific task, which is completely not considering inittab. Initrd file system, INITRD is loaded into a small file system in a minimal mechanism that is loaded from the storage medium into memory. This file system is preferably stored on the medium in a compressed manner, unzipped to the RAM disk. By using initrd, the small file system containing core drivers and startup scripts can be started directly from the media and the kernel, the kernel session is compressed, and the script file called / LinuxRC on this file system, this script The driver required during the startup process is usually loaded. After the script exits, the Initrd file system is also removed, the startup process enters the real initialization process. For embedded, you can run the required application software on this initrd file system, as long as the / linxrc file is not over, the other parts of the kernel start process will not continue. Make a test: cp /boot/initrd-2.4.20.img / tmpcd / tmpmv initrd-2.4.2-.img initrd.img.gzgunzip init.img.gzmount -o loop init.img / mntcd / mntls cat Linuxrc Seeing the operation in which two modules is loaded, you will see the screen print information when you start Linxu. Getting started test, making a simple application: We use a floppy disk to start a serial port, keyboard input, display output X86 architecture Linux system, the specific application execute is running minicom, dialing through serial port. Need software: minicom-xx.src.tar.gz and syslinux-xx.tar.gz, XX representative version number, before starting, set a directory in the primary directory, to release these two packages: CD MKDIR -P Project / Minilinuxcd Project / MiniLinuxTar ZXVF Minicom-xx.src.tar.gztar ZXVF Syslinux-xx.tar.gz1, Restoring Linux kernel (requires a system Installing the kernel file package) When we need to select these: touch blocks into the kernel, 386 processor, physical memory OFF, support ELF, standard PC floppy disk, support RAM disk (4096), support INITIAL RAM Disk (Initrd), vain, virtual terminal console, standard serial port, EXT2 file system, console driver, VGA Text Console, DOS FAT, MSDOS file system, other can not, so the kernel is smaller. Steps: CD / USR / SRC / LinuxMake MrPropermake Xconfigmake DEP && Make Bzimage Gets the kernel file BZIAMGE for / usr / src / linux / arch / i386 / boot / directory.
2. Compile a static minicom to modify it as a future LinuxRCCD Minicom-XX / srcvi makefile, this line is MINICOM: $ (minicom_objects) $ (minicom_dependencies) RM-F Minicom below the row below, connected to static programs (Link) -static $ (minicom_ldflags) $ (minicom_ldadd) $ (limited) vi minicom.c Find if (Real_UID == 0 && DOSETUP == 0) Delete this judgment condition statement, mainly for permission judgment Because this embedding application does not pay attention to the permissions, it will be wrong. Make gets an executable, check with LDD is not a static program.