(转郭任前辈)uClinux驱动开发入门

来源:百度文库 编辑:神马文学网 时间:2024/04/27 18:31:25
Tag:

下面还是从"linux Device Driver"中经典的hello开始:

cd linux-2.6.x/drivers/misc/

在drivers/misc下 vi hello.c

#include linux/init.h>
#include linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);

在drivers/misc/Kconfig中,在"menuconfig"中添加以下代码:

config HELLO
tristate "example hello module"
help
Enable example hello module.

在drivers/misc/Makefile中添加:

obj-$(CONFIG_HELLO) += hello.o

在内核配置中打开如下选项:

Loadable module support -->
[*] Enable loadable module support
[*] Module unloadingDevice Drivers -->
Misc devices --->
example hello module[/quote]

In apps selection of uClinux-dist,
Busybox -->

[*] insmod
[*] insmod: lsmod
[*] insmod: modprobe
[*] insmod: rmmod
[ ] insmod: Pre 2.1 kernel modules
[ ] insmod: 2.1 - 2.4 kernel modules
[*] insmod: 2.6 and above kernel modules
[ ] insmod: Model version checks
[ ] insmod: Support tainted module checking with new kernels

然后make,make linux image,hello.ko会在romfs/lib/modules目录下

用modprobe hello测试。

注意要保证最早的make成功

* 下面介绍如何单独编译hello.ko

在上面的编译成功后,以后就可以单独进行编译了:

在drivers/misc/下执行:

make ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- -C../../linux-2.6.x M=`pwd` modules

nios2-linux-uclibc-strip -R .comment -R .note -g --strip-unneededhello.ko

接下来,你可以使用NFS,通过网络直接进行,insmod hello,rmmod hello