简单字符设备驱动编写,可传参,在内核之外编译

驱动程序:hello.c


#include 
#include 
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Hanson He");

static char *whom = "world";
static int howmany = 5;

static int hello_init(void)
{
	int i;
	for(i=0;i

Makefile:Makefile

ifeq ($(KERNELRELEASE),)
KERNELDIR ?=/home/user/kernel  #内核所在目录

#当前Makefile所在目录
PWD := $(shell pwd)	

#	-C $(KERNELDIR)指明跳转到内核源码目录下读取那里的Makefile
#	M=$(PWD) 表明然后返回到当前目录继续读入、执行当前的Makefile
modules:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

modules_install:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install

clean:
	rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

.PHONY: modules modules_install clean

else
    obj-m := hello.o
endif

Makefile相关解释,点击打开链接


make之后把hello.ko 通过网线tftp下载到开发板上,通过下面命令运行(带参数):

    insmod hello.ko  whom=Students   howmany=5

你可能感兴趣的:(ARM学习笔记)