update_cmd.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2002
  4. * Richard Jones, rjones@nexus-tech.net
  5. */
  6. /*
  7. * Boot support
  8. */
  9. #include <common.h>
  10. #include <command.h>
  11. #include <s_record.h>
  12. #include <net.h>
  13. #include <ata.h>
  14. #include <asm/io.h>
  15. #include <mapmem.h>
  16. #include <part.h>
  17. #include <fat.h>
  18. #include <fs.h>
  19. #include <environment.h>
  20. typedef enum {
  21. MMC = 0,
  22. USB,
  23. NFLASH
  24. } MEDIA_TYPE;
  25. static int get_data_from_media(MEDIA_TYPE type, char index, char *file_name)
  26. {
  27. int ret = -1;
  28. char cmd[128] = { 0 };
  29. printf("file_name=%s\n", file_name);
  30. if (type == NFLASH)
  31. sprintf(cmd, "ubifsload %s %s ", env_get("loadaddr"), file_name);
  32. else if (type == MMC)
  33. sprintf(cmd, "fatload mmc %d %s %s", index, env_get("loadaddr"), file_name);
  34. else if (type == USB)
  35. sprintf(cmd, "fatload usb %d %s %s", index, env_get("loadaddr"), file_name);
  36. printf("cmd=%s\n", cmd);
  37. ret = run_command(cmd, 0);
  38. return ret;
  39. }
  40. static int burn_data_2_partition(char *partition_name)
  41. {
  42. char cmd[128] = { 0 };
  43. int ret = -1;
  44. int file_size = 0;
  45. sprintf(cmd, "nand erase.part %s", partition_name);
  46. printf("cmd=%s\n", cmd);
  47. ret = run_command(cmd, 0);
  48. if (ret)
  49. return ret;
  50. file_size = env_get_ulong("filesize", 16, 0x2000);
  51. sprintf(cmd, "nand write %s %s 0x%x", env_get("loadaddr"), partition_name, file_size);
  52. printf("cmd=%s\n", cmd);
  53. ret = run_command(cmd, 0);
  54. return ret;
  55. }
  56. static int ark_update_partition(MEDIA_TYPE type, char card_index, char *partition_name, char *file_name)
  57. {
  58. int ret;
  59. ret = get_data_from_media(type, card_index, file_name);
  60. if (!ret) {
  61. burn_data_2_partition(partition_name);
  62. return 0;
  63. }
  64. return 1;
  65. }
  66. int do_UpdataOther(cmd_tbl_t * cmdtp, int flag, int argc, char *const argv[])
  67. {
  68. unsigned long type = 0;
  69. unsigned long card_index = 0;
  70. char *filename = NULL;
  71. char *partname = NULL;
  72. unsigned int ret = 0;
  73. strict_strtoul(argv[1], 16, &type);
  74. strict_strtoul(argv[2], 16, &card_index);
  75. partname = argv[3];
  76. filename = argv[4];
  77. ret = ark_update_partition(type, card_index, partname, filename);
  78. mdelay(1000);
  79. return ret;
  80. }
  81. U_BOOT_CMD(Updata, 5, 1, do_UpdataOther, "updata boot loader and save the ", "<interface> <dev[:part]> <filename>\n");
  82. unsigned int updata_the_ubootspl(void)
  83. {
  84. int ret;
  85. ret = get_data_from_media(2, 0, "ubootspl.bin");
  86. if (!ret)
  87. {
  88. run_command("switchecc 1", 0);
  89. mdelay(100);
  90. burn_data_2_partition("bootstrap");
  91. mdelay(100);
  92. run_command("switchecc 0", 0);
  93. return 1;
  94. }
  95. return 0;
  96. }
  97. #define ARK1668_UPDATE_MAGIC "ada7f0c6-7c86-11e9-8f9e-2a86e4085a59"
  98. int do_Update_flash(cmd_tbl_t * cmdtp, int flag, int argc, char *const argv[])
  99. {
  100. char cmd[32];
  101. unsigned int index = 0;
  102. unsigned int loadaddr;
  103. char *update_fdt = NULL;
  104. unsigned int ret = 0;
  105. sprintf((char *)cmd,"disconfig 0");
  106. run_command(cmd, 0);
  107. sprintf(cmd, "ubi part ota");
  108. printf("cmd=%s\n", cmd);
  109. run_command(cmd, 0);
  110. sprintf((char *)cmd,"disconfig 5");
  111. run_command(cmd, 0);
  112. mdelay(300);
  113. sprintf(cmd, "ubifsmount ubi:ota");
  114. printf("cmd=%s\n", cmd);
  115. run_command(cmd, 0);
  116. mdelay(300);
  117. sprintf((char *)cmd,"disconfig 8");
  118. run_command(cmd, 0);
  119. loadaddr = env_get_hex("loadaddr", 0);
  120. update_fdt = env_get("nandfdt");
  121. printf("update_fdt:%s\n", update_fdt);
  122. sprintf(cmd, "ubifsload %s %s ", env_get("loadaddr"),"update-magic");
  123. run_command(cmd, 0);
  124. if (loadaddr && !memcmp((void *)loadaddr, ARK1668_UPDATE_MAGIC, strlen(ARK1668_UPDATE_MAGIC))) {
  125. //env_set("update_from_flash", "no");
  126. //sprintf(cmd, "saveenv");
  127. printf("ARK1668_UPDATE_MAGIC CHECK OK!!\n");
  128. //run_command(cmd, 0);
  129. } else {
  130. printf("Wrong update magic, do not update from flash.\n");
  131. goto bootoldsys;
  132. }
  133. sprintf((char *)cmd,"disconfig 10");
  134. run_command(cmd, 0);
  135. printf("\r\n *****Now update ubootspl.bin ......\r\n");
  136. updata_the_ubootspl();
  137. printf("\r\n **** update from update bootloader .....\r\n");
  138. sprintf(cmd, "Updata 0x%x 0x%x %s %s", NFLASH, index, "bootloader", "u-boot.img");
  139. printf("cmd=%s\n", cmd);
  140. ret = run_command(cmd, 0);
  141. if(ret == 0)
  142. {
  143. sprintf((char *)cmd,"disconfig 15");
  144. run_command(cmd, 0);
  145. }
  146. printf("\r\n **** update from update fdt .....\r\n");
  147. sprintf(cmd, "Updata 0x%x 0x%x %s %s", NFLASH, index, "fdt", update_fdt);
  148. printf("cmd=%s\n", cmd);
  149. ret = run_command(cmd, 0);
  150. mdelay(30);
  151. if(ret == 0)
  152. {
  153. sprintf(cmd, "setenv fdtsize %s",env_get("filesize"));
  154. run_command(cmd, 0);
  155. printf("cmd=%s\n", cmd);
  156. mdelay(30);
  157. sprintf((char *)cmd,"disconfig 20");
  158. run_command(cmd, 0);
  159. }
  160. printf("\r\n **** update from update kernel .....\r\n");
  161. sprintf(cmd, "Updata 0x%x 0x%x %s %s", NFLASH, index, "kernel", "zImage");
  162. printf("cmd=%s\n", cmd);
  163. ret = run_command(cmd, 0);
  164. mdelay(30);
  165. if(ret == 0)
  166. {
  167. sprintf(cmd, "setenv kernelsize %s",env_get("filesize"));
  168. printf("cmd=%s\n", cmd);
  169. run_command(cmd, 0);
  170. sprintf((char *)cmd,"disconfig 30");
  171. run_command(cmd, 0);
  172. }
  173. printf("\r\n **** update from update rootfs .....\r\n");
  174. sprintf(cmd, "Updata 0x%x 0x%x %s %s", NFLASH, index, "rootfs", "rootfs.ubi");
  175. printf("cmd=%s\n", cmd);
  176. ret = run_command(cmd, 0);
  177. mdelay(30);
  178. if(ret == 0)
  179. {
  180. sprintf(cmd, "setenv rootfssize %s",env_get("filesize"));
  181. printf("cmd=%s\n", cmd);
  182. run_command(cmd, 0);
  183. mdelay(30);
  184. sprintf((char *)cmd,"disconfig 70");
  185. run_command(cmd, 0);
  186. }
  187. printf("\r\n **** update from update bootanimation .....\r\n");
  188. sprintf(cmd, "Updata 0x%x 0x%x %s %s", NFLASH, index, "bootanimation", "bootanimation");
  189. printf("cmd=%s\n", cmd);
  190. ret = run_command(cmd, 0);
  191. mdelay(30);
  192. if(ret == 0)
  193. {
  194. sprintf(cmd, "setenv bootanimationsize %s",env_get("filesize"));
  195. printf("cmd=%s\n", cmd);
  196. run_command(cmd, 0);
  197. mdelay(30);
  198. sprintf((char *)cmd,"disconfig 75");
  199. run_command(cmd, 0);
  200. }
  201. printf("\r\n **** update from update reversingtrack .....\r\n");
  202. sprintf(cmd, "Updata 0x%x 0x%x %s %s", NFLASH, index, "reversingtrack", "reversingtrack");
  203. printf("cmd=%s\n", cmd);
  204. ret = run_command(cmd, 0);
  205. mdelay(30);
  206. if(ret == 0)
  207. {
  208. sprintf(cmd, "setenv reversingtracksize %s",env_get("filesize"));
  209. printf("cmd=%s\n", cmd);
  210. run_command(cmd, 0);
  211. mdelay(30);
  212. sprintf((char *)cmd,"disconfig 80");
  213. run_command(cmd, 0);
  214. }
  215. printf("\r\n **** update from update bootloader back.....\r\n");
  216. sprintf(cmd, "Updata 0x%x 0x%x %s %s", NFLASH, index, "bootloader_bak", "u-boot.img");
  217. printf("cmd=%s\n", cmd);
  218. ret = run_command(cmd, 0);
  219. if(ret == 0)
  220. {
  221. sprintf((char *)cmd,"disconfig 90");
  222. run_command(cmd, 0);
  223. }
  224. printf("##set update_from_flash no##\n");
  225. env_set("update_from_flash", "no");
  226. mdelay(10);
  227. env_set("need_update", "no");
  228. mdelay(10);
  229. sprintf((char *)cmd,"disconfig 100");
  230. run_command(cmd, 0);
  231. bootoldsys:
  232. sprintf(cmd, "saveenv");
  233. printf("cmd=%s\n", cmd);
  234. run_command(cmd, 0);
  235. mdelay(20);
  236. sprintf(cmd, "run nandboot");
  237. printf("cmd=%s\n", cmd);
  238. run_command(cmd, 0);
  239. return 1;
  240. }
  241. U_BOOT_CMD(UpdateFlash, 4, 0, do_Update_flash, "updata Flash ", "<interface> <dev[:part]> <filename>\n");