内核启动的第一阶段:
这个阶段主要是处理uboot传入的参数
我们从分析第一个 arch/arm/kernel/head.S 汇编程序开始: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 //判断是否支持cpu
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 __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//跳到第一个c函数
@ mmu has been enabled
adr lr, __enable_mmu @ return (PIC) address //使能mmu
add pc, r10, #PROCINFO_INITFUNC
第一个阶段主要是汇编代码,第二阶段开始进入c语言。
内核启动的第二阶段:
这个阶段主要是初始化程序,挂接根文件系统,最终启动应用程序
start_kernel
setup_arch(&command_line); //解析uboot启动参数
setup_command_line(command_line); //解析uboot启动参数
rest_init //启动init过程
kernel_init
prepare_namespace
mount_root //挂接根文件系统
init_post
//执行应用程序