bugsplat


1)实验平台:正点原子Linux开发板2)摘自《正点原子I.MX6U嵌入式Linux驱动开发指南》

bugsplat

文章插图



看完Linux内核的顶层Makefile以后再来看Linux内核的大致启动流程,Linux内核的启动流程要比uboot复杂的多,涉及到的内容也更多,因此本章我们就大致的了解一下Linux内核的启动流程 。


36.1 链接脚本vmlinux.lds要分析Linux启动流程,同样需要先编译一下Linux源码,因为有很多文件是需要编译才会生成的 。首先分析Linux内核的连接脚本文件
arch/arm/kernel/vmlinux.lds,通过链接脚本可以找到Linux内核的第一行程序是从哪里执行的 。vmlinux.lds中有如下代码:
示例代码36.1.1 vmlinux.lds链接脚本
492 OUTPUT_ARCH(arm)
493 ENTRY(stext)
494 jiffies = jiffies_64;
495 SECTIONS
496{
497/*
498 * XXX: The linker does not define how output sections are
499 * assigned to input sections when there are multiple statements
500 * matching the same input section name. There is no documented
501 * order of matching.
502 *
503 * unwind exit sections must be discarded before the rest of the
504 * unwind sections get included.
505 */
506 /DISCARD/:{
507 *(.ARM.exidx.exit.text)
508 *(.ARM.extab.exit.text)
509
......
645}
第493行的ENTRY指明了了Linux内核入口,入口为stext,stext定义在文件arch/arm/kernel/head.S中,因此要分析Linux内核的启动流程,就得先从文件arch/arm/kernel/head.S的stext处开始分析 。
36.2 Linux内核启动流程分析36.2.1 Linux内核入口stextstext是Linux内核的入口地址,在文件arch/arm/kernel/head.S中有如下所示提示内容:
示例代码36.2.1.1 arch/arm/kernel/head.S代码段
/*
* Kernel startup entry point.
* ---------------------------
*
* This is normally called from the decompressor code. The requirements
* are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0,
* r1 = machine nr, r2 = atags or dtb pointer.
.....
*/
根据示例代码36.2.1.1中的注释,Linux内核启动之前要求如下:
①、关闭MMU 。
②、关闭D-cache 。
③、I-Cache无所谓 。
④、r0=0 。
⑤、r1=machinenr(也就是机器ID) 。
⑥、r2=atags或者设备树(dtb)首地址 。
Linux内核的入口点stext其实相当于内核的入口函数,stext函数内容如下:
示例代码36.2.1.2 arch/arm/kernel/head.S代码段
80 ENTRY(stext)
......
91 @ ensure svc mode and all interrupts masked
92 safe_svcmode_maskall r9
93
94 mrc p15,0, r9, c0, c0 @ get processor id
95 bl __lookup_processor_type @ r5=procinfo r9=cpuid
96 movs r10, r5 @ invalid processor (r5=0)?
97 THUMB( it eq ) @ force fixup-able long branch encoding
98 beq __error_p @ yes, error \'p\'
99
......
107
108 #ifndef CONFIG_XIP_KERNEL
......
113 #else
114 ldr r8,=PLAT_PHYS_OFFSET @ always constant in this case
115 #endif
116
117/*
118 * r1 = machine no, r2 = atags or dtb,
119 * r8 = phys_offset, r9 = cpuid, r10 = procinfo
120 */
121 bl __vet_atags
......
128 bl __create_page_tables
129
130/*
131 * The following calls CPU specific code in a position independent
132 * manner. See arch/arm/mm/proc-*.S for details. r10 = base of
133 * xxx_proc_info structure selected by __lookup_processor_type
134 * above. On return, the CPU will be ready for the MMU to be
135 * turned on, and r0 will hold the CPU control register value.
136 */
137 ldr r13,=__mmap_switched @ address to jump to after


特别声明:本站内容均来自网友提供或互联网,仅供参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。