1.有MMU的设备的启动过程
arch/arm/kernel/head.S
.section ".text.head", "ax"
ENTRY(stext)
msr cpsr_c, #PSR_F_BIT | PSR_I_BIT | SVC_MODE @ ensure svc mode
@ and irqs disabled
mrc p15, 0, r9, c0, c0 @ get processor id
bl __lookup_processor_type @ r5=procinfo r9=cpuid
movs r10, r5 @ invalid processor (r5=0)?
beq __error_p @ yes, error 'p'
bl __lookup_machine_type @ r5=machinfo
movs r8, r5 @ invalid machine (r5=0)?
beq __error_a @ yes, error 'a'
bl __vet_atags
bl __create_page_tables
/*
* The following calls CPU specific code in a position independent
* manner. See arch/arm/mm/proc-*.S for details. r10 = base of
* xxx_proc_info structure selected by __lookup_machine_type
* above. On return, the CPU will be ready for the MMU to be
* turned on, and r0 will hold the CPU control register value.
*/
ldr r13, __switch_data @ address to jump to after
@ mmu has been enabled
adr lr, __enable_mmu @ return (PIC) address
add pc, r10, #PROCINFO_INITFUNC
ENDPROC(stext)
执行流程
1.__lookup_processor_type:确定内核是否支持该构架
2.__lookup_machine_type:确定内核是否支持此平台
3.__create_page_tables:建立一级页表
4.__enable_mmu:使能mmu
5.__switch_data
arch/arm/kernel/head-common.S
__switch_data --> __mmap_switched --> start_kernel
2.无MMU的设备的启动过程
.section ".text.head", "ax"
.type stext, %function
ENTRY(stext)
ldr r1, =machine_arch_type @ find the machine type
msr cpsr_c, #PSR_F_BIT | PSR_I_BIT | SVC_MODE @ ensure svc mode
@ and irqs disabled
#ifndef CONFIG_CPU_CP15
ldr r9, =CONFIG_PROCESSOR_ID
#else
mrc p15, 0, r9, c0, c0 @ get processor id
#endif
bl __lookup_processor_type @ r5=procinfo r9=cpuid
movs r10, r5 @ invalid processor (r5=0)?
beq __error_p @ yes, error 'p'
bl __lookup_machine_type @ r5=machinfo
movs r8, r5 @ invalid machine (r5=0)?
beq __error_a @ yes, error 'a'
ldr r13, __switch_data @ address to jump to after
@ the initialization is done
adr lr, __after_proc_init @ return (PIC) address
add pc, r10, #PROCINFO_INITFUNC
其启动流程和上面基本相同
例子分享:
我现在移植的一个板子,是不带mmu的,刚开始怎么都启动不起来,打印出“done, booting the kernel",然后就无声无息了。后来在Kernel startup entry point开始处的ENTRY(stext)下添加了句代码:
”ldr r1, =machine_arch_type“就很顺利得起来了.后来分析知道,添加这句代码后就不会进行平台的匹配了!但是启动以后也是正常的!不知道此处平台匹配的真正意义是什么,还需要与有经验的朋友共同探讨。
xin.jin