完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
一、编写程序
新建文件夹 hello_module,创建hello_module.c文件,代码内容为: #include #include MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("SONGJL"); static int hello_init(void) { printk(KERN_EMERG "HELLO WORD SJL ENTER!n"); return 0; } static void hello_exit(void) { printk(KERN_EMERG "HELLO WORD EXIT!n"); } module_init(hello_init); module_exit(hello_exit); 创建Makefile文件,内容为: #!/bin/bash CROSS_COMPILE:= /home/forlinx/OK3399/OK3399-linux-release/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- ARCH:= arm64 CC:= $(CROSS_COMPILE)gcc LD:= $(CROSS_COMPILE)ld PWD:= $(shell pwd) obj-m := hello_module.o KERNELDIR:= /home/forlinx/OK3399/OK3399-linux-release/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/forlinx/OK3399/OK3399-linux-release/kernel M=/home/project/hellomodule modules make[1]: Entering directory '/home/forlinx/OK3399/OK3399-linux-release/kernel' WARNING: Symbol version dump ./Module.symvers is missing; modules will have no dependencies and modversions. CC [M] /home/project/hellomodule/hello_module.o Building modules, stage 2. MODPOST 1 modules CC /home/project/hellomodule/hello_module.mod.o LD [M] /home/project/hellomodule/hello_module.ko make[1]: Leaving directory '/home/forlinx/OK3399/OK3399-linux-release/kernel' 查看目录下会发现: root@sjl-virtual-machine:/home/project/hellomodule# ls hello_module.c hello_module.ko hello_module.mod.c hello_module.mod.o hello_module.o Makefile modules.order Module.symvers 三、执行 将ko文件放入目标板内,可以通过HTTP Server.exe 或者TFTP将文件上传。 加载模块 sudo insmod hello_module.ko 查看模块 cat /proc/modules 或 lsmod 卸载模块 sudo rmmod hello_module 四、注意事项 编译过程中可能会报错 1、Makefile 文件编辑出错,回车键,还有tab键。可以在Linux环境下编写避免错误。 2、报这个错误 make[1]: Entering directory '/home/forlinx/OK3399/OK3399-linux-release/kernel' ERROR: Kernel configuration is invalid. include/generated/autoconf.h or include/config/auto.conf are missing. Run 'make oldconfig && make prepare' on kernel src to fix it. WARNING: Symbol version dump ./Module.symvers is missing; modules will have no dependencies and modversions. CC [M] /home/project/hellomodule/hello_module.o In file included from ././include/linux/kconfig.h:4:32: fatal error: generated/autoconf.h: No such file or directory #include ^ compilation terminated. scripts/Makefile.build:283: recipe for target '/home/project/hellomodule/hello_module.o' failed 解决办法:重新编译一下内核就好了。 |
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
谁有3566+电池+POE充电的方案,有个项目需要用该功能的主板
437 浏览 0 评论
RK3588的GMAC0与PHY的参考时钟电平匹配问题??????
4425 浏览 1 评论
请问各位大佬,如何解决,瑞芯微 RV1126B 使用 mpp 自带工具 调试时,内核直接报错崩溃!
1802 浏览 0 评论
使用rk3568开发板,核0\\1\\3运行linux,核2运行hal,在核0中怎么关闭核2
2359 浏览 0 评论
2363 浏览 0 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 06:54 , Processed in 0.579530 second(s), Total 41, Slave 34 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2293