ark1668e_devb.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. #include <common.h>
  2. #include <dwmmc.h>
  3. #include <malloc.h>
  4. #include <debug_uart.h>
  5. #include <asm-generic/gpio.h>
  6. #include <asm/arch/ark-common.h>
  7. #include <linux/usb/musb.h>
  8. DECLARE_GLOBAL_DATA_PTR;
  9. #define ARK1668_UPDATE_MAGIC "ada7f0c6-7c86-11e9-8f9e-2a86e4085a59"
  10. #define rSYS_BOOT_SAMPLE *((volatile unsigned int *)(0xe4900000))
  11. #define rSYS_SD_CLK_CFG *((volatile unsigned int *)(0xe4900058))
  12. #define rSYS_SD1_CLK_CFG *((volatile unsigned int *)(0xe490005c))
  13. #define rSYS_SOFT_RSTNA *((volatile unsigned int *)(0xe4900074))
  14. #define rSYS_SOFT_RSTNB *((volatile unsigned int *)(0xe4900078))
  15. #define rSYS_DDR_STATUS *((volatile unsigned int *)(0xe4900180))
  16. #define rSYS_DDR_IO_CFG *((volatile unsigned int *)(0xe490019C))
  17. #define rSYS_PAD_CTRL00 *((volatile unsigned int *)(0xe49001c0))
  18. #define rSYS_PAD_CTRL01 *((volatile unsigned int *)(0xe49001c4))
  19. #define rSYS_PAD_CTRL02 *((volatile unsigned int *)(0xe49001c8))
  20. #define rSYS_PAD_CTRL04 *((volatile unsigned int *)(0xe49001d0))
  21. #define rSYS_PAD_CTRL05 *((volatile unsigned int *)(0xe49001d4))
  22. #define rSYS_PAD_CTRL06 *((volatile unsigned int *)(0xe49001d8))
  23. #define rSYS_PAD_CTRL07 *((volatile unsigned int *)(0xe49001dc))
  24. #define rSYS_PAD_CTRL08 *((volatile unsigned int *)(0xe49001e0))
  25. #define rSYS_PAD_CTRL09 *((volatile unsigned int *)(0xe49001e4))
  26. #define rSYS_PAD_CTRL0A *((volatile unsigned int *)(0xe49001e8))
  27. #define rSYS_PAD_CTRL0B *((volatile unsigned int *)(0xe49001ec))
  28. #define rSYS_PAD_CTRL0C *((volatile unsigned int *)(0xe49001f0))
  29. #define rSYS_PAD_CTRL0D *((volatile unsigned int *)(0xe49001f4))
  30. #define rSYS_PAD_CTRL0E *((volatile unsigned int *)(0xe49001f8))
  31. #define rSYS_PAD_CTRL38 *((volatile unsigned int *)(0xe49001fc))
  32. #define rSYS_PAD_CTRL3E *((volatile unsigned int *)(0xe4900200))
  33. #define rSYS_PAD_CTRL0F *((volatile unsigned int *)(0xe4900204))
  34. #define rSYS_CPU_CTL *((volatile unsigned int *)(0xe4900208))
  35. #define rSYS_MFC_GMAC_CTL *((volatile unsigned int *)(0xe490020c))
  36. #define rSYS_DEVICE_CLK_CFG7 *((volatile unsigned int *)(0xe4900230))
  37. #define rSYS_DEVICE_CLK_CFG8 *((volatile unsigned int *)(0xe4900234))
  38. #define rSYS_USB_CFG *((volatile unsigned int *)(0xe4900260))
  39. #define rSYS_USB1_CFG *((volatile unsigned int *)(0xe490026C))
  40. #define rWDT_CR *((volatile unsigned int *)(0xe4b00000))
  41. #define MUSB_BASE 0xe0100000
  42. extern struct SYS_INFO sys_info;
  43. extern int ark_check_data_from_partition(char *part_name,unsigned int crc_data);
  44. extern int ark_check_data_from_devide(char *file_name,unsigned int crc_data);
  45. extern int get_crc_data_from_device(char *file_name);
  46. extern int get_data_from_media(char *file_name);
  47. extern const struct musb_platform_ops ark_musb_ops;
  48. static struct musb_hdrc_config musb_config = {
  49. .multipoint = 1,
  50. .dyn_fifo = 0,
  51. .num_eps = 6,
  52. .ram_bits = 12
  53. };
  54. static struct musb_hdrc_platform_data musb_platform_data = {
  55. .mode = MUSB_HOST,
  56. .config = &musb_config,
  57. .power = 100,
  58. .platform_ops = &ark_musb_ops,
  59. };
  60. static void dwmci_select_pad(void)
  61. {
  62. unsigned int val;
  63. /* use sd/mmc 0 */
  64. val = rSYS_PAD_CTRL00;
  65. val &= ~((0x7<<18)|(0x7<<15)|(0x7<<12)|(0x7<<9)|(0x7<<6)|(0x7<<3)|(0x7<<0));
  66. val |= ((0x1<<18)|(0x1<<15)|(0x1<<12)|(0x1<<9)|(0x1<<6)|(0x1<<3)|(0x1<<0));
  67. rSYS_PAD_CTRL00 = val;
  68. val = rSYS_PAD_CTRL0E;
  69. val &= ~((0x7<<27)|(0x7<<24));
  70. val |= ((0x1<<27)|(0x1<<24));
  71. rSYS_PAD_CTRL0E = val;
  72. val = rSYS_PAD_CTRL38;
  73. val &= ~((0x7<<9)|(0x7<<6)|(0x7<<3)|(0x7<<0));
  74. val |= ((0x1<<9)|(0x1<<6)|(0x1<<3)|(0x1<<0));
  75. rSYS_PAD_CTRL38 = val;
  76. /* use sd/mmc 1 */
  77. val = rSYS_PAD_CTRL00;
  78. val &= ~((0x7<<27)|(0x7<<24)|(0x7<<21));
  79. val |= ((0x1<<27)|(0x1<<24)|(0x1<<21));
  80. rSYS_PAD_CTRL00 = val;
  81. val = rSYS_PAD_CTRL01;
  82. val &= ~((0x7<<9)|(0x7<<6)|(0x7<<3)|(0x7<<0));
  83. val |= ((0x1<<9)|(0x1<<6)|(0x1<<3)|(0x1<<0));
  84. rSYS_PAD_CTRL01 = val;
  85. /* use sdio wifi/mmc 2*/
  86. val = rSYS_PAD_CTRL01;
  87. val &= ~((0x7<<27)|(0x7<<24)|(0x7<<21)|(0x7<<18)|(0x7<<15)|(0x7<<12));
  88. val |= ((0x1<<27)|(0x1<<24)|(0x1<<21)|(0x1<<18)|(0x1<<15)|(0x1<<12));
  89. rSYS_PAD_CTRL01 = val;
  90. val = rSYS_PAD_CTRL02;
  91. val &= ~(0x7<<0);
  92. val |= (0x1<<0);
  93. rSYS_PAD_CTRL02 = val;
  94. }
  95. /* static void dwmci_reset(void)
  96. {
  97. rSYS_SOFT_RSTNA &= ~((1<<29)|(1<<16));
  98. rSYS_SOFT_RSTNB &= ~(1<<3);
  99. udelay(100);
  100. rSYS_SOFT_RSTNA |= ((1<<29)|(1<<16));
  101. rSYS_SOFT_RSTNB |= (1<<3);
  102. } */
  103. static void usb_controller_reset(void)
  104. {
  105. rSYS_SOFT_RSTNA &= ~(3 << 5);
  106. udelay(100);
  107. rSYS_SOFT_RSTNA |= 3 << 5;
  108. udelay(10);
  109. /* enhance usb driving capability */
  110. rSYS_USB_CFG = 0x3c2e0020;
  111. udelay(10);
  112. rSYS_USB1_CFG = 0x3c2e0020;
  113. }
  114. #define ARK_MMC_CLK 48000000
  115. #define ARK_MMC_NUM 3
  116. struct dwmci_host dwmcihost[ARK_MMC_NUM];
  117. static int ark_dwmci_init(char *name,u32 regbase, int bus_width, int index)
  118. {
  119. struct dwmci_host *host = NULL;
  120. host = &dwmcihost[index];
  121. memset(host, 0, sizeof(struct dwmci_host));
  122. dwmci_select_pad();
  123. //dwmci_reset();
  124. /* config clk in sample delay */
  125. //rSYS_SD_CLK_CFG &= ~(0x7f << 13);
  126. //rSYS_SD_CLK_CFG |= 52 << 13;
  127. //rSYS_SD1_CLK_CFG &= ~(0x7f << 13);
  128. //rSYS_SD1_CLK_CFG |= 52 << 13;
  129. /* mmc clk apbpll(480M) / ((4 + 1) * 2) */
  130. rSYS_SD_CLK_CFG &= ~0xfff;
  131. rSYS_SD_CLK_CFG |= (0 << 8) | (1 << 7) | (1 << 5) | 4;
  132. rSYS_SD1_CLK_CFG &= ~0xfff;
  133. rSYS_SD1_CLK_CFG |= (0 << 8) | (1 << 7) | (1 << 5) | 4;
  134. host->name = name;
  135. host->ioaddr = (void *)regbase;
  136. host->buswidth = bus_width;
  137. host->dev_index = index;
  138. host->bus_hz = ARK_MMC_CLK;
  139. host->fifoth_val = 64;
  140. host->fifo_mode = 1;
  141. add_dwmci(host, host->bus_hz, 400000);
  142. return 0;
  143. }
  144. int board_mmc_init(bd_t *bis)
  145. {
  146. ark_dwmci_init("ARK_MMC0", 0xec400000, 8, 0);
  147. #ifndef CONFIG_SPL_BUILD
  148. ark_dwmci_init("ARK_MMC1", 0xec800000, 4, 1);
  149. #endif
  150. ark_dwmci_init("ARK_MMC2", 0xecc00000, 4, 2);
  151. return 0;
  152. }
  153. int dram_init(void)
  154. {
  155. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  156. CONFIG_SYS_SDRAM_SIZE);
  157. return 0;
  158. }
  159. int board_init(void)
  160. {
  161. unsigned int val;
  162. /* watchdog disable */
  163. rWDT_CR = 0;
  164. /* cpu1 disable */
  165. rSYS_CPU_CTL &= ~(1 << 7);
  166. /* cpu cnt clk enable */
  167. rSYS_CPU_CTL |= 1 << 23;
  168. /* nand pad enable */
  169. val = rSYS_PAD_CTRL08;
  170. val &= ~((0x7<<27) | (0x7<<24) | (0x7<<21) | (0x7<<18) | (0x7<<15) | (0x7<<12) | (0x7<<9) | (0x7<<6));
  171. val |= (0x1<<27) | (0x1<<24) | (0x1<<21) | (0x1<<18) | (0x1<<15) | (0x1<<12) | (0x1<<9) | (0x1<<6);
  172. rSYS_PAD_CTRL08 = val;
  173. val = rSYS_PAD_CTRL09;
  174. val &= ~((0x7<<15) | (0x7<<12) | (0x7<<9) | (0x7<<6) | (0x7<<3) | (0x7<<0));
  175. val |= (1<<15) | (1<<12) | (1<<9) | (1<<6) | (1<<3) | (1<<0);//enable nand cle, ale,ren,wen
  176. rSYS_PAD_CTRL09 = val;
  177. /* spi pad enable */
  178. val = rSYS_PAD_CTRL09;
  179. val &= ~((0x7<<27) | (0x7<<24));
  180. val |= (0x2<<27) | (0x2<<24);
  181. rSYS_PAD_CTRL09 = val;
  182. val = rSYS_PAD_CTRL0A;
  183. val &= ~((0x7<<3) | (0x7<<0));
  184. val |= (0x2<<0);
  185. rSYS_PAD_CTRL0A = val;
  186. /* gmac pad enable */
  187. rSYS_PAD_CTRL0C = (1 << 27) | (1 << 24) | (1 << 21) | (1 << 18) | (1 << 15) | (1 << 12) | (1 << 9) |
  188. (1 << 6) | (1 << 3) | (1 << 0);
  189. //rSYS_PAD_CTRL0D = (1 << 24) | (1 << 9) | (1 << 6) | (1 << 3) | (1 << 0);
  190. rSYS_PAD_CTRL0D = (1 << 24) | (1 << 21) | (1 << 18) | (1 << 15) | (1 << 12) | (1 << 9) |
  191. (1 << 6) | (1 << 3) | (1 << 0);
  192. /* gmac tx clk out */
  193. rSYS_PAD_CTRL0F |= (1 << 31);
  194. /* select rgmii interface */
  195. rSYS_MFC_GMAC_CTL &= ~(7 << 1);
  196. rSYS_MFC_GMAC_CTL |= (1 << 1);
  197. /* mac rx clk inv */
  198. rSYS_DEVICE_CLK_CFG7 |= (1 << 1);
  199. /* mac tx clk inv */
  200. rSYS_DEVICE_CLK_CFG8 |= (1 << 7);
  201. /* i2s0 sadata in */
  202. rSYS_PAD_CTRL0F &= ~(1 << 28);
  203. /* i2s1 sadata out */
  204. rSYS_PAD_CTRL0F |= (1 << 29);
  205. /* select pwm0 pad */
  206. rSYS_PAD_CTRL05 &= ~0x7;
  207. rSYS_PAD_CTRL05 |= 1;
  208. return 0;
  209. }
  210. #ifdef CONFIG_BOARD_EARLY_INIT_F
  211. int board_early_init_f(void)
  212. {
  213. #ifdef CONFIG_DEBUG_UART
  214. debug_uart_init();
  215. #endif
  216. return 0;
  217. }
  218. #endif
  219. int burn_data_to_partition(char *partition_name)
  220. {
  221. char cmd[128] = { 0 };
  222. int ret = -1;
  223. int file_size = 0;
  224. unsigned int crc_des = 0;
  225. unsigned int *dstdata = (unsigned int *)(env_get_hex("cmploadaddr", 0));
  226. sprintf(cmd, "nand erase.part %s", partition_name);
  227. printf("cmd=%s\n", cmd);
  228. ret = run_command(cmd, 0);
  229. if (ret)
  230. return ret;
  231. file_size = env_get_ulong("filesize", 16, 0x2000);
  232. sprintf(cmd, "nand write %s %s 0x%x", env_get("loadaddr"), partition_name, file_size);
  233. printf("cmd=%s\n", cmd);
  234. ret = run_command(cmd, 0);
  235. if(ret)
  236. {
  237. printf("Nand write %s Error\n",partition_name);
  238. return 1;
  239. }
  240. mdelay(50);
  241. sprintf(cmd, "nand read %s %s 0x%x",env_get("cmploadaddr"),partition_name, file_size);
  242. printf("cmd=%s\n", cmd);
  243. ret = run_command(cmd, 0);
  244. if(ret)
  245. {
  246. printf("Nand read %s Error\n",partition_name);
  247. return 1;
  248. }
  249. crc_des = crc32(0, (const unsigned char *)dstdata, file_size);
  250. ret = ark_check_data_from_partition(partition_name,crc_des);
  251. if(ret)
  252. return 1;
  253. return 0;
  254. }
  255. static int ark_update_partition(char *partition_name, char *file_name)
  256. {
  257. int ret;
  258. char *update_device = env_get("update_dev_type");
  259. printf("\r\n****** update %s from %s:%s .....\r\n",partition_name,update_device,file_name);
  260. ret = get_data_from_media(file_name);
  261. if (!ret) {
  262. return burn_data_to_partition(partition_name);
  263. }
  264. return ret;
  265. }
  266. static int ark_burn_bootstrap(char *partition_name)
  267. {
  268. char cmd[128] = { 0 };
  269. int ret = -1;
  270. int file_size = 0;
  271. unsigned int crc_des = 0;
  272. unsigned int *dstdata = (unsigned int *)(env_get_hex("cmploadaddr", 0));
  273. sprintf(cmd, "nand erase.part %s", partition_name);
  274. printf("cmd=%s\n", cmd);
  275. ret = run_command(cmd, 0);
  276. if (ret)
  277. return ret;
  278. file_size = env_get_ulong("filesize", 16, 0x2000);
  279. run_command("switchecc 1", 0);
  280. mdelay(10);
  281. sprintf(cmd, "nand write %s %s 0x%x", env_get("loadaddr"), partition_name, file_size);
  282. printf("cmd=%s\n", cmd);
  283. ret = run_command(cmd, 0);
  284. if(ret)
  285. {
  286. printf("Nand write %s Error\n",partition_name);
  287. return 1;
  288. }
  289. mdelay(50);
  290. sprintf(cmd, "nand read %s %s 0x%x",env_get("cmploadaddr"),partition_name, file_size);
  291. printf("cmd=%s\n", cmd);
  292. ret = run_command(cmd, 0);
  293. if(ret)
  294. {
  295. printf("Nand read %s Error\n",partition_name);
  296. return 1;
  297. }
  298. run_command("switchecc 0", 0);
  299. mdelay(10);
  300. crc_des = crc32(0, (const unsigned char *)dstdata, file_size);
  301. printf("crc_des 0x%x,sys_info.ubootspl_crc 0x%x\n",crc_des,sys_info.ubootspl_crc);
  302. ret = ark_check_data_from_partition(partition_name,crc_des);
  303. if(ret)
  304. return 1;
  305. return 0;
  306. }
  307. static int ark_update_bootstrap(char *partition_name, char *file_name)
  308. {
  309. int ret;
  310. char *update_device = env_get("update_dev_type");
  311. printf("\r\n****** update %s from %s:%s .....\n",partition_name,update_device,file_name);
  312. ret = get_data_from_media(file_name);
  313. if (!ret) {
  314. return ark_burn_bootstrap(partition_name);
  315. }
  316. return ret;
  317. }
  318. static int ark_update_from_media(unsigned int updateDevice)
  319. {
  320. char cmd[32];
  321. unsigned int ret = 0;
  322. char *update_fdt = NULL;
  323. unsigned int dis_pos_x;
  324. unsigned int dis_pos_y;
  325. unsigned int resetuboot = 0;
  326. resetuboot = env_get_hex("ubootreset", 0);
  327. printf("resetuboot = %d \n",resetuboot);
  328. run_command("env default -f -a", 0);
  329. mdelay(100);
  330. if (updateDevice) {
  331. printf("update form mmc...\n");
  332. env_set("update_dev_type", "mmc");
  333. mdelay(10);
  334. env_set("update_dev_part", env_get("sd_dev_part"));
  335. } else {
  336. printf("update form usb...\n");
  337. env_set("update_dev_type", "usb");
  338. mdelay(10);
  339. env_set("update_dev_part", "0");
  340. mdelay(10);
  341. env_set("updata_status", "usb");
  342. }
  343. mdelay(10);
  344. if(resetuboot)
  345. {
  346. sprintf((char *)cmd,"disconfig 0");
  347. run_command(cmd, 0);
  348. }
  349. update_fdt = env_get("boardfdt");
  350. printf("update_fdt:%s\n", update_fdt);
  351. get_crc_data_from_device("crcdata.bin");
  352. dis_pos_x = 6;
  353. dis_pos_y = 20;
  354. ret = ark_update_bootstrap("bootstrap", "ubootspl.bin");
  355. mdelay(30);
  356. if(!ret)
  357. {
  358. sprintf(cmd, "setenv bootstrapsize %s",env_get("filesize"));
  359. printf("cmd=%s\n", cmd);
  360. run_command(cmd, 0);
  361. mdelay(30);
  362. sprintf((char *)cmd,"disconfig 5");
  363. run_command(cmd, 0);
  364. mdelay(30);
  365. if(resetuboot)
  366. {
  367. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"bootstrap",0);
  368. printf("cmd=%s\n", cmd);
  369. run_command(cmd, 0);
  370. }
  371. }
  372. else
  373. {
  374. mdelay(30);
  375. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"bootstrap",1);
  376. printf("cmd=%s\n", cmd);
  377. run_command(cmd, 0);
  378. goto bootoldsys;
  379. }
  380. ret = ark_update_partition("bootloader", "u-boot.img");
  381. if(!ret)
  382. {
  383. sprintf(cmd, "setenv bootloadersize %s",env_get("filesize"));
  384. printf("cmd=%s\n", cmd);
  385. run_command(cmd, 0);
  386. mdelay(30);
  387. sprintf((char *)cmd,"disconfig 10");
  388. run_command(cmd, 0);
  389. mdelay(30);
  390. dis_pos_y = dis_pos_y + 20;
  391. if(resetuboot)
  392. {
  393. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"bootloader",0);
  394. printf("cmd=%s\n", cmd);
  395. run_command(cmd, 0);
  396. }
  397. if(resetuboot == 0)
  398. {
  399. env_set("ubootreset", "1");
  400. run_command("saveenv", 0);
  401. mdelay(20);
  402. run_command("reset", 0);
  403. while(1);
  404. }
  405. env_set("ubootreset", "0");
  406. run_command("saveenv", 0);
  407. mdelay(20);
  408. }
  409. else
  410. {
  411. dis_pos_y = dis_pos_y + 20;
  412. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"bootloader",1);
  413. printf("cmd=%s\n", cmd);
  414. run_command(cmd, 0);
  415. goto bootoldsys;
  416. }
  417. ret = ark_update_partition("fdt", update_fdt);
  418. if(!ret)
  419. {
  420. dis_pos_y = dis_pos_y + 20;
  421. sprintf(cmd, "setenv fdtsize %s",env_get("filesize"));
  422. run_command(cmd, 0);
  423. printf("cmd=%s\n", cmd);
  424. mdelay(30);
  425. sprintf((char *)cmd,"disconfig 15");
  426. run_command(cmd, 0);
  427. mdelay(30);
  428. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"fdt",0);
  429. printf("cmd=%s\n", cmd);
  430. run_command(cmd, 0);
  431. }
  432. else
  433. {
  434. mdelay(30);
  435. dis_pos_y = dis_pos_y + 20;
  436. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"fdt",1);
  437. printf("cmd=%s\n", cmd);
  438. run_command(cmd, 0);
  439. goto bootoldsys;
  440. }
  441. ret = ark_update_partition("kernel", "zImage");
  442. if(!ret)
  443. {
  444. sprintf(cmd, "setenv kernelsize %s",env_get("filesize"));
  445. printf("cmd=%s\n", cmd);
  446. run_command(cmd, 0);
  447. mdelay(30);
  448. sprintf((char *)cmd,"disconfig 25");
  449. run_command(cmd, 0);
  450. mdelay(30);
  451. dis_pos_y = dis_pos_y + 20;
  452. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"kernel",0);
  453. printf("cmd=%s\n", cmd);
  454. run_command(cmd, 0);
  455. }
  456. else
  457. {
  458. dis_pos_y = dis_pos_y + 20;
  459. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"kernel",1);
  460. printf("cmd=%s\n", cmd);
  461. run_command(cmd, 0);
  462. goto bootoldsys;
  463. }
  464. #if 0
  465. ret = ark_update_partition("bootanimation", "bootanimation");
  466. if(!ret)
  467. {
  468. sprintf(cmd, "setenv bootanimationsize %s",env_get("filesize"));
  469. run_command(cmd, 0);
  470. printf("cmd=%s\n", cmd);
  471. mdelay(30);
  472. sprintf((char *)cmd,"disconfig 30");
  473. run_command(cmd, 0);
  474. mdelay(30);
  475. dis_pos_y = dis_pos_y + 20;
  476. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"bootanimation",0);
  477. printf("cmd=%s\n", cmd);
  478. run_command(cmd, 0);
  479. }
  480. else
  481. {
  482. dis_pos_y = dis_pos_y + 20;
  483. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"bootanimation",1);
  484. printf("cmd=%s\n", cmd);
  485. run_command(cmd, 0);
  486. goto bootoldsys;
  487. }
  488. #endif
  489. ret = ark_update_partition("bootloader_bak", "u-boot.img");
  490. if(!ret)
  491. {
  492. sprintf((char *)cmd,"disconfig 40");
  493. run_command(cmd, 0);
  494. dis_pos_y = dis_pos_y + 20;
  495. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"bootloader_bak",0);
  496. printf("cmd=%s\n", cmd);
  497. run_command(cmd, 0);
  498. }
  499. else
  500. {
  501. dis_pos_y = dis_pos_y + 20;
  502. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"bootloader_bak",1);
  503. printf("cmd=%s\n", cmd);
  504. run_command(cmd, 0);
  505. goto bootoldsys;
  506. }
  507. ret = ark_update_partition("rootfs","rootfs.ubi");
  508. if(!ret)
  509. {
  510. sprintf((char *)cmd,"disconfig 95");
  511. run_command(cmd, 0);
  512. mdelay(30);
  513. dis_pos_y = dis_pos_y + 20;
  514. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"rootfs",0);
  515. printf("cmd=%s\n", cmd);
  516. run_command(cmd, 0);
  517. }
  518. else
  519. {
  520. mdelay(30);
  521. dis_pos_y = dis_pos_y + 20;
  522. sprintf((char *)cmd,"disstring %d %d %s %d",dis_pos_x,dis_pos_y,"rootfs",1);
  523. printf("cmd=%s\n", cmd);
  524. run_command(cmd, 0);
  525. goto bootoldsys;
  526. }
  527. env_set("need_update", "no");
  528. mdelay(5);
  529. env_set("updata_status", "none");
  530. sprintf(cmd, "saveenv");
  531. printf("cmd=%s\n", cmd);
  532. run_command(cmd, 0);
  533. mdelay(30);
  534. sprintf((char *)cmd,"disconfig 100");
  535. run_command(cmd, 0);
  536. printf("\r\n **** update the device over! .....\r\n");
  537. return 0;
  538. bootoldsys:
  539. env_set("updata_status", "error");
  540. sprintf(cmd, "saveenv");
  541. printf("cmd=%s\n", cmd);
  542. run_command(cmd, 0);
  543. mdelay(20);
  544. sprintf((char *)cmd,"disconfig 100");
  545. run_command(cmd, 0);
  546. return 1;
  547. }
  548. int board_late_init(void)
  549. {
  550. char cmd[128];
  551. char *need_update,*update_flash;
  552. unsigned int loadaddr;
  553. int do_update = 0, update_from_mmc = 1;
  554. int update_detect = 0; //0:no update 1:need_update env 2:usb update boot 3:sd update boot
  555. run_command("sf probe", 0);
  556. #ifdef CONFIG_USB_MUSB_HOST
  557. usb_controller_reset();
  558. musb_register(&musb_platform_data, NULL, (void *)MUSB_BASE);
  559. #endif
  560. update_flash = env_get("update_from_ota");
  561. need_update = env_get("need_update");
  562. if (!strcmp(need_update, "yes"))
  563. update_detect = 1;
  564. else if (((rSYS_BOOT_SAMPLE >> 2) & 3) == 1)
  565. update_detect = 2;
  566. else if (((rSYS_BOOT_SAMPLE >> 2) & 3) == 2)
  567. update_detect = 3;
  568. //由于usb升级检测的时候,会需要一段时间所以这个地方需要时间长一些,设置3s
  569. ark_watchdog_start(3000);
  570. printf("update_detect=%d.\n", update_detect);
  571. if (update_detect) {
  572. loadaddr = env_get_hex("loadaddr", 0);
  573. if (loadaddr)
  574. memset((void*)loadaddr, 0, strlen(ARK1668_UPDATE_MAGIC));
  575. if (update_detect == 1 || update_detect == 3) {
  576. sprintf(cmd, "fatload %s %s %s update-magic", "mmc", env_get("sd_dev_part"), env_get("loadaddr"));
  577. run_command(cmd, 0);
  578. if (loadaddr && !memcmp((void *)loadaddr, ARK1668_UPDATE_MAGIC, strlen(ARK1668_UPDATE_MAGIC))) {
  579. do_update = 1;
  580. goto update_done;
  581. } else {
  582. printf("Wrong update magic, do not update from mmc.\n");
  583. }
  584. }
  585. #ifdef CONFIG_USB_MUSB_HOST
  586. if (update_detect == 1 || update_detect == 2) {
  587. run_command("usb start", 0);
  588. sprintf(cmd, "fatload %s %s %s update-magic", "usb", "0", env_get("loadaddr"));
  589. run_command(cmd, 0);
  590. if (loadaddr && !memcmp((void *)loadaddr, ARK1668_UPDATE_MAGIC, strlen(ARK1668_UPDATE_MAGIC))) {
  591. do_update = 1;
  592. update_from_mmc = 0;
  593. goto update_done;
  594. } else {
  595. printf("Wrong update magic, do not update from usb.\n");
  596. }
  597. }
  598. #endif
  599. }
  600. if (!strcmp(update_flash, "yes")){
  601. //升级的时候关闭看门够功能
  602. ark_watchdog_stop();
  603. sprintf(cmd, "run updatefromflash");
  604. printf("cmd=%s\n", cmd);
  605. run_command(cmd, 0);
  606. }
  607. update_done:
  608. if (do_update) {
  609. run_command("nand erase.part userdata", 0);
  610. env_set("do_update", "yes");
  611. mdelay(10);
  612. //升级的时候关闭看门狗
  613. ark_watchdog_stop();
  614. ark_update_from_media(update_from_mmc);
  615. } else {
  616. env_set("do_update", "no");
  617. }
  618. return 0;
  619. }