Ubuntu driver development environment

Source: Internet
Author: User
Ubuntu driver development environment-general Linux technology-Linux programming and kernel information. The following is a detailed description. The version I used is ubuntu8.04, and the kernel tree has been created.
The/usr/src directory has the following version directories:
Linux-headers-2.6.24-19
Linux-headers-2.6.24-19-generic, if not, need to go online to download.

// Hello. c
# Include
# Include
# Include

MODULE_LICENSE ("GPL ");
Static int init_routine (void)
{
Printk ("module init \ n ");
Return 0;
}
Void cleanup_routine (void)
{
Printk ("Cleanup module \ n ");
}
Module_init (init_routine );
Module_exit (cleanup_routine );

Below is the makfile

Obj-m: = hello. o

KERNELDIR? =/Lib/modules/$ (shell uname-r)/build
PWD: = $ (shell pwd)

All:
$ (MAKE)-C $ (KERNELDIR) M = $ (PWD)

Clean:
Rm-rf *. o *~ Core. depend. *. cmd *. ko *. mod. c. tmp_versions

Save the file and compile it. If
Sysu @ sysu-desktop :~ /Driver $ make
Makefile: 10: *** the Delimiter is missing (you mean to use TAB to replace 8 spaces ?). Stop. Or
Root @ sysu-desktop :~ /Driver # make
Make: nothing can be done as 'all '.
The error is because the Makefile format is incorrect. The spaces in front of $ (MAKE) and rm-rf *. o * are completed by a TAB key.

Root @ sysu-desktop :~ /Driver # make
Make-C/lib/modules/2.6.24-19-generic/build M =/home/sysu/driver
Make [1]: Entering directory '/usr/src/linux-headers-2.6.24-19-generic'
LD/home/sysu/driver/built-in.o
CC [M]/home/sysu/driver/hello. o
Building modules, stage 2.
MODPOST 1 modules
CC/home/sysu/driver/hello. mod. o
LD [M]/home/sysu/driver/hello. ko
Make [1]: Leaving directory '/usr/src/linux-headers-2.6.24-19-generic'

All right, compilation successful.
Test:

Load Module
Root @ sysu-desktop :~ /Driver # insmod hello. ko

View module
Root @ sysu-desktop :~ /Driver # lsmod
Module Size Used
Hello 2432 0
I915 32512 2
Drm 82452 3 i915
Rfcomm 41744 2

Delete A Module
Root @ sysu-desktop :~ /Driver # rmmod hello

View output
Root @ sysu-desktop :~ /Driver # tail dmesg
[2, 173.995486] netdev watchdog: eth0: transmit timed out
[173.995506] eth0: Transmit timed out, status 00000000, resetting...
[173.995510] Rx ring dd7e4000: 80000000 80000000 80000000 80000000 80000000 80000000 80000000 80000000 80000000 80000000 80000000 80000000
[173.995527] Tx ring dd7eb000: 80000000 80000000 80000000 0000 80000000
[2, 2722.659875] module init
[2, 2833.604333] Cleanup module

The first driver ends pulling.
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.