2. 3. 4. 5. 6. 7. 8.
GENERATED += \\
$(BUILDDIR)/system-onesegment.ld\\ $(BUILDDIR)/system-twosegment.ld
# rules for generating the linker scripts …
$(BUILDDIR)/system-onesegment.ld:$(LOCAL_DIR)/system-onesegment.ld 9. @echogenerating $@ 10. @$(MKDIR)
11. $(NOECHO)sed\$(MEMSIZE)/\
12. $(BUILDDIR)/system-twosegment.ld:$(LOCAL_DIR)/system-twosegment.ld
13. @echogenerating $@ 14. @$(MKDIR)
15. $(NOECHO)sed\$(MEMBASE)/;s/%MEMSIZE%/$(MEMSIZE)/\ 接着看\\bootable\\bootloader\\lk\\arch\\arm\\system-onesegment.ld文件 [plain] view plain copy 1. OUTPUT_FORMAT(\ 2. OUTPUT_ARCH(arm) 3. 4. ENTRY(_start)
system-onesegment.ld连接文件中 ENTRY(_start0指定 LK 从_start 函数开始,_start 在 lk/arch/arm/crt0.S中 。crt0.S 主要做一些基本的 CPU 的初始化再通过 bl kmain ;跳转到 C 代码中。 kmain 在lk/kernel/main.c 中
kmain()
1. thread_init_early()
// get us into some sort of thread context
thread_init_early();
让我们进入某种线程上下文,初始化线程系统,此函数只被调用一次。主要的工作如下:
(1) 初始化运行队列list_initialize(&run_queue[i])
(2) 初始化线程列表list_initialize(&thread_list)
(3) 创建一个线程来覆盖当前的运行状态,并初始化次线程的结构体。
/* create a thread to cover the currentrunning state */ thread_t*t = &bootstrap_thread; init_thread_struct(t,\
/* half construct this thread, since we'realready running */ t->priority= HIGHEST_PRIORITY; t->state= THREAD_RUNNING; t->saved_critical_section_count= 1;
list_add_head(&thread_list,&t->thread_list_node); current_thread= t;
2. arch_early_init()
做一些关闭cache,使能MMU的arm相关工作。
void arch_early_init(void) {
/*turn off the cache */ arch_disable_cache(UCACHE);
/*set the vector base to our exception vectors so we dont need to double map at 0*/ #if ARM_WITH_MMU arm_mmu_init();
#endif
/*turn the cache back on */ arch_enable_cache(UCACHE);
#if ARM_WITH_NEON /*enable cp10 and cp11 */ uint32_tval;
__asm__volatile(\val|= (3<<22)|(3<<20);
__asm__volatile(\
/*set enable bit in fpexc */
__asm__volatile(\val|= (1<<30);
__asm__volatile(\
#endif }
3. platform_early_init()
平台的早期初始化
void platform_early_init(void) {
board_init();
platform_clock_init(); qgic_init(); qtimer_init(); }
3.1 board_init()
void board_init() {
platform_detect();
target_detect(&board);//对于msm8909是空函数,在platform_detect()实现 target_baseband_detect(&board);//填充board->baseband = BASEBAND_MSM; }
platform_detect()
Smem:共享内存
struct smem {
structsmem_proc_comm proc_comm[4]; unsignedversion_info[32]; structsmem_heap_info heap_info;
structsmem_alloc_info alloc_info[SMEM_MAX_SIZE]; };
共享内存对应的结构体
SMEM :sharedmemory,是高通平台各子系统共享信息的一种机制,通过SMEM机制,PBL可以将信息传递给SBL1,SBL1可以将信息传递给RPM、LK。下面分析一个SMEM信息传递的具体实现过程。
Platform id信息
SBL1会将board levelplatform id信息通过SMEM机制保存,LK在启动过程中会自动platform detect,检测当前平台board infor信息,然后填充board结构体实例的值
struct board_data { uint32_tplatform; uint32_tfoundry_id; uint32_tplatform_version; uint32_tplatform_hw; uint32_tplatform_subtype;