linux 2.6内核编程-Hello world程序

<script type="text/javascript"> document.body.oncopy = function() { if (window.clipboardData) { setTimeout(function() { var text = clipboardData.getData("text"); if (text && text.length > 300) { text = text + "/r/n/n本文来自CSDN博客,转载请标明出处:" + location.href; clipboardData.setData("text", text); } }, 100); } } </script>

/**************************************************************

 module program:hello.c

**************************************************************/

 

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

static int hello3_data __initdata= 3;
static int __init hello_3_init(void)
{
   printk(KERN_INFO "Hello, world %d/n",hello3_data);
   return 0;
}
static void __exit hello_3_exit(void)
{
   printk(KERN_INFO "Goodbye,world 3/n");
}
module_init(hello_3_init);//insmod 调用
module_exit(hello_3_exit);//rmmod调用

 

<script type="text/javascript"> document.body.oncopy = function() { if (window.clipboardData) { setTimeout(function() { var text = clipboardData.getData("text"); if (text && text.length > 300) { text = text + "/r/n/n本文来自CSDN博客,转载请标明出处:" + location.href; clipboardData.setData("text", text); } }, 100); } } </script>

/**************************************************************

 Makefile

**************************************************************/

#指定内核的位置
KERNELDIR =/usr/src/kernels/2.6.31.12-174.2.3.fc12.i686.PAE/
#/home/laq/linux-2.6.32.7
# The current directory is passed to sub-makes as argument

# 表示当前源文件所在的目录
PWD := $(shell pwd)

#表示安装到哪里
INSTALLDIR=/lib/modules/$(shell uname -r)/build
#/lib/modules/2.6.31.12-174.2.3.fc12.i686.PAE/kernel/sound/core/

#表示编译器的位置
#CROSS_COMPILE=/home/tekkaman/working/crosstool-gcc410-k26222/gcc-4.1.0-glibc-2.3.2/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-
CC    = $(CROSS_COMPILE)gcc

#表示生成的目标(2.6内核的目标文件为.ko)但写还是这样的
obj-m :=hello.o

#表示编译内核模块
modules:
    $(MAKE) -w -C $(KERNELDIR) M=$(PWD) modules


#gcc -DMODULE -D__KERNEL__ -c hello1.c
modules_install:
#      cp hello.ko $(INSTALLDIR)
#安装模块 模块实际是被安装在/lib/modules/$(shell uname -r)/extra下  注意这是/lib/modules/2.6.31.12-174.2.3.fc12.i686.PAE/modules.dep还没有变化,需要执行depmod命令
    $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules_install
    depmod



#ifneq ($(KERNELRELEASE),)
#        obj-m := HelloModule.o
#else
#        KERNELDIR ?= /lib/modules/$(shell uname -r)/build
#        PWD := $(shell pwd)

#default:
#        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

#endif


clean:
    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

#一次可以执行多个
PHONY: modules modules_install clean

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值