platform.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2015. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. #include <debug.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <video.h>
  35. #include <dev/uart.h>
  36. #include <arch/arm.h>
  37. #include <arch/arm/mmu.h>
  38. #include <arch/ops.h>
  39. #include <target/board.h>
  40. #include <platform/mt_reg_base.h>
  41. #include <platform/mt_disp_drv.h>
  42. #include <platform/disp_drv.h>
  43. #include <platform/boot_mode.h>
  44. #include <platform/mt_logo.h>
  45. #include <platform/partition.h>
  46. #include <env.h>
  47. #include <platform/mt_gpio.h>
  48. #include <platform/mt_pmic.h>
  49. #include <platform/mt_pmic_dlpt.h>
  50. #include <platform/mt_pmic_wrap_init.h>
  51. #include <platform/mt_i2c.h>
  52. #include <platform/mt_spi_slave.h>
  53. #include <platform/mtk_key.h>
  54. #include <platform/mtk_smi.h>
  55. #include <platform/mt_rtc.h>
  56. #include <platform/mt_leds.h>
  57. #include <platform/upmu_common.h>
  58. #ifdef CFG_MTK_WDT_COMMON
  59. #include <mtk_wdt.h>
  60. #else
  61. #include <platform/mtk_wdt.h>
  62. #endif
  63. #include <platform/disp_drv_platform.h>
  64. #include <platform/verified_boot.h>
  65. #include <platform/sec_devinfo.h>
  66. #include <plinfo.h> // for plinfo_get_brom_header_block_size()
  67. #include <libfdt.h>
  68. #include <mt_gic.h> // for platform_init_interrupts()
  69. #include <mt_boot.h> // for bldr_load_dtb()
  70. #include <mtk_dcm.h> // for mt_dcm_init()
  71. #include <fpga_boot_argument.h>
  72. #include <profiling.h>
  73. #include <assert.h>
  74. #include <platform/mt_gpt.h> // for get_timer()
  75. #include <sec_export.h>
  76. #include "memory_layout.h"
  77. #include "load_vfy_boot.h"
  78. #include <fdt_op.h>
  79. #include <verified_boot_common.h>
  80. #include <platform/mtk_charger_intf.h>
  81. #include <rsc.h>
  82. #ifdef MTK_SMC_ID_MGMT
  83. #include "mtk_secure_api.h"
  84. #endif
  85. #include "mtk_dcm.h" //for mt_dcm_init()
  86. #ifdef MTK_EMMC_SUPPORT
  87. #include "mmc_rpmb.h"
  88. #endif
  89. #define DEVAPC_TURN_ON 1
  90. #if defined(MTK_VPU_SUPPORT)
  91. #include <platform/mt_vpu.h>
  92. #endif
  93. #ifdef MTK_AB_OTA_UPDATER
  94. #include "bootctrl.h"
  95. #endif
  96. #if defined(MTK_SECURITY_SW_SUPPORT)
  97. #include "oemkey.h"
  98. #endif
  99. #ifdef MTK_UFS_SUPPORT
  100. #include "ufs_aio_interface.h"
  101. #endif
  102. #ifdef MTK_CHARGER_NEW_ARCH
  103. #include <mtk_charger.h>
  104. #include <mtk_battery.h>
  105. #endif
  106. #include "show_animation_common.h"
  107. #ifdef MTK_SECURITY_SW_SUPPORT
  108. extern u8 g_oemkey[OEM_PUBK_SZ];
  109. #endif
  110. #ifdef LK_DL_CHECK
  111. /*block if check dl fail*/
  112. #undef LK_DL_CHECK_BLOCK_LEVEL
  113. #endif
  114. extern void platform_early_init_timer();
  115. extern void jump_da(u32 addr, u32 arg1, u32 arg2);
  116. extern int i2c_hw_init(void);
  117. extern int mboot_common_load_logo(unsigned long logo_addr, char* filename);
  118. extern int sec_func_init(u64 pl_start_addr);
  119. extern int sec_usbdl_enabled (void);
  120. extern unsigned int crypto_hw_engine_disable(void);
  121. extern void mtk_wdt_disable(void);
  122. extern void platform_deinit_interrupts(void);
  123. extern int mmc_get_dl_info(void);
  124. extern int mmc_legacy_init(int);
  125. extern void platform_clear_all_on_mux(void);
  126. extern unsigned int crypto_hw_engine_disable(void);
  127. #ifdef MTK_AEE_PLATFORM_DEBUG_SUPPORT
  128. extern void latch_lastbus_init(void);
  129. #endif
  130. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  131. extern kal_bool is_low_battery(kal_int32 val);
  132. extern int hw_charging_get_charger_type(void);
  133. #endif
  134. #ifdef MTK_LK_REGISTER_WDT
  135. extern void lk_register_wdt_callback(void);
  136. #endif
  137. void platform_uninit(void);
  138. void config_shared_SRAM_size(void);
  139. extern int dev_info_nr_cpu(void);
  140. extern void mt_pll_turn_off(void);
  141. struct mmu_initial_mapping mmu_initial_mappings[] = {
  142. {
  143. .phys = (uint64_t)0,
  144. .virt = (uint32_t)0,
  145. .size = 0x40000000,
  146. .flags = MMU_MEMORY_TYPE_STRONGLY_ORDERED | MMU_MEMORY_AP_P_RW_U_NA,
  147. .name = "mcusys"
  148. },
  149. {
  150. .phys = (uint64_t)MEMBASE,
  151. .virt = (uint32_t)MEMBASE,
  152. .size = ROUNDUP(MEMSIZE, SECTION_SIZE),
  153. .flags = MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA,
  154. .name = "ram"
  155. },
  156. {
  157. .phys = (uint64_t)SCRATCH_ADDR,
  158. .virt = (uint32_t)SCRATCH_ADDR,
  159. .size = SCRATCH_SIZE,
  160. .flags = MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA,
  161. .name = "download"
  162. },
  163. /* null entry to terminate the list */
  164. { 0 }
  165. };
  166. BOOT_ARGUMENT *g_boot_arg;
  167. BOOT_ARGUMENT boot_addr;
  168. int g_nr_bank;
  169. BI_DRAM bi_dram[MAX_NR_BANK];
  170. unsigned int g_fb_base;
  171. unsigned int g_fb_size;
  172. static int g_dram_init_ret;
  173. static unsigned int bootarg_addr;
  174. static unsigned int bootarg_size;
  175. extern unsigned int logo_lk_t;
  176. extern unsigned int boot_time;
  177. int dram_init(void)
  178. {
  179. unsigned int i;
  180. struct boot_tag *tags;
  181. /* Get parameters from pre-loader. Get as early as possible
  182. * The address of BOOT_ARGUMENT_LOCATION will be used by Linux later
  183. * So copy the parameters from BOOT_ARGUMENT_LOCATION to LK's memory region
  184. */
  185. g_boot_arg = &boot_addr;
  186. bootarg_addr = (unsigned int)((unsigned int *)BOOT_ARGUMENT_LOCATION);
  187. bootarg_size = 0;
  188. fpga_set_boot_argument((BOOT_ARGUMENT*)bootarg_addr);
  189. if (*(unsigned int *)BOOT_ARGUMENT_LOCATION == BOOT_ARGUMENT_MAGIC) {
  190. memcpy(g_boot_arg, (void*)BOOT_ARGUMENT_LOCATION, sizeof(BOOT_ARGUMENT));
  191. bootarg_size = sizeof(BOOT_ARGUMENT);
  192. } else {
  193. g_boot_arg->maggic_number = BOOT_ARGUMENT_MAGIC;
  194. for (tags = (void *)BOOT_ARGUMENT_LOCATION; tags->hdr.size; tags = boot_tag_next(tags)) {
  195. switch (tags->hdr.tag) {
  196. case BOOT_TAG_BOOT_REASON:
  197. g_boot_arg->boot_reason = tags->u.boot_reason.boot_reason;
  198. break;
  199. case BOOT_TAG_BOOT_MODE:
  200. g_boot_arg->boot_mode = tags->u.boot_mode.boot_mode;
  201. break;
  202. case BOOT_TAG_META_COM:
  203. g_boot_arg->meta_com_type = tags->u.meta_com.meta_com_type;
  204. g_boot_arg->meta_com_id = tags->u.meta_com.meta_com_id;
  205. g_boot_arg->meta_uart_port = tags->u.meta_com.meta_uart_port;
  206. g_boot_arg->meta_log_disable = tags->u.meta_com.meta_log_disable;
  207. g_boot_arg->fast_meta_gpio = tags->u.meta_com.fast_meta_gpio;
  208. break;
  209. case BOOT_TAG_LOG_COM:
  210. g_boot_arg->log_port = tags->u.log_com.log_port;
  211. g_boot_arg->log_baudrate = tags->u.log_com.log_baudrate;
  212. g_boot_arg->log_enable = tags->u.log_com.log_enable;
  213. g_boot_arg->log_dynamic_switch = tags->u.log_com.log_dynamic_switch;
  214. break;
  215. case BOOT_TAG_MEM:
  216. g_boot_arg->dram_rank_num = tags->u.mem.dram_rank_num;
  217. for (i = 0; i < tags->u.mem.dram_rank_num; i++) {
  218. g_boot_arg->dram_rank_size[i] = tags->u.mem.dram_rank_size[i];
  219. }
  220. g_boot_arg->mblock_info = tags->u.mem.mblock_info;
  221. g_boot_arg->orig_dram_info = tags->u.mem.orig_dram_info;
  222. g_boot_arg->lca_reserved_mem = tags->u.mem.lca_reserved_mem;
  223. g_boot_arg->tee_reserved_mem = tags->u.mem.tee_reserved_mem;
  224. break;
  225. case BOOT_TAG_MD_INFO:
  226. for (i = 0; i < 4; i++) {
  227. g_boot_arg->md_type[i] = tags->u.md_info.md_type[i];
  228. }
  229. break;
  230. case BOOT_TAG_BOOT_TIME:
  231. g_boot_arg->boot_time = tags->u.boot_time.boot_time;
  232. break;
  233. case BOOT_TAG_DA_INFO:
  234. memcpy(&g_boot_arg->da_info, &tags->u.da_info.da_info, sizeof(da_info_t));
  235. break;
  236. case BOOT_TAG_SEC_INFO:
  237. memcpy(&g_boot_arg->sec_limit, &tags->u.sec_info.sec_limit, sizeof(SEC_LIMIT));
  238. break;
  239. case BOOT_TAG_PART_NUM:
  240. g_boot_arg->part_num = tags->u.part_num.part_num;
  241. break;
  242. case BOOT_TAG_PART_INFO:
  243. g_boot_arg->part_info = tags->u.part_info.part_info; /* only copy the pointer but the contains*/
  244. break;
  245. case BOOT_TAG_EFLAG:
  246. g_boot_arg->e_flag = tags->u.eflag.e_flag;
  247. break;
  248. case BOOT_TAG_DDR_RESERVE:
  249. g_boot_arg->ddr_reserve_enable = tags->u.ddr_reserve.ddr_reserve_enable;
  250. g_boot_arg->ddr_reserve_success = tags->u.ddr_reserve.ddr_reserve_success;
  251. g_boot_arg->ddr_reserve_ready = tags->u.ddr_reserve.ddr_reserve_ready;
  252. break;
  253. case BOOT_TAG_DRAM_BUF:
  254. g_boot_arg->dram_buf_size = tags->u.dram_buf.dram_buf_size;
  255. break;
  256. case BOOT_TAG_SRAM_INFO:
  257. g_boot_arg->non_secure_sram_addr = tags->u.sram_info.non_secure_sram_addr;
  258. g_boot_arg->non_secure_sram_size = tags->u.sram_info.non_secure_sram_size;
  259. break;
  260. case BOOT_TAG_PLAT_DBG_INFO:
  261. g_boot_arg->plat_dbg_info_max = tags->u.plat_dbg_info.info_max;
  262. if (g_boot_arg->plat_dbg_info_max > INFO_TYPE_MAX)
  263. g_boot_arg->plat_dbg_info_max = INFO_TYPE_MAX;
  264. for (i = 0; i < g_boot_arg->plat_dbg_info_max; i++) {
  265. g_boot_arg->plat_dbg_info[i].key = tags->u.plat_dbg_info.info[i].key;
  266. g_boot_arg->plat_dbg_info[i].base = tags->u.plat_dbg_info.info[i].base;
  267. g_boot_arg->plat_dbg_info[i].size = tags->u.plat_dbg_info.info[i].size;
  268. }
  269. break;
  270. case BOOT_TAG_PTP:
  271. memcpy(&g_boot_arg->ptp_volt_info, &tags->u.ptp_volt.ptp_volt_info, sizeof(ptp_info_t));
  272. break;
  273. case BOOT_TAG_EMI_INFO:
  274. memcpy(&(g_boot_arg->emi_info), &(tags->u.emi_info), sizeof(emi_info_t));
  275. break;
  276. case BOOT_TAG_IMGVER_INFO:
  277. g_boot_arg->pl_imgver_status = tags->u.imgver_info.pl_imgver_status;
  278. break;
  279. case BOOT_TAG_MAX_CPUS:
  280. g_boot_arg->max_cpus = tags->u.max_cpus.max_cpus;
  281. break;
  282. case BOOT_TAG_BAT_INFO:
  283. g_boot_arg->boot_voltage = tags->u.bat_info.boot_voltage;
  284. g_boot_arg->shutdown_time= tags->u.bat_info.shutdown_time;
  285. break;
  286. case BOOT_TAG_RAM_CONSOLE_INFO:
  287. g_boot_arg->ram_console_sram_addr = tags->u.ram_console_info.sram_addr;
  288. g_boot_arg->ram_console_sram_size = tags->u.ram_console_info.sram_size;
  289. g_boot_arg->ram_console_def_type = tags->u.ram_console_info.def_type;
  290. g_boot_arg->ram_console_memory_info_offset = tags->u.ram_console_info.memory_info_offset;
  291. break;
  292. case BOOT_TAG_CHR_INFO:
  293. g_boot_arg->charger_type = tags->u.chr_info.charger_type;
  294. break;
  295. #if WITH_GZ_MD_SHAREMEM
  296. case BOOT_TAG_GZ_PARAM:
  297. g_boot_arg->gz_md_shm_pa = tags->u.gz_param.modemMteeShareMemPA;
  298. g_boot_arg->gz_md_shm_sz = tags->u.gz_param.modemMteeShareMemSize;
  299. break;
  300. #endif
  301. case BOOT_TAG_SOC_ID:
  302. memcpy(g_boot_arg->socid, tags->u.socid.id, SOC_ID_LEN);
  303. break;
  304. default:
  305. break;
  306. }
  307. bootarg_size += tags->hdr.size;
  308. }
  309. }
  310. fpga_copy_boot_argument(g_boot_arg);
  311. g_nr_bank = g_boot_arg->dram_rank_num;
  312. if (g_nr_bank == 0 || g_nr_bank > MAX_NR_BANK) {
  313. g_dram_init_ret = -1;
  314. //dprintf(CRITICAL, "[LK ERROR] DRAM bank number is not correct!!!");
  315. //while (1) ;
  316. return -1;
  317. }
  318. return 0;
  319. }
  320. unsigned int platform_get_bootarg_addr(void)
  321. {
  322. return bootarg_addr;
  323. }
  324. unsigned int platform_get_bootarg_size(void)
  325. {
  326. return bootarg_size;
  327. }
  328. /*******************************************************
  329. * Routine: memory_size
  330. * Description: return DRAM size to LCM driver
  331. ******************************************************/
  332. u32 ddr_enable_4gb(void)
  333. {
  334. u32 status;
  335. #define INFRA_MISC (INFRACFG_AO_BASE + 0x0F00)
  336. #define INFRA_4GB_EN (1 << 13)
  337. #define PERI_MISC (PERICFG_BASE + 0x0208)
  338. #define PERI_4GB_EN (1 << 15)
  339. status = ((DRV_Reg32(INFRA_MISC) & INFRA_4GB_EN) && (DRV_Reg32(PERI_MISC) & PERI_4GB_EN)) ? 1 : 0;
  340. dprintf(CRITICAL, "%s() status=%u\n", __func__, status);
  341. return status;
  342. }
  343. u64 physical_memory_size(void)
  344. {
  345. int i;
  346. unsigned long long size = 0;
  347. for (i = 0; i < (int)(g_boot_arg->orig_dram_info.rank_num); i++) {
  348. size += g_boot_arg->orig_dram_info.rank_info[i].size;
  349. }
  350. return size;
  351. }
  352. u32 memory_size(void)
  353. {
  354. unsigned long long size = physical_memory_size();
  355. while (((unsigned long long)DRAM_PHY_ADDR + size) > 0x100000000ULL) {
  356. size -= (unsigned long long)(1024*1024*1024);
  357. }
  358. return (unsigned int)size;
  359. }
  360. void sw_env()
  361. {
  362. #ifdef LK_DL_CHECK
  363. #if defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
  364. int dl_status = 0;
  365. dl_status = mmc_get_dl_info();
  366. dprintf(INFO, "mt65xx_sw_env--dl_status: %d\n", dl_status);
  367. if (dl_status != 0) {
  368. video_printf("=> TOOL DL image Fail!\n");
  369. dprintf(CRITICAL, "TOOL DL image Fail\n");
  370. #ifdef LK_DL_CHECK_BLOCK_LEVEL
  371. dprintf(CRITICAL, "uboot is blocking by dl info\n");
  372. while (1) ;
  373. #endif
  374. }
  375. #endif
  376. #endif
  377. #ifndef MACH_FPGA_NO_DISPLAY
  378. #ifndef USER_BUILD
  379. switch (g_boot_mode) {
  380. case META_BOOT:
  381. video_printf(" => META MODE\n");
  382. break;
  383. case FACTORY_BOOT:
  384. video_printf(" => FACTORY MODE\n");
  385. break;
  386. case RECOVERY_BOOT:
  387. video_printf(" => RECOVERY MODE\n");
  388. break;
  389. case SW_REBOOT:
  390. //video_printf(" => SW RESET\n");
  391. break;
  392. case NORMAL_BOOT:
  393. //if(g_boot_arg->boot_reason != BR_RTC && get_env("hibboot") != NULL && atoi(get_env("hibboot")) == 1)
  394. if (get_env("hibboot") != NULL && atoi(get_env("hibboot")) == 1)
  395. video_printf(" => HIBERNATION BOOT\n");
  396. else
  397. video_printf(" => NORMAL BOOT\n");
  398. break;
  399. case ADVMETA_BOOT:
  400. video_printf(" => ADVANCED META MODE\n");
  401. break;
  402. case ATE_FACTORY_BOOT:
  403. video_printf(" => ATE FACTORY MODE\n");
  404. break;
  405. #ifdef MTK_KERNEL_POWER_OFF_CHARGING
  406. case KERNEL_POWER_OFF_CHARGING_BOOT:
  407. video_printf(" => POWER OFF CHARGING MODE\n");
  408. break;
  409. case LOW_POWER_OFF_CHARGING_BOOT:
  410. video_printf(" => LOW POWER OFF CHARGING MODE\n");
  411. break;
  412. #endif
  413. case ALARM_BOOT:
  414. video_printf(" => ALARM BOOT\n");
  415. break;
  416. case FASTBOOT:
  417. video_printf(" => FASTBOOT mode...\n");
  418. break;
  419. default:
  420. video_printf(" => UNKNOWN BOOT\n");
  421. }
  422. return;
  423. #endif
  424. #ifdef USER_BUILD
  425. /* it's ok to display META MODE since it already verfied by preloader */
  426. if (g_boot_mode == META_BOOT)
  427. video_printf(" => META MODE\n");
  428. if (g_boot_mode == FASTBOOT)
  429. video_printf(" => FASTBOOT mode...\n");
  430. return;
  431. #endif
  432. #endif /* MACH_FPGA_NO_DISPLAY */
  433. }
  434. extern uint64_t ld_tt_l1[4];
  435. void platform_init_mmu(void)
  436. {
  437. /* configure available RAM banks */
  438. dram_init();
  439. /* Long-descriptor translation with lpae enable */
  440. arm_mmu_lpae_init();
  441. struct mmu_initial_mapping *m = mmu_initial_mappings;
  442. for (uint i = 0; i < countof(mmu_initial_mappings); i++, m++) {
  443. arch_mmu_map(m->phys, m->virt, m->flags, m->size);
  444. }
  445. arch_enable_mmu(); //enable mmu after setup page table to avoid cpu prefetch which may bring on emi violation
  446. }
  447. /******************************************************************************
  448. ******************************************************************************/
  449. void init_storage(void)
  450. {
  451. PROFILING_START("NAND/EMMC init");
  452. #if defined(MTK_EMMC_SUPPORT)
  453. mmc_legacy_init(1);
  454. #elif defined(MTK_UFS_SUPPORT)
  455. ufs_lk_init();
  456. #else
  457. #ifndef MACH_FPGA
  458. nand_init();
  459. nand_driver_test();
  460. #endif // MACH_FPGA
  461. #endif // MTK_EMMC_SUPPORT
  462. #if defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
  463. init_rpmb_sharemem();
  464. #endif
  465. PROFILING_END(); /* NAND/EMMC init */
  466. }
  467. /******************************************************************************
  468. ******************************************************************************/
  469. void platform_early_init(void)
  470. {
  471. PROFILING_START("platform_early_init");
  472. #ifdef MTK_LK_REGISTER_WDT
  473. lk_register_wdt_callback();
  474. #endif
  475. /* initialize the uart */
  476. uart_init_early();
  477. PROFILING_START("Devinfo Init");
  478. init_devinfo_data();
  479. PROFILING_END();
  480. platform_init_interrupts();
  481. platform_early_init_timer();
  482. #if !defined(USE_DTB_NO_DWS) && !defined(MACH_FPGA)
  483. mt_gpio_set_default();
  484. #endif // !defined(USE_DTB_NO_DWS) && !defined(MACH_FPGA)
  485. dprintf(SPEW, "bootarg_addr: 0x%x, bootarg_size: 0x%x\n", platform_get_bootarg_addr(), platform_get_bootarg_size());
  486. if (g_dram_init_ret < 0) {
  487. dprintf(CRITICAL, "[LK ERROR] DRAM bank number is not correct!!!\n");
  488. while (1) ;
  489. }
  490. //i2c_v1_init();
  491. PROFILING_START("WDT Init");
  492. mtk_wdt_init();
  493. PROFILING_END();
  494. //i2c init
  495. i2c_hw_init();
  496. #ifdef MACH_FPGA
  497. mtk_timer_init(); // GPT4 will be initialized at PL after
  498. mtk_wdt_disable(); // WDT will be triggered when uncompressing linux image on FPGA
  499. #endif
  500. pwrap_init_lk();
  501. #if !defined(MACH_FPGA) && !defined(NO_PMIC)
  502. PROFILING_START("pmic_init");
  503. pmic_init();
  504. PROFILING_END();
  505. #endif // !defined(MACH_FPGA) && !defined(NO_PMIC)
  506. PROFILING_END(); /* platform_early_init */
  507. }
  508. extern void mt65xx_bat_init(void);
  509. extern bool mtk_bat_allow_backlight_enable(void);
  510. #if defined (MTK_KERNEL_POWER_OFF_CHARGING)
  511. int kernel_charging_boot(void)
  512. {
  513. if ((g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT || g_boot_mode == LOW_POWER_OFF_CHARGING_BOOT) && upmu_is_chr_det() == KAL_TRUE) {
  514. dprintf(INFO,"[%s] Kernel Power Off Charging with Charger/Usb \n", __func__);
  515. return 1;
  516. } else if ((g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT || g_boot_mode == LOW_POWER_OFF_CHARGING_BOOT) && upmu_is_chr_det() == KAL_FALSE) {
  517. dprintf(INFO,"[%s] Kernel Power Off Charging without Charger/Usb \n", __func__);
  518. return -1;
  519. } else
  520. return 0;
  521. }
  522. #endif
  523. static void lk_vb_init(void)
  524. {
  525. #ifdef MTK_SECURITY_SW_SUPPORT
  526. u64 pl_start_addr = 0;
  527. #ifdef MTK_VER_SIMPLE_TEST
  528. u32 ret = 0;
  529. ret = sec_mtk_internal_ver_test(MTK_VER_SIMPLE_TEST);
  530. if (ret)
  531. assert(0);
  532. #endif
  533. #ifdef MTK_OTP_FRAMEWORK_V2
  534. enable_anti_rollback_v2_framework();
  535. #endif
  536. plinfo_get_brom_header_block_size(&pl_start_addr);
  537. PROFILING_START("Security init");
  538. /* initialize security library */
  539. sec_func_init(pl_start_addr);
  540. seclib_set_oemkey(g_oemkey, OEM_PUBK_SZ);
  541. PROFILING_END();
  542. #endif
  543. }
  544. static void lk_vb_vfy_logo(void)
  545. {
  546. #ifdef MTK_SECURITY_SW_SUPPORT
  547. /* bypass logo vfy in fast meta mode */
  548. if(g_boot_mode == META_BOOT)
  549. return;
  550. PROFILING_START("logo verify");
  551. /*Verify logo before use it*/
  552. if (0 != img_auth_stor("logo", "logo", 0x0))
  553. assert(0);
  554. PROFILING_END();
  555. #endif
  556. }
  557. void platform_init(void)
  558. {
  559. bool backlight_on = false;
  560. int logo_size;
  561. PROFILING_START("platform_init");
  562. dprintf(CRITICAL, "platform_init()\n");
  563. init_storage();
  564. lk_vb_init();
  565. extern void dummy_ap_entry(void)__attribute__((weak)); /* This is empty function for normal load */
  566. if (dummy_ap_entry)
  567. dummy_ap_entry();
  568. #ifdef MTK_AB_OTA_UPDATER
  569. /* get A/B system parameter before load dtb from boot image */
  570. get_AB_OTA_param();
  571. #endif
  572. /*
  573. * RSC initialize. It must be done before load device tree.
  574. * rsc_init will ectract DTBO index, which will be used in device
  575. * tree overlay, from PARA partition
  576. */
  577. rsc_init();
  578. /* The device tree should be loaded as early as possible. */
  579. load_device_tree();
  580. #if defined(USE_DTB_NO_DWS) && !defined(MACH_FPGA)
  581. mt_gpio_set_default();
  582. #endif // defined(USE_DTB_NO_DWS) && !defined(MACH_FPGA)
  583. bdg_tx_pull_6382_reset_pin();
  584. clk_buf_disp_ctrl(true);
  585. /*spi slave init*/
  586. spi_slave_probe();
  587. #ifndef MACH_FPGA
  588. PROFILING_START("led init");
  589. leds_init();
  590. PROFILING_END();
  591. #endif // MACH_FPGA
  592. #ifdef MTK_KERNEL_POWER_OFF_CHARGING
  593. if ((g_boot_arg->boot_reason == BR_USB) && (upmu_is_chr_det() == KAL_FALSE)) {
  594. dprintf(INFO, "[%s] Unplugged Charger/Usb between Pre-loader and Uboot in Kernel Charging Mode, Power Off \n", __func__);
  595. mt_power_off();
  596. }
  597. #endif // MTK_KERNEL_POWER_OFF_CHARGING
  598. PROFILING_START("ENV init");
  599. env_init();
  600. print_env();
  601. PROFILING_END();
  602. /* initialize the frame buffet information */
  603. g_fb_size = mt_disp_get_vram_size();
  604. g_fb_base = mblock_reserve_ext(&g_boot_arg->mblock_info, g_fb_size, 0x10000, 0x80000000, 0, "framebuffer");
  605. if (!g_fb_base) {
  606. dprintf(CRITICAL, "reserve framebuffer failed\n");
  607. }
  608. dprintf(CRITICAL, "FB base = 0x%x, FB size = 0x%x (%d)\n", g_fb_base, g_fb_size, g_fb_size);
  609. #ifndef MACH_FPGA
  610. #ifdef MTK_SMI_SUPPORT
  611. /* write SMI non on-the-fly register before DISP init */
  612. smi_apply_register_setting();
  613. #endif
  614. #endif
  615. #ifndef MACH_FPGA_NO_DISPLAY
  616. PROFILING_START("disp init");
  617. mt_disp_init((void *)g_fb_base);
  618. PROFILING_END();
  619. PROFILING_START("vedio init");
  620. drv_video_init();
  621. PROFILING_END();
  622. #endif /* MACH_FPGA_NO_DISPLAY */
  623. /*for kpd pmic mode setting*/
  624. set_kpd_pmic_mode();
  625. #ifndef MACH_FPGA
  626. PROFILING_START("boot mode select");
  627. #if !defined(NO_BOOT_MODE_SEL)
  628. boot_mode_select();
  629. #endif
  630. #ifdef CFG_MTK_WDT_COMMON
  631. PROFILING_START("wdt_check_exception");
  632. wdt_check_exception();
  633. PROFILING_END();
  634. #endif //CFG_MTK_WDT_COMMON
  635. #ifdef MTK_USB2JTAG_SUPPORT
  636. if (g_boot_mode != FASTBOOT) {
  637. extern void usb2jtag_init(void);
  638. usb2jtag_init();
  639. }
  640. #endif
  641. #ifdef MTK_AEE_PLATFORM_DEBUG_SUPPORT
  642. /* init lastbus: MUST call after kedump (in boot_mode_select) */
  643. latch_lastbus_init();
  644. #endif
  645. PROFILING_END(); /* boot mode select */
  646. #endif /*MACH_FPGA */
  647. lk_vb_vfy_logo();
  648. #ifndef MACH_FPGA_NO_DISPLAY
  649. /* fast meta mode */
  650. if(g_boot_mode != META_BOOT){
  651. PROFILING_START("load_logo");
  652. logo_size = mboot_common_load_logo((unsigned long)mt_get_logo_db_addr_pa(), "logo");
  653. assert(logo_size <= LK_LOGO_MAX_SIZE);
  654. PROFILING_END();
  655. } else
  656. /* Indicate logo lib that logo partition is not loaded */
  657. enable_logo(0);
  658. #endif // MACH_FPGA_NO_DISPLAY
  659. /*Show download logo & message on screen */
  660. if (g_boot_arg->boot_mode == DOWNLOAD_BOOT) {
  661. dprintf(CRITICAL, "[LK] boot mode is DOWNLOAD_BOOT\n");
  662. #ifndef MACH_FPGA_NO_DISPLAY
  663. PROFILING_START("show logo");
  664. mt_disp_show_boot_logo();
  665. PROFILING_END();
  666. #endif
  667. video_printf(" => Downloading...\n");
  668. dprintf(CRITICAL, "enable backlight after show bootlogo! \n");
  669. #ifndef MACH_FPGA
  670. PROFILING_START("backlight");
  671. mt65xx_backlight_on();
  672. PROFILING_END();
  673. #endif
  674. #ifndef MACH_FPGA_NO_DISPLAY
  675. /* pwm need display sof */
  676. PROFILING_START("disp update");
  677. mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  678. PROFILING_END();
  679. #endif
  680. logo_lk_t = ((unsigned int)get_timer(boot_time));
  681. PROFILING_START("disable wdt, l2, cache, mmu");
  682. mtk_wdt_disable(); //Disable wdt before jump to DA
  683. platform_uninit();
  684. #ifdef HAVE_CACHE_PL310
  685. l2_disable();
  686. #endif
  687. arch_disable_cache(UCACHE);
  688. arch_disable_mmu();
  689. #ifdef ENABLE_L2_SHARING
  690. config_shared_SRAM_size();
  691. #endif
  692. PROFILING_END();
  693. jump_da(g_boot_arg->da_info.addr, g_boot_arg->da_info.arg1, g_boot_arg->da_info.arg2);
  694. }
  695. #ifdef MTK_KERNEL_POWER_OFF_CHARGING
  696. else if (g_boot_mode != META_BOOT &&
  697. g_boot_mode != ALARM_BOOT &&
  698. g_boot_mode != FASTBOOT &&
  699. g_boot_mode != KERNEL_POWER_OFF_CHARGING_BOOT &&
  700. g_boot_mode != LOW_POWER_OFF_CHARGING_BOOT &&
  701. mtk_bat_allow_backlight_enable()) {
  702. #ifndef MACH_FPGA_NO_DISPLAY
  703. PROFILING_START("show logo");
  704. mt_disp_show_boot_logo();
  705. PROFILING_END();
  706. #endif // MACH_FPGA_NO_DISPLAY
  707. #ifndef MACH_FPGA
  708. PROFILING_START("backlight");
  709. mt65xx_backlight_on();
  710. PROFILING_END(); /* backlight */
  711. #endif
  712. #ifndef MACH_FPGA_NO_DISPLAY
  713. /* pwm need display sof */
  714. PROFILING_START("disp update");
  715. mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  716. PROFILING_END();
  717. #endif
  718. backlight_on = true;
  719. dprintf(INFO, "backlight enabled before battery init\n");
  720. logo_lk_t = ((unsigned int)get_timer(boot_time));
  721. }
  722. #endif // MTK_KERNEL_POWER_OFF_CHARGING
  723. PROFILING_START("battery init");
  724. #ifndef MACH_FPGA
  725. #if !defined(NO_PLL_TURN_OFF)
  726. mt_pll_turn_off();
  727. #endif // !defined(NO_PLL_TURN_OFF)
  728. #if !defined(NO_DCM)
  729. if (mt_dcm_init())
  730. dprintf(CRITICAL, "mt_dcm_init fail\n");
  731. #endif // !defined(NO_DCM)
  732. #if !defined(NO_BAT_INIT)
  733. #ifdef MTK_CHARGER_NEW_ARCH
  734. PROFILING_START("charger init");
  735. mtk_charger_init();
  736. PROFILING_END(); /* charger init */
  737. PROFILING_START("DLPT init");
  738. pmic_dlpt_init();
  739. PROFILING_END(); /* dlpt init */
  740. PROFILING_START("check sw_ocv");
  741. check_sw_ocv();
  742. PROFILING_END(); /* battery check sw_ocv */
  743. PROFILING_START("charger start");
  744. mtk_charger_start();
  745. PROFILING_END(); /* charger start */
  746. PROFILING_START(" DLPT get imix");
  747. get_dlpt_imix_r();
  748. PROFILING_END(); /* DLPT get imix */
  749. #else
  750. mt65xx_bat_init();
  751. #endif // MTK_CHARGER_NEW_ARCH
  752. #endif // !defined(NO_BAT_INIT)
  753. #endif // MACH_FPGA
  754. PROFILING_END(); /* battery init */
  755. #ifndef CFG_POWER_CHARGING
  756. PROFILING_START("RTC boot check Init");
  757. /* NOTE: if define CFG_POWER_CHARGING, will rtc_boot_check() in mt65xx_bat_init() */
  758. rtc_boot_check(false);
  759. PROFILING_END();
  760. #endif // CFG_POWER_CHARGING
  761. #ifdef MTK_KERNEL_POWER_OFF_CHARGING
  762. if (kernel_charging_boot() == 1) {
  763. PROFILING_START("show logo");
  764. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  765. CHARGER_TYPE CHR_Type_num = CHARGER_UNKNOWN;
  766. CHR_Type_num = hw_charging_get_charger_type();
  767. if ((g_boot_mode != LOW_POWER_OFF_CHARGING_BOOT) ||
  768. ((CHR_Type_num != STANDARD_HOST) && (CHR_Type_num != NONSTANDARD_CHARGER))) {
  769. #endif // MTK_BATLOWV_NO_PANEL_ON_EARLY
  770. mt_disp_power(TRUE);
  771. #ifndef MACH_FPGA_NO_DISPLAY
  772. mt_disp_show_low_battery();
  773. #endif
  774. mt65xx_leds_brightness_set(6, 110);
  775. #ifndef MACH_FPGA_NO_DISPLAY
  776. /* pwm need display sof */
  777. PROFILING_START("display update");
  778. mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  779. PROFILING_END();
  780. #endif
  781. backlight_on = true;
  782. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  783. }
  784. #endif
  785. PROFILING_END();
  786. }
  787. #endif // MTK_KERNEL_POWER_OFF_CHARGING
  788. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  789. if (!is_low_battery(0)) {
  790. #endif
  791. /*
  792. * Update LCM with framebuffer before
  793. * turning on backlight to avoid LCM noise if there is
  794. * no any logo showed on screen before.
  795. */
  796. if (!backlight_on) {
  797. logo_lk_t = ((unsigned int)get_timer(boot_time));
  798. #ifndef MACH_FPGA_NO_DISPLAY
  799. PROFILING_START("display update");
  800. mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  801. PROFILING_END();
  802. #endif
  803. #ifndef MACH_FPGA
  804. PROFILING_START("backlight");
  805. mt65xx_backlight_on();
  806. PROFILING_END(); /* backlight */
  807. #endif
  808. }
  809. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  810. }
  811. #endif
  812. #ifndef MACH_FPGA
  813. PROFILING_START("sw_env");
  814. sw_env();
  815. PROFILING_END();
  816. #endif
  817. PROFILING_END(); /* platform_init */
  818. }
  819. void platform_uninit(void)
  820. {
  821. #ifndef MACH_FPGA
  822. leds_deinit();
  823. platform_clear_all_on_mux();
  824. #endif
  825. platform_deinit_interrupts();
  826. return;
  827. }
  828. #ifdef ENABLE_L2_SHARING
  829. #define ADDR_CA7L_CACHE_CONFIG_MP(x) (CA7MCUCFG_BASE + 0x200 * x)
  830. #define L2C_SIZE_CFG_OFFSET 8
  831. #define L2C_SHARE_EN_OFFSET 12
  832. /* 4'b1111: 2048KB(not support)
  833. * 4'b0111: 1024KB(not support)
  834. * 4'b0011: 512KB
  835. * 4'b0001: 256KB
  836. * 4'b0000: 128KB (not support)
  837. */
  838. int is_l2_need_config(void)
  839. {
  840. volatile unsigned int cache_cfg, addr;
  841. addr = ADDR_CA7L_CACHE_CONFIG_MP(0);
  842. cache_cfg = DRV_Reg32(addr);
  843. cache_cfg = cache_cfg >> L2C_SIZE_CFG_OFFSET;
  844. /* only read 256KB need to be config.*/
  845. if ((cache_cfg &(0x7)) == 0x1) {
  846. return 1;
  847. }
  848. return 0;
  849. }
  850. void cluster_l2_share_enable(int cluster)
  851. {
  852. volatile unsigned int cache_cfg, addr;
  853. addr = ADDR_CA7L_CACHE_CONFIG_MP(cluster);
  854. /* set L2C size to 256KB */
  855. cache_cfg = DRV_Reg32(addr);
  856. cache_cfg &= (~0x7) << L2C_SIZE_CFG_OFFSET;
  857. cache_cfg |= 0x1 << L2C_SIZE_CFG_OFFSET;
  858. /* enable L2C_share_en. Sram only for other to use*/
  859. cache_cfg |= (0x1 << L2C_SHARE_EN_OFFSET);
  860. DRV_WriteReg32(addr, cache_cfg);
  861. }
  862. void cluster_l2_share_disable(int cluster)
  863. {
  864. volatile unsigned int cache_cfg, addr;
  865. addr = ADDR_CA7L_CACHE_CONFIG_MP(cluster);
  866. /* set L2C size to 512KB */
  867. cache_cfg = DRV_Reg32(addr);
  868. cache_cfg &= (~0x7) << L2C_SIZE_CFG_OFFSET;
  869. cache_cfg |= 0x3 << L2C_SIZE_CFG_OFFSET;
  870. DRV_WriteReg32(addr, cache_cfg);
  871. /* disable L2C_share_en. Sram only for cpu to use*/
  872. cache_cfg &= ~(0x1 << L2C_SHARE_EN_OFFSET);
  873. DRV_WriteReg32(addr, cache_cfg);
  874. }
  875. /* config L2 cache and sram to its size */
  876. void config_L2_size(void)
  877. {
  878. int cluster;
  879. if (is_l2_need_config()) {
  880. /*
  881. * Becuase mcu config is protected.
  882. * only can write in secutity mode
  883. */
  884. if (dev_info_nr_cpu() == 6) {
  885. cluster_l2_share_disable(0);
  886. cluster_l2_share_enable(1);
  887. }
  888. else {
  889. for (cluster = 0; cluster < 2; cluster++) {
  890. cluster_l2_share_disable(cluster);
  891. }
  892. }
  893. }
  894. }
  895. /* config SRAM back from L2 cache for DA relocation */
  896. void config_shared_SRAM_size(void)
  897. {
  898. int cluster;
  899. if (is_l2_need_config()) {
  900. /*
  901. * Becuase mcu config is protected.
  902. * only can write in secutity mode
  903. */
  904. for (cluster = 0; cluster < 2; cluster++) {
  905. cluster_l2_share_enable(cluster);
  906. }
  907. }
  908. }
  909. #endif
  910. void platform_sec_post_init(void)
  911. {
  912. unsigned int ret = 0;
  913. ret = crypto_hw_engine_disable();
  914. if (ret) {
  915. dprintf(CRITICAL, "[SEC] crypto engine HW disable fail\n");
  916. }
  917. /* Lock Device APC in LK */
  918. dprintf(CRITICAL, "[DEVAPC] sec_post_init\n");
  919. #if DEVAPC_TURN_ON
  920. dprintf(CRITICAL, "[DEVAPC] platform_sec_post_init - SMC call to ATF from LK\n");
  921. #ifdef MTK_SMC_ID_MGMT
  922. mt_secure_call(MTK_SIP_LK_DAPC_INIT, 0, 0, 0, 0);
  923. #else
  924. mt_secure_call(0x82000101, 0, 0, 0);
  925. #endif
  926. #endif
  927. }
  928. u32 get_devinfo_with_index(u32 index)
  929. {
  930. return internal_get_devinfo_with_index(index);
  931. }
  932. int platform_skip_hibernation(void)
  933. {
  934. switch (g_boot_arg->boot_reason) {
  935. #if 0 // let schedule power on to go hiberantion bootup process
  936. case BR_RTC:
  937. #endif
  938. case BR_WDT:
  939. case BR_WDT_BY_PASS_PWK:
  940. case BR_WDT_SW:
  941. case BR_WDT_HW:
  942. return 1;
  943. }
  944. return 0;
  945. }
  946. int is_meta_log_disable(void)
  947. {
  948. return g_boot_arg->meta_log_disable;
  949. }