target //通用init.c,具体目标板的初始化(主要为板子设备资源init.c代码中),编译规则代码(一级s810.mk二级hdc8094.mk)
====================程序执行流程============================
主函数lk/kernel/main.c
/* called from crt0.S */
void kmain(void) __NO_RETURN __EXTERNALLY_VISIBLE;
void kmain(void) //从kmain函数开始执行
{
thread_init_early(); //
线程初始化
arch_early_init();
//平台体系x86或者arm初始化,类似uboot的第一阶段汇编,在arch/arm下面实现
实现功能:关闭cache,设置异常向量,mmu初始化,打开cache
// do any super early platform initialization
platform_early_init();----> //开始涉及到具体平台
void platform_early_init(void)
board_init(); //目标平台板的初始化
platform_clock_init(); //平台时钟初始化msm8994_clock
// do any super early target initialization
target_early_init(); //只初始化串口为了打印信息,与后面的target_init对应
以上采用层层递进的关系进行初始化
dprintf(INFO, "welcome to lk\n\n"); //开始进入LK,INFO级别在console打印
// initialize the threading system
dprintf(SPEW, "initializing threads\n");
//SPEW级别在console口不打印
thread_init();
// initialize the dpc system
dprintf(SPEW, "initializing dpc\n");
dpc_init();
// initialize kernel timers
dprintf(SPEW, "initializing timers\n");
timer_init();
// create a thread to complete system initialization -->创建线程完成系统初始化,跳转到第二阶段
dprintf(SPEW, "creating bootstrap completion thread\n");
/*jump to bootstrap2*/
thread_resume(thread_create("bootstrap2", &bootstrap2, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE));
// become the idle thread //变成空闲线程
thread_become_idle();
}
static int bootstrap2(void *arg)
{
platform_init(); --->
void platform_init(void) //msm8994
dprintf(INFO, "platform_init()\n");
scm_xpu_err_fatal_init();
target_init(); //各种板子资源初始化,mmc,sdc,usb,volumn等---->
//里面最重要的是mmc的初始化
target_sdc_init();
//还有RPM
rpm_smd_init();
dprintf(SPEW, "calling apps_init()\n");//app初始化以及启动app
apps_init();//开始执行app/aboot.c中的aboot_init函数
}
接下来开始执行app/aboot/aboot.c
在amboot.c的源码最底端:
APP_START(aboot) //可以看出上述的app启动的第一个就是aboot_init
.init = aboot_init,
APP_END
/* each app needs to define one of these to define its startup conditions */每个app需要的定义
struct app_descriptor {
const char *name;
app_init init;
app_entry entry;
unsigned int flags;
};
开始研究aboot_init函数:
void aboot_init(const struct app_descriptor *app)
{
/* Setup page size information for nv storage */首先判断从哪启动emmc还是flash
if (target_is_emmc_boot())
{
page_size = mmc_page_size();
page_mask = page_size - 1;
}
else
{
page_size = flash_page_size();
page_mask = page_size - 1;
}
read_device_info(&device); //读取设备信息
/* Display splash screen if enabled */
#if DISPLAY_SPLASH_SCREEN //初始化显示屏
dprintf(SPEW, "Display Init: Start\n");
target_display_init(device.display_panel);
dprintf(SPEW, "Display Init: Done\n");
#endif
target_serialno((unsigned char *) sn_buf); //获取串口号
dprintf(SPEW,"serial number: %s\n",sn_buf);
memset(display_panel_buf, '\0', MAX_PANEL_BUF_SIZE);