RV1126 驱动模块编译安装

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值