分类: LINUX
2011-07-22 19:05:33
在arch/arm/mach-davinci/board_evm.c中有:
MACHINE_START(DAVINCI_EVM, "Dahua Product")
MAINTAINER("Dahua")
BOOT_MEM(DAVINCI_DDR_BASE, IO_PHYS, IO_VIRT)
BOOT_PARAMS(0x80000100)
MAPIO(davinci_map_io)
INITIRQ(davinci_irq_init)
.timer = &davinci_timer,
INIT_MACHINE (evm_init)
这里实际上是定义了一个struct machine_desc结构,放在.arch.info段中。MAPIO定义了machine_desc的map_io函数,INIT_MACHINE定义了 init_machine函数。这两个函数在什么时候执行呢。
MAPIO:
文件:arch/arm/kernel/setup.c
setup_arch
==> paging_init(mdesc);
文件:arch/arm/mm/mmu.c
==> paging_init
==> devicemaps_init(mdesc);
if (mdesc->map_io)
mdesc->map_io();
INIT_MACHINE:
文件:init/main.c
start_kernel
==> setup_arch(&command_line);
文件:arch/arm/kernel/setup.c
setup_arch
/*
* Set up various architecture-specific pointers
*/
init_arch_irq = mdesc->init_irq;
system_timer = mdesc->timer;
init_machine = mdesc->init_machine;
文件:arch/arm/kernel/setup.c
static int __init customize_machine(void)
{
/* customizes platform devices, or adds new ones */
if (init_machine)
init_machine();
return 0;
}
arch_initcall(customize_machine);
定义在了initcall里,所以他将和驱动程序一样在内核线程kernel_init中完成
start_kernel
==> rest_init
==*> kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND); 创建内核线程
kernel_init
==> do_basic_setup
==*> do_initcalls
static void __init do_initcalls(void)
{
initcall_t *call;
for (call = __early_initcall_end; call < __initcall_end; call++)
do_one_initcall(*call); // 将按照排序规则在相应的存储位置执行函数customize_machine()
/* Make sure there is no pending stuff from the initcall sequence */
flush_scheduled_work();
}
原文地址:http://blog.chinaunix.net/space.php?uid=14782631&do=blog&id=112127