1. Write the driver (hello. c) and place the driver under linux-2.6.38/Drivers/Char.
# Include <Linux/module. h>
# Include <Linux/init. h>
Static int _ init hello_init (void)
{
Printk (kern_alert "Hello world \ n ");
Return0;
}
Static void _ exit hello_exit (void)
{
Printk (kern_alert "Good bye, world \ n ");
}
Module_init (hello_init );
Module_exit (hello_exit );
Module_license ("GPL ");
Module_author ("bql ");
2. Add hello to the kernel code tree and compile
Step 1: edit the configuration file kconfig and add the driver option to make it appear when makemenuconfig
Open the linux-2.6.38/Drivers/Char/kconfig file and add as follows:
Config hello_world_module
Tristate "this is an example of Hello World"
Depends on cpu_cloud6410
Defaulty
Help
This is an example of hello world
Save and exit, then run make in the linux-2.6.38 directory location
Menuconfig can be
Device
Drivers ---> the options just added are displayed in the Character devices menu. Press the Space key and select <M>,
This means to compile this option into a module mode, and press a space to change to <*>, which means to compile this option into the kernel, select <M> here to load the driver as a module.
Step 2: Through the previous step, you can select the kernel during Kernel configuration, but in fact, the kernel cannot be hello during kernel compilation. c compiled, you also need to link the Kernel configuration and options with the real source code in Makefile,
Open the linux-2.6.38/drivers/char/Makefile,
Add and save as follows and exit:
Obj-$ (CONFIG_HELLO_WORLD_MODULE) + = hello. o
Step 3: Return to the linux-2.6.38 source code root directory location, execute makemodules, you can generate the required kernel module File hello. ko, note: Before executing makemodules, you must first execute makezImage, only once. At this point, the compilation of the module driver has been completed.
3. Download Hello to the Development Board and install and use it.
Use the ftp command to download the compiled hello. ko to the board and move it
Go to the/lib/modules/2.6.38-FriendlyARM directory and execute
# Modprobe hello
You can see that this module has been loaded. (Note: you do not need to add "ko" to the module by using the modprobe command.
Fix)
Run the following command to check whether the module is uninstalled.
# Rmmod hello
Note: Required
The module must be placed in the opening Board
/Lib/modules/2.6.38-FriendlyARM directory
Note that the kernel is sometimes updated. If the kernel version has changed
Create a new directory for storing modules based on the specific kernel version. The directory is/lib/modules/2.6.38-FriendlyARM.