1.编译kernel:
./build.sh kernel 单独编译kernel
2.配置交叉编译
export PATH=$PATH:/build/platform/rv1126_rv1109/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-
3.安装内核
cd kernel
make modules_install
4.Makefile
obj-m:= hello_world.o #填写你要编译的驱动
KDIR := /lib/modules/4.19.111/build #内核位置
PWD := $(shell pwd)
CROSS_COMPILE=arm-linux-gnueabihf- #交叉编译链
all:
make -C $(KDIR) M=$(PWD) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules
clean:
rm *.o *.ko *.mod.c
5.hello_world.c
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");//许可证
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);//加载模块时调用
module_exit(hello_exit);//卸载模块时调用
6.make
7.将编译出来的hello_world.ko放到板子上安装
insmod hello_world.ko
查看
lsmod
卸载
rmmod hello_world
demsg查看驱动的输出
[49736.581087] Hello, world
[49752.605037] Goodbye, cruel world