cmd_jffs2.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. static struct part_info part;
  44. struct part_info*
  45. jffs2_part_info(int part_num)
  46. {
  47. extern flash_info_t flash_info[]; /* info for FLASH chips */
  48. int i;
  49. if(part_num==0){
  50. if(part.usr_priv==(void*)1)
  51. return &part;
  52. memset(&part, 0, sizeof(part));
  53. #if defined(CFG_JFFS2_FIRST_SECTOR)
  54. part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
  55. #else
  56. part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
  57. #endif
  58. /* Figure out flash partition size */
  59. for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++)
  60. part.size += flash_info[i].size;
  61. #if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
  62. part.size -=
  63. flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
  64. flash_info[CFG_JFFS2_FIRST_BANK].start[0];
  65. #endif
  66. /* unused in current jffs2 loader */
  67. part.erasesize = 0;
  68. /* Mark the struct as ready */
  69. part.usr_priv=(void*)1;
  70. return &part;
  71. }
  72. return 0;
  73. }
  74. #endif /* ifndef CFG_JFFS_CUSTOM_PART */
  75. int
  76. do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  77. {
  78. struct part_info* jffs2_part_info(int);
  79. int jffs2_1pass_load(char *, struct part_info *,const char *);
  80. char *fsname;
  81. char *filename = "uImage";
  82. ulong offset = load_addr;
  83. int size;
  84. struct part_info *part;
  85. if (argc == 2) {
  86. filename = argv[1];
  87. }
  88. if (argc == 3) {
  89. offset = simple_strtoul(argv[1], NULL, 16);
  90. load_addr = offset;
  91. filename = argv[2];
  92. }
  93. if (0 != (part=jffs2_part_info(part_num))){
  94. /* check partition type for cramfs */
  95. fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
  96. printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
  97. if (cramfs_check(part)) {
  98. size = cramfs_load ((char *) offset, part, filename);
  99. } else {
  100. /* if this is not cramfs assume jffs2 */
  101. size = jffs2_1pass_load((char *)offset, part, filename);
  102. }
  103. if (size > 0) {
  104. char buf[10];
  105. printf("### %s load complete: %d bytes loaded to 0x%lx\n",
  106. fsname, size, offset);
  107. sprintf(buf, "%x", size);
  108. setenv("filesize", buf);
  109. } else {
  110. printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
  111. }
  112. return !(size > 0);
  113. }
  114. puts ("Active partition not valid\n");
  115. return 0;
  116. }
  117. int
  118. do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  119. {
  120. struct part_info* jffs2_part_info(int);
  121. int jffs2_1pass_ls(struct part_info *,char *);
  122. char *filename = "/";
  123. int ret;
  124. struct part_info *part;
  125. if (argc == 2)
  126. filename = argv[1];
  127. if (0 != (part=jffs2_part_info(part_num))){
  128. /* check partition type for cramfs */
  129. if (cramfs_check(part)) {
  130. ret = cramfs_ls (part, filename);
  131. } else {
  132. /* if this is not cramfs assume jffs2 */
  133. ret = jffs2_1pass_ls(part, filename);
  134. }
  135. return (ret == 1);
  136. }
  137. puts ("Active partition not valid\n");
  138. return 0;
  139. }
  140. int
  141. do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  142. {
  143. struct part_info* jffs2_part_info(int);
  144. int jffs2_1pass_info(struct part_info *);
  145. struct part_info *part;
  146. char *fsname;
  147. int ret;
  148. if ((part=jffs2_part_info(part_num))){
  149. /* check partition type for cramfs */
  150. fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
  151. printf("### filesystem type is %s\n", fsname);
  152. if (cramfs_check(part)) {
  153. ret = cramfs_info (part);
  154. } else {
  155. /* if this is not cramfs assume jffs2 */
  156. ret = jffs2_1pass_info(part);
  157. }
  158. return (ret == 1);
  159. }
  160. puts ("Active partition not valid\n");
  161. return 0;
  162. }
  163. int
  164. do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  165. {
  166. int tmp_part;
  167. char str_part_num[3];
  168. struct part_info* jffs2_part_info(int);
  169. if (argc >= 2) {
  170. tmp_part = simple_strtoul(argv[1], NULL, 16);
  171. }else{
  172. puts ("Need partition number in argument list\n");
  173. return 0;
  174. }
  175. if (jffs2_part_info(tmp_part)){
  176. printf("Partition changed to %d\n",tmp_part);
  177. part_num=tmp_part;
  178. sprintf(str_part_num, "%d", part_num);
  179. setenv("partition", str_part_num);
  180. return 0;
  181. }
  182. printf("Partition %d is not valid partiton\n",tmp_part);
  183. return 0;
  184. }
  185. /***************************************************/
  186. U_BOOT_CMD(
  187. fsload, 3, 0, do_jffs2_fsload,
  188. "fsload - load binary file from a filesystem image\n",
  189. "[ off ] [ filename ]\n"
  190. " - load binary file from flash bank\n"
  191. " with offset 'off'\n"
  192. );
  193. U_BOOT_CMD(
  194. fsinfo, 1, 1, do_jffs2_fsinfo,
  195. "fsinfo - print information about filesystems\n",
  196. " - print information about filesystems\n"
  197. );
  198. U_BOOT_CMD(
  199. ls, 2, 1, do_jffs2_ls,
  200. "ls - list files in a directory (default /)\n",
  201. "[ directory ]\n"
  202. " - list files in a directory.\n"
  203. );
  204. U_BOOT_CMD(
  205. chpart, 2, 0, do_jffs2_chpart,
  206. "chpart - change active partition\n",
  207. " - change active partition\n"
  208. );
  209. #endif /* CFG_CMD_JFFS2 */