Entry.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. **********************************************************************
  3. Copyright (c)2009 Arkmicro Technologies Inc. All Rights Reserved
  4. Filename: boot.c
  5. Version : 1.00
  6. Date : 2010.06.29
  7. Author : Donier
  8. Abstract: Ark2116 SoC boot rom code file.
  9. Note : The size the code(*.bin) loaded should never exceed 10K Bytes.
  10. History : From the ark2116 SoC boot rom code file.
  11. ***********************************************************************
  12. */
  13. #include "typedef.h"
  14. #include "amt630h.h"
  15. #include "BootModeSel.h"
  16. #include "UartPrint.h"
  17. #include "timer.h"
  18. #include "mmu.h"
  19. #include "sysinfo.h"
  20. #include "spi.h"
  21. #define PROJECT_FOR_DDR_INIT 0
  22. #define PROJECT_FOR_SPINOR_LOADER 1
  23. #define PROJECT_FOR_SD_UPDATE 2
  24. #define PROJECT_FOR_JTAG_UPDATE 3
  25. #define PROJECT_PURPOSE PROJECT_FOR_DDR_INIT
  26. #define SYSPLL_CLK 480//400//400//400//200 //336
  27. #define CPUPLL_CLK 500//250//500//500//250 //500
  28. // don't change is macro
  29. #define DDR2_SRC_CLK_CPUPLL 0
  30. #define DDR2_SRC_CLK_SYSPLL 1
  31. #define DDR2_SRC_CLK_AUDPLL 2
  32. #define DDR2_SRC_CLK_24M 4
  33. #define DDR_TOTAL 0x400000 //8m x16
  34. extern void SetSysPLL(unsigned int freq);
  35. extern void SetCpuPLL(unsigned int freq);
  36. extern void SetXclkAHBclkAPBclk(void);
  37. extern void SwitchTo24MHz(void);
  38. extern void updateFromSD(int chipid);
  39. extern void SpiNorBurn(void *buf, unsigned int offset, unsigned int size);
  40. extern int wdt_init(void);
  41. static void delay(volatile UINT32 count )
  42. {
  43. while(count--);
  44. }
  45. void ddr_rd_clk_config()
  46. {
  47. unsigned int i;
  48. rSYS_DDRCTL1_CFG = 0x01; //reset pll
  49. delay(1000);
  50. rSYS_DDRCTL1_CFG = 0x00; //enable pll
  51. delay(100000);
  52. i = 0x01 << 1 | 200 << 8;
  53. rSYS_DDRCTL1_CFG = i;
  54. delay(100000);
  55. }
  56. void ddr3_sdramc_init(void)
  57. {
  58. unsigned long i;
  59. i = rSYS_DDRCTL1_CFG;
  60. i &= ~((0xFF << 24) |(0xFF << 16) | (0x7F << 8) | 0x7F);
  61. //i |= (0x40 << 24) |(0x40 << 8) | 0x40;
  62. rSYS_DDRCTL1_CFG = i;
  63. //ddr initialization
  64. //active_chip qos burst stop auto_power_down power_down_cycle ap_bit row col
  65. #ifdef DDR16X16
  66. i = 0x0 << 21 | 0x0 <<18 | 0x2 << 15 | 0x0 <<14 | 0x0 <<13 | 0x0 << 7 | 0x0 <<6 | 0x2 <<3 | 0x1<< 0 ; //16M*16
  67. #else
  68. i = 0x0 << 21 | 0x0 <<18 | 0x2 << 15 | 0x0 <<14 | 0x0 <<13 | 0x0 << 7 | 0x0 <<0 | 0x1 <<3 | 0x1<< 0 ; //8M*16
  69. #endif
  70. MEM_CFG_REG = i ;
  71. //read_delay mem_pro mem_width cke_init dqm_init clk_cfg
  72. i = 0x6 << 9 | 0x1 <<6 | 0x0 << 4 | 0x1 <<3 | 0x0 <<2 | 0x00 << 0 ;
  73. MEM_CFG2_REG = i ;
  74. //addr_fmt addr_match addr_mask
  75. //i = 0x1 << 16 | 0x80 <<8 | 0xff << 0 ;
  76. //CHIP_CFG_REG = i ;
  77. //early_resp
  78. i= 0x0 << 0;
  79. FEA_CTL_REG = i ;
  80. //tref
  81. #ifdef DDR16X16
  82. i= 380;
  83. #else
  84. i= 1734;
  85. #endif
  86. REF_PRD_REG = i ;
  87. //cas //half cycle
  88. i= 0x3<<1 | 0x0<< 0; //
  89. TCAS_REG = i ;
  90. //tdqss
  91. i= 0x1<< 0;
  92. TDQSS_REG = i ;
  93. //tmrd
  94. i= 0x2<< 0;
  95. TMRD_REG = i ;
  96. //tras
  97. i= 0x8<< 0;
  98. TRAS_REG = i ;
  99. //trc
  100. i= 0xB << 0;
  101. TRC_REG = i ;
  102. //trcd schelue rcd
  103. i= 0x3<< 0 | 0x3<<3;
  104. TRCD_REG = i ;
  105. //schelue trfc trfc
  106. i= 15<<5|18<< 0;
  107. TRFC_REG = i ;
  108. //trp
  109. i= 0x3<< 0 | 0x3 << 3;
  110. TRP_REG = i ;
  111. //trrd
  112. i= 0x2<< 0;
  113. TRRD_REG = i ;
  114. //twr
  115. i= 0x3<< 0;
  116. TWR_REG = i ;
  117. //twtr
  118. i= 0x2<< 0;
  119. TWTR_REG = i ;
  120. //txp
  121. i= 0x1<< 0;
  122. TXP_REG = i ;
  123. //txsr
  124. i= 10<< 0;
  125. TXSR_REG = i ;
  126. //tesr
  127. i= 0x15<< 0;
  128. TESR_REG = i ;
  129. //
  130. // //precharge
  131. DIR_CMD_REG = 0x000c0000 ; //direct_cmd_reg nop
  132. DIR_CMD_REG = 0x00000000 ; //direct_cmd_reg precharge
  133. DIR_CMD_REG = 0x00010000 ; //direct_cmd_reg precharge
  134. DIR_CMD_REG = 0x00020000 ; //direct_cmd_reg precharge
  135. DIR_CMD_REG = 0x00030000 ; //direct_cmd_reg precharge
  136. DIR_CMD_REG = 0x00040000 ; //direct_cmd_reg autorefresh
  137. DIR_CMD_REG = 0x00040000 ; //direct_cmd_reg autorefresh
  138. DIR_CMD_REG = 0x00090000 ; //direct_cmd_reg exmodereg set
  139. DIR_CMD_REG = 0x00080032 ; //direct_cmd_reg modereg set
  140. DIR_CMD_REG = 0x00030000 ; //direct_cmd_reg precharge
  141. DIR_CMD_REG = 0x00040000 ; //direct_cmd_reg autorefresh
  142. DIR_CMD_REG = 0x00040000 ; //direct_cmd_reg autorefresh
  143. DIR_CMD_REG = 0x000c0000 ; //direct_cmd_reg nop
  144. MEM_CMD_REG = 0x00000000 ; //mem_cmd_reg go
  145. while ((MEM_STA_REG &0x01)!=0x01) ;
  146. }
  147. void updateFromJtag(void)
  148. {
  149. unsigned int loader_addr = 0x20000000;
  150. unsigned int stepldr_addr = 0x20010000;
  151. unsigned int app_addr = 0x20100000;
  152. UpFileHeader *header = (UpFileHeader *)app_addr;
  153. SendUartString("burn loader start... \r\n");
  154. SpiNorBurn((void*)loader_addr, LOADER_OFFSET, LOADER_MAX_SIZE);
  155. SendUartString("burn loader end. \r\n");
  156. SendUartString("burn stepldr start... \r\n");
  157. SpiNorBurn((void*)stepldr_addr, STEPLDRA_OFFSET, STEPLDR_MAX_SIZE);
  158. SendUartString("burn stepldr end. \r\n");
  159. SendUartString("burn app start... \r\n");
  160. SpiNorBurn((void*)app_addr, IMAGE_OFFSET, header->size);
  161. SendUartString("burn app end. \r\n");
  162. SysInfo *sysinfo = GetSysInfo();
  163. sysinfo->app_checksum = header->checksum;
  164. sysinfo->stepldr_offset = STEPLDRA_OFFSET;
  165. sysinfo->stepldr_size = STEPLDR_MAX_SIZE;
  166. sysinfo->update_status = UPDATE_STATUS_END;
  167. SaveSysInfo(sysinfo);
  168. SendUartString("Update is finished. Please reset. \r\n");
  169. while(1);
  170. }
  171. void main(void)
  172. {
  173. unsigned int val;
  174. SwitchTo24MHz();
  175. timer_init();
  176. InitUart(115200);
  177. SendUartString("\nARK AMT 630 H FROM SD V 1.21\r\n");
  178. val = rSYS_ANA1_CFG;
  179. val |= (1 << 4)|(5 << 1);
  180. rSYS_ANA1_CFG = val;
  181. udelay(300);
  182. val = rSYS_ANA1_CFG;
  183. val |= (0x1 <<5);
  184. rSYS_ANA1_CFG = val;
  185. val = rSYS_ANA2_CFG;
  186. val = (0x3F <<6)|(0 << 2)|(1 << 0);
  187. rSYS_ANA2_CFG = val;
  188. SetSysPLL(SYSPLL_CLK);
  189. SetCpuPLL(CPUPLL_CLK);
  190. udelay(500);
  191. // delay(600000);
  192. SetXclkAHBclkAPBclk();
  193. udelay(10);
  194. #if PROJECT_PURPOSE == PROJECT_FOR_SPINOR_LOADER
  195. wdt_init();
  196. #endif
  197. ddr3_sdramc_init();
  198. udelay(10);
  199. SendUartString("\nDDR init over2!!\r\n");
  200. SpiSelectPad();
  201. SpiInit();
  202. #ifdef MMU_ENABLE
  203. MMU_Init();
  204. #endif
  205. #if PROJECT_PURPOSE == PROJECT_FOR_DDR_INIT
  206. while(1);
  207. #elif PROJECT_PURPOSE == PROJECT_FOR_SPINOR_LOADER
  208. bootFromSPI();
  209. #elif PROJECT_PURPOSE == PROJECT_FOR_SD_UPDATE
  210. SetDefaultSysInfo();
  211. SaveSysInfo(0);
  212. updateFromSD(0);
  213. bootFromSPI();
  214. #elif PROJECT_PURPOSE == PROJECT_FOR_JTAG_UPDATE
  215. updateFromJtag();
  216. #endif
  217. }