设备驱动开发_2

编译和调试

主要内容

  • 写一个可加载模块
  • 编译和加载一个可加载模块
  • 使用printk 进行跟踪和调试
  • 使用跟踪和调试

1 写一个可加载模块

内核头文件 linux/module.h
module_init(e1000_init_module)
static int __init e1000_init_module(void)
module_exit (e1000_exit_module)
static void _exit e1000_exit_module(void)

tan@ubuntu:~/samba_workspaces/linux-5.4.26$ cat -n ./include/linux/module.h   | grep "module_init("
    78   * module_init() - driver initialization entry point
    81   * module_init() will either be called during do_initcalls() (if
    85  #define module_init(x)  __initcall(x);
   108  #define early_initcall(fn)              module_init(fn)
   109  #define core_initcall(fn)               module_init(fn)
   110  #define core_initcall_sync(fn)          module_init(fn)
   111  #define postcore_initcall(fn)           module_init(fn)
   112  #define postcore_initcall_sync(fn)      module_init(fn)
   113  #define arch_initcall(fn)               module_init(fn)
   114  #define subsys_initcall(fn)             module_init(fn)
   115  #define subsys_initcall_sync(fn)        module_init(fn)
   116  #define fs_initcall(fn)                 module_init(fn)
   117  #define fs_initcall_sync(fn)            module_init(fn)
   118  #define rootfs_initcall(fn)             module_init(fn)
   119  #define device_initcall(fn)             module_init(fn)
   120  #define device_initcall_sync(fn)        module_init(fn)
   121  #define late_initcall(fn)               module_init(fn)
   122  #define late_initcall_sync(fn)          module_init(fn)
   124  #define console_initcall(fn)            module_init(fn)
   126  /* Each module must use one module_init(). */
   127  #define module_init(initfn)                                     \
   546  static inline bool within_module_init(unsigned long addr,
   555          return within_module_init(addr, mod) || within_module_core(addr, mod);
   725  static inline bool within_module_init(unsigned long addr,

module_init(e1000_init_module);

/**
 * e1000_exit_module - Driver Exit Cleanup Routine
 *
 * e1000_exit_module is called just before the driver is removed
 * from memory.
 **/
static void __exit e1000_exit_module(void)
{
   
   
        pci_unregister_driver(&e1000_driver);
}
module_exit(e1000_exit_module);

MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
MODULE_LICENSE("GPL v2");
MODULE_VERSION(DRV_VERSION);
"drivers/net/ethernet/intel/e1000e/netdev.c" 7927L, 227450C 

2 编译和加载一个可加载模块

obj-m
cat skeleton.c
cat makefile.1
cat makefile.2 —> 多文件 指向内核参数
/lib/modules/uname -r/build M= P W D m o d u l e s l n − s f m a k e f i l e . 1 m a k e f i l e m a k e − C / l i b / m o d u l e s / ‘ u n a m e − r ‘ / b u i l d M = PWD modules ln -sf makefile.1 makefile make -C /lib/modules/`uname -r`/build M= PWDmoduleslnsfmakefile.1mak

相关推荐

  1. 设备驱动开发_2

    2024-02-17 06:18:03       46 阅读
  2. 设备驱动开发_1

    2024-02-17 06:18:03       53 阅读
  3. Linux驱动开发——(十)MISC设备驱动

    2024-02-17 06:18:03       36 阅读
  4. Linux驱动开发之杂项设备注册和Linux2.6设备注册

    2024-02-17 06:18:03       40 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-17 06:18:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-17 06:18:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-17 06:18:03       82 阅读
  4. Python语言-面向对象

    2024-02-17 06:18:03       91 阅读

热门阅读

  1. SpringBoot后端Long数据传到前端js精度损失问题

    2024-02-17 06:18:03       57 阅读
  2. 力扣:122. 买卖股票的最佳时机 II

    2024-02-17 06:18:03       51 阅读
  3. 【前端工程化面试题】说一下 webpack 的构建流程

    2024-02-17 06:18:03       65 阅读
  4. 使用 C++23 从零实现 RISC-V 模拟器(6):权限支持

    2024-02-17 06:18:03       44 阅读
  5. python自动定时任务schedule库的使用方法

    2024-02-17 06:18:03       54 阅读
  6. 搜索引擎枚举

    2024-02-17 06:18:03       58 阅读
  7. ACP科普:敏捷开发之kanban

    2024-02-17 06:18:03       45 阅读
  8. OpenAI 生成视频模型 Sora 论文翻译

    2024-02-17 06:18:03       46 阅读