linux核心模組學習筆記

來源:互聯網
上載者:User


linux核心模組學習筆記 ########## Makefile ##########obj-m := modname.o編譯完會有modname.ko目前的目錄下必須有modname.[c/s/S]檔案obj-m的值有多少個*.o就會有多少個*.ko ++++++++++++++++++++++++++++++多檔案:obj-m := modname.omodname-objs := 1.o 2.o ...編譯完的modname.o由modname-objs的所有*.o產生 ***不會編譯目前的目錄下的modname.[c/s/S]檔案########## 模組命令 ##########insmod modname.ko or modprobe modname 用modprobe命令需要把模組安裝到檔案系統lsmod [modname]  or cat /proc/modulesrmmod module_name  or modprobe -r modnamemodinfo modname.ko########## 模組基本結構 ##########include <linux/init.h>include <linux/module.h>static int __init test_init(void){        printk("hello test init!!!\n");        return 0;}static void __exit test_exit(void){        printk("hello test exit!!!\n");}module_init(test_init);module_exit(test_exit);MODULE_LICENSE("GPL");MODULE_AUTHOR("...");MODULE_DESCRIPTION("...");  www.2cto.com  ########## 模組參數 ##########type var_name;module_param(var_name, type, perm);   insmod modname.ko var_name=value++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++int num = SIZE;type var_name[SIZE];module_param_array(var_name, type, &num, perm);  insmod modname.ko var_name=val0, val1, val2, ..., valSIZE++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++var_name: 變數(必須是全域)type:  byte  short  ushort  int  uint  long  ulong  charp  bool  invboolperm: 指定/sys/module/$(modname)/parameters/$(param_name)檔案的許可權(該檔案的內容為var_name的值) --->>  kernel/include/linux/stat.h:50 0 --->(沒有相對應的檔案) S_IRWXUGO S_IALLUGO S_IRUGO S_IWUGO S_IXUGO &num: 參數長度指標(必須是全域)  www.2cto.com  ########## 符號匯出 ##########EXPORT_SYMBOL(symbol_name);核心---->核心 or 模組A---->模組A 不需要匯出符號模組---->核心 or 模組A---->模組B 只能使用對方已匯出的符號核心---->模組    不管模組符號是否匯出都不能使用 ########## printk ##########層級: include/linux/printk.h:9cat /proc/sys/kernel/printkecho a [b]  > /proc/sys/kernel/printk a: 層級小於a的訊息將會列印到控制台b: 預設層級

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.