MTK lk源码解析5( lk 阶段aboot.c 解析)

来源:互联网 发布:linux下查看用户权限 编辑:程序博客网 时间:2024/06/08 17:55

http://blog.csdn.net/xichangbao/article/details/51484610

现在开始分析关键函数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
}


0 0
原创粉丝点击