LK源码解析 5 aboot.c

现在开始分析关键函数aboot_init(),岔开一句lk在分区表的名称即为aboot。
  1. aboot_init()。
void aboot_init(const struct app_descriptor *app)
{
    unsigned reboot_mode = 0;
    unsigned hard_reboot_mode = 0;
    bool boot_into_fastboot = false;

    /* Setup page size information for nv storage */
    if (target_is_emmc_boot())
    {
        page_size = mmc_page_size(); // 获取mmc/ufs的页大小,ufs为4096,emmc为2048
        page_mask = page_size - 1; // 获取mmc/ufs的页掩码
    }
    else
    {
        page_size = flash_page_size();
        page_mask = page_size - 1;
    }

    ASSERT((MEMBASE + MEMSIZE) > MEMBASE);

    read_device_info(&device); // 获取device_info信息,开发中需要关注 device_info信息,它牵扯到fastboot是否被禁掉,boot.img是否需要鉴权等等

    /* Display splash screen if enabled */
#if DISPLAY_SPLASH_SCREEN
    dprintf(SPEW, "Display Init: Start\n");
    target_display_init(device.display_panel); // 初始化lcd驱动,显示第一张开机图片
    dprintf(SPEW, "Display Init: Done\n");
#endif


    target_serialno((unsigned char *) sn_buf); // 获取emmc/ufs的product serial number,fastboot和cmdline都会用到
    dprintf(SPEW,"serial number: %s\n",sn_buf);

    memset(display_panel_buf, '\0', MAX_PANEL_BUF_SIZE); // 清除显示面板信息(即lcd屏幕)

    /*
     * Check power off reason if user force reset,
     * if yes phone will do normal boot.
     */
    if (is_user_force_reset()) // 关机原因是hard reset,则跳到normal_boot继续运行
        goto normal_boot;

    /* Check if we should do something other than booting up */
    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)) // 尝试进入9008下载模式
        {
            dprintf(CRITICAL,"dload mode not supported by target\n");
        }
        else
        {
            reboot_device(DLOAD); // 进入9008下载模式失败,尝试 进入9006下载模式
            dprintf(CRITICAL,"Failed to reboot into dload mode\n");
        }
        boot_into_fastboot = true; // 进入下载模式失败,设置fastboot模式标志
    }
    if (!boot_into_fastboot)
    {
        if (keys_get_state(KEY_HOME) || keys_get_state(KEY_VOLUMEUP))
            boot_into_recovery = 1; // home键和音量上键同时按下, 设置fastboot模式标志
        if (!boot_into_recovery &&
            (keys_get_state(KEY_BACK) || keys_get_state(KEY_VOLUMEDOWN)))
            boot_into_fastboot = true; // back键和音量下键同时按下,设置recovery模式标志
    }
    #if NO_KEYPAD_DRIVER // 没有按键驱动,不关注
    if (fastboot_trigger())
        boot_into_fastboot = true;
    #endif

    reboot_mode = check_reboot_mode(); // 获取重启原因,设置相应的开机模式标志,之前使用的是共享内存记录重启原因,最新转为使用pmic的pon寄存器记录重启原因
    hard_reboot_mode = check_hard_reboot_mode();
    if (reboot_mode == RECOVERY_MODE ||
        hard_reboot_mode == RECOVERY_HARD_RESET_MODE) {
        boot_into_recovery = 1; //  recovery
    } else if(reboot_mode == FASTBOOT_MODE ||
        hard_reboot_mode == FASTBOOT_HARD_RESET_MODE) {
        boot_into_fastboot = true; // fastboot
    } else if(reboot_mode == ALARM_BOOT ||
        hard_reboot_mode == RTC_HARD_RESET_MODE) {
        boot_reason_alarm = true; // alarm,关机充电时,闹钟重启开机
    }

normal_boot:
    if (!boot_into_fastboot) // 非fastboot模式
    {
        if (target_is_emmc_boot()) // 从emmc/ufs启动
        {
            if(emmc_recovery_init()) // recovery模式需要的一些初始化
                dprintf(ALWAYS,"error in emmc_recovery_init\n");
            if(target_use_signed_kernel()) // 判断是否使用了签名的kernel(即boot.img)
            {
                if((device.is_unlocked) || (device.is_tampered))
                {
                #ifdef TZ_TAMPER_FUSE
                    set_tamper_fuse_cmd(); // 暂不关注fuse
                #endif
                #if USE_PCOM_SECBOOT
                    set_tamper_flag(device.is_tampered); // 暂不关注secboot
                #endif
                }
            }

            boot_linux_from_mmc(); // 从emmc/ufs加载boot.img,选择dts,设置cmdline,跳转到kernel
        }
        else // 从nanflash启动,当前已经没有手机厂商在使用nandflash了,因此不关注
        {
            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");
    }

    /* We are here means regular boot did not happen. Start fastboot. */
    // fasboot模式或者正常启动失败才会执行到这里
    /* register aboot specific fastboot commands */
    aboot_fastboot_register_commands(); // 注册fastboot支持的命令

    /* dump partition table for debug info */
    partition_dump(); // 打印分区表信息

    /* initialize and start fastboot */
    fastboot_init(target_get_scratch_address(), target_get_max_flash_size()); // 初始化并启动fastboot,参数1为fastboot使用的内存buffer的地址,参数2位内存buffer的大小
#if FBCON_DISPLAY_MSG
    display_fastboot_menu_thread(); // 为fastboot提供了一个简易图形显示,可以显示手机的部分信息,以及通过按键选择进入其他开机模式或关机
#endif
}

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值