在Linux下编译内核模块的Makefile的简单写法

1 Makefile

新建文件,命名为Makefile,将下面的代码拷贝到文件中

#!/bin/bash

obj-m += test-demo.o 

#CROSS_COMPILE	?= /opt/linaro/gcc-linaro-5.3-2016.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-	# Compiler path settings

KERNELDIR :=/usr/src/kernel/kernel-4.4	# Kernel code directory

PWD ?= $(shell pwd)

all:
	make -C $(KERNELDIR) M=$(PWD) modules	# Compile the instructions of the kernel module

clean:                                              
	rm -rf *.ko *.mod.c *.o modules.* Module.symvers	# delete all generated files

将生成的Makefile文件复制到Linux系统下的某路径下,使其与 test-demo.c保存在同一路径下。
打开终端,进入上述路径,输入 make 命令,即可编译成对应的内核模块

 

2 Linux下.ko驱动模块管理

2.1 insmod加载驱动模块

insmod <module_name> .ko

2.2 lsmod查询驱动模块

lsmod

2.3 rmmod卸载驱动模块

rmmod <module_name> 
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值