cmd_jffs2.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * (C) Copyright 2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. * (C) Copyright 2002
  5. * Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de>
  6. * (C) Copyright 2003
  7. * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. /*
  28. * Boot support
  29. */
  30. #include <common.h>
  31. #include <command.h>
  32. #include <s_record.h>
  33. #include <jffs2/load_kernel.h>
  34. #include <net.h>
  35. #if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
  36. #include <cramfs/cramfs_fs.h>
  37. extern int cramfs_check (struct part_info *info);
  38. extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
  39. extern int cramfs_ls (struct part_info *info, char *filename);
  40. extern int cramfs_info (struct part_info *info);
  41. static int part_num=0;
  42. #ifndef CFG_JFFS_CUSTOM_PART
  43. #define CFG_JFFS_SINGLE_PART 1
  44. static struct part_info part;
  45. #ifndef CONFIG_JFFS2_NAND
  46. struct part_info*
  47. jffs2_part_info(int part_num)
  48. {
  49. extern flash_info_t flash_info[]; /* info for FLASH chips */
  50. int i;
  51. if(part_num==0){
  52. if(part.usr_priv==(void*)1)
  53. return &part;
  54. memset(&part, 0, sizeof(part));
  55. #if defined(CFG_JFFS2_FIRST_SECTOR)
  56. part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
  57. #else
  58. part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
  59. #endif
  60. /* Figure out flash partition size */
  61. for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++)
  62. part.size += flash_info[i].size;
  63. #if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
  64. part.size -=
  65. flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
  66. flash_info[CFG_JFFS2_FIRST_BANK].start[0];
  67. #endif
  68. /* Mark the struct as ready */
  69. part.usr_priv=(void*)1;
  70. return &part;
  71. }
  72. return 0;
  73. }
  74. #else /* CONFIG_JFFS2_NAND */
  75. struct part_info*
  76. jffs2_part_info(int part_num)
  77. {
  78. if(part_num==0){
  79. if(part.usr_priv==(void*)1)
  80. return &part;
  81. memset(&part, 0, sizeof(part));
  82. part.offset = (char *)CONFIG_JFFS2_NAND_OFF;
  83. part.size = CONFIG_JFFS2_NAND_SIZE; /* the bigger size the slower jffs2 */
  84. #ifndef CONFIG_JFFS2_NAND_DEV
  85. #define CONFIG_JFFS2_NAND_DEV 0
  86. #endif
  87. /* nand device with the JFFS2 parition plus 1 */
  88. part.usr_priv = (void*)(CONFIG_JFFS2_NAND_DEV+1);
  89. return &part;
  90. }
  91. return 0;
  92. }
  93. #endif /* CONFIG_JFFS2_NAND */
  94. #endif /* ifndef CFG_JFFS_CUSTOM_PART */
  95. int
  96. do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  97. {
  98. struct part_info* jffs2_part_info(int);
  99. int jffs2_1pass_load(char *, struct part_info *,const char *);
  100. char *fsname;
  101. char *filename;
  102. int size;
  103. struct part_info *part;
  104. ulong offset = load_addr;
  105. /* pre-set Boot file name */
  106. if ((filename = getenv("bootfile")) == NULL) {
  107. filename = "uImage";
  108. }
  109. if (argc == 2) {
  110. filename = argv[1];
  111. }
  112. if (argc == 3) {
  113. offset = simple_strtoul(argv[1], NULL, 16);
  114. load_addr = offset;
  115. filename = argv[2];
  116. }
  117. if (0 != (part=jffs2_part_info(part_num))){
  118. /* check partition type for cramfs */
  119. fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
  120. printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
  121. if (cramfs_check(part)) {
  122. size = cramfs_load ((char *) offset, part, filename);
  123. } else {
  124. /* if this is not cramfs assume jffs2 */
  125. size = jffs2_1pass_load((char *)offset, part, filename);
  126. }
  127. if (size > 0) {
  128. char buf[10];
  129. printf("### %s load complete: %d bytes loaded to 0x%lx\n",
  130. fsname, size, offset);
  131. sprintf(buf, "%x", size);
  132. setenv("filesize", buf);
  133. } else {
  134. printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
  135. }
  136. return !(size > 0);
  137. }
  138. puts ("Active partition not valid\n");
  139. return 0;
  140. }
  141. int
  142. do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  143. {
  144. struct part_info* jffs2_part_info(int);
  145. int jffs2_1pass_ls(struct part_info *,char *);
  146. char *filename = "/";
  147. int ret;
  148. struct part_info *part;
  149. if (argc == 2)
  150. filename = argv[1];
  151. if (0 != (part=jffs2_part_info(part_num))){
  152. /* check partition type for cramfs */
  153. if (cramfs_check(part)) {
  154. ret = cramfs_ls (part, filename);
  155. } else {
  156. /* if this is not cramfs assume jffs2 */
  157. ret = jffs2_1pass_ls(part, filename);
  158. }
  159. return (ret == 1);
  160. }
  161. puts ("Active partition not valid\n");
  162. return 0;
  163. }
  164. int
  165. do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  166. {
  167. struct part_info* jffs2_part_info(int);
  168. int jffs2_1pass_info(struct part_info *);
  169. struct part_info *part;
  170. char *fsname;
  171. int ret;
  172. if ((part=jffs2_part_info(part_num))){
  173. /* check partition type for cramfs */
  174. fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
  175. printf("### filesystem type is %s\n", fsname);
  176. if (cramfs_check(part)) {
  177. ret = cramfs_info (part);
  178. } else {
  179. /* if this is not cramfs assume jffs2 */
  180. ret = jffs2_1pass_info(part);
  181. }
  182. return (ret == 1);
  183. }
  184. puts ("Active partition not valid\n");
  185. return 0;
  186. }
  187. #ifndef CFG_JFFS_SINGLE_PART
  188. int
  189. do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  190. {
  191. int tmp_part;
  192. char str_part_num[3];
  193. struct part_info* jffs2_part_info(int);
  194. if (argc >= 2) {
  195. tmp_part = simple_strtoul(argv[1], NULL, 16);
  196. } else {
  197. puts ("Need partition number in argument list\n");
  198. return 0;
  199. }
  200. if (jffs2_part_info(tmp_part)){
  201. printf("Partition changed to %d\n",tmp_part);
  202. part_num=tmp_part;
  203. sprintf(str_part_num, "%d", part_num);
  204. setenv("partition", str_part_num);
  205. return 0;
  206. }
  207. printf("Partition %d is not valid partiton\n",tmp_part);
  208. return 0;
  209. }
  210. U_BOOT_CMD(
  211. chpart, 2, 0, do_jffs2_chpart,
  212. "chpart\t- change active partition\n",
  213. " - change active partition\n"
  214. );
  215. #endif /* CFG_JFFS_SINGLE_PART */
  216. /***************************************************/
  217. U_BOOT_CMD(
  218. fsload, 3, 0, do_jffs2_fsload,
  219. "fsload\t- load binary file from a filesystem image\n",
  220. "[ off ] [ filename ]\n"
  221. " - load binary file from flash bank\n"
  222. " with offset 'off'\n"
  223. );
  224. U_BOOT_CMD(
  225. fsinfo, 1, 1, do_jffs2_fsinfo,
  226. "fsinfo\t- print information about filesystems\n",
  227. " - print information about filesystems\n"
  228. );
  229. U_BOOT_CMD(
  230. ls, 2, 1, do_jffs2_ls,
  231. "ls\t- list files in a directory (default /)\n",
  232. "[ directory ]\n"
  233. " - list files in a directory.\n"
  234. );
  235. #endif /* CFG_CMD_JFFS2 */