Firefly-RK3399第一个驱动程序编制
编写程序 hello_module.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("ZWWANG");
static int hello_init(void)
{
printk(KERN_EMERG "HELLO WORLD enter!\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_EMERG "HELLO WORLD exit!\n");
}
module_init(hello_init);
module_exit(hello_exit);
编写Makefile
#!/bin/bash
CROSS_COMPILE:= aarch64-linux-gnu-
ARCH:= arm64
CC:= $(CROSS_COMPILE)gcc
LD:= $(CROSS_COMPILE)ld
obj-m += hello_module.o
KERNELDIR := /home/zwwang/sdk/linux-sdk/kernel
all:
make -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -f *.o
rm -f *.symvers
rm -f *.order
rm -f *.ko
rm -f *.mod.c
编译
在hello_module 的文件夹下使用
make
编译程序
结果:
make -C /home/zwwang/sdk/linux-sdk/kernel M=/home/zwwang/testDriver/hello_mod modules
make[1]: Entering directory '/home/zwwang/sdk/linux-sdk/kernel'
CC [M] /home/zwwang/testDriver/hello_mod/hello_module.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/zwwang/testDriver/hello_mod/hello_module.mod.o
LD [M] /home/zwwang/testDriver/hello_mod/hello_module.ko
make[1]: Leaving directory '/home/zwwang/sdk/linux-sdk/kernel'
查看目录中已经产生
hello_module.ko
执行
把ko文件放入目标主机
加载模块
sudo insmod hello_module.ko
查看模块
cat /proc/modules
或
lsmod
卸载模块
sudo rmmod hello_module