hv_boot_Main.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. /**
  2. * @file hv_boot_Main.c
  3. * @brief boot main source code.
  4. * @details This file provides the following functions: \n
  5. * (1) Initialization and de-initialization functions \n
  6. * (2) Start and stop functions \n
  7. * (3) Feed functions \n
  8. *
  9. * @author HiView SoC Software Team
  10. * @version 1.0.0
  11. * @date 2022-08-18
  12. * @copyright Copyright(c),2022-8, Hiview Software. All rights reserved.
  13. * @par History:
  14. * <table>
  15. * <tr><th>Author <th>Date <th>Change Description
  16. * <tr><td>HiView SoC Software Team <td>2022-08-23 <td>init
  17. * </table>
  18. */
  19. #include <mips/cpu.h>
  20. #include <mips/hal.h>
  21. #include "hv_chip_Config.h"
  22. #include "hv_chip_Memory.h"
  23. #include "hv_comm_FlashConfig.h"
  24. #include "hv_boot_Lzss.h"
  25. #include "hv_boot_Common.h"
  26. __attribute__((long_call)) extern int main(int argc, char **argv);
  27. __attribute__((long_call)) extern void Hv_Vos_Init(void);
  28. #define PAGEMASK_256M 0x1FFFE000
  29. #define EHINV (1 << 10)
  30. #define ENTRY_MASK (7) // GLOBAL, VALID, DIRTY
  31. #define ENTRY_MASK_INVALID (1) // GLOBAL, VALID, DIRTY
  32. #define FLASH_END 0x4000000
  33. #define CONFIG_MONITOR_DATA_SIZE (0x10000)
  34. /* temp ddr address for code to decompress. */
  35. #define DDR_TEMP_ADDR 0x82000000
  36. unsigned int g_uiFlashUpgradeOffset = 0;
  37. /*
  38. TLB memory mapping
  39. PAddr - VAddr - kseg0 - uncached kseg0
  40. -----------------------------------------------------
  41. 0x00000000 - N/A - 0x80000000 - 0xA0000000
  42. 0x10000000 - N/A - 0x90000000 - 0xB0000000
  43. 0x80000000 - 0x60000000 - N/A - N/A
  44. 0x90000000 - 0x70000000 - N/A - N/A
  45. */
  46. static void Hv_Boot_InitTlb(void)
  47. {
  48. unsigned int uiVaddr = 0;
  49. unsigned int uiEvenAddr = 0;
  50. unsigned int uiOddAaddr = 0;
  51. uiVaddr = 0x00000000;
  52. mips_tlbrwr2(uiVaddr | EHINV, ENTRY_MASK_INVALID, ENTRY_MASK_INVALID, PAGEMASK_256M);
  53. uiVaddr = 0x20000000;
  54. mips_tlbrwr2(uiVaddr | EHINV, ENTRY_MASK_INVALID, ENTRY_MASK_INVALID, PAGEMASK_256M);
  55. uiVaddr = 0x30000000;
  56. mips_tlbrwr2(uiVaddr | EHINV, ENTRY_MASK_INVALID, ENTRY_MASK_INVALID, PAGEMASK_256M);
  57. /* mapping 0x80000000 => 0x60000000 mapping 0x90000000 => 0x70000000 */
  58. uiVaddr = 0x60000000;
  59. uiEvenAddr = 0x80000000;
  60. uiOddAaddr = 0x90000000;
  61. mips_tlbrwr2(uiVaddr | EHINV,
  62. (uiEvenAddr >> 12 << 6) | ENTRY_MASK,
  63. (uiOddAaddr >> 12 << 6) | ENTRY_MASK,
  64. PAGEMASK_256M);
  65. return;
  66. }
  67. void Hv_Boot_ClearBss(void)
  68. {
  69. extern void *__bss_start, *__bss_end;
  70. unsigned int *puiStart = (unsigned int*)(&__bss_start);
  71. unsigned int *puiEnd = (unsigned int*)(&__bss_end);
  72. while ((unsigned int)puiStart < (unsigned int)puiEnd)
  73. {
  74. *puiStart ++ = 0;
  75. }
  76. mips_flush_cache();
  77. return;
  78. }
  79. void Hv_Boot_CopyDdrCodeData(void)
  80. {
  81. extern void *_text_lma,*__text_start, *__rodata_end;
  82. extern void *_data_lma, *__data_start, *__data_end;
  83. unsigned int iIndex = 0;
  84. unsigned int uiDataSize = 0;
  85. unsigned int *puiData = NULL;
  86. unsigned int *puiFlash = NULL;
  87. /* Copy text and rodata segment from Flash to ddr */
  88. uiDataSize = ((unsigned int)(&__rodata_end) - (unsigned int)(&__text_start)) / sizeof(unsigned int);
  89. puiData = (unsigned int *)&__text_start;
  90. puiFlash = ((unsigned int *)&_text_lma) + g_uiFlashUpgradeOffset;
  91. for (iIndex = 0; iIndex < uiDataSize ; iIndex++)
  92. {
  93. puiData[iIndex] = puiFlash[iIndex];
  94. }
  95. /* Copy data segment from Flash to ddr */
  96. uiDataSize = ((unsigned int)(&__data_end) - (unsigned int)(&__data_start)) / sizeof(unsigned int);
  97. puiData = (unsigned int *)&__data_start;
  98. puiFlash = ((unsigned int *)&_data_lma) + g_uiFlashUpgradeOffset;
  99. for (iIndex = 0; iIndex < uiDataSize ; iIndex++)
  100. {
  101. puiData[iIndex] = puiFlash[iIndex];
  102. }
  103. return;
  104. }
  105. static void Hv_Boot_CopyDdrCodeDataCompressed(int uiCompressed)
  106. {
  107. unsigned int uiDdrAddr = 0;
  108. extern void *_text_lma, *__text_start, *__data_end;
  109. unsigned int *puiData = NULL;
  110. unsigned int *puiFlash = NULL;
  111. unsigned int iIndex = 0;
  112. unsigned int uiDataSize = 0;
  113. uiDataSize = ((unsigned int)(&__data_end) - (unsigned int)(&__text_start)) / sizeof(unsigned int);
  114. puiData = (unsigned int *)&__text_start;
  115. puiFlash = ((unsigned int *)&_text_lma) + g_uiFlashUpgradeOffset;
  116. if (uiCompressed)
  117. {
  118. puiData = (unsigned int *)DDR_TEMP_ADDR;
  119. uiDataSize = HV_FLASH_CONFIG_CODE_PART_SIZE / sizeof(unsigned int);
  120. }
  121. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_INFO, ">>> Hv_Boot_CopyDdrCodeDataCompressed enter.\n");
  122. Hv_Boot_PrintHex(BOOT_DEBUG_LEVEL_DEBUG, uiDataSize);
  123. Hv_Boot_PrintHex(BOOT_DEBUG_LEVEL_DEBUG, (unsigned int)puiData);
  124. Hv_Boot_PrintHex(BOOT_DEBUG_LEVEL_DEBUG, (unsigned int)puiFlash);
  125. for (iIndex = 0; iIndex < uiDataSize ; iIndex++)
  126. {
  127. puiData[iIndex] = puiFlash[iIndex];
  128. }
  129. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_DEBUG, ">>> Hv_Boot_CopyDdrCodeDataCompressed over.\n");
  130. return;
  131. }
  132. extern void Hv_Ddr_Init(void);
  133. void Hv_Boot_InitDDR(void)
  134. {
  135. Hv_Ddr_Init();
  136. return;
  137. }
  138. static void _Boot_DmaCopyFlashToDDR(unsigned int uiFlashAddr, unsigned int uiDdrAddr, unsigned int uiDataSize)
  139. {
  140. /*use two dma channel for rx/tx,most high speed is 4 division*/
  141. unsigned int auiCmdAddr[2] = {0};
  142. unsigned int uiPageCount = 0;
  143. unsigned int uiSurplusSize = 0;
  144. unsigned int iIndex = 0;
  145. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_INFO, ">>> Hv_Boot_DmaCopyFlashToDDR.\n");
  146. Hv_Boot_PrintHex(BOOT_DEBUG_LEVEL_DEBUG, uiDataSize);
  147. Hv_Boot_PrintHex(BOOT_DEBUG_LEVEL_DEBUG, uiDdrAddr);
  148. Hv_Boot_PrintHex(BOOT_DEBUG_LEVEL_DEBUG, uiFlashAddr);
  149. BOOT_WT32(CPU_SYS_DMAC_CTL0_L, 0xa09405);
  150. BOOT_WT32(CPU_SYS_DMAC_CFG0_L, 0x800000);
  151. BOOT_WT32(CPU_SYS_DMAC_CFG0_H, 0x82);
  152. BOOT_WT32(CPU_SYS_DMAC_MASKTFR, 0x101);
  153. BOOT_WT32(CPU_SYS_DMAC_CLEARTFR, 0x01);
  154. BOOT_WT32(CPU_SYS_DMACFGREG, 0x01);
  155. BOOT_W32_FIELD(SYS_REG_SH5_TOP0_REG_SH5_WDG_FILED2, reg_sh5_qspi_xip_en, 0x0);
  156. BOOT_WT32(CPU_SYS_2_QSPI_SSIENR, 0x00);
  157. BOOT_RD32(CPU_SYS_2_QSPI_ICR);
  158. #ifdef HV_FLASH_CONFIG_4LINE_DMA
  159. /* 8bit read only, four line select */
  160. BOOT_WT32(CPU_SYS_2_QSPI_CTRLR0, 0x800807);
  161. #else
  162. BOOT_WT32(CPU_SYS_2_QSPI_CTRLR0, 0x400807);
  163. #endif
  164. /* division set */
  165. #ifdef HV_FLASH_CONFIG_BOOT_SPEED_100
  166. BOOT_WT32(CPU_SYS_2_QSPI_BAUDR, 2);
  167. BOOT_W32_FIELD(CPU_SYS_2_QSPI_RX_SAMPLE_DELAY, RSD, 0x2);
  168. #else
  169. BOOT_WT32(CPU_SYS_2_QSPI_BAUDR, 4);
  170. BOOT_W32_FIELD(CPU_SYS_2_QSPI_RX_SAMPLE_DELAY, RSD, 0x2);
  171. #endif
  172. BOOT_WT32(CPU_SYS_2_QSPI_TXFTLR, 0x08);
  173. BOOT_WT32(CPU_SYS_2_QSPI_RXFTLR, 0x00);
  174. /* addr 24bit, instru 8bit, standard mode. */
  175. BOOT_W32_FIELD(CPU_SYS_2_QSPI_SPI_CTRLR0, TRANS_TYPE, 0);
  176. BOOT_W32_FIELD(CPU_SYS_2_QSPI_SPI_CTRLR0, ADDR_L, 0x6);
  177. BOOT_W32_FIELD(CPU_SYS_2_QSPI_SPI_CTRLR0, INST_L, 0x2);
  178. /* read cmd 4line */
  179. #ifdef HV_FLASH_CONFIG_4LINE_DMA
  180. auiCmdAddr[0]= 0x6B;
  181. #else
  182. /* read cmd 2line */
  183. auiCmdAddr[0]= 0x3B;
  184. #endif
  185. /* read dma enable */
  186. BOOT_WT32(CPU_SYS_2_QSPI_DMACR, 0x01);
  187. BOOT_WT32(CPU_SYS_2_QSPI_DMARDLR, 0x07);
  188. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_DEBUG, ">>> Read time start.\n");
  189. uiPageCount = uiDataSize >> 11;
  190. uiSurplusSize = uiDataSize & 0x7ff;
  191. Hv_Boot_PrintHex(BOOT_DEBUG_LEVEL_DEBUG, uiPageCount);
  192. Hv_Boot_PrintHex(BOOT_DEBUG_LEVEL_DEBUG, uiSurplusSize);
  193. for (iIndex = 0; iIndex < uiPageCount; iIndex++)
  194. {
  195. BOOT_WT32(CPU_SYS_DMAC_SAR0, CPU_SYS_2_QSPI_DR0);
  196. BOOT_WT32(CPU_SYS_DMAC_DAR0, uiDdrAddr & 0x1fffffff);
  197. BOOT_WT32(CPU_SYS_DMAC_CTL0_H, 0x800);
  198. BOOT_WT32(CPU_SYS_DMAC_CHENREG, 0x101);
  199. BOOT_WT32(CPU_SYS_2_QSPI_CTRLR1, 0x7ff);
  200. BOOT_WT32(CPU_SYS_2_QSPI_SSIENR, 0x01);
  201. BOOT_WT32(CPU_SYS_2_QSPI_DR0, auiCmdAddr[0]);
  202. BOOT_WT32(CPU_SYS_2_QSPI_DR0, uiFlashAddr);
  203. while(!(BOOT_RD32(CPU_SYS_DMAC_STATUSINT) & 0x01));
  204. BOOT_WT32(CPU_SYS_DMAC_CLEARTFR, 0x1);
  205. Hv_Boot_Wait_Us(1);
  206. while((BOOT_RD32(CPU_SYS_2_QSPI_SR) & 0x01) == 0x01);
  207. Hv_Boot_Wait_Us(1);
  208. BOOT_WT32(CPU_SYS_2_QSPI_SSIENR,0x0);
  209. Hv_Boot_Wait_Us(1);
  210. uiFlashAddr = uiFlashAddr + 0x800;
  211. uiDdrAddr = uiDdrAddr + 0x800;
  212. }
  213. if (uiSurplusSize > 0)
  214. {
  215. BOOT_WT32(CPU_SYS_DMAC_SAR0, CPU_SYS_2_QSPI_DR0);
  216. BOOT_WT32(CPU_SYS_DMAC_DAR0, uiDdrAddr & 0x1fffffff);
  217. BOOT_WT32(CPU_SYS_DMAC_CTL0_H, uiSurplusSize);
  218. BOOT_WT32(CPU_SYS_DMAC_CHENREG, 0x101);
  219. BOOT_WT32(CPU_SYS_2_QSPI_CTRLR1, uiSurplusSize-1);
  220. BOOT_WT32(CPU_SYS_2_QSPI_SSIENR, 0x01);
  221. BOOT_WT32(CPU_SYS_2_QSPI_DR0, auiCmdAddr[0]);
  222. BOOT_WT32(CPU_SYS_2_QSPI_DR0, uiFlashAddr);
  223. while(!(BOOT_RD32(CPU_SYS_DMAC_STATUSINT) & 0x01));
  224. BOOT_WT32(CPU_SYS_DMAC_CLEARTFR, 0x1);
  225. while((BOOT_RD32(CPU_SYS_2_QSPI_SR) & 0x01) == 0x01);
  226. }
  227. BOOT_WT32(CPU_SYS_DMAC_MASKTFR,0x100);
  228. BOOT_WT32(CPU_SYS_DMACFGREG,0x0);
  229. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_DEBUG, ">>> Read time end.\n");
  230. /* togle ssien before xip mode. */
  231. BOOT_WT32(CPU_SYS_2_QSPI_SSIENR, 0x00);
  232. //BOOT_RD32(CPU_SYS_2_QSPI_ICR);
  233. //BOOT_WT32(CPU_SYS_2_QSPI_BAUDR, 0x8);
  234. //BOOT_WT32(CPU_SYS_2_QSPI_DMACR, 0x00);
  235. BOOT_WT32(CPU_SYS_2_QSPI_SSIENR, 0x1);
  236. BOOT_W32_FIELD(SYS_REG_SH5_TOP0_REG_SH5_WDG_FILED2, reg_sh5_qspi_xip_en, 0x1);
  237. return;
  238. }
  239. static void Hv_Boot_DmaCopyFlashToDDR(int uiCompressed)
  240. {
  241. unsigned int uiDdrAddr = 0;
  242. unsigned int uiFlashAddr = 0;
  243. extern void *_text_lma, *__text_start, *__data_end;
  244. unsigned int iIndex = 0;
  245. unsigned int uiDataSize = 0;
  246. uiDataSize = ((unsigned int)(&__data_end) - (unsigned int)(&__text_start));
  247. uiDdrAddr = (unsigned int )&__text_start;
  248. uiFlashAddr = (unsigned int)((unsigned int)&_text_lma - 0xBfc00000) + g_uiFlashUpgradeOffset;
  249. if (uiCompressed)
  250. {
  251. uiDdrAddr = DDR_TEMP_ADDR;
  252. uiDataSize = HV_FLASH_CONFIG_CODE_PART_SIZE;
  253. }
  254. if (uiFlashAddr + uiDataSize > FLASH_END)
  255. {
  256. uiDataSize = FLASH_END - uiFlashAddr;
  257. }
  258. _Boot_DmaCopyFlashToDDR(uiFlashAddr, uiDdrAddr, uiDataSize);
  259. return;
  260. }
  261. static void Hv_Boot_CopyPqFlashToDDR(void)
  262. {
  263. unsigned int uiDdrAddr = DDR_TEMP_ADDR;
  264. unsigned int uiFlashAddr = HV_FLASH_CONFIG_PQ_DATA_PART_START;
  265. unsigned int uiDataSize = HV_FLASH_CONFIG_PQ_DATA_PART_SIZE;
  266. if (uiFlashAddr + uiDataSize > FLASH_END)
  267. {
  268. uiDataSize = FLASH_END - uiFlashAddr;
  269. }
  270. _Boot_DmaCopyFlashToDDR(uiFlashAddr, uiDdrAddr, uiDataSize);
  271. return;
  272. }
  273. static void Hv_Boot_CopyLogoFlashToDDR(void)
  274. {
  275. unsigned int uiDdrAddr = HV_MEMORY_CONFIG_OSD_LOGO_DDR_START;
  276. unsigned int uiFlashAddr = HV_FLASH_CONFIG_LOGO_PART_START;
  277. unsigned int uiDataSize = HV_FLASH_CONFIG_LOGO_PART_SIZE;
  278. if (uiFlashAddr + uiDataSize > FLASH_END)
  279. {
  280. uiDataSize = FLASH_END - uiFlashAddr;
  281. }
  282. _Boot_DmaCopyFlashToDDR(uiFlashAddr, uiDdrAddr, uiDataSize);
  283. return;
  284. }
  285. static void Hv_Boot_CopyFireFlashToDDR(void)
  286. {
  287. unsigned int uiDdrAddr = HV_MEMORY_CONFIG_MONITOR_HOTFIX_START;
  288. unsigned int uiFlashAddr = HV_FLASH_CONFIG_HOTFIX_START;
  289. unsigned int uiDataSize = HV_FLASH_CONFIG_HOTFIX_SIZE;
  290. if (uiFlashAddr + uiDataSize > FLASH_END)
  291. {
  292. uiDataSize = FLASH_END - uiFlashAddr;
  293. }
  294. _Boot_DmaCopyFlashToDDR(uiFlashAddr, uiDdrAddr, uiDataSize);
  295. return;
  296. }
  297. static void Hv_Boot_CopyCfgFlashToDDR(void)
  298. {
  299. unsigned int uiDdrAddr = HV_MEMORY_CONFIG_AUDIO_DDR_START;
  300. unsigned int uiFlashAddr = HV_FLASH_CONFIG_MONITOR_DATA_PART_START;
  301. unsigned int uiDataSize = CONFIG_MONITOR_DATA_SIZE;
  302. if (uiFlashAddr + uiDataSize > FLASH_END)
  303. {
  304. uiDataSize = FLASH_END - uiFlashAddr;
  305. }
  306. _Boot_DmaCopyFlashToDDR(uiFlashAddr, uiDdrAddr, uiDataSize);
  307. return;
  308. }
  309. void Hv_Boot_WatchdogInit(void)
  310. {
  311. BOOT_WT32(SYS_REG_SH5_TOP0_REG_SH5_WDG_FILED5, 5000);
  312. /* wdt reload */
  313. BOOT_W32_FIELD(SYS_REG_SH5_TOP0_REG_SH5_WDG_FILED7, reg_sh5_wdg_reload_en, 1);
  314. BOOT_W32_FIELD(SYS_REG_SH5_TOP0_REG_SH5_WDG_FILED7, reg_sh5_wdg_reload_en, 0);
  315. unsigned int uiVal = BOOT_RD32(SYS_REG_SH5_TOP0_REG_SH5_WDG_FILED4);
  316. /* count enable */
  317. uiVal |= 0x00000001;
  318. /* wdg reset enable to reset whole system */
  319. uiVal |= 0x00000008;
  320. /* set count period 1ms from APB_CLK */
  321. BOOT_WT32(SYS_REG_SH5_TOP0_REG_SH5_WDG_FILED6, (HV_CHIP_CLK_APB / 1000));
  322. /* start the wdt */
  323. BOOT_WT32(SYS_REG_SH5_TOP0_REG_SH5_WDG_FILED4, uiVal);
  324. }
  325. static unsigned char s_ucBootType = 0;
  326. static unsigned char s_cAcFlag = 0;
  327. void Hv_Boot_Check_BootReason(void)
  328. {
  329. int iData = 0;
  330. iData = BOOT_RD32(STANDBY_STANDBY_MCU_REG_STBY_MCU6);
  331. if (4 == (iData&0xff))/* wakeup */
  332. {
  333. iData = BOOT_RD32(STANDBY_STANDBY_MCU_REG_STBY_MCU7);
  334. s_ucBootType = (iData&0xff);
  335. BOOT_WT32(SW_DUMMY_JTAG, s_ucBootType);
  336. }
  337. return;
  338. }
  339. unsigned char Hv_Boot_Get_BootReason(void)
  340. {
  341. return s_ucBootType;
  342. }
  343. unsigned char Hv_Boot_Get_BootType(void)
  344. {
  345. return s_cAcFlag;
  346. }
  347. static void BootPwrOff(void)
  348. {
  349. /* E_MAILBOX_CMD_RISC_TO_PM_NORMAL */
  350. BOOT_WT32(STANDBY_STANDBY_MCU_REG_STBY_MCU10, 7);
  351. BOOT_WT32(STANDBY_STANDBY_MCU_REG_STBY_MCU15, 1);
  352. Hv_Boot_Wait_Ms(20);
  353. /* E_MAILBOX_CMD_RISC_TO_PM_POWER_OFF_ACK */
  354. BOOT_WT32(STANDBY_STANDBY_MCU_REG_STBY_MCU10, 5);
  355. BOOT_WT32(STANDBY_STANDBY_MCU_REG_STBY_MCU15, 1);
  356. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_WAR, ">>> poweroff\n");
  357. while(1);
  358. }
  359. void Hv_Boot_Check_SecondPowerOn(void)
  360. {
  361. unsigned int uiData = 0;
  362. unsigned int uiLoop = 0;
  363. unsigned int uiAddr = HV_FLASH_CONFIG_START_XIP+HV_FLASH_CONFIG_MONITOR_DATA_PART_START+HV_FLASH_CONFIG_TIMER_START;
  364. BOOT_R32_DECL_VAR();
  365. s_cAcFlag = BOOT_R32_FIELD(STANDBY_AON_REG_PMU_REG3, reg_first_start_flag);
  366. if (s_cAcFlag)
  367. {
  368. BOOT_W32_FIELD(STANDBY_AON_REG_PMU_REG3, reg_first_start_flag, 0);
  369. #if (HV_PROJECT_CONFIG_AC_POWER_STATE == 1)
  370. BootPwrOff();
  371. #elif (HV_PROJECT_CONFIG_AC_POWER_STATE == 2)
  372. return;
  373. #else
  374. ;
  375. #endif
  376. }
  377. else
  378. {
  379. return;
  380. }
  381. for (uiLoop = 0; uiLoop<4096; uiLoop+=16)
  382. {
  383. /* magic TIMD or HT7315 */
  384. if ((BOOT_RD32(uiAddr+uiLoop+4) != 0x54494D45)
  385. && (BOOT_RD32(uiAddr+uiLoop+4) != 0x48547315))
  386. {
  387. break;
  388. }
  389. uiData = BOOT_RD32(uiAddr+uiLoop+0xc);
  390. }
  391. if (8 == (uiData&0xff))/* poweroff */
  392. {
  393. BootPwrOff();
  394. }
  395. return;
  396. }
  397. int _start(void)
  398. {
  399. int iRet = 0;
  400. char cGpioIndex = 16;
  401. int iPqCompressSize = 0;
  402. char *pucAddr = NULL;
  403. #ifdef SW_DUMMY_DEBUG
  404. while(HV_RD32(SW_DUMMY_JTAG)==0x11223344);
  405. #endif
  406. mips_bissr(SR_CU1);
  407. Hv_Chip_DebugUartInit(115200);
  408. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_WAR, ">>> BOOT RISC0\n");
  409. /* find upgrade section. */
  410. if (*(char *)(HV_FLASH_CONFIG_START_XIP + HV_FLASH_CONFIG_PM_DATA_START + 4 + 5) == 0xaa)
  411. {
  412. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_WAR, ">>> user second part.\n");
  413. }
  414. #ifdef CONFIG_USER_WATCHDOG_ON
  415. Hv_Boot_WatchdogInit();
  416. #endif
  417. Hv_Boot_Check_BootReason();
  418. Hv_Boot_Check_SecondPowerOn();
  419. if (11 != s_ucBootType)
  420. {
  421. #if HV_BOARD_CONFIG_LED_R_POL
  422. BOOT_W32_FIELD(STANDBY_STANDBY_PERI_REG_PWM0, reg_pwm_pol, 0);
  423. #else
  424. BOOT_W32_FIELD(STANDBY_STANDBY_PERI_REG_PWM0, reg_pwm_pol, 1);
  425. #endif
  426. BOOT_W32_FIELD(STANDBY_STANDBY_PERI_REG_PWM0, reg_pwm_ch_en, 0);
  427. BOOT_W32_FIELD(STANDBY_STANDBY_PERI_REG_PWM0, reg_pwm_output_mode, 1);
  428. #if (HV_BOARD_CONFIG_GPIO_LED_B == 61)
  429. /* pin61-gpio21-bit16*/
  430. BOOT_W32_FIELD(RX_SH08_TOP_RX_CTRL_0, reg_gpio21_func_sel, 0);
  431. cGpioIndex = 16;
  432. #endif
  433. #if HV_BOARD_CONFIG_LED_B_POL
  434. BOOT_W32_FIELD(CPU_SYS_GPIO0_GPIO_OUT0_SET, gpio0_out_set, (1<<cGpioIndex));
  435. BOOT_W32_FIELD(CPU_SYS_GPIO0_GPIO_OE0_SET, gpio0_oe_set, (1<<cGpioIndex));
  436. #else
  437. BOOT_W32_FIELD(CPU_SYS_GPIO0_GPIO_OUT0_CLR, gpio0_out_clr, (1<<cGpioIndex));
  438. BOOT_W32_FIELD(CPU_SYS_GPIO0_GPIO_OE0_SET, gpio0_oe_set, (1<<cGpioIndex));
  439. #endif
  440. }
  441. Hv_Boot_InitDDR();
  442. Hv_Boot_Wait_Ms(1);
  443. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_INFO, ">>> boot_ddr_init over\n");
  444. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_INFO, ">>> copy_ddr_code_data...\n");
  445. #ifdef CONFIG_CODE_COMPRESSED
  446. extern void *_text_lma,*__text_start;
  447. extern void *__data_start;
  448. Hv_Boot_DmaCopyFlashToDDR(1);
  449. iRet = Hv_Boot_LzssDecompress((char *)DDR_TEMP_ADDR, ((char *)&__text_start), 1, 0);
  450. if ( iRet != 0)
  451. {
  452. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_INFO, ">>> decompress code error\n");
  453. }
  454. #else
  455. Hv_Boot_DmaCopyFlashToDDR(0);
  456. #endif
  457. #ifdef CONFIG_PQ_COMPRESSED
  458. Hv_Boot_CopyPqFlashToDDR();
  459. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_DEBUG, ">>> decompress pq...\n");
  460. Hv_Boot_LzssDecompress((char *)DDR_TEMP_ADDR,((char *)HV_MEMORY_CONFIG_PQ_DATA_START), 1, 0);
  461. #endif
  462. Hv_Boot_ClearBss();
  463. Hv_Boot_CopyLogoFlashToDDR();
  464. Hv_Boot_CopyFireFlashToDDR();
  465. Hv_Boot_CopyCfgFlashToDDR();
  466. /* set stack to the symbol of __stack */
  467. __asm__ __volatile__ ("la $29, __stack");
  468. Hv_Boot_InitTlb();
  469. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_INFO, ">>> risc init\n");
  470. Hv_Vos_Init();
  471. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_WAR, ">>> enter main");
  472. iRet = main(0, 0);
  473. Hv_Boot_Print_String(BOOT_DEBUG_LEVEL_INFO, ">>> over\n");
  474. return iRet;
  475. }