1.建立drv_hello.c
#include <linux/init.h>
#include <linux/module.h>
static int __init nuc977_hello_init(void)
{
printk("nuc977_hello_init() \r\n");
return 0;
}
static void __exit nuc977_hello_exit(void)
{
printk("nuc977_hello_exit()\r\n");
}
module_init(nuc977_hello_init);
module_exit(nuc977_hello_exit);
MODULE_LICENSE("GPL");
2.Makefile文件如下:
obj-m := drv_hello.o
PWD := $(shell pwd)
KDIR ?= /home/hbin/nuc977_bsp/nuc970bsp/linux-3.10.x
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
rm -rf .*.cmd *.o *.mod.c *.ko
3.以上兩個文件用fpt傳到 /home/hbin/nfs/driver/drv_hello/
4.make
.
5.啓動開發板SecureCRT 調試
~ # ifconfig eth0 192.168.0.4 up
nuc970-emac0 nuc970-emac0: eth0 is OPENED
~ # mount -t nfs -o nolock 192.168.0.199:/home/hbin/nfs/ /mnt
~ # cd /mnt
/mnt # ls
app driver rootfs_hb
/mnt # cd driver
/mnt/driver # ls
drv_hello drv_led
/mnt/driver # cd drv_hello/
/mnt/driver/drv_hello # cp drv_hello.ko /lib/modules/
/mnt/driver/drv_hello # insmod drv_hello.ko
nuc977_hello_init()
/mnt/driver/drv_hello # rmmod drv_hello.ko
rmmod: can't change directory to '3.10.101': No such file or directory
/mnt/driver/drv_hello # cd /lib/modules/
/lib/modules # mkdir 3.10.101
/lib/modules # rmmod drv_hello.ko
/lib/modules #