# Linux驱动测试
测试一把最简单helloworld驱动程序,了解一下驱动编程的基本概念。源文件包含两个文件:helloworld.c和Makefile
```bash
➜helloworld tree
.
├── helloworld.c
├── Makefile
1 directory, 2 files
```
helloworld.c
```c
#include
#include
static int helloworld_init(void)
{
printk("helloworld!\n");
return 0;
}
static void helloworld_exit(void)
{
printk("helloworld bye\n");
}
module_init(helloworld_init);
module_exit(helloworld_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Luckfox");
MODULE_VERSION("V1.0");
```
Makefile
```makefile
obj-m += helloworld.o
KDIR:=/home/bruce/Documents/luckfox-pico/sysdrv/source/kernel
PWD?=$(shell pwd)
MAKE := make
ARCH := arm
CROSS_COMPILE := /home/bruce/Documents/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-
KBUILD_OUTPUT := $(abspath $(dir $(lastword $(KDIR))))/objs_kernel
all:
echo KBUILD_OUTPUT = $(KBUILD_OUTPUT)
$(MAKE) O=$(KBUILD_OUTPUT) -C $(KDIR) M=$(PWD) modules ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE)
echo $(PWD)
clean:
rm -f *.ko *.o *.mod *.mod.o *.mod.c *.symvers *.order
```
编译,查看生成的文件
上传到板子测试