我们都知道在启动的时候会先跑lk(little kernel),然后才会跑kernel,在某些场景下我们需要修改lk里面的东西。所以就去简单的看了一下,在启动的时候lk做什么事了。
代码路径:
bootable/bootloader/lk/app/aboot/aboot.c
进入后从aboot_init()开始:
1.target_display_init(device.display_panel);
这是在lk中对显示相关的初始化等,这部分没问题的话,开机时就可以看到开机log。
2.正常启动
if (is_user_force_reset())
goto normal_boot;
normal_boot:
if (!boot_into_fastboot)
{
if (target_is_emmc_boot())
{
if(emmc_recovery_init())
dprintf(ALWAYS,"error in emmc_recovery_init\n");
if(target_use_signed_kernel())
{
if((device.is_unlocked) || (device.is_tampered))
{
#ifdef TZ_TAMPER_FUSE
set_tamper_fuse_cmd();
#endif
#if USE_PCOM_SECBOOT
set_tamper_flag(device.is_tampered);
#endif
}
}
boot_linux_from_mmc();
}
else
{
recovery_init();
#if USE_PCOM_SECBOOT
if((device.is_unlocked) || (device.is_tampered))
set_tamper_flag(device.is_tampered);
#endif
boot_linux_from_flash();
}
dprintf(CRITICAL, "ERROR: Could not do normal boot. Reverting "
"to fastboot mode.\n");
}
可以看到,当boot_into_fastboot = false时,系统还不会正常启动,这里会判断是否进入升级模式或者外部。
如果target_is_emmc_boot()返回1,就可以从emmc正常启动了。
boot_linux_from_mmc();
如果target_is_emmc_boot()返回0,就会进入升级模式了。
recovery_init();
boot_linux_from_flash();
3.组合键的作用:
(1)音量减键和音量加键同时按下进入下载模式(没有试过):
if (keys_get_state(KEY_VOLUMEUP) && keys_get_state(KEY_VOLUMEDOWN))
{
dprintf(ALWAYS,"dload mode key sequence detected\n");
if (set_download_mode(EMERGENCY_DLOAD))
{
dprintf(CRITICAL,"dload mode not supported by target\n");
}
else
{
reboot_device(DLOAD);
dprintf(CRITICAL,"Failed to reboot into dload mode\n");
}
boot_into_fastboot = true;
}
(2)按下home键或者音量减键进入recovery模式,按下返回键或者音量减键进入fastboot模式
if (!boot_into_fastboot)
{
if (keys_get_state(KEY_HOME) || keys_get_state(KEY_VOLUMEUP))
boot_into_recovery = 1;
if (!boot_into_recovery &&
(keys_get_state(KEY_BACK) || keys_get_state(KEY_VOLUMEDOWN)))
boot_into_fastboot = true;
}
aboot_init 就简单的介绍完了,在调试的时候有时为了方便,会让设备每次启动都自动进入fastboot 模式,如果想继续往下跑,可以执行:fastboot continue
如何让设备每次启动都进如fastboot 模式呢?很简单,只需要做如下修改即可:
+ boot_into_fastboot = true;
normal_boot:
if (!boot_into_fastboot)
{
if (target_is_emmc_boot())
{