"); //-->
Uclinux Hello Module Drivers
By panasonic.lin@163.com
由于linux2.4和linux2.6的区别,ldd第三版讲的都是linux2.6内核的驱动,linux2.4最好参考ldd第二版的。
linux2.6中,hello模块的Makefile:
obj-m := hello.o
然后只需在此目录下执行:
make -C /<your 2.6 kernel's dir> M=`pwd` modules
下面是linux2.4内核的方法,也适用uclinux2.4
1.新建目录hello,建立hello.c和Makefile如下
/*
* $Id: hello.c,v 1.5 2009/10/26 03:32:21 $
*/
#ifndef MODULE
#define MODULE
#endif
#ifndef __KERNEL__
#define __KERNEL__
#endif
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello,Uclinux world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, Uclinux world\n");
}
module_init(hello_init);
module_exit(hello_exit);
/**********************************************************************************/
/* $Id: Makefile,v 1.5 2009/10/26 03:32:21 $ */
/***********************************************************************************/
# Change it here or specify it on the "make" command line
CC=arm-elf-gcc
KERNELDIR = /home/panasonic/Data/uClinux-dist20050311/linux-2.4.x
#include $(KERNELDIR)/.config
CFLAGS = -D__KERNEL__ -DMODULE -I$(KERNELDIR)/include -O -Wall
all: hello.o
hello.o:hello.c
$(CC) $(CFLAGS) -c hello.c
clean:
rm -f hello.o
2.配置内核,Enable loadable module support,然后重新make生成uclinux_rom.bin,然后再拷贝到tftp下载目录。
3.配置busybox支持insmod,lsmod,rmmod命令,然后make dep,make user_only,make romfs生成romfs目录,把里面bin目录下的文件拷贝到nfs根目录下的bin,因为我们仅仅是比以前多了module的几个程序而已,其他东西大可不必要动。
4.准备好内核和根文件系统后,只需在hello目录下执行make生成hello.o,把它拷贝到nfs文件系统的任意位置。
5.打开minicom,
$tftpboot 0xc500000下载内核到内存0xc500000
$bootm 0xc500000启动内核
如果出现如下错误提示,需要在lib目录新建modules/内核版本目录
# insmod ./hello.o
# lsmod
# rmmod hello
rmmod: chdir(2.x.x): No such file or directory
# cd /
# mkdir -p /lib/modules/`uname -r`
# rmmod hello
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。