基于s3c6410开发板helloworld驱动模块开发

本文介绍了一个简单的Linux内核模块开发实例,包括源代码和Makefile配置。通过具体步骤展示了如何在特定开发环境中编译和运行模块,同时解决了一些常见的编译错误及模块加载问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【开发环境】
PC:win7 x64
VMware:Ubuntu14.04
s3c6410开发板:linux-2.6.28.6

【源代码】
hello.c
---------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Defining __KERNEL__ and MODULE allows us to access kernel-level code not usually available to userspace programs.
#undef __KERNEL__ //为了引用内核数据结构
#define __KERNEL__
  
#undef MODULE
#define MODULE

// Linux Kernel/LKM headers: module.h is needed by all modules and kernel.h is needed for KERN_INFO.
#include <linux/module.h>     // included for all kernel modules
#include <linux/kernel.h>     // included for KERN_INFO
#include <linux/init.h>         // included for __init and __exit macros

MODULE_LICENSE("Dual BSD/GPL");

static int __init hello_init(void)
{
    printk(KERN_INFO "Hello world!\n");
    return 0;     //Non-zero return means that the module couldn't be loaded
}
  
static void __exit hello_cleanup(void)
{
    printk(KERN_INFO "Cleaning up module! this is exit\n");
}
  
module_init(hello_init);
module_exit(hello_cleanup);

MODULE_AUTHOR("andrew yue");  
MODULE_DESCRIPTION("A hello word module for testing module parameters");  
MODULE_VERSION("V1.0");  

Makefile
---------------------------------------------------------------------------------------------------------------
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else 
KDIR := /home/yzli/yzli_lib/s3c-linux-2.6.28.6-TOP6410//移植的linux源码目录

all:
make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=/home/yzli/yzli_lib/arm-2008q3/bin/arm-none-linux-gnueabi-//交叉编译路径

clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers

endif


【问题】
1.error: linux/bounds.h: No such file or directory
-------------------------------------------------------------------------------------
在linux-2.6.28.6源码目录,执行make重新编译一遍(拷贝过来,未编译过)。

2.执行模块卸载时(rmmod hello)提示"rmmod: module 'hello' not found",其实模块已经卸载
---------------------------------------------------------------------------------------------------------------------------
个人理解,是由于移植文件系统时,编译busybox的原因,暂不考虑。详见
http://www.cnblogs.com/feisky/archive/2010/05/29/1746888.html

3.编译后的驱动模块是hello.ko,加载和卸载模块操作如下
-------------------------------------------------------------------------------
加载模块:insmod hello.ko
卸载模块    rmmod hello

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值