A General ' Hello World ' src code for linux3.0 driver programing

Source: Internet
Author: User

/*hello.c*/#include<linux/kernel.h>#include<linux/module.h>Static intHello_init (void) {PRINTK (Kern_alert"Hello init"\ n); return 0;}Static voidHello_exit (void) {PRINTK (Kern_alert"Hello exit\n");} Module_init (Hello_init); Module_exit (Hello_exit); Module_license ("Dual BSD/GPL");

A Makefile format before linux2.6 (would encountered with Error:include/linux/linkage.h:5:25:fatal Error:asm/linkage.h: No such file or directory)

#Makefile #makefile fora basic kernel MODULECC=GCCModcflags:=-wall-dmodule-d__kernel__-Dlinuxinclude:= -ipathtolinuxkernelsrcincludehello.o:hello.c $ (CC) $ (modcflags) $ (INCLUDE)-C hello.cEcho Insmodhello.o to turn it onEchoRmmod Hello to turnifoffEcho    EchoX and kernel programming DoNot mix. EchoDo theInsmodand Rmmod from outside x# note:a"Tab"Before"$ (CC) XXX"Means this is a shell command

A Makefile format as kbuild after linux2.6

# Makefileobj-M: = hello.o
# use "make-c/opt/linux-3.0.4 subdirs= $PWD modules" to compile this driver
# Insmod Hello.ko
# Cat/proc/modules
# Lsmod

For Kbuild kernel driver programming, pls reference to the Linux Kernel Module Programming Guide

A General ' Hello World ' src code for linux3.0 driver programing

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.