Linux kernel compilation (ZT)

xiaoxiao2021-03-06  14

Linux kernel compilation (ZT) is here to post some articles about kernel compilation, and it is not originally original, and there is no intention to indicate. Some content has repeat, please forgive. ============= ======================= 1, the kernel introduction kernel is the core of an operating system. It is responsible for managing system processes, memory, equipment drivers, files, and network systems, which determines the performance and stability of the system. An important feature of Linux is the disclosure of its source code. All kernel source programs can be found under / usr / src / linux, most of the application is also designed with GPL, you can get the corresponding Source program. Any software engineer in the world can add ourselves to the code, and an obvious advantage that is triggered is the rapidness of Linux repair vulnerabilities and the utilization of the latest software technology. The LINUX kernel is the most direct representative of these features. Imagine, what does the source of the kernel do? First, we can understand how the system works. Through the password source code, we can understand the working principle of the system, which is simply in Windows. Second, we can make our own system, and customize the system that is suitable for your own, so you need to recompile the kernel. What is the situation under Windows? I believe that many people have been more and more huge windows. Again, we can modify the kernel to meet your needs. what does this mean? Yes, it is equivalent to developing an operating system, but most of the work is already done, what you have to do is to increase and implement the features you need. Under Windows, unless you are a Microsoft's core technician, you don't want to think. Second, the kernel version number Since Linux's source program is fully disclosed, anyone can use the GPL to modify and publish it to others. The development of Linux is a market model (Bazaar, corresponding to CATHEDRAL - church model - corresponding), in order to ensure that these disruptible development processes can be done in an orderly manner, Linux uses a double tree system. A tree is a stable tree, and the other tree is a unsteable tree or a development tree. Some new features, experimental improvements, etc. will be carried out in the development tree. If the improvements made in the development tree can also be applied to stabilizing trees, then the same improvements will be performed in the stabilizing tree after the test is tested in the development tree. Once the development tree has been sufficiently developing, the development tree will become a new stable tree. The number of developments is reflected in the version number of the source program; the source version number is XYZ: For stabilization tree, Y is an even number; for the development tree, Y is more stable than the corresponding stable tree (therefore, odd) ). So far, the highest version of the stable tree is 2.4.18; the latest version of the development tree is 2.5.10. Download Nuclear Version Please visit http://www.kernel.org. Third, why recompile the kernel Linux as a free software, with the support of the majority of enthusiasts, the kernel version is constantly updated. The new core revised the BUG of the old kernel and added many new features. If the user wants to use these new features, or want to customize a more efficient and more stable kernel according to your own system, you need to recompile the kernel.

Typically, the updated core will support more hardware, with better process management capabilities, faster running, more stable, and generally repair many vulnerabilities found in the old release, etc., often select the upgrade update system kernel It is the necessary operation of Linux users. In order to correctly set the kernel compilation configuration option, only the code required by the system needs, generally have the following four considerations: the built-in bundled kernel is faster (with less code) The system will have more Memory (kernel sections will not be swapped into virtual memory) Unwanted feature compilation into the kernel may increase the vulnerability utilized by the system attacker to compile some function as a module mode to compile the way to the kernel. Some four, kernel compilation mode to increase support for a certain part of the function, such as the network, can compile the corresponding part into the kernel (build-in), or compile the part into a module (Module), dynamically called. If you compile into the kernel, you can automatically support the function of the corresponding part when the kernel is started, this advantage is convenient, fast, the machine is started, you can use this part of the function; the shortcomings will make the kernel huge No matter if you need this part of the function, it will exist, this is the tricks used to Windows. It is recommended to use the part to use directly to the kernel, such as the network card. If you compile into a module, you will generate a corresponding .o file, you can dynamically load it when you are using, the advantage is that you won't make the kernel, the disadvantage is that you have to call these modules. 5. The new version of the core acquisition and update the official website published by the Linux kernel version is http://www.kernel.org. Two new version of the core division, one is the full source version, and the other is the patch file, ie patch. The complete kernel version is relatively large, generally tar.gz or .bz2 file, both of which are compressed using Gzip or BZIP2, need to decompress when using. The Patch file is smaller, usually only tens of k to hundreds k, but the Patch file is for a specific version, you need to find your corresponding version to use. Compile the kernel requires root permissions, the following is assumed that you are root users. Please copy the kernel you need to upgrade to / usr / src / down (hereinafter, the Linux-2.4.18.tar.gz of 2.4.18), command to #cp Linux-2.4.18.tar. GZ / USR / SRC let's take the content of the current / usr / src, note that there is a Linux-2.4 symbolic link to point to a directory of Linux-2.4.7-10 (with redhat7.2 as an example). This is the kernel source code you installed, delete this link. Now decompress the source program files we downloaded.

If the downloaded .tar.gz (.tgz) file, please use the following command: #tar -zxvf linux-2.4.18.tar.gz.tar.gz If you download it is .bz2 file, such as Linux -2.4.0test8.tar.bz2, please use the following command # bzip2 -d Linux-2.4.18.tar.bz2 # tar -xvf Linux-2.4.18.tar file will be extracted into the / usr / src / linux directory We use it slightly modified: #mv Linux Linux-2.4.18 # ln -s Linux-2.4.18 Linux If the Patch file is downloaded, you can perform Patch operation (below, Patch-2.4.18 is already in / usr) / SRC directory, otherwise you need to copy the file to / usr / src first): # patch -p0

Although the interface is better than the above, it is much better than Make Config. The picture below is the interface of Make MenuConfig: Select the corresponding configuration, there are three options, and they represent the meaning of each other as follows: Y - Compile this function into the kernel N - This function is not compiled into the kernel M. The module that can be compiled into the kernel can be dynamically inserted into the kernel when needed. If you use Make XConfig, you can select the corresponding option. If you use Make MenuConfig, you need to use the space bar to choose. You will find that there is a bracket before every option, but some are a bracket, and there is a parenthery. When you use the space bar to choose, you can find that in the middle brackets are empty, or "*", and the anglene brackets can be empty, "*" and "m". This means that the items corresponding to the former are either, either compile into the kernel; the latter is more choices, and can be compiled into a module. The content of parentheses is to select an item in several options provided. In the process of compiling the kernel, the most annoying thing is that this step is working, and many newers don't know how to choose these options. In fact, most of the options can use their default values, only small parts need to be selected according to different needs. The principle of choice is to compile the partial function code that is far from other partial relationships of the kernel, and is used to use the portion of the function code to be loaded to reduce the length of the kernel, reduce the memory consumption of kernel, simplify the corresponding environment changes. The impact of the kernel; do not choose the function; close to the kernel, and often use the partial function code that is used directly into the kernel. As for the option, because more complicated, simply make an introduction, compile time depending on the specific situation, refer to the content of the help. 1. Code Maturity Level Options code mats. There is only one item: prompt for development and / or ibplete code, if you want to test the functionality that is still in the experimental phase, such as khttpd, IPv6, etc., you must choose the item as y; otherwise you can choose it N. 2. Loadable Module Support support for module. There are three items: Enable loadable module support: This item should be required unless you are ready to compile all the required content. Set Version Information On All Module Symbols: You can don't choose it. KERNEL MODULE Loader: Let the kernel have the ability to load the required module during startup, and suggest it. 3. Processor Type and Features CPU type. There are quite a lot, and it is introduced. Several as follows: Processor Family: Select the CPU type according to your own situation. High Memory Support: Support for large capacity memory. You can support 4G, 64G, usually not available. Math Emulation: Coprocessor Simulation. The coordinator is the pet in the 386 era, and now it is no longer available. MTTR Support: MTTR support. Optional. Symmetric Multi-Processing Support: Symmetric multi-process support. Unless you are rich in multiple CPUs, you don't have to choose. 4. General Setup This is set to some of the most common properties. This part of the content is very large, usually using the default settings.

Here are some options that are often used: Networking Support: Network support. Must, no NIC also suggest you choose. PCI Support: PCI support. If the card of the PCI is used, it is certain. PCI Access Mode: PCI Access Mode. Alternative to BIOS, Direct and Any, choose ANY. Support for Hot-Pluggabel Devices: Hot-swap equipment support. Support is not too good, you can not choose. PCMCIA / Cardbus Support: PCMCIA / Cardbus support. There is a PCMCIA. System V IPC BSD Process Accounting Sysctl Support: The above is related to the process processing / IPC call, mainly in both SYSTEM V and BSD style. If you are not using BSD, follow the default. Power Management Support: Power Management Support. Advanced Power Management BIOS Support: Advanced Power Management BIOS Support. 5. MEMORY TECHNOLOGY DEVICE (MTD) MTD device support. Optional. 6. Parallel Port Support parallel support. If you don't plan to use the serial port, don't choose. 7. Plug and play configuration plug and play support. Although Linux is not as good as Windows for plug and play, but still select it, so you can unplug the mouse to experience the feeling of playback under Linux. 8. Block Devices block device support. This will be selected for your own situation, briefly explain: Normal PC Floppy Disk support: Ordinary PC floppy support. This should be necessary. XT Hard Disk Support: Compaq Smart2 Support: MULEX DAC960 / DAC1100 PCI RAID Controller Support: RAID mirroring. Loopback Device Support: Network BLOCK Device Support: Network block device support. If you want to access something on the online neighbors, you choose. Logical Volume Manager (LVM) Support: Logical Volume Management Support. Multiple Devices Driver Support: Multi-device Drive Support. RAM Disk Support: RAM disk support. 9. Networking Options Network option. The network protocol is configured here. There are too many content, introduce it, look at it, if you know what to understand the network protocol, you should be able to understand. If you are too lazy, use the default option (you must select TCP / IP Networking oh). Let's see, TCP / IP, ATM, IPX, Decnet, AppleTalk ... supported protocols, IPv6 also supports, QoS and / or fair queueing also supports, and khttpd, but These are still in the experimental phase. 10. Telephony Support Phone support. Phone card can be supported under Linux so you can use a normal phone to provide voice service on IP. Remember, phone cards can have no relationship with MODEM.

11. ATA / IDE / MFM / RLL Support This is the hard disk / optical drive / tape / floppy disk support for various interfaces. It is too much to use the default option. If you use a relatively special device, such as PCMCIA Wait, I will find the corresponding options inside. 12. Support for SCSI Support SCSI devices. I don't have SCSI's equipment, so I don't have to choose at all. If you use SCSI hard drive / optical drive / tape, you can find it. 13. Fusion Mpt Device Support Requires Fusion MPT compatible with PCI adapter, do not choose. 14. I2O Device Support requires I2O interface adapter support to use in the Smart Input / Output (I2O) system interface. 15. Network Device Support Network Device Support. The above is selected, and now the device is now, it is impossible to know that the content is certain. Fortunately, it is probably classified, with Arcnet equipment, Ethernet (10 or 100 mbit), Ethernet (1000Mbit), Wireless Lan (Non-Hamradio), Token Ring Device, Wan Interface, PCMCIA Network Device Support, Best Class. I use 10 / 100m Ethernet, it seems that I only need to choose this. Still 10 / 100m Ethernet device is familiar, the content is much, you can see the realteck RTL-8139 PCI Fast Ethernet Adapter Support I used, in order to avoid trouble, compiled into the kernel, do not choose M, choose Y . Patience, usually you can find your own network card. If not, you have to go to the manufacturer to drive. 16. Amateur Radio Support Configuring Amateur Wireless Broadcasting. 17. Irda (Infrared) Support Infrared Support. 18. Isdn Subsystem If you use ISDN to access the Internet, this will not be less. 19. Old CD-ROM Drivers (NOT SCSI, Not IDE) is really thoughtful, the original, those who are non-SCSI / IDE mouth, who are still use, choose it, use IDE's CD-ROM without choosing. 20. Character Devices character device. This content is too much, first use the default settings, you need to modify it. Try the big category: I2C Support: I2C is the low-speed serial bus protocol used in the PHILIPS highly driven microcontrol application. If you want to choose the following Video for Linux, this must be selected. Mice: mouse. You can now support bus, serial port, PS / 2, C & T 82C710 MOUSE PORT, PC110 Digitizer Pad, you can choose as needed. Joysticks: Handle. Even if you drive the handle under Linux, it is not too big, and the game is too small. WatchDog Cards: Although called Cards, this can be implemented with pure software, of course, has hardware. If you choose this, you will create a file called WatchDog under your / dev, which can record your system's operation, until the system restarts for about 1 minute. With this file, you can recover the status before the system is restarted. Video for Linux: Supports audio / video cards.

FTAPE, The Floppy Tape Device Driver: PCMCIA Character Device Support: 21. File Systems file system. There are too many content, the old man, modified on the basis of the default option. Describe the following: Quota Support: Quota can limit the upper limit of the hard disk space that each user can use, which is very valid in the case of multi-user uses a host. DOS FAT FS Support: Support for DOS FAT file format, you can support FAT16, FAT32. ISO 9660 CD-ROM FILE SYSTEM Support: The disc is used by the ISO 9660 file format. NTFS File System Support: NTFS is the file format used by NT. / Proc file system support: / proc file system is a channel that Linux is provided to users and systems, and suggests, otherwise some features cannot be executed correctly. There are also three major categories to come here: Network file system, Partition Types, Native Language Support (Local Language Support). It is worth mentioning that both of the NETWORK File Systems: NFS and SMBs are Linux and Windows to access the file system used by each other in the form of network neighbors, and select as needed. 22. Console Drivers console driver. Generally, VGA Text Console is usable, standard 80 * 25 text console. 23. Sound sound card driver. If you can find the sound card driver in the list, you will try the OSS. 24. USB Supprot USB support. Many USB devices, such as mice, modems, printers, scanners, etc., can be supported in Linux, and choose it as needed. 25. Kernel Hacking is configured, even when the system crashes, you can do a certain job. Ordinary users don't need this feature. After the configuration is complete, the deployment exits, of course, you can also save the current profile so that it is safe to save next time. Next is compiled, enter the following command. # Make Dep # make Clean # make bzimage or make zimage # make modules # make modules_install # depmod -a The first command Make DEP actually reads the configuration file generated by the configuration process to create a dependency tree corresponding to the configuration, thus Decide which needs to be compiled and those do not need; the second command Make Clean completes the file left by the previous step to avoid some errors; make Zimage and make Bzimage implements complete compiled kernels, the cores generated are compressed using GZIP compression As long as one is used, their difference is that using make bzimage can generate a big kernel. It is recommended that you use the make bzimage command. The following three commands are only in the process of configuring Enable Loadable Module Support (config_modules) is the necessary, make modules and make modules_install generate the corresponding module and copy the module to the needs, respectively. Directory.

Strictly speaking, the depmod -a command and the compilation process do not have a relationship. It is the dependency between the modules so that you can correct the module when you start the new kernel. Updated the above steps, we finally got a new version of the kernel. In order to be able to use the new version of the kernel, we also need to do some changes: #CP /usr/src/linux/system.map /boot/system.map-2.4.18#cp / usr / src / linux / arch / i386 / Bzimage /Boot/vmlinuz-2.4.18 These two files are newly generated when we have just compiled. The two links System.map and VMLinuz under / boot are modified to point to the files of the new kernel: #CD / boot; rm -f system.map VMLinuz # ln -s vmlinuz-2.4.18 VMLinuz # ln-s system .map-2.4.18 system.map seven, modify the startup manager If you use LILO, modify /etc/lilo.conf, add the following item: image = / boot / vmlinuz-2.4.18Label = Linux240read-onlyroot = / dev / hda2 Where root = / dev / hda2 must be modified as needed. Operation: # / sbin / lilo -v Confirmation Pair of editing of /etc/lilo.conf, now restarting the system: #SHUTDOWN -R Now If you use the GRUB Start Manager, add the following items. Title Red Hat Linux (2.4.18) root (HD0, 0) kernel /Vmlinuz-2.4.18 Ro root = / dev / hda2grub No need to call the command again, automatically take effect. The new kernel can be used after restarting.

The meaning of the relevant options in the kernel compile menu ===================================================================================================================================================================================================================== A lot of reference books said that this developers believe that it is not very stable, but according to my experience, this is an option to choose, because modern Linux is based on these, so I should answer Y, Unless you just want to use the things that have been fully constitutive in Linux, the performance is definitely not good, and the support for system characteristics will not be good. 2.Processor Family (386, 486 / CX486, 586 / K5 / 5X86 / 6X86, PENTINUM / K6 / TSC, PPRO / 6X86) This should not be too much, choose your CPU, BIOS can Get it, pay attention to the system's startup information. It should be noted that the CPU that cannot be selected than your CPU type, otherwise it may not work properly. 3. Math Emulation Simulation Mathematical Cooperation, if your machine has no mathematical coordinator, then select to improve performance, but 486 after the math coordinator is integrated into the CPU, it should be not used, so The general choice is N. Of course, there will be no problems, except that the core is slightly larger. 4. MTTR (Memory Type Range Register) The option is used to start the special features of the Pentinum Pro and Pentinum II. If you are not using this CPU, you will only make the kernel change. 5. Symmetric Multi-Processing Support Synchronous Processor Support, if you have multiple CPUs, choose. 6. Enable loadable module support This will start the functionality of the additional module, so it is sure to select. 7. SET VERSION INFORMATION ON All Symbols for modules This option can be used for a version of the kernel to be used in another version of the kernel, but it is generally not used. 8. Kernel Module Loader If you enable this option, you can automatically load or uninstall those portable modules at needed at need. The suggestion is recommended. 9. Networking support If you use any network, you should choose 10. PCI BIOS Support is usually selected, unless you use a machine without any PCI device. PCIBIOS is used to detect and enable PCI devices. 11. PCI Bridge Optimization (V1.3) When this option is started, the operating system is optimized for data from the PCI bus from the CPU and the system. This function has completed the experimental phase, which should be safe. And also enhance the efficiency of the system. 12. SYSTEM V IPC Use this option to enable the kernel to support the functionality (IPC) of the SYSTEM V process, and some programs that are transferred from System V will require this feature, which is recommended to enable this feature. 13. SysctL Support Unless you have less memory, you should start this feature, enable this option, the kernel will be 8K, but you can change the parameters of the kernel without having to reboot.

14. Keernel Support for Elf Binaries This option allows your system to perform executables stored in ELF format, while ELF is a standard format of modern Linux executable files, target files, and system libraries. These criteria are required when the operating system should work with the compiler and the connector, so I should answer Y. 15. Compile Kernel AS ELF This option makes your kernel itself compiles in ELF format. If the process GCC on your system generates an executable file in ELF format, then you should start this option. Let's take a look at the version of your compiler and decide. 16. Parallel Port Support If you have any parallel ports and want Linux to use, you can enable this option. Linux can not only use the parallel printer, but also support PLIP (a network communication protocol designed for parallel port), ZIP disk drive, scanner, etc. In most cases, you need additional drivers to use external parallel devices. 17. Plug and play support supports PNP devices Not Microsoft's patents, if you want Linux support PNP devices, you can conflict with other devices, but some cases are enabled (I / O, DMA, IRQ, etc.) ). This option has no effect on the PCI device, because they are born to PNP devices. 18. Normal Floppy Disk Support should answer Y, unless you don't want to use a floppy disk under Linux. But for some systems that do not need to support floppy drives, this option saves some memory. 19. Enhanced IDE / MFM / DLL Disk Support Unless you don't need the support of the MFM / DLL / IDE hard disk, you should answer Y, but if you only have SCSI's hard drive, turn off this option to be safe. 20. Enhanced IDE / MFM / DLL CDROM Support and the above, but it is only support for CDROM. 21. Enhanced IDE / MFM / DLL TAPE Support generally does not have many people in using a tape, so answering N is a better answer. 22. Enhanced IDE / MFM / DLL FLOPPY Support This device seems to be generally used, so I can answer N. 23. Xt HardDisk support If you have this stone's XT hard drive, congratulations, you can use him. 24. Parallel Port IDE Device Supportlinux is an IDE device that supports this very new parallel port. If you have, you will use it. 25. Networking Options If you choose a support network in front, you will answer a lot of questions here. Unless you have a special requirement, you should use the default options should be enough. 26. SCSI Support If you have any SCSI control card, this option should answer Y. Find your hardware types in advance, because these issues are for specific SCSI control chips and control cards, if you are not sure which type you use, check your hardware's instructions or Linux's HOWTO document. Also let you answer a lot of SCSI devices (hard drives, cdrom, tape, floppy, etc.), based on your situation. If you don't have a SCSI device, it is recommended not to support because it saves a lot of kernel space. 27. Network Device Support There are a lot of questions about the network control card. If you can't determine how to choose correctly, check the hardware document or Linux Howto document.

28. Amateur Radio Support This option can be used to initiate basic support for wireless networks, and current wireless networks can transfer data through the public frequency. If you have such a device, you can be enabled, please refer to the AX25 and HAM HOWTO documents. 29. ISDN Subsystem If you have ISDN hardware, you should enable this option and install the appropriate hardware driver, you should also need to enable the Support Synchronous PPP option (refer to PPP overisdn). 30. Old CD-ROM Drivers This is a problem for some special disc drive programs. If you have IDE or SCSI CDROM control card, then this option is not enabled. 31. Character DeviceSlinux supports many special character devices, such as parallel ports, serial control cards, QiC02 tape drives, and mice in specific interfaces, and in addition to the game rod and image intake and microphone, according to your own situation Bar. 32. FileSystems This is a series of file systems supported by the kernel. For the EXT2 / PROC file system, it should be supported. There are optical drives to support ISO9660 (or module support), have Windows or DOS partitions and want to be in Linux. Access them can also support it. 33. Console Drivers You should at least support VGA Text Console, otherwise you cannot use Linux from the console. 34. Sound Card Support Answer y here Y will have a lot of questions about the sound card, and configure it according to your own situation. 35. Keernel Profiling Support (v1.3) This option enables the function of kernel to perform efficiency statistics and provides other information useful when it is detected. These features will need to pay some costs and cause the system to be performed slowly, unless you are studying a problem with the kernel, otherwise you should answer N. 36. kernel Hacking If you are planning to study how Linux running on your system is working, there are many options, but there is no need to turn off.

On the Linux kernel configuration system: the original author: Tom Kay ====================================== =================================================================================================================================================================== # The development of the embedded field, more and more people began to get into the development of Linux kernel. In the face of increasingly huge Linux kernel source code, the developer will face the same problem after completing its own kernel code, that is, how to integrate the source code into the Linux kernel, increase the corresponding Linux configuration option, and finally compiled Enter the Linux kernel. This requires understanding Linux's kernel configuration system. As we all know, the Linux kernel is developed by Linux enthusiasts distributed around the world, and Linux core is facing many new changes every day. However, the organization of the Linux kernel does not have a chaotic phenomenon, but it looks very concise, and has good scalability, developers can easily add new content to the Linux core. One of the reasons is that Linux uses a modular kernel configuration system to ensure the scalability of the kernel. This article first analyzes the configuration system structure in the Linux kernel, and then explains the format of the makefile and configuration file, and the meaning of the configuration statement. Finally, through a simple example - Test Driver, how to add the code that will be developed Linux kernel. In the following article, it is impossible to explain all the features and commands, only explain those commonly used, as for those who are not discussed, please refer to the references later. 1. Configuring the basic structure of the system Linux kernel configuration system consists of three parts, named: makefile: distributed Makefile in the Linux kernel source code, defines the compilation rules for Linux kernels; configuration files (config.in): Provide users with configuration Selected features; Configuration Tools: Include Configure Command Interpreters (Interpretation of Configuration Commands Used in Configuration Scripts) and Configure User Interfaces (Provides a character interface, NCURSES-based interface, and user configuration interface based on XWINDOWS graphics interface, each correspond Make Config, Make MenuConfig and make Xconfig. These configuration tools are written using scripting languages, such as TCL / TK, and PERL (also containing some code written with C). This article is not analyzing the configuration system itself, but is described on how to use the configuration system. Therefore, unless the maintenance of the system is configured, the general kernel developers do not need to understand their principles, just know how to write Makefile and configuration files. So, in this article, we only discuss the Makefile and configuration files.

In addition, anything related to the specific CPU architecture is involved in ARM as an example, which can not only be explicitly discussed, but also affect the content itself. 2. Makefile2.1 Makefile Overview Makefile The role of Makefile constructs a list of source files that need to be compiled, and then compile, and then connect the target code link, and finally forms a Linux kernel binary file. Since the Linux kernel source code is organized according to the tree structure, Makefile is also distributed in the directory tree. Makefile in the Linux kernel and files directly related to Makefile are: makefile: top Makefile, is the overall control file for the entire kernel configuration, compiled. .config: The kernel profile contains the configuration options selected by the user to store the results after the kernel configuration (such as Make MenuConfig). Arch / * / makefile: Makefile under various CPU systems, such as Arch / ARM / Makefile, is a Makefile for a specific platform. Makefile under each child: such as Drivers / Makefile, is responsible for the management of the subscription of the subdirectory. Rules.make: Rules files are used by all makefile. After the user is configured by the make menuconfig, it creates .config. The top layer makefile reads the configuration selection in .config. Top Makefile has two main tasks: generating a VMLinux file and kernel module. In order to achieve this, the top Makefile recursive into each subdirectory of the kernel, which calls the Makefile located in these subdirectories, respectively. As for which subdirectories in the end, depending on the configuration of the kernel.

In the top Makefile, there is a saying: including include Arch / $ (Arch) / makefile, contains Makefile under a specific CPU architecture, which contains platform-related information in this makefile. Makefile located in each sub-directory also constructs a list of source files required under current configuration according to the configuration information given by .config, and has the last included files / Rules.make. Rules.make files play a very important role in which all Makefile shared compilation rules. For example, if you need to compile all the C programs in this directory into assembly code, you need to have the following compilation rules in Makefile:%. S:% .C $ (cc) $ (cflags) -s $ <-o $ @ There are also many subdirectories, which will need this compilation rules in their respective makefiles. This will be more troublesome. In the Linux kernel, set such compilation rules to Rules.make and include Rules.make (include Rules.make) in their respective makefiles, which avoids the same thing in multiple Makefile. rule. For the above example, the rules corresponding to rules.make are:%. S:% .C $ (cc) $ (cflags) $ (cflags _ $ @ f)) $ (cflags _ $ @) - S $ <--o $@2.2 Makefile The top layer makefile defines and outputs many variables to the environment, and passes some information for Makefiles under each child. Some variables, such as Subdirs, not only defined in the top Makefile, but also expanded in Arch / * / Makefile. Common variables have the following categories: 1) Version information version information is: Version, Patchlevel, SUBEVEL, Extraversion, kernelrelease. The version information defines the current core version, such as Version = 2, PatchLevel = 4, SUBLEVEL = 18, ExataVersion = -rmk7, which constitutes a library of kernel release kernelrelease: 2.4.18-RMK72) CPU architecture: Arch on the top Makefile The beginning, define the architecture of the target CPU with Arch, such as Arch: = ARM, etc. In Makefile of many subdirectories, select the list of selected source files based on the definition of Arch. 3) Path Information: TOPDIR, SUBDIRSTOPDIR Defines the root directory where Linux kernel source code is located. For example, Makefile under each child can find the location of Rules.make through $ (TOPDIR) /Rules.make. Subdirs defines a list of directory. When compiling kernel or modules, the top Makefile is based on SubDirs to decide which subdirectory. The value of SubDirs depends on the configuration of the kernel. The SubDirs in the top Makefile assigns Kernel Drivers MM FS Net IPC lib. According to the configuration of the kernel, the example in which SubDirs is expanded in the Arch / * / Makefile, see 4).

4) Core Composition Information: Head, core_files, networks, drivers, libslinux kernel file VMLinux is generated by the following rules: VMLINUX: $ (Configuration) Init / Main.o Init / Version.o LinuxSubDirs $ (LD) $ (linkflags) $ (HEAD) INIT / Main.o Init / Version.o / - Start-Group / $ (Core_Files) / $ (DRIVERS) / $ (NETWORKS) / $ (LIBS) / - End-Group / -o VMLinux It can be seen that VMLinux consists of Head, Main.o, Version.o, Core_Files, Drivers, Networks, and Libs. These variables (such as HEAD) are used to define a list of target files and library files that generate VMLinux. Among them, Head is defined in Arch / * / Makefile to determine the list of files that are first link to VMLinux. For example, for the ARM series CPU, Head is defined as: head: = arch / arm / kernel / head - $ (processor) .o /arch/rm/kernel/init_task.o indicates Head - $ (Processor) .o and init_task .o needs to be first linked to VMLinux. Processor is ARMV or ARMO, depending on the target CPU. Core_files, network, drivers, and libs are defined in the top Makefile and expanded as needed by Arch / * / Makefile. Core_files corresponds to the core file of the kernel, with kernel / kernel.o, mm / mm.o, fs / fs.o, IPC / IPC.O, which can be seen that these are the most important files that make up the kernel. At the same time, Arch / ARM / Makefile is expanded to Core_Files: # Arch / ARM / Makefile # IF WE HAVE A MAKEFIC DIRECTORY, THEN INCLUDE ITIENT.MACHDIR: = Arch / ARM / Mach - $ (Machine) iFeq ($ (MachDir), $ (Wildcard $ (Machdir)) Subdirs = $ (Machdir) Core_Files: = $ (MachDir) / $ (Machine) .o $ (Core_Files) endifhead: = Arch / ARM / KERNEL / HEAD $ (Processor) .o /arch/arm/kernel/init_task.osubdirs = Arch / ARM / KERNEL ARM / ARM ARCH / ARM / LIB ARM / ARM / NWFPECORE_FILES: = Arch / ARM / KERNELO / KERNEL.O Arch / ARM / MM / mm.o $ (Core_Files) Libs: = Arch / ARM / LIB / LIB.A $ (LIBS) 5) Compile Information: CPP, CC, AS, LD, Ar, CFLAGS, LINKFLAGS in Rules. Make defines the common rules of compilation, specific to specific occasions, need to explicitly give the compilation environment, the compilation environment is defined in the above variables. CROSS_COMPILE is defined for cross-compilation requirements.

For example: cross_compile = arm-linux-cc = $ (cross_compile) gcCLD = $ (cross_compile) ld ... cross_compile defines cross-compiler prefix ARM-Linux-, indicating that all cross-compilation tools are ARM- Linux-started, so $ (Cross_Compile) has been added before each cross-compiler tool to form a complete cross-compilation tool file name, such as ARM-Linux-GCC. CFLAGS defines the parameters passing to the C compiler. LinkFlags is the parameter used by the linker when the link generates VMLinUX. LinkFlags defines in ARM / * / Makefile, such as: # arch / arm / makefilelinkflags: = - p-t arch / arm / vmlinux.lds6) Configure variable config _ *. Config files have many configuration variables, Used to explain the result of the user configuration. For example, Config_Modules = Y indicates that the user selects the module function of the Linux kernel. After the .config is included, a number of configuration variables are formed, each configuration variable has a determined value: Y indicates that the core code corresponding to the compilation option is static to the Linux kernel; M represents the core code corresponding to the compilation option Compiled into a module; n means that you don't select this compilation option; if you don't choose at all, the value of the configuration variable is empty. 2.3 Rules.make variables, Rules.make is a compilation rule file, and all Makefile includes rules.make. The rules.make file defines a lot of variables, most important to compile, link list variables. O_OBJS, L_OBJS, OX_OBJS, LX_OBJS: This directory needs to be compiled into the list of target files for Linux kernel VMLinux, where "X" in OX_OBJS and LX_OBJS indicates that the target file uses the export_symbol output symbol. M_OBJS, MX_OBJS: This directory needs to be compiled into a list of target files that can be loaded. Similarly, "X" in MX_OBJS indicates that the target file uses the export_symbol output symbol. O_target, l_target: There is an o_target or l_target in each subdirectory, and Rules.make first recombines all target files in O_OBJS and OX_OBJS from source code, and then link them into an o_target or l_target using $ (ld) -r. O_Target ends with .o, and l_target ends. 2.4 Subdate Makefile Sub Directory Makefile Used to control the compilation rules for the following source code.

We use an example to explain the composition of Makefile: ## makefile for the linux kernel. ## all of the (potential) Objects That Export Symbols. # This list comes from 'grep -l export_symbol *. [Hc]'. Export-objs: = tc.o # Object file lists.obj-y: = Obj-m: = Obj-N: = Obj-: = Obj - $ (config_tc) = tc.oobj - $ (config_zs) = ZS.OOBJ - $ (config_vt) = lk201.o lk201-map.o lk201-remap.o # files That Are Both Resident and Modular: Remove from Modular.Obj-M: = $ (Filter-Out $ (Obj- Y), $ (OBJ-M)) # translate to rules.make lists.l_target: = tc.al_objs: = $ (Sort $ (Filter-Out $ (Export-Objs), $ (OBJ-Y))) LX_OBJS : = $ (Sort $ (Filter $ (Export-Objs), $ (OBJ-Y))) M_OBJS: = $ (Sort $ (Filter-Out $ (Export-Objs), $ (OBJ-M))) MX_OBJS : = $ (Sort $ (Filter $ (export-objs), $ (OBJ-M))) Include $ (TOPDIR) /Rules.makea) Note The description and explanation of Makefile, starting by #.

Compilation Target Definition is similar to the OBJ-$ (config_tc) = Tc.o statement is the most important part of the subdirectory Makefile used to define compilation. Compilation Target Definitions those list of target files in the Linux kernel in this subdirectory. In order to compile only this feature only, all target definitions combine the judgment of the configuration variable. As mentioned earlier, each configuration variable range is: Y, N, M and empty, OBJ - $ (config_tc) corresponds to OBJ-Y, OBJ-N, OBJ-M, OBJ-. If config_tc is configured as y, Tc.o enters the OBJ-Y list. Obj-y is a list of target files containing the Linux kernel VMLinux; OBJ-M is a list of target files compiled into a module; the list of files in OBJ-N and OBJ-Ignore is ignored. The configuration system compiles and links according to the properties of these lists. The target file in Export-Objs uses export_symbol () to define a common symbol to load the module. At the last part of the Tc.c file, there is "export_symbol (search_tc_card);" indicating that Tc.o has a symbol output. It is to be pointed out here that there are two formats for the definition of the compilation target, which is old-fashioned and newly defined. The old-fashioned definition is those variables used in front of Rules.make, the new definition is OBJ-Y, OBJ-M, OBJ-N and OBJ-. Linux kernel recommends using new definitions, but because rules.make does not understand new definitions, it is necessary to convert it into an old-fashioned definition in the adapter segment in Makefile. c) The function of the adapter section adapter segment is to convert the new definition into an old-fashioned definition. In the above example, the adaptation segment is L_Target, L_OBJS, LX_OBJS, M_OBJS, MX_OBJS, which converts OBJ-Y and OBJ-M to Rules.make, which can be understood. L_objs: = $ (Sort $ (Filter-Out $ (Export-Objs), $ (OBJ-Y))) Defines the way to build l_objs: Filter out Export-Objs (Tc.o) in the list of OBJ-Y , Then sort and remove the repeated file name. Some special functions of GNU Make are used here, and the specific meaning can be referred to the Make document (INFO MAKE). d) Include $ (TOPDIR) /Rules.make3. Profile 3.1 Configuration Function Overview In addition to Makefile, another important job is to add new features to Linux configuration options, provide instructions for this feature, allowing users to have the opportunity to select this feature. All of this needs to write configuration scripts in config.in files, in the Linux kernel, in the Linux kernel, have a variety of ways: Configuration command Explanation Script Make Config, Make Oldconfig Scripts / Configure Make Menuconfig Scripts / MenuConfig Make Xconfig Scripts / TKPARS is used as an example of the Make Config. The top Makefile calls Scripts / Configure to configure it according to Arch / ARM / Config.in. After the command is executed, the file is generated. Config, which saves configuration information.

Next time, Make Config will produce a new.config file, the original .config is renamed .config.old3.2 Configuration Language 1) Top Menu MainMenu_Name / Prompt / / Prompt / is the string of 'or "surrounded by" The difference in "difference is the value of the reference variable can be used in '...'. MainMenu_name sets the name of the highest layer menu, which is only displayed when Make Xconfig. 2) Inquiry statement bool / prompt / / symbol / hEX / prompt / / symbol / / word / int / prompt / / symbol / / word / string / prompt / / / / / / / word / tristate / prompt / / / / / / / / us First display a string prompt / prompt /, wait for the user to enter, and assign the input result to the configuration variable represented by Symbol /. The difference between different interrogation statements is that they are accepted differently, such as Bool accepts Boolean type (Y or N), HEX accepts 16 credit data. Some query statements have the third parameter / word / for a default. 3) Define statement define_bool / symbol / / word / define_hex / symbol / / word / define_inter / symbol / / word / define_tring / symbol / / word / define_tristate / symbol / / word / unlike the inquiry statement waiting for user input, definition Configure variable / symbol / assignment / Word /. 4) Depending on the statement dep_bool / prompt / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / DEP / ... / symbol / / word / / / / / ... dep_string / prompt / / / / / / / / / / / / / ... DEP_TRISTATE / PROMPT / / SYMBOL / / DEP / ... similar to the inquiry statement, dependent statements are defined New configuration variable. Different, the configuration variable / symbol / value range will depend on the configuration variable list / dep / .... This means that the corresponding function of the defined configuration variable depends on the selection of the corresponding functionality depending on the list. Take DEP_BOOL as an example, if all the configuration variables of the / DEP / ... are all value Y, the / prompt /, the user can enter any value to configure variable / symbol /, but as long as there is a configuration variable value N Then / Symbol / is forced to be n. The difference between different dependent statements is different from the range of values ​​generated by dependent conditions. 5) Select statement choice / prompt / / / / / / word / choice statement first give a list of selection for users to select one.

Such as Linux for ARM supports a variety of ARM core-based CPU, Linux using statement provides a CPU choice list for users to choose: choice 'ARM system type' / "Anakin CONFIG_ARCH_ANAKIN / Archimedes / A5000 CONFIG_ARCH_ARCA5K / Cirrus-CL-PS7500FE CONFIG_ARCH_CLPS7500 / ... ... SA1100-based config_arch_sa1100 / shark config_arch_sha1100 / Shark config_arch_shark "Riscpcchoice first displays / prompt /, and then breaks / Word / decomposes to two parts before and after, the front portion is the corresponding selected prompt, and the rear portion is the corresponding selection variable. The configuration variable selected by the user is Y, the rest is n. 6) IF statement if [/ expr /]; then / statement / ... fiif [/ expr / ... Else / statement / ... fiif statement pair configuration variable (or combination of variables) Decision, and make different processing. The determination condition / EXPR / can be a single configuration variable or string or an expression of the operator. Operators are: =,! =, - O, -A, etc. 7) Menu Block statement mainmenu_option next_commentcomment '... ..' ... EndMenu introduces a new menu. After adding a new feature to the kernel, you need to add a new menu accordingly and give the configuration options for this feature under the new menu. Comment is the name of the new menu. All configuration option statements that belong to this menu are written between Comment and endmenu. 8) Source Statement Source / Word // Word / is the file name, and the role of Source is to transfer new files. 3.3 Default Configuration Linux kernel supports a lot of hardware platforms. For specific hardware platforms, some configurations are required, and some configurations are not required. In addition, the normal operation of newly added functions often requires certain prerequisites, for new functions, must be configured. Therefore, the particular hardware platform can function properly corresponding to a minimum basic configuration, which is the default configuration. There is a default configuration for each Arch in the Linux core. After adding a new feature to the kernel code, if the new feature is required for this Arch, it is necessary to modify the default configuration of this ARCH. The modification method is as follows: Backup .config file cp arch / arm / deconfig .config modified .config cp .config arch / arm / decig recovered .config If the new function applies to many Arch, Repeat the above steps for specific Arch. 3.4 Help File Everyone has such an experience. When configuring the Linux kernel, encounter configuration options that you don't understand, you can view its help, from which you can get the suggestions. Let's take a look at how to add help information to a configuration option.

Help information for all configuration options is in documentation / configure.help, its format is: The name of this configuration option, Corresponding to configuring variables, Corresponds to Configure Help Information. In the help information, first describe this feature, followed by the choice of this feature, there is any effect, don't choose any effect, and finally, don't forget to write "If you don't know, choose n (or) y", Users who do not know to prompt. 4. Examples For a developer, add the kernel code you develop to the Linux kernel, there is three steps. First, determine the location of your own development code into the kernel; secondly, add your own functions to the Configuration options for your Linux kernel, users can choose this feature; Finally, construct the subdirectory Makefile, according to the user's choice, will The code is compiled into the finally generated Linux kernel. Below, we will explain how to add new features to the Linux core through a simple example - Test Driver, combined with the previous knowledge. 4.1 Directory Structure Test Driver is placed in drivers / test / directory: $ CD Drivers / Test $ Tree. | - Config.in | - Makefile | - CPU | | - Makefile | `- cpu.c | - Test.c | - Test_Client.c | - Test_iocTl.c | - Test_Proc.c | - Test_queue.c` - Test | - Makefile` - Test.c4.2 Profile 1) DRIVERS / test / Config.in ## TEST driver configuration # mainmenu_option next_commentcomment 'TEST Driver'bool' TEST support 'CONFIG_TESTif [ "$ CONFIG_TEST" = "y"]; thentristate' TEST user-space interface 'CONFIG_TEST_USERbool' TEST CPU 'CONFIG_TEST_CPUfiendmenu Since test Driver is a new feature for kernels, so you first create a menu Test Driver. Then, "Test Support" is displayed, waiting for user selection; then determine if the user selects Test Driver, if (config_test = y), further display subunies: user interface and CPU function support; due to user interface functions can be compiled It is a kernel module, so the inquiry statement here uses Tristate (because the value range of Tristate includes Y, N, M, M correspond to the module). 2) Arch / arm / config.in At the end of the file: Source Drivers / Test / Config.in, incorporating the configuration of the Test Driver substructure into the Linux kernel configuration.

4.3 Makefile1) drivers / test / Makefile # drivers / test / Makefile ## Makefile for the TEST # SUB_DIRS:. = MOD_SUB_DIRS: = $ (SUB_DIRS) ALL_SUB_DIRS: = $ (SUB_DIRS) cpuL_TARGET: = test.aexport-objs: = test .o test_client.oobj - $ (CONFIG_TEST) = test.o test_queue.o test_client.oobj - $ (CONFIG_TEST_USER) = test_ioctl.oobj - $ (CONFIG_PROC_FS) = test_proc.osubdir - $ (CONFIG_TEST_CPU) = cpuinclude $ (TOPDIR) /Rules.makeclean: 201_Sub_dirs); do make -c $ dir clean; donerm -f *. [OA]. *. The final generated target file in the FlagsDrivers / Test directory is TEST.A . Export_Symbol output symbols in Test.c and Test-Client.c, so Test.o and Test-Client.o are located in the Export-Objs list. Then, according to the selection of the user (specifically, the value of the configurable variable), the respective corresponding OBJ- * list is constructed. Due to the Test Driver, a subdirectory CPU is included, when config_test_cpu = y (ie, the user selects this feature), you need to add the CPU directory into the SubDIR-Y list. 2) drivers / test / cpu / Makefile # drivers / test / test / Makefile ## Makefile for the TEST CPU #SUB_DIRS: = MOD_SUB_DIRS: = $ (SUB_DIRS) ALL_SUB_DIRS: = $ (SUB_DIRS) L_TARGET: = test_cpu.aobj- $ (Config_test_cpu) = CPU.Oinclude $ (TOPDIR) /Rules.makeclean: RM -F *. [OA]. *. Flags3) Drivers / makefile ... Subdir - $ (config_test) = Test ... include $ (TOPDIR ) /Rules.make Adds SubDir - $ (config_test) = TEST in Drivers / makefile so that after the user selects the Test Driver function, the TEST directory can be entered when the kernel compiles. 4) Makefile ...... DRIVERS - $ (CONFIG_PLD) = drivers / pld / pld.oDRIVERS - $ (CONFIG_TEST) = drivers / test / test.aDRIVERS - $ (CONFIG_TEST_CPU) = drivers / test / cpu / test_cpu.aDRIVERS : = $ (Drivers-Y) ... Add Drivers - $ (config_test) = Drivers / Test / Test.a and Drivers / Test / CPU / TEST_CPU.A in the top Makefile.

转载请注明原文地址:https://www.9cbs.com/read-50830.html

New Post(0)