nuc977 linux 最简单的驱动测试

32 篇文章 8 订阅

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 # 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值