Firefly-RK3399 第一个驱动程序编制

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
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值