在驱动程序中,我经常看到使用这三种类型的 init 函数。
module_init()
core_initcall()
early_initcall()
请您参考如下方法:
module_init 用于标记要用作 Linux 设备驱动程序入口点的函数。
它被称为
do_initcalls() 期间(对于内置驱动程序)或
*.ko 模块)可以有 只有 1
module_init() 每个驱动模块。
*_initcall()函数通常用于设置函数指针以初始化各种子系统。
do_initcalls() within Linux kernel source code包含对各种 initcall 列表的调用以及在 Linux 内核启动期间调用它们的相对顺序。
early_initcall() core_initcall() postcore_initcall() arch_initcall() subsys_initcall() fs_initcall() device_initcall() late_initcall() 内置模块结束modprobe或 insmod的 *.ko模块。 使用
module_init() 在设备驱动程序中是
equivalent to registering a device_initcall() .
请记住,在编译期间,在 Linux 内核中链接各种驱动程序目标文件(
*.o )的顺序很重要;它决定了它们在运行时被调用的顺序。
*_initcallfunctions of the same level
will be called during boot in the order they are linked.
例如更改
drivers/scsi/Makefile 中 SCSI 驱动程序的链接顺序将更改检测 SCSI Controller 的顺序,从而更改磁盘的编号。

