Linux2.6 Internal Model module Loading Problems

Source: Internet
Author: User
Linux-Linux general technology-Linux programming and kernel information-how to load internal model modules. 1. A simple driver

// Hello. c

# Ifndef _ KERNEL __
# Define _ KERNEL __
# Endif
# Ifndef MODULE
# Define MODULE
# Endif

# Include
# Include
# Include
Int hello (void)
{
Printk ("This is a module, hello PeiJun! \ N ");
Return 0;

}

Void bye (void)
{
Printk ("Bye-bye! \ N ");
}

Module_init (hello );
Module_exit (bye );


2. Write Makefile

Obj-m: = hello. o
KERNELDIR =/lib/modules/$ (shell uname-r)/build
PWD: = $ (shell pwd)
Default:
$ (MAKE)-C $ (KERNELDIR) M = $ (PWD) modules
Clean:
Rm-f hello. ko hello. mod hello. mod. o hello. o


3. Run make to generate hello. ko hello. mod hello. mod. o hello. o.


4. Execute insmod hello. o.

.....

Insmod: erro inserting 'hello. o':-1 Invalid module format

2.4 will not generate these files, and only 2.6 will generate hello. ko file, *. the ko suffix is used to distinguish kernel modules from general target files. This module is also loaded at the gnome terminal port of x window in 2.4. printk can print normally, but it won't work when it reaches 2.6. not in text mode, mainly because of the priority of printk. the kernel priority can be defined in linux/kernel. h and kernel/printk. c.


5. Execute insmod hello. ko.

Show This is a module, hello PeiJun!


6. View lsmod

Module Size Used

Hello 1536 0


7. Run rmmod hello.

Display: Bye-bye!
Related Article

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.