int efuse_write(char *buf, unsigned count, unsigned *ppos, int from) { unsigned pos = *ppos; const char *pc; unsigned long contents[EFUSE_DWORDS]; if (pos >= EFUSE_BYTES) return 0; /* Past EOF */ if (count > EFUSE_BYTES - pos) count = EFUSE_BYTES - pos; if (count > EFUSE_BYTES) return -1; which=from; efuse_init(); int i; // checkout if have been written memset(contents, 0, EFUSE_DWORDS); pc = (char*)contents; efuse_read(pc, count, &pos, from); for(i=0; i<count; i++){ if(pc[i] != 0) return -1; } pos = *ppos; for (pc = buf; count--; ++pos, ++pc) __efuse_write_byte(pos, *pc); *ppos = pos; return 0; }
static unsigned int efuse_read_byte(unsigned long addr){ efuse_init(); unsigned int int_addr = addr; unsigned int off_addr = addr % 4; unsigned int r_data = 0; __efuse_read_dword(int_addr, &r_data); //serial_put_hex(r_data, 32); //serial_put_hex(((r_data >> (off_addr*8)) & 0xff), 8); return ((r_data >> (off_addr*8)) & 0xff); }
int do_read_efuse(int ppos,int *flag,int *temp,int *TS_C, int print) { char buf[2]; int ret; int cpu = 0; char *cpu_str[] = {"M8", "M8M2", "M8Baby", "G9TV", "G9TVBaby"}; *flag=0; buf[0]=0; buf[1]=0; //read efuse tsc,flag efuse_init(); ret=efuse_read(buf,2,(loff_t *)&ppos); if (print) { printf("buf[0]=%x,buf[1]=%x\n",buf[0],buf[1]); } if (IS_MESON_M8_CPU) { *temp=buf[1]; *temp=(*temp<<8)|buf[0]; *TS_C=*temp&0xf; *flag=(*temp&0x8000)>>15; *temp=(*temp&0x7fff)>>4; cpu = 0; } else if (IS_MESON_M8M2_CPU) {
int efuse_read(char *buf, unsigned count, unsigned *ppos, int from) { unsigned long contents[EFUSE_DWORDS]; unsigned pos = *ppos; unsigned long *pdw; unsigned residunt = pos%4; unsigned int dwsize = (count+residunt+3)>>2; if (pos >= EFUSE_BYTES) return 0; if (count > EFUSE_BYTES - pos) count = EFUSE_BYTES - pos; if (count > EFUSE_BYTES) return -1; which = from; efuse_init(); memset(contents, 0, sizeof(contents)); // Enabel auto-read mode WRITE_EFUSE_REG_BITS( efuse_reg_addr(EFUSE_CNTL1), CNTL1_AUTO_RD_ENABLE_ON, CNTL1_AUTO_RD_ENABLE_BIT, CNTL1_AUTO_RD_ENABLE_SIZE ); pos = (pos/4)*4; for (pdw = contents; dwsize-- > 0 && pos < EFUSE_BYTES; pos += 4, ++pdw) __efuse_read_dword(pos, pdw); // Disable auto-read mode WRITE_EFUSE_REG_BITS( efuse_reg_addr(EFUSE_CNTL1), CNTL1_AUTO_RD_ENABLE_OFF, CNTL1_AUTO_RD_ENABLE_BIT, CNTL1_AUTO_RD_ENABLE_SIZE ); memcpy(buf, (char*)contents+residunt, count); *ppos += count; return 0; }
static void efuse_write_byte(unsigned long addr, unsigned char data){ efuse_init(); unsigned int int_addr = addr; __efuse_write_byte(int_addr, (unsigned long)data); }
/** * @brief Stage 2 loader "C" entry point. Started from Stage 1 * bootloader. Primary function is to load, validate, and start * executing a stage 3 image. Also will (when fully implemented) * perform startup negotiations with AP, cryptographic initialzations * and tests, module authentication, flash update, and other housekeeping. * Image load and validation are essntially identical to the crresponding * functions in stage 1, although different keys are used for signature * validation. * * @param none * * @returns Nothing. Will launch/restart image if successful, halt if not. */ void bootrom_main(void) { int rc; /* TA-20 R/W data in bufRAM */ uint32_t boot_status = INIT_STATUS_OPERATING; bool boot_from_spi = true; bool fallback_boot_unipro = false; uint32_t is_secure_image; secondstage_cfgdata *cfgdata; chip_init(); dbginit(); /* Ensure that we start each boot with an assumption of success */ init_last_error(); crypto_init(); dbgprint("\nHello world from s2fw\n"); if (!get_2ndstage_cfgdata(&cfgdata)) { dbgprint("found valid config data\n"); if (cfgdata->use_fake_ims) { /** * We don't really need to handle all the efuses as boot ROM * does. But we do want to update the EPUID according to the * fake IMS. And the rest of the efuse handling do no harm * anyway. */ if (efuse_init() != 0) { halt_and_catch_fire(boot_status); } } } uint8_t ims[TSB_ISAA_NUM_IMS_BYTES]; tsb_get_ims(ims, TSB_ISAA_NUM_IMS_BYTES); key_generation(ims); chip_unipro_init(); boot_control(&boot_from_spi); /* Advertise our boot status */ chip_advertise_boot_status(boot_status); /* Advertise our initialization type */ rc = chip_advertise_boot_type(); if (rc) { halt_and_catch_fire(boot_status); } if (boot_from_spi) { dbgprint("Boot from SPIROM\n"); spi_ops.init(); /** * Call locate_ffff_element_on_storage to locate next stage FW. * Do not care about the image length here so pass NULL. */ if (locate_ffff_element_on_storage(&spi_ops, FFFF_ELEMENT_STAGE_3_FW, NULL) == 0) { boot_status = INIT_STATUS_SPI_BOOT_STARTED; chip_advertise_boot_status(boot_status); if (!load_tftf_image(&spi_ops, &is_secure_image)) { spi_ops.finish(true, is_secure_image); if (is_secure_image) { boot_status = INIT_STATUS_TRUSTED_SPI_FLASH_BOOT_FINISHED; dbgprintx32("SPI Trusted: (", merge_errno_with_boot_status(boot_status), ")\n"); } else { boot_status = INIT_STATUS_UNTRUSTED_SPI_FLASH_BOOT_FINISHED; dbgprintx32("SPI Untrusted: (", merge_errno_with_boot_status(boot_status), ")\n"); /* * Disable IMS, CMS access before starting untrusted image. * NB. JTAG continues to be not enabled at this point */ efuse_rig_for_untrusted(); } /* Log that we're starting the boot-from-SPIROM */ chip_advertise_boot_status(merge_errno_with_boot_status(boot_status)); /* TA-16 jump to SPI code (BOOTRET_o = 0 && SPIBOOT_N = 0) */ jump_to_image(); } } spi_ops.finish(false, false); /* Fallback to UniPro boot */ boot_from_spi = false; fallback_boot_unipro = true; chip_clear_image_loading_ram(); } else { /* (Not boot-from-spi, */ fallback_boot_unipro = false; } if (greybus_init()) { set_last_error(BRE_BOU_GBCTRL_CPORT); halt_and_catch_fire(boot_status); } /* Boot-Over-UniPro... * We get here if directed to do so by the bootselector, or as a fallback * for a failed SPIROM boot. */ if (!boot_from_spi) { /* Boot over Unipro */ if (fallback_boot_unipro) { boot_status = merge_errno_with_boot_status( INIT_STATUS_FALLLBACK_UNIPRO_BOOT_STARTED); dbgprintx32("Spi boot failed (", boot_status, "), "); } else { boot_status = INIT_STATUS_UNIPRO_BOOT_STARTED; } chip_advertise_boot_status(boot_status); dbgprintx32("Boot over UniPro (", merge_errno_with_boot_status(boot_status), ")\n"); advertise_ready(); #if RUN_SPI_TEST spi_gb_init(); dbgprint("Running in loop to perform as SPI over Greybus\n"); while (1) { if (greybus_loop()) { dbgprint("ERROR in greuybus loop\n"); halt_and_catch_fire(boot_status); } } #endif dbgprint("Ready-poked; download-ready\n"); if (greybus_ops.init() != 0) { halt_and_catch_fire(boot_status); } if (!load_tftf_image(&greybus_ops, &is_secure_image)) { if (greybus_ops.finish(true, is_secure_image) != 0) { halt_and_catch_fire(boot_status); } if (is_secure_image) { boot_status = fallback_boot_unipro ? INIT_STATUS_FALLLBACK_TRUSTED_UNIPRO_BOOT_FINISHED : INIT_STATUS_TRUSTED_UNIPRO_BOOT_FINISHED; dbgprintx32("UP Trusted: (", merge_errno_with_boot_status(boot_status), ")\n"); } else { boot_status = fallback_boot_unipro ? INIT_STATUS_FALLLBACK_UNTRUSTED_UNIPRO_BOOT_FINISHED : INIT_STATUS_UNTRUSTED_UNIPRO_BOOT_FINISHED; dbgprintx32("UP Trusted: (", merge_errno_with_boot_status(boot_status), ")\n"); /* * Disable IMS, CMS access before starting * untrusted image * NB. JTAG continues to be not enabled at this point */ efuse_rig_for_untrusted(); } /* Log that we're starting the boot-from-UniPro */ chip_advertise_boot_status(boot_status); /* TA-17 jump to Workram code (BOOTRET_o = 0 && SPIM_BOOT_N = 1) */ jump_to_image(); } if (greybus_ops.finish(false, is_secure_image) != 0) { halt_and_catch_fire(boot_status); } } /* If we reach here, we didn't find an image to boot - stop while we're * ahead... */ halt_and_catch_fire(boot_status); }
void BSP_DRV_Init() { #ifdef CONFIG_MODULE_VIC s32 ret = 0; #endif /***********************基础模块初始化***************************/ #ifdef CONFIG_BALONG_CCLK hi6930_clock_init(); #endif #ifdef CONFIG_CCORE_PM bsp_dpm_init(); #endif #ifdef K3_TIMER_FEATURE k3_timer_init(); #endif adp_timer_init(); timer_dpm_init(); if(0 != BSP_UDI_Init()) logMsg("BSP_UDI_Init fail\n",0,0,0,0,0,0); bsp_ipc_init(); bsp_icc_init(); #ifdef CONFIG_K3V3_CLK_CRG /*CONFIG_K3V3_CLK_CRG*/ gps_refclk_icc_read_cb_init(); #endif /* Cshell init if magic number is set to PRT_FLAG_EN_MAGIC_M */ #ifdef CONFIG_CSHELL if(0 != cshell_init()) { logMsg("cshell init fail\n",0,0,0,0,0,0); } #endif #ifdef CONFIG_NVIM if(0 != bsp_nvm_init()) logMsg("nv init fail\n",0,0,0,0,0,0); #endif /* axi monitor监控初始化 */ (void)bsp_amon_init(); /*此初始化必须放置在MSP/OAM/PS初始化之前,请不要随意改动顺序*/ tcxo_init_configure(); if(0 != bsp_rfile_init()) logMsg("rfile init fail\n",0,0,0,0,0,0); /* version inits */ bsp_productinfo_init(); hwspinlock_init(); bsp_hkadc_init(); bsp_version_init(); bsp_lowpower_mntn_init(); #ifdef CONFIG_MODULE_VIC ret = bsp_vic_init(); if(ret != OK) { logMsg("bsp_vic_init error\n", 0, 0, 0, 0, 0, 0); } #endif (void)bsp_softtimer_init(); #ifdef CONFIG_BALONG_EDMA if(0 != bsp_edma_init()) { logMsg("edma init fail \n",0,0,0,0,0,0); } #endif /*C core init ipc module*/ if(0 != socp_init()) logMsg("socp init fail\n",0,0,0,0,0,0); if(0 != bsp_om_server_init()) logMsg("om init fail\n",0,0,0,0,0,0); if(0 != bsp_dual_modem_init()) logMsg("dual modem uart init fail\n",0,0,0,0,0,0); /***********************外设模块初始化***************************/ bsp_dsp_init(); #ifdef CONFIG_BBP_INT bbp_int_init();/*此处需要放在dsp初始化之后,放在pastar/abb之前*/ #endif bsp_spi_init(); bsp_pmu_init(); regulator_init(); #if defined(CONFIG_PMIC_HI6559) if(bsp_pa_rf_init()) /* 依赖于regulator_init */ { logMsg("bsp_pa_rf_init fail\n",0,0,0,0,0,0); } #endif /*init mipi*/ #ifdef CONFIG_MIPI bsp_mipi_init(); #endif #ifdef CONFIG_TUNER bsp_tuner_init(); #endif #ifdef CONFIG_PASTAR /*此函数的位置不可以向后移动,为pastar上电后,提供足够的稳定时间*/ pmu_hi6561_init_phase1(); #endif if(0 != hi6930_wdt_init()) logMsg("wdt init fail\n",0,0,0,0,0,0); #ifdef CONFIG_CCORE_I2C if(0!=bsp_i2c_initial()) logMsg("i2c init fail\n",0,0,0,0,0,0); #endif if(0 != bsp_gpio_init()) logMsg("gpio init fail\n",0,0,0,0,0,0); #ifdef CONFIG_EFUSE if(0 != efuse_init()) { logMsg("efuse init fail \n",0,0,0,0,0,0); } #endif #ifdef CONFIG_LEDS_CCORE if(0 != bsp_led_init()) { logMsg("led init fail\n",0,0,0,0,0,0); } #endif /***********************通信支撑模块初始化***************************/ #ifdef CONFIG_CIPHER if(0 != cipher_init()) { logMsg("cipher init fail \n",0,0,0,0,0,0); } if(0 != bsp_acc_init()) { logMsg("acc init fail \n",0,0,0,0,0,0); } #endif #ifdef CONFIG_IPF if(0 != ipf_init()) logMsg("ipf init fail\n",0,0,0,0,0,0); #endif #ifdef CONFIG_MODULE_BUSSTRESS ipf_ul_stress_test_start(10); #endif #ifdef FEATURE_TLPHY_MAILBOX bsp_mailbox_init(); #endif mailbox_init(); #ifdef CONFIG_ANTEN if(0 != bsp_anten_init()) logMsg("anten init fail.\n",0,0,0,0,0,0); #endif bsp_sci_cfg_init(); bsp_abb_init(); bsp_on_off_init(); cpufreq_init(); /*初始化醒来的时间戳*/ update_awake_time_stamp(); #ifdef CONFIG_CCORE_BALONG_PM balong_pm_init(); #endif #ifdef CONFIG_AUDIO audio_init(); #endif #ifdef CONFIG_BALONG_MODEM_RESET bsp_reset_init(); #endif (void)bsp_rf_rse_init(); #ifdef CONFIG_PASTAR /*勿动!此处需要放置在该函数最后,确保pastar上电后稳定后,进行初始化配置*/ pmu_hi6561_init_phase2(); #endif (void)bsp_antn_sw_init(); }