Complete process for driving compilation examples (modular form)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.