2023-07-08 Understanding Linux Kernel Module Basic Concepts

#include <linux/module.h>

#include <linux/init.h>

static int __init helloworld_init(void) {

pr_info("Hello world initialization!\n");

return 0;

}

static void __exit helloworld_exit(void) {

pr_info("Hello world exit\n");

}

module_init(helloworld_init);

module_exit(helloworld_exit);

MODULE_LICENSE("GPL");? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// GPL (General Public License)

MODULE_AUTHOR("John Madieu <john.madieu@gmail.com>");

MODULE_DESCRIPTION("Linux kernel module skeleton");

模塊骨架代碼

模塊加載:modprobe or insmod? 卸載:rmmod or? modprobe -r

MODULE_INFO(my_field_name, "What easy value");


kbuild? ?Kconfig? ?Makefile

內(nèi)核模塊構建命令模式類似于如下: make -C $KERNEL_SRC M=$(shellpwd)[目標]??????????

Makefile:

# kbuild part of makefile

obj-m := helloworld.o

#the following is just an example

#ldflags-y := -T foo_sections.lds

# normal makefile

KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build

all default: modules

install: modules_install

modules modules_install help clean:

$(MAKE) -C $(KERNEL_SRC) M=$(shell pwd) $@


報錯?Makefile:10: *** missing separator. Stop.? 第十行命令必須以tab鍵開頭,解決



Out-of-tree module cross-compiling

https://blog.csdn.net/Tdh5258/article/details/108501265? ? 可以參考!

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容