// Add a program to the Linux kernel and complete the following three tasks:
1. Copy the source code to the corresponding Linux directory.
2. Add the compilation option of the project corresponding to the new source code to the kconfig file in the directory.
3. Add the new source code compilation entries to the MAKEFILE file in the directory.
The following uses the LED driver as an example:
1. Copy the LED. C source code to the kernel \ drivers \ char directory.
2. Add the LED compilation configuration option to the kconfig file in the directory.
config LED
bool "LED driver"
depends on ARCH_S3C6410
help
LED driver for the samsung s3c6410
The preceding kconfig file means that the LED configuration project appears only when the arch_initi6410 project is configured. This project is Boolean (either compiled into the kernel or not compiled, Y or N) the string displayed on the menu is "LED driver", and the content after help is help information.
The kernel is configured to obtain the Kernel configuration file. config. By configuring the kernel, you can increase or decrease the support for some kernel features for the kernel that is successfully compiled in the future. There are multiple methods to configure the kernel, including text-based configuration methods and graphical user interfaces. The following uses the make menuconfig method that is widely used:
Sudo apt-Get install libncurses5-dev
Sudo make menuconfig
In addition to boolean configuration items, there are also tristate configuration options, which means either compiling into the kernel, compiling into the kernel module, or not compiling, the options are y, m, or N.
In the makefile of the directory, the compiling script for the LED is:
obj-$(CONFIG_LED) += led.o
The above script means that if the LED configuration option is selected as Y or N, that is, obj-$ (config_led) is equivalent to OBJ-y or obj-n.
Make sure that the kernel directory has already passed the make zimage command. You can compile the module code in make modules once.
Compiling the kernel includes two parts: one is to compile the kernel, that is, the part marked as Y in the compilation configuration option, which eventually forms the bziamge image file; the other is to compile the kernel module, that is, the part of the kernel marked as m in the compilation configuration option. the target file of the kernel module ending with Ko.
The compilation of the above two parts can be completed in sequence through make bzimage and make modules, or directly through a make command. The entire process of compiling the kernel is long. Therefore, you can add the-J parameter to make to improve the compilation efficiency. Using this option in make will allocate n concurrent tasks to the compilation process, which can shorten the Compilation Time. N is twice the number of CPUs.
Sudo make-J4
Bytes ------------------------------------------------------------------------------------------------------------------
Author: PANG Hui
Source: http://www.cnblogs.com/pang123hui/
This article is based on the signature 2.5 mainland China license agreement. You are welcome to repost, interpret, or use it for commercial purposes. However, you must keep the signature Pang Hui (including the link) of this Article ).