Wednesday, February 16, 2011

Introduction to finishing linux

 Detailed structure of Linux kernel
[of: Chen Lijun]
Linux kernel consists of five main subsystems: process scheduling, memory management, virtual file systems, network interfaces, inter-process communication.
1. The process of scheduling (SCHED): control process on the CPU access. When you need to select the next process run by the scheduler to select the most worthy of running processes. runnable process is actually waiting for CPU resources, only the process, if a process is waiting for the other resources, the process is not running the process. Linux uses a relatively simple process of priority-based scheduling algorithm to select a new process.
2. memory management (MM) allows multiple processes to share the main memory area safe. Linux memory management support for virtual memory, which is running in the computer program, its code, data, stack, the total amount could exceed the actual memory size, operating system, currently used only to remain in the memory block, while the rest of the block remain in the disk. If necessary, the operating system is responsible for the exchange between the disk and memory blocks. memory management is divided into logical parts and hardware on hardware-independent parts. provides a hardware-independent part of the process of memory mapping and logic on the exchange; hardware-related parts of the memory management hardware, provides a virtual interface.
3. virtual file system (VirtualFileSystem, VFS) hides the details of a variety of hardware for all of the equipment provides a unified interface, VFS provides up to dozens of different file systems. virtual file system can be divided into logical file system and device drivers. logical file system that Linux supported file systems, such as ext2, fat, etc., device drivers, refer to a hardware controller for each The device driver module is written.
4. Network Interface (NET) provides access to various network standards and a variety of network hardware support. network interface can be divided into network protocols and network drivers. network protocol partially responsible for the realization of every possible network transmission protocol. network device driver is responsible for communication with hardware devices, each hardware device may have a corresponding device driver.
5. interprocess communication (IPC) support the process communication mechanism between the various.
in the center of the process of scheduling, all other subsystems are dependent on it, because each subsystem needs to suspend or resume the process. In general, when a process waits for the hardware operation is completed, It is suspended; when the operation actually completed, the process is reinstated. For example, when a process sends a message through the network, the network interface needs to suspend the sending process until the successful completion of the hardware to send the message, when the message is successfully sent out, the network interface to process returns a code to indicate success or failure of the operation. other subsystems rely on a similar process of scheduling reasons.
dependencies between the various subsystems are as follows:
process scheduling and The relationship between memory management: The two subsystems depend on each other. In the multiprogramming environment, the program created to run the process to whom, and create a process first thing is to program and data loaded into memory.
inter-process communication and memory management relations: inter-process communication subsystem to rely on memory management support for shared memory communication mechanism that allows the two processes in addition to its own private space, you can also access the shared memory area.
virtual file system and the relationship between the network interface: network interface using the virtual file system support Network File System (NFS), also used RAMDISK device memory management support.
memory management and the relationship between the virtual file system: memory management virtual file system supports the exchange, the exchange process (swapd) regularly scheduled by the scheduler, which is dependent on the process scheduling memory management, the only reason. When a memory access mapping process is swapped out, the memory management issue to the file system request, at the same time, suspend the currently running process.
addition to these dependencies, the kernel of all the subsystems have to rely on some common resources. These resources include all subsystems are used in the process. For example: allocate and free memory space, process, print a warning or error messages in the process, as well as system debugging routines and so on.

system data structure implementation in the linux kernel, there are some data structure, frequency of use high, they are:
task_struct.
Linux kernel using a data structure (task_struct) represents a process data structure representative of the process formed a task pointer array (Linux, the task and the process is the same term) This pointer array is sometimes referred to as a pointer vector. The size of the array by the NR_TASKS (default is 512), indicating that the Linux system up to the number of processes running simultaneously. When the time to create a new process, Linux for the new process is assigned a task_struct structure, then the pointer stored in the task array. scheduler has to maintain a current pointer, and he points to the current running processes.
Mm_struct
virtual memory each process is represented by a mm_struct structure, the structure actually contains information about the currently executing image and contains a set of pointers pointing to vm_area_struct structure, vm_area_struct structure describes a region of virtual memory.
Inode
Virtual File System (VFS) in the file, directory and so are the corresponding index node (inode) representative. Each VFS inode contents of the file system to provide dedicated routines. VFS inodes exist only in kernel memory, actually stored in the VFS inode cache . If the two processes using the same process of open, you can share inade data structure, this sharing of data through two processes to the same inode block completion.
Linux
the specific structure of the concrete structure is the so-called The structure of a system implementation.
Linux is similar to the abstract structure of the concrete structure, this correspondence is because the abstract structure from the concrete structure, our division is not strictly in accordance with the source code directory structure, and the group is not and subsystems exact match, but it is very close to the source code directory structure.
Although the preceding discussion of the abstract structure shows very little between the various subsystems dependence, but the specific structure of the 5 sub-systems are highly dependencies. we can see that many of the specific structure and dependency structure does not appear in the abstract.
Linux kernel source code
present, relatively new and stable kernel version is 2.0.x and 2.2. x, because of slightly different versions, so if you want a new driver supports both 2.0.x, and supports 2.2.x, need to compile the kernel version of the conditions to achieve this, we must support the macro LINUX_VERSION_CODE, if the kernel version to use abc, said the value of this macro is to use 216a +28 b + c. The value to the specified kernel version, we can use KERNEL_VERSION macro, we can also go to define its own.
kernel changes the way with a patch file released. Patch utility to the kernel source files used to conduct a series of changes. For example: you have the source code of 2.2.9, but want to move to 2.2.10. to get 2.2 .10 patch file, apply patch to modify the 2.2.9 source files. For example:
$ cd / usr / src / linux
$ patch npl Linux kernel source code Structure
Linux kernel source code is in / usr / src / linux directory.
/ include subdirectory contains the code needed to build most of the kernel include files, this module rebuild the kernel to use other modules.
/ init subdirectory contains the kernel initialization code, which is the starting point for the beginning of the kernel work.
/ arch subdirectory contains all the hardware architecture specific kernel code. such as: i386, alpha
/ drivers sub- directory contains the kernel of all the device drivers, such as block devices, and SCSI devices.
/ fs subdirectory contains all the file system code. such as: ext2, vfat, etc..
/ net subdirectory contains kernel networking code.
/ mm subdirectory contains all the memory management code.
/ ipc subdirectory contains the inter-process communication code.
/ kernel subdirectory contains the main kernel code.
Where to start reading the source code?
the Internet, was made the source code navigator, source code available for reading a good condition, the site is lxr.linux.no / source.
given below to read the source Code clue:
system startup and initialization:
Intel-based systems, when loadlin.exe or LILO to load the kernel into memory and pass control to the kernel, the kernel started. See on the part of, arch/i386/kernel/head.S, head.S the specific structure of the set, and then jump to the init / main.c's main () routine.
memory management:
memory management code, mainly in / mm, but the specific structure of the code in arch / * / mm. page fault handling code in / mm / memory.c, the memory mapping and page cache code in / mm / filemap . c. buffer cache in / mm / buffer.c to achieve, and exchange of high-speed cache is in mm / swap_state.c and mm / swapfile.c.
kernel:
kernel, a specific structure code in arch / * / kernel, the scheduler in the kernel / sched.c, fork the code in kernel / fork.c, the kernel routine process in include / linux / interrupt.h, task_struct data structure in inlucde / linux / sched . h in.
PCI:
PCI pseudo driver in drivers / pci / pci.c, which is defined in the inclulde / linux / pci.h. Each structure has specific PCI BIOS code, Intel in in arch/alpha/kernel/bios32.c.
inter-process communication:
all SystemVIPC ipc_perm object privileges are included in the data structure, which can include / linux / ipc.h found. SystemV news is that in ipc / msg.c to achieve. shared memory in ipc / shm.c to achieve. semaphore in ipc / sem.c, the pipeline / ipc / pipe.c achieve.
interrupt handling: < br> kernel's interrupt handling code specific to almost all of the microprocessor. arch/i386/kernel/irq.c in the interrupt handling code, which is defined in the include/asm-i386/irq.h.
[turn quote] ARM development steps

ARM development steps
1. to be a minimal system board: If you have not done the development of ARM, I suggest you start not Tandaqiuquan to all applications are good, because the startup mode and ARM microcontroller dsp or different, often encounter problems, it is recommended that only the first distribution of a Flash, SRAM or SDRAM, CPU, JTAG, and a small system board reset signal, allow expansion interface. so that the smallest system to function properly, your task is half done, and good basic ARM peripheral interfaces are standard interfaces, if you have the hardware, cabling experience, which is a for you in terms of easy to do.
2. write startup code, according to the hardware address of the first to start writing a little code, including the following sections:
initialize the port, mask the interrupt, the program copied to the SRAM in; completion code The re-mapping; configuration interrupt handler, connected to the C language portal. Maybe you can see some examples of programs you were, bootloader there will be many things, but do not be troubled by these complex procedures, because you are not doing development board Your task is to do a small section of program that allows your application to run down
3. careful study of the chip you use the information, even though the kernel on the ARM-compatible, but each chip has its own characteristics, the preparation of program must consider these issues. especially the girls, here do not have to rely on psychology, people always want to take the sample application to modify, change myself are a mess.
4. to look at some operating system program, the ARM's Many open-source application program, to improve ourselves, we should look at other people's programs, linux, uc / os-II, etc. These are all very good source.
6. If you are for hardware, Basically, each manufacturer has a chip for the DEMO board schematic. first schematic digestion. so you do after design, a pretty good idea of the allocation of resources. DATSHEET device must be properly digested.
7. If to do the best operating system software to understand the mechanism. Of course, this is a piece of cake for software engineers. but if it is a bit strenuous the hardware origin.
Q: do the minimum system board is 2 or 4 layers Layer good?
A: Only two layers can be used AT91 board, the other at least 4 layers; 44b0 deal of ground and power can also be two panels;
about four plates and 33 ohm
use four-layer board is not only a problem of power and ground, high-speed digital circuit trace impedance is required, two-story board not to control impedance .33 ohm general increase in the drive side, but also played the role of impedance matching; wiring first distribution data address lines, and the need to ensure that high-speed line;
when high-frequency, PCB board traces must be regarded as transmission lines. transmission line has its characteristic impedance, transmission line theory learned all know, when the transmission line resistance mutations appear somewhere (not match), the signal will occur through reflection, reflections cause interference to the original signal, the circuit will affect the serious work. using four-layer board, usually take the outer layer signal line, the middle two layer power and ground planes, respectively, so that isolation of the two signal layers on the one hand, is more important is the alignment of the outer layer near the plane and they formed called impedance relatively fixed, and can be calculated. For the two panels is more difficult to do so. The transmission line impedance mainly in trace width, the distance to the reference plane, the thickness of deposited copper and dielectric properties of the materials concerned, there are many ready-made formulas and procedures for calculating.
33 ohm usually one end of thread on the drive (in fact, not 33 in Europe, from a few ohms to fifty or sixty in Europe have, depending on the specific circumstances of the circuit), its role is the output impedance of the transmitter to go after serial line impedance matching, so that reflected back (assuming that the solution does not match the impedance of the receiving end) of the signal does not reflect back again (absorbed), so the signal to the receiver will not be affected . receiver can be matched, for example, a resistor in parallel, but less used in digital systems, it is more trouble, and many times is the situation got more income, such as the address bus, as the source match and easy to do.
shuttle here said high-frequency, high clock frequency is not necessarily the circuit, is not more than look at high frequency, more important is to see the signal rise and fall time. usually can increase (or decrease) the time estimate the frequency of the circuit, and generally increase countdown of the half, such as if the rise time is 1ns, then its inverse is 1000MHz, which means that the circuit is designed to bring into account according to the frequency of 500MHz. sometimes have to deliberately slow down the edge of the time, many high-speed driver IC output of its The slope is adjustable
constructed their own embedded Linux
Linux tool chain with a set of easy to create your own embedded system development environment and cross-operating environment, and embedded system development across the simulation tools (ICE ) obstacles. kernel completely open so that people can design and develop their true hard real-time systems, soft real-time system in Linux is also easy to be realized. a strong network of support makes it possible to use Linux network protocol stack to be embedded in its development type of TCP / IP network protocol stack.
Linux provides a complete embedded features needed for basic kernel and all user interface, it is multi-faceted. It handles embedded tasks and user interface.
a small Embedded Linux system, requires only three basic elements:
* Boot Tools
* Linux micro-kernel, the memory management, process management and transaction processing
* initialize the process pose
if you want It can do something and continue to maintain a small, had to add:
* hardware drivers
* to provide the required functionality of one or more applications.
additional features may need these: < br> * a file system (perhaps in ROM or RAM) in the * TCP / IP network stack
Here we are streamlining the kernel, system startup, the driver, X-Window into the four steps described MicroWindows Embedded Linux the actual development.
core structure to streamline core
common commands, including: make config, dep, clean, mrproper, zImage, bzImage, modules, modules_install. ordered that a little.
explain now, for example:
I am using Mandrake the included 2.2.15. I did not modify any line of program code, relying solely on the data obtained to modify the configuration file.
First, use the make config all the options can be removed have paid too.
not floppy; not SMP, MTRR; not Networking, SCSI; to remove all of the block device, leaving only the old IDE device; to remove all of the character device; to remove all of the filesystem, leaving only the minix; not sound support. Believe me, I have all the options are removed. Having done this, I got a 188K core.
small enough you? OK, plus a move, please send the following two file-O3,-O2 replaced with-Os.
. / Makefile
./arch/i386/kernel /
Makefile
this way, the entire core smaller 9K, a 179K.
would be difficult to play, but the core function of Linux, so I decided to go back to the network increases. the General added back in the network support, recompile, the core into a 189 K.10K to with a TCP / IP stack, seems to be get on with business.
there is no driver stack is wasted, so I used the RTL8139 embedded board the driver added back, 195K.
If you need DOS file system that the size of a 213K. If you use ext2 minix replacement, the size of the growth to 222K.
Linux memory required between about 600K ~ 800K .1 MB of memory may be able to boot, but not very useful, because the serial into the C library has a difficult .2 MB of memory should be able to do something, but to go to more than 4MB can perform a more complete system.
because Linux's filesystem quite large, about 230K or so, accounting for 1 / 3 volume. memory management accounting 80K, and the rest of the sum of the core is almost .TCP / IP stack accounted for 65K, drivers account for 120K.SysV IPC accounted for 21K, if necessary, can be removed, the core files can be even smaller a 10K or so.
If you want to cut the core size, should move there? The answer is obvious, of course, the file system. Linux's VFS file system simplifies the design, buffer cache, directory cache to increase the efficiency of the system. but embedded system is simply not very useful. if they could be removed, the core can immediately reduce the 20K or so. If you skip the VFS, file system is written directly to the type of a driver should be able to be around 230K down to 50K. the core reduced to about 100K.
system starts the boot sequence
system and associated files are still the core source directory, see the following documents:
. / arch / $ ARCH / boot /
bootsect. s
. / arch / $ ARCH / boot / setup.s
. / init / main.c
bootsect.S and setup.S
this program is the first Linux kernel procedures, including the Linux bootstrap their own procedures, but that this program, they must first explain the general IBM PC boot action (where the power is When the memory address is FFFF: 0000 to start (this address must be in the ROM BIOS, ROM BIOS is typically FEOOOh to FFFFFh in), but the content here is a jump instruction, jump to another located in the ROM BIOS the location begin implementation of a series of actions.
followed by system test code, the control is transferred to start the program in ROM (ROM bootstrap routine). This program will track the zero on the disk the zero fan area into memory, as memory read where? - absolute position 07C0: 0000 (ie 07C00h Office), which is the characteristics of IBM PC series. And in the Linux boot disk on the boot sector, it is Linux, bootsect program.
will be familiar to MS DOS and Linux boot part to be a shallow comparison. MS DOS boot sector from the disk in the boot program is responsible for the IO.SYS into memory, while IO.SYS is bears the DOS-kernel - MSDOS. SYS load memory task. And Linux is in the boot sector of the bootsect by the program is responsible for the setup and the Linux kernel loaded into memory, and then hand over control setup.
in the Linux driver
system, device drivers provided by this set of entry points to the system by a structure to be explained.
device driver entry point provided by the device driver initialization When registering to the system so that the system call at the appropriate time. Linux system, up to the system by calling register_chrdev character device driver.
in Linux, in addition to directly modifying the kernel source code, the device driver added to the core of miles away, the device driver can be loaded as a module, the system administrator to dynamically load it, make it a part of the core. as well as by system administrators to dynamically loaded modules Uninstall down. Linux, the module can be used C language, compiled into object files with gcc (but do not link, as *. o files exist). This requires the gcc command line with-c parameter. successful to the system after registration of the device driver (called register_chrdev successful), you can use the mknod command to the device mapped to a particular file. other programs when using this device, as long as the operation of this particular file on the line.
will X-Window into MicroWindows
MicroWindows is to use hierarchical design method. allowed to change to adapt to different practical applications layer. In the bottom layer, provides a screen, mouse / touch screen and keyboard drivers, make the program access to actual hardware devices, and other custom equipment. in the middle layer, a lightweight graphics engine that provides drawing lines, area fills, draw the polygon, cutting methods and the use of color patterns. In the top layer, providing different API to the graphics application. The API can provide or not provide the desktop and window shape. At present, MicroWindows support Windows Win32/WinCE GDI and Nano-X API. The Win32 API provides the X Window System and the close compatibility so other applications can be easily ported to MicroWindows on.
What
embedded systems embedded systems is defined as: application-centric, computer technology, software and hardware can be cut to meet the application system functionality, reliability, cost, size, power consumption requirements of a dedicated computer system strictly.
embedded system is a user-oriented, product-oriented, application-oriented, independent of the application if its own, will lose market. embedded processor power consumption, size, cost, reliability, speed, processing power, electromagnetic compatibility, etc. are subject to the constraints of application requirements, these are all the hot competition among semiconductor manufacturers. embedded processor applications are the key features of embedded systems. solidification storage software requirements, software code, with high quality, high reliability, system software (OS) of high real-time is a basic requirement.
in the manufacturing industry, process control, communications, , instruments, meters, automotive, marine, aviation, aerospace, military equipment, consumer products, etc. are embedded computer applications.
uCLinux implementation of the kernel boot process can be ARM + uCLinux
system startup process summarized in the following stages: (1) PC reset address points to the entrance at the 0x0H Bootloader code. Bootloader to complete some basic initialization, the system's hardware and software environment into an appropriate state; (2) Bootloader will control to the operating system kernel boot process, start loading the kernel uCLinux; (3) uCLinux kernel loads the boot to complete, init starts the process to complete the system boot process.
start the program using the system uCLinux own bootloader loads the kernel. In the kernel boot process several files in the main call this: head.S (in the linux-2.4.x arch armnommu boot compressed directory), main.c ( In the linux-2.4.x init init directory), simpleinit.c (in the user init directory) [1]. practice should be based on the hardware platform and system functions, modify the relevant documents to the right guide system.
when Bootloader control to the kernel boot process, the first execution of the program is head.S, it completed most of the work load the kernel; misc.c provides load the kernel needs of the subroutine, which extract the kernel of the subroutine is an important process head.S call, another to load the kernel must know the system hardware, the hardware information is defined in the hardware.h cited by head.S .
this system, head.S first configure the system S3C4510B register SYSCFG, initialize the system, Flash, SDRAM and the bus control register, the Flash and SDRAM, respectively, the address range is set to 0x0-0x1fffff and 0x1000000-0x1ffffff; According to features of the system, re-defines the interrupt priority, and I / O port configuration; order to improve the running speed of the kernel, the kernel image file to 2M copied from Flash to SDRAM; by operating some system registers, the system's memory remapping, the Flash and SDRAM, respectively, re-mapped to address range 0x1000000-0x11fffff and 0x0-0xffffff; and then initialize the system stack; then calls a function in misc.c decompress_kernel, copied to the SDRAM on the kernel image file to decompress ; the final jump to the calling kernel functions call_kernel, call call_kernel function is actually the implementation of main.c in start_kernel function, which include completion of the initialization of processor architecture, interrupt initialization, the initial timer the beginning of the process related to the initialization and memory initialization and other initialization; last kernel init to create a thread in the thread to call init process to complete the system startup [1] [2].
worth Again, note that in the kernel boot process, called defined in the file hardware.h hardware-related information. Linux-based embedded system boot is heavily dependent on the hardware platform, the kernel boot, you must According to the hardware platform and system functions, with the necessary documents [2]. this system to modify the hardware.h in flash, SDRAM control register ROMCON0, DRAMCON0 and SYSCFG other.
uCLinux startup, running a named init The program, which was started by the operating system user level process started by it to the back of tasks, including multi-user environment, network, etc.. init process behavior is defined in the function simpleinit.c, so the system functions according to custom init into ...

No comments:

Post a Comment