void platform_post_init(void) { struct ram_console_buffer *ram_console; #if CFG_BATTERY_DETECT /* normal boot to check battery exists or not */ if (g_boot_mode == NORMAL_BOOT && !hw_check_battery() && usb_accessory_in()) { print("%s Wait for battery inserted...\n", MOD); /* disable pmic pre-charging led */ pl_close_pre_chr_led(); /* enable force charging mode */ pl_charging(1); do { mdelay(300); /* check battery exists or not */ if (hw_check_battery()) break; /* kick all watchdogs */ platform_wdt_all_kick(); } while(1); /* disable force charging mode */ pl_charging(0); } #endif #if !CFG_FPGA_PLATFORM /* security check */ sec_lib_read_secro(); sec_boot_check(); device_APC_dom_setup(); #endif #if CFG_MDJTAG_SWITCH unsigned int md_pwr_con; /* md0 default power on and clock on */ /* md1 default power on and clock off */ /* ungate md1 */ /* rst_b = 0 */ md_pwr_con = DRV_Reg32(0x10006280); md_pwr_con &= ~0x1; DRV_WriteReg32(0x10006280, md_pwr_con); /* enable clksq2 for md1 */ DRV_WriteReg32(0x10209000, 0x00001137); udelay(200); DRV_WriteReg32(0x10209000, 0x0000113f); /* rst_b = 1 */ md_pwr_con = DRV_Reg32(0x10006280); md_pwr_con |= 0x1; DRV_WriteReg32(0x10006280, md_pwr_con); /* switch to MD legacy JTAG */ /* this step is not essentially required */ #endif #if CFG_MDMETA_DETECT if (g_boot_mode == META_BOOT || g_boot_mode == ADVMETA_BOOT) { /* trigger md0 to enter meta mode */ DRV_WriteReg32(0x20000010, 0x1); /* trigger md1 to enter meta mode */ DRV_WriteReg32(0x30000010, 0x1); } else { /* md0 does not enter meta mode */ DRV_WriteReg32(0x20000010, 0x0); /* md1 does not enter meta mode */ DRV_WriteReg32(0x30000010, 0x0); } #endif #if CFG_RAM_CONSOLE ram_console = (struct ram_console_buffer *)RAM_CONSOLE_ADDR; if (ram_console->sig == RAM_CONSOLE_SIG) { print("%s ram_console->start=0x%x\n", MOD, ram_console->start); if (ram_console->start > RAM_CONSOLE_MAX_SIZE) ram_console->start = 0; ram_console->hw_status = g_rgu_status; print("%s ram_console(0x%x)=0x%x (boot reason)\n", MOD, ram_console->hw_status, g_rgu_status); } #endif platform_set_boot_args(); /* post init pll */ mt_pll_post_init(); }
void main(u32 *arg) { struct bldr_command_handler handler; u32 jump_addr; /* get the bldr argument */ bldr_param = (bl_param_t *)*arg; mtk_uart_init(UART_SRC_CLK_FRQ, CFG_LOG_BAUDRATE); bldr_pre_process(); #ifdef HW_INIT_ONLY bldr_wait_forever(); #endif handler.priv = NULL; handler.attr = 0; handler.cb = bldr_cmd_handler; BOOTING_TIME_PROFILING_LOG("before bldr_handshake"); bldr_handshake(&handler); BOOTING_TIME_PROFILING_LOG("bldr_handshake"); #if !CFG_FPGA_PLATFORM /* security check */ sec_lib_read_secro(); sec_boot_check(); device_APC_dom_setup(); #endif BOOTING_TIME_PROFILING_LOG("sec_boot_check"); #if CFG_ATF_SUPPORT trustzone_pre_init(); #endif if (0 != bldr_load_images(&jump_addr)) { print("%s Second Bootloader Load Failed\n", MOD); goto error; } bldr_post_process(); #ifdef SLT mt_usb_phy_recover(); //mu3d_hal_rst_dev(); #endif #if CFG_ATF_SUPPORT trustzone_post_init(); #endif //Yi-Lung: recover pmic normal reset platform_pmic_full_reset_disable(); #if CFG_LOAD_SLT_AARCH64_KERNEL if (0 == aarch64_slt_done()) { *(unsigned int*) AARCH64_SLT_DONE_ADDRESS = AARCH64_SLT_DONE_MAGIC; jump_addr = CFG_BOOTA64_MEMADDR; //set up slave cpu reset address *(unsigned int*) 0x10200040 = CFG_BOOTA64_MEMADDR; //cpu1 *(unsigned int*) 0x10200048 = CFG_BOOTA64_MEMADDR; //cpu2 *(unsigned int*) 0x10200050 = CFG_BOOTA64_MEMADDR; //cpu3 *(unsigned int*) 0x10200238 = CFG_BOOTA64_MEMADDR; //cpu4 *(unsigned int*) 0x10200240 = CFG_BOOTA64_MEMADDR; //cpu5 *(unsigned int*) 0x10200248 = CFG_BOOTA64_MEMADDR; //cpu6 *(unsigned int*) 0x10200250 = CFG_BOOTA64_MEMADDR; //cpu7 print("%s Aarch64 Kernel SLT , jump to 64 bit kernel, address: 0x%x\n", MOD,jump_addr); bldr_jump64(jump_addr, (u32)&bootarg, sizeof(boot_arg_t)); } #endif /* 64S3,32S1,32S1 (MTK_ATF_BOOT_OPTION = 0) * re-loader jump to LK directly and then LK jump to kernel directly */ #if CFG_ATF_SUPPORT if ( BOOT_OPT_64S3 == bootarg.smc_boot_opt && BOOT_OPT_32S1 == bootarg.lk_boot_opt && BOOT_OPT_32S1 == bootarg.kernel_boot_opt) { print("%s 64S3,32S1,32S1, jump to LK\n", MOD); bldr_jump(jump_addr, (u32)&bootarg, sizeof(boot_arg_t)); } else { print("%s Others, jump to ATF\n", MOD); bldr_jump64(jump_addr, (u32)&bootarg, sizeof(boot_arg_t)); } #else bldr_jump(jump_addr, (u32)&bootarg, sizeof(boot_arg_t)); #endif error: platform_error_handler(); }
void platform_post_init(void) { boot_arg_t *bootarg; struct ram_console_buffer *ram_console; #ifdef PL_PROFILING u32 profiling_time; profiling_time = 0; #endif bootarg = (boot_arg_t*)BOOT_ARGUMENT_ADDR; #if CFG_BATTERY_DETECT #ifdef PL_PROFILING profiling_time = get_timer(0); #endif /* normal boot to check battery exists or not */ if (g_boot_mode == NORMAL_BOOT && !hw_check_battery() && usb_accessory_in()) { print("%s Wait for battery inserted...\n", MOD); /* disable pmic pre-charging led */ pl_close_pre_chr_led(); /* enable force charging mode */ pl_charging(1); do { mdelay(300); /* check battery exists or not */ if (hw_check_battery()) break; /* kick all watchdogs */ platform_wdt_all_kick(); } while(1); /* disable force charging mode */ pl_charging(0); } #ifdef PL_PROFILING printf("#T#bat_detc=%d\n", get_timer(profiling_time)); #endif #endif #if !CFG_FPGA_PLATFORM #ifdef PL_PROFILING profiling_time = get_timer(0); #endif /* security check */ sec_lib_read_secro(); sec_boot_check(); device_APC_dom_setup(); #ifdef PL_PROFILING printf("#T#sec_init=%d\n", get_timer(profiling_time)); #endif #endif /* Note that the powering on MD is AP CCCI's task. */ /* Because the following code is for MT6589, */ /* although CFG_MDJTAG_SWITCH should not be defined, */ /* we still disable the following code just in case */ #if 0 #if CFG_MDJTAG_SWITCH unsigned int md_pwr_con; /* md0 default power on and clock on */ /* md1 default power on and clock off */ /* ungate md1 */ /* rst_b = 0 */ md_pwr_con = DRV_Reg32(0x10006280); md_pwr_con &= ~0x1; DRV_WriteReg32(0x10006280, md_pwr_con); /* enable clksq2 for md1 */ DRV_WriteReg32(0x10209000, 0x00001137); udelay(200); DRV_WriteReg32(0x10209000, 0x0000113f); /* rst_b = 1 */ md_pwr_con = DRV_Reg32(0x10006280); md_pwr_con |= 0x1; DRV_WriteReg32(0x10006280, md_pwr_con); /* switch to MD legacy JTAG */ /* this step is not essentially required */ #endif #endif /* Note that the triggering MD META modeis AP CCCI's task. */ /* Because the following code is for MT6589, */ /* although CFG_MDMETA_DETECT should not be defined, */ /* we still disable the following code just in case */ #if 0 #if CFG_MDMETA_DETECT if (g_boot_mode == META_BOOT || g_boot_mode == ADVMETA_BOOT) { /* trigger md0 to enter meta mode */ DRV_WriteReg32(0x20000010, 0x1); /* trigger md1 to enter meta mode */ DRV_WriteReg32(0x30000010, 0x1); } else { /* md0 does not enter meta mode */ DRV_WriteReg32(0x20000010, 0x0); /* md1 does not enter meta mode */ DRV_WriteReg32(0x30000010, 0x0); } #endif #endif #if CFG_RAM_CONSOLE ram_console = (struct ram_console_buffer *)RAM_CONSOLE_ADDR; if (ram_console->sig == RAM_CONSOLE_SIG) { print("%s ram_console->start=0x%x\n", MOD, ram_console->start); if (ram_console->start > RAM_CONSOLE_MAX_SIZE) ram_console->start = 0; ram_console->hw_status = g_rgu_status; print("%s ram_console(0x%x)=0x%x (boot reason)\n", MOD, ram_console->hw_status, g_rgu_status); } #endif #if defined(CFG_MEM_PRESERVED_MODE) //wake up core 1 and flush core 1 cache print("%s core1 flush start\n", MOD); bootup_slave_cpu(); print("%s core1 flush done\n", MOD); //flush core 1 cache print("%s core0 flush start\n", MOD); #if 0 { u32 i; volatile u32 tmp; tmp = 1; // for verify cache flush, write in LK, flush in preloader do { }while(tmp); for (i=0;i<0x100;i=i+4) { *(volatile u32 *)(CFG_DRAM_ADDR + 0x120000 + i) = 0xFFFFFFFF; } } #endif apmcu_dcache_clean_invalidate(); print("%s core0 flush done\n", MOD); // while(1); #endif //#if !defined(CFG_MEM_PRESERVED_MODE) #if CFG_BOOT_ARGUMENT //set UART1 GPIO to mode5, MD mt_gpio_init_post(1); bootarg->magic = BOOT_ARGUMENT_MAGIC; bootarg->mode = g_boot_mode; //efuse should use seclib_get_devinfo_with_index(), //no need check 3G in 72 bootarg->e_flag = 0; bootarg->log_port = CFG_UART_LOG; bootarg->log_baudrate = CFG_LOG_BAUDRATE; bootarg->log_enable = (u8)log_status(); bootarg->dram_rank_num = get_dram_rank_nr(); get_dram_rank_size(bootarg->dram_rank_size); bootarg->boot_reason = g_boot_reason; bootarg->meta_com_type = (u32)g_meta_com_type; bootarg->meta_com_id = g_meta_com_id; bootarg->boot_time = get_timer(g_boot_time); print("\n%s boot reason: %d\n", MOD, g_boot_reason); print("%s boot mode: %d\n", MOD, g_boot_mode); print("%s META COM%d: %d\n", MOD, bootarg->meta_com_id, bootarg->meta_com_type); print("%s <0x%x>: 0x%x\n", MOD, &bootarg->e_flag, bootarg->e_flag); print("%s boot time: %dms\n", MOD, bootarg->boot_time); #endif }