不知不觉,其实也已经做bsp快三年了. 有些知识点,开始大概知道一点,但是还是比较抽象的. 经过这么长时间的使用,还是觉得有必要好好整理一下的.比如module_init.
下面的code是在Android p,kernel/msm-4.14.
首先是module_init(x)函数.在kernel/msm-4.14/include/linux/module.h中:
/**
* module_init() - driver initialization entry point
* @x: function to be run at kernel boot time or module insertion
*
* module_init() will either be called during do_initcalls() (if
* builtin) or at module insertion time (if a module). There can only
* be one per module.
*/
#define module_init(x) __initcall(x);
/**
* module_exit() - driver exit entry point
* @x: function to be run when driver is removed
*
* module_exit() will wrap the driver clean-up code
* with cleanup_module() when used with rmmod when
* the driver is a module. If the driver is statically
* compiled into the kernel, module_exit() has no effect.
* There can only be one per module.
*/
#define module_exit(x) __exitcall(x);
注释中说,如果是常驻的driver,那么会在do_initcalls的时候调到module_init添加的函数.那么先看看do_initcalls怎么调过来的吧. 在kernel/msm-4.14/init/main.c中有do_initcalls(). 实际上前面还有这样的调用过程:start_kernel->rest_init->kernel_init->kernel_init_freeable->do_basic_setup->do_initcalls.
static void __init do_initcalls(void)
{
int level;
for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++)
do_initcall_level(leve