static void fastboot_command_loop(void) { struct fastboot_cmd *cmd; int r; dprintf(ALWAYS,"fastboot: processing commands\n"); again: while (fastboot_state != STATE_ERROR) { memset(buffer, 0, sizeof(buffer)); r = usb_read(buffer, MAX_RSP_SIZE); if (r < 0) break; //no input command buffer[r] = 0; dprintf(ALWAYS,"[fastboot: command buf]-[%s]-[len=%d]\n", buffer, r); dprintf(ALWAYS,"[fastboot]-[download_base:0x%x]-[download_size:0x%x]\n",(unsigned int)download_base,(unsigned int)download_size); /*Pick up matched command and handle it*/ for (cmd = cmdlist; cmd; cmd = cmd->next) { fastboot_state = STATE_COMMAND; if (memcmp(buffer, cmd->prefix, cmd->prefix_len)) { continue; } dprintf(ALWAYS,"[Cmd process]-[buf:%s]-[lenBuf:%s]\n", buffer, buffer + cmd->prefix_len); #ifdef MTK_SECURITY_SW_SUPPORT if( !sec_usbdl_enabled() || cmd->sec_support ) #endif { cmd->handle((const char*) buffer + cmd->prefix_len, (void*) download_base, download_size); } if (fastboot_state == STATE_COMMAND) { #ifdef MTK_SECURITY_SW_SUPPORT if( sec_usbdl_enabled() && !cmd->sec_support ) { fastboot_fail("not support on security"); } else #endif { fastboot_fail("unknown reason"); } } goto again; } dprintf(ALWAYS,"[unknown command]*[%s]*\n", buffer); fastboot_fail("unknown command"); } fastboot_state = STATE_OFFLINE; dprintf(ALWAYS,"fastboot: oops!\n"); }
/****************************************************************************** * CHECK IF SECROIMG AC IS ENABLED ******************************************************************************/ bool sec_secro_ac (void) { /* PLEASE NOTE THAT !!!!!!!!!!!!!!!!!! SECRO AC is only effected when SUSBDL is on */ if(TRUE == sec_usbdl_enabled()) { return TRUE; } /* If security chip, secroimage must be encrypted */ else if(TRUE == es_sbc_enabled()) { return TRUE; } else { return FALSE; } }
void platform_init(void) { #ifdef LK_PROFILING unsigned int time_nand_emmc; unsigned int time_load_logo; unsigned int time_bat_init; unsigned int time_backlight; unsigned int time_show_logo; unsigned int time_boot_mode; unsigned int time_sw_env; unsigned int time_platform_init; unsigned int time_env; unsigned int time_disp_init; unsigned int time_security_init; unsigned int time_RTC_boot_Check; time_platform_init = get_timer(0); time_nand_emmc = get_timer(0); #endif dprintf(INFO, "platform_init()\n"); #ifdef DUMMY_AP dummy_ap_entry(); #endif #ifdef MTK_EMMC_SUPPORT mmc_legacy_init(1); #else #ifndef MACH_FPGA nand_init(); nand_driver_test(); #endif #endif #ifdef MTK_KERNEL_POWER_OFF_CHARGING if((g_boot_arg->boot_reason == BR_USB) && (upmu_is_chr_det() == KAL_FALSE)) { printf("[%s] Unplugged Charger/Usb between Pre-loader and Uboot in Kernel Charging Mode, Power Off \n", __func__); mt6575_power_off(); } #endif #ifdef LK_PROFILING printf("[PROFILE] ------- NAND/EMMC init takes %d ms -------- \n", get_timer(time_nand_emmc)); time_env = get_timer(0); #endif env_init(); print_env(); #ifdef LK_PROFILING dprintf(INFO,"[PROFILE] ------- ENV init takes %d ms -------- \n", (int)get_timer(time_env)); #endif #ifdef LK_PROFILING time_disp_init = get_timer(0); #endif //FIXME: Disable for MT6582 FPGA Ealry Porting #ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP if(lcm_params->type==LCM_TYPE_DSI && lcm_params->dsi.mode ==CMD_MODE) mt_disp_init((void *)g_fb_base); #endif #ifdef LK_PROFILING dprintf(INFO,"[PROFILE] ------- disp init takes %d ms -------- \n", (int)get_timer(time_disp_init)); #endif #ifdef LK_PROFILING time_load_logo = get_timer(0); #endif #ifdef CONFIG_CFB_CONSOLE //FIXME: Disable for MT6582 FPGA Ealry Porting #ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP drv_video_init(); #endif #endif //#endif #ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP mboot_common_load_logo((unsigned long)mt_get_logo_db_addr(), "logo"); dprintf(INFO, "Show BLACK_PICTURE\n"); #endif //FIXME: Disable for MT6582 FPGA Ealry Porting #ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY if(!is_low_battery(0)) { #endif mt_disp_fill_rect(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT, 0x0); mt_disp_power(TRUE); mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT); mt_disp_wait_idle(); mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT); mt_disp_wait_idle(); mt_disp_power(1); //power on display related modules #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY } #endif #endif #ifdef LK_PROFILING printf("[PROFILE] ------- load_logo takes %d ms -------- \n", get_timer(time_load_logo)); time_backlight = get_timer(0); #endif /*for kpd pmic mode setting*/ set_kpd_pmic_mode(); //FIXME: Disable for MT6582 FPGA Ealry Porting //#ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY if(!is_low_battery(0)) { #endif /*some lcm panel need more time to start show picture*/ msleep(50); mt65xx_backlight_on(); #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY } #endif //#endif #ifdef LK_PROFILING printf("[PROFILE] ------- backlight takes %d ms -------- \n", get_timer(time_backlight)); time_boot_mode = get_timer(0); #endif boot_mode_select(); #ifdef LK_PROFILING printf("[PROFILE] ------- boot mode select takes %d ms -------- \n", get_timer(time_boot_mode)); #endif #ifdef MTK_SECURITY_SW_SUPPORT #ifdef LK_PROFILING time_security_init = get_timer(0); #endif /* initialize security library */ #ifdef MTK_EMMC_SUPPORT sec_func_init(1); #else sec_func_init(0); #endif #ifdef LK_PROFILING dprintf(INFO,"[PROFILE] ------- Security init takes %d ms -------- \n", (int)get_timer(time_security_init)); #endif #endif /*Show download logo & message on screen */ if (g_boot_arg->boot_mode == DOWNLOAD_BOOT) { printf("[LK] boot mode is DOWNLOAD_BOOT\n"); #ifdef MTK_SECURITY_SW_SUPPORT /* verify da before jumping to da*/ if (sec_usbdl_enabled()) { u8 *da_addr = (u8 *)g_boot_arg->da_info.addr; u32 da_len = g_boot_arg->da_info.len; u32 sig_len = g_boot_arg->da_info.sig_len; u8 *sig_addr = (unsigned char *)da_addr + (da_len - sig_len); if (da_len == 0 || sig_len == 0) { printf("[LK] da argument is invalid\n"); printf("da_addr = 0x%x\n", da_addr); printf("da_len = 0x%x\n", da_len); printf("sig_len = 0x%x\n", sig_len); } if (sec_usbdl_verify_da(da_addr, (da_len - sig_len), sig_addr, sig_len)) { /* da verify fail */ video_printf(" => Not authenticated tool, download stop...\n"); while(1); /* fix me, should not be infinite loop in lk */ } } else #endif { printf(" DA verification disabled...\n"); } mt_disp_show_boot_logo(); video_printf(" => Downloading...\n"); mt65xx_backlight_on(); mtk_wdt_disable();//Disable wdt before jump to DA platform_uninit(); #ifdef HAVE_CACHE_PL310 l2_disable(); #endif #ifdef ENABLE_L2_SHARING config_shared_SRAM_size(); #endif arch_disable_cache(UCACHE); arch_disable_mmu(); jump_da(g_boot_arg->da_info.addr, g_boot_arg->da_info.arg1, g_boot_arg->da_info.arg2); } #ifdef LK_PROFILING time_bat_init = get_timer(0); #endif mt65xx_bat_init(); #ifdef LK_PROFILING printf("[PROFILE] ------- battery init takes %d ms -------- \n", get_timer(time_bat_init)); #endif #ifndef CFG_POWER_CHARGING #ifdef LK_PROFILING time_RTC_boot_Check = get_timer(0); #endif /* NOTE: if define CFG_POWER_CHARGING, will rtc_boot_check() in mt65xx_bat_init() */ rtc_boot_check(false); #ifdef LK_PROFILING dprintf(INFO,"[PROFILE] ------- RTC boot check Init takes %d ms -------- \n", (int)get_timer(time_RTC_boot_Check)); #endif #endif #ifdef LK_PROFILING time_show_logo = get_timer(0); #endif #ifdef MTK_KERNEL_POWER_OFF_CHARGING if(kernel_charging_boot() == 1) { #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY CHARGER_TYPE CHR_Type_num = CHARGER_UNKNOWN; charging_get_charger_type(&CHR_Type_num); if ((g_boot_mode != LOW_POWER_OFF_CHARGING_BOOT) || ((CHR_Type_num != STANDARD_HOST) && (CHR_Type_num != NONSTANDARD_CHARGER))) { dprintf(INFO, "[PROFILE] ------- g_boot_mode = %d -------- \n", g_boot_mode); #endif mt_disp_power(TRUE); mt_disp_show_low_battery(); mt_disp_wait_idle(); mt65xx_leds_brightness_set(6, 110); #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY } #endif } else if(g_boot_mode != KERNEL_POWER_OFF_CHARGING_BOOT && g_boot_mode != LOW_POWER_OFF_CHARGING_BOOT) { #ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP if (g_boot_mode != ALARM_BOOT && (g_boot_mode != FASTBOOT)) { mt_disp_show_boot_logo(); } #endif } #else #ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP if (g_boot_mode != ALARM_BOOT && (g_boot_mode != FASTBOOT)) { mt_disp_show_boot_logo(); } #endif #endif #ifdef LK_PROFILING printf("[PROFILE] ------- show logo takes %d ms -------- \n", get_timer(time_show_logo)); time_sw_env= get_timer(0); #endif //sw_env(); #ifdef LK_PROFILING printf("[PROFILE] ------- sw_env takes %d ms -------- \n", get_timer(time_sw_env)); printf("[PROFILE] ------- platform_init takes %d ms -------- \n", get_timer(time_platform_init)); #endif }
/************************************************************************** * SEC DRIVER IOCTL **************************************************************************/ long sec_core_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int err = 0; int ret = 0; unsigned int cipher_len = 0; unsigned int rid[4]; unsigned char part_name[10]; META_CONTEXT meta_ctx; /* ---------------------------------- */ /* IOCTL */ /* ---------------------------------- */ if (_IOC_TYPE(cmd) != SEC_IOC_MAGIC) return -ENOTTY; if (_IOC_NR(cmd) > SEC_IOC_MAXNR) return -ENOTTY; if (_IOC_DIR(cmd) & _IOC_READ) err = !access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd)); if (_IOC_DIR(cmd) & _IOC_WRITE) err = !access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd)); if (err) return -EFAULT; switch (cmd) { /* ---------------------------------- */ /* get random id */ /* ---------------------------------- */ case SEC_GET_RANDOM_ID: SMSG(bMsg,"[%s] CMD - SEC_GET_RANDOM_ID\n",MOD); sec_get_random_id(&rid[0]); ret = osal_copy_to_user((void __user *)arg, (void *)&rid[0], sizeof(unsigned int) * 4); break; /* ---------------------------------- */ /* init boot info */ /* ---------------------------------- */ case SEC_BOOT_INIT: SMSG(bMsg,"[%s] CMD - SEC_BOOT_INIT\n",MOD); ret = sec_boot_init(); ret = osal_copy_to_user((void __user *)arg, (void *)&ret, sizeof(int)); break; /* ---------------------------------- */ /* check if secure boot is enbaled */ /* ---------------------------------- */ case SEC_BOOT_IS_ENABLED: SMSG(bMsg,"[%s] CMD - SEC_BOOT_IS_ENABLED\n",MOD); ret = sec_boot_enabled(); ret = osal_copy_to_user((void __user *)arg, (void *)&ret, sizeof(int)); break; /* ---------------------------------- */ /* encrypt sec cfg */ /* ---------------------------------- */ case SEC_SECCFG_ENCRYPT: SMSG(bMsg,"[%s] CMD - SEC_SECCFG_ENCRYPT\n",MOD); if(copy_from_user((void *)&seccfg, (void __user *)arg, sizeof(SECCFG_U))) { return -EFAULT; } /* specify encrpytion length */ SMSG(true,"[%s] SECCFG v%d\n",MOD,get_seccfg_ver()); if (SEC_CFG_END_PATTERN == seccfg.v1.end_pattern) { if((SECCFG_V1 != get_seccfg_ver()) && (SECCFG_V1_2 != get_seccfg_ver())) { SMSG(true,"[%s] mismatch seccfg version v%d\n",MOD,get_seccfg_ver()); SEC_ASSERT(0); } cipher_len = get_seccfg_cipher_len(); sp_hacc_enc((unsigned char*)&seccfg.v1.image_info,cipher_len,rom_info.m_SEC_CTRL.m_seccfg_ac_en,HACC_USER1,FALSE); } else if (SEC_CFG_END_PATTERN == seccfg.v3.end_pattern) { if(SECCFG_V3 != get_seccfg_ver()) { SMSG(true,"[%s] mismatch seccfg version v%d\n",MOD,get_seccfg_ver()); SEC_ASSERT(0); } cipher_len = get_seccfg_cipher_len(); sp_hacc_enc((unsigned char*)&seccfg.v3.image_info,cipher_len,rom_info.m_SEC_CTRL.m_seccfg_ac_en,HACC_USER1,FALSE); } else { SMSG(true,"[%s] wrong seccfg version v%d\n",MOD,seccfg.v3.seccfg_ver) SEC_ASSERT(0); } ret = osal_copy_to_user((void __user *)arg, (void *)&seccfg, sizeof(SECCFG_U)); break; /* ---------------------------------- */ /* decrypt sec cfg */ /* ---------------------------------- */ case SEC_SECCFG_DECRYPT: SMSG(bMsg,"[%s] CMD - SEC_SECCFG_DECRYPT\n",MOD); if(copy_from_user((void *)&seccfg, (void __user *)arg, sizeof(SECCFG_U))) { return -EFAULT; } /* specify decrpytion length */ if (SEC_CFG_END_PATTERN == seccfg.v1.end_pattern) { /* seccfg version should be corrected by caller */ set_seccfg_ver(SECCFG_V1); cipher_len = get_seccfg_cipher_len(); sp_hacc_dec((unsigned char*)&seccfg.v1.image_info,cipher_len,rom_info.m_SEC_CTRL.m_seccfg_ac_en,HACC_USER1,FALSE); } else if (SEC_CFG_END_PATTERN == seccfg.v3.end_pattern) { /* seccfg version should be corrected by caller */ set_seccfg_ver(SECCFG_V3); cipher_len = get_seccfg_cipher_len(); sp_hacc_dec((unsigned char*)&seccfg.v3.image_info,cipher_len,rom_info.m_SEC_CTRL.m_seccfg_ac_en,HACC_USER1,FALSE); } else { SMSG(true,"[%s] wrong seccfg version v%d\n",MOD,seccfg.v3.seccfg_ver) SEC_ASSERT(0); } SMSG(bMsg,"[%s] SECCFG v%d\n",MOD,get_seccfg_ver()); ret = osal_copy_to_user((void __user *)arg, (void *)&seccfg, sizeof(SECCFG_U)); break; /* ---------------------------------- */ /* NVRAM HW encryption */ /* ---------------------------------- */ case SEC_NVRAM_HW_ENCRYPT: SMSG(bMsg,"[%s] CMD - SEC_NVRAM_HW_ENCRYPT\n",MOD); if(osal_copy_from_user((void *)&meta_ctx, (void __user *)arg, sizeof(meta_ctx))) { return -EFAULT; } /* TODO : double check if META register is correct ? */ sp_hacc_enc((unsigned char*)&(meta_ctx.data),NVRAM_CIPHER_LEN,TRUE,HACC_USER2,FALSE); meta_ctx.ret = SEC_OK; ret = osal_copy_to_user((void __user *)arg, (void *)&meta_ctx, sizeof(meta_ctx)); break; /* ---------------------------------- */ /* NVRAM HW decryption */ /* ---------------------------------- */ case SEC_NVRAM_HW_DECRYPT: SMSG(bMsg,"[%s] CMD - SEC_NVRAM_HW_DECRYPT\n",MOD); if(osal_copy_from_user((void *)&meta_ctx, (void __user *)arg, sizeof(meta_ctx))) { return -EFAULT; } sp_hacc_dec((unsigned char*)&(meta_ctx.data),NVRAM_CIPHER_LEN,TRUE,HACC_USER2,FALSE); meta_ctx.ret = SEC_OK; ret = osal_copy_to_user((void __user *)arg, (void *)&meta_ctx, sizeof(meta_ctx)); break; /* ---------------------------------- */ /* check if secure usbdl is enbaled */ /* ---------------------------------- */ case SEC_USBDL_IS_ENABLED: SMSG(bMsg,"[%s] CMD - SEC_USBDL_IS_ENABLED\n",MOD); ret = sec_usbdl_enabled(); ret = osal_copy_to_user((void __user *)arg, (void *)&ret, sizeof(int)); break; /* ---------------------------------- */ /* configure HACC HW (include SW KEY) */ /* ---------------------------------- */ case SEC_HACC_CONFIG: SMSG(bMsg,"[%s] CMD - SEC_HACC_CONFIG\n",MOD); ret = sec_boot_hacc_init(); ret = osal_copy_to_user((void __user *)arg, (void *)&ret, sizeof(int)); break; /* ---------------------------------- */ /* enable HACC HW clock */ /* ---------------------------------- */ case SEC_HACC_ENABLE_CLK: SMSG(bMsg,"[%s] CMD - SEC_HACC_ENABLE_CLK\n",MOD); ret = osal_copy_to_user((void __user *)arg, (void *)&ret, sizeof(int)); break; /* ---------------------------------- */ /* lock hacc function */ /* ---------------------------------- */ case SEC_HACC_LOCK: SMSG(bMsg,"[%s] CMD - SEC_HACC_LOCK\n",MOD); SMSG(bMsg,"[%s] lock\n",MOD); /* If the semaphore is successfully acquired, this function returns 0.*/ ret = osal_hacc_lock(); if(ret) { SMSG(true,"[%s] ERESTARTSYS\n",MOD); return -ERESTARTSYS; } return ret; /* ---------------------------------- */ /* unlock hacc function */ /* ---------------------------------- */ case SEC_HACC_UNLOCK: SMSG(bMsg,"[%s] CMD - SEC_HACC_UNLOCK\n",MOD); SMSG(bMsg,"[%s] unlock\n",MOD); osal_hacc_unlock(); break; /* ---------------------------------- */ /* check if secure boot check enabled */ /* ---------------------------------- */ case SEC_BOOT_PART_CHECK_ENABLE: SMSG(bMsg,"[%s] CMD -SEC_BOOT_PART_CHECK_ENABLE\n",MOD); if(copy_from_user((void *)part_name, (void __user *)arg, sizeof(part_name))) { return -EFAULT; } ret = sec_boot_check_part_enabled (part_name); SMSG(bMsg,"[%s] result '0x%x'\n",MOD,ret); return ret; /* ---------------------------------- */ /* notify mark incomplete */ /* ---------------------------------- */ case SEC_BOOT_NOTIFY_MARK_STATUS: SMSG(true,"[%s] mark status\n",MOD); /* may do some post process here ... */ break; /* ---------------------------------- */ /* notify check pass */ /* ---------------------------------- */ case SEC_BOOT_NOTIFY_PASS: SMSG(true,"[%s] sbchk pass\n",MOD); SMSG(true,"[%s] sbchk pass\n",MOD); SMSG(true,"[%s] sbchk pass\n",MOD); SMSG(true,"[%s] sbchk pass\n",MOD); SMSG(true,"[%s] sbchk pass\n",MOD); /* may do some post process here ... */ break; /* ---------------------------------- */ /* notify check fail */ /* ---------------------------------- */ case SEC_BOOT_NOTIFY_FAIL: if(osal_copy_from_user((void *)part_name, (void __user *)arg, sizeof(part_name))) { return -EFAULT; } SMSG(true,"[%s] sbchk fail '%s'\n",MOD,part_name); SMSG(true,"[%s] sbchk fail '%s'\n",MOD,part_name); SMSG(true,"[%s] sbchk fail '%s'\n",MOD,part_name); SMSG(true,"[%s] sbchk fail '%s'\n",MOD,part_name); SMSG(true,"[%s] sbchk fail '%s'\n",MOD,part_name); osal_msleep(3000); /* punishment ... */ SEC_ASSERT(0); break; /* ---------------------------------- */ /* notify recovery mode done */ /* ---------------------------------- */ case SEC_BOOT_NOTIFY_RMSDUP_DONE: SMSG(true,"[%s] recovery mode done\n",MOD); /* may do some post process here ... */ break; /* ---------------------------------- */ /* read rom info */ /* ---------------------------------- */ case SEC_READ_ROM_INFO: SMSG(bMsg,"[%s] read rom info\n",MOD); ret = osal_copy_to_user((void __user *)arg, (void *)&rom_info, sizeof(AND_ROMINFO_T)); break; } return 0; }