nuc977 linux 最简单的驱动测试

1.建立drv_hello.c

#include 
#include 


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

.nuc977 linux 最简单的驱动测试_第1张图片

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 # 

 

你可能感兴趣的:(NUC977,Linux)