cmd_jffs2.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 = CFG_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. filename = argv[2];
  91. }
  92. if (0 != (part=jffs2_part_info(part_num))){
  93. /* check partition type for cramfs */
  94. fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
  95. printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
  96. if (cramfs_check(part)) {
  97. size = cramfs_load ((char *) offset, part, filename);
  98. } else {
  99. /* if this is not cramfs assume jffs2 */
  100. size = jffs2_1pass_load((char *)offset, part, filename);
  101. }
  102. if (size > 0) {
  103. char buf[10];
  104. printf("### %s load complete: %d bytes loaded to 0x%lx\n",
  105. fsname, size, offset);
  106. sprintf(buf, "%x", size);
  107. setenv("filesize", buf);
  108. } else {
  109. printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
  110. }
  111. return !(size > 0);
  112. }
  113. printf("Active partition not valid\n");
  114. return 0;
  115. }
  116. int
  117. do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  118. {
  119. struct part_info* jffs2_part_info(int);
  120. int jffs2_1pass_ls(struct part_info *,char *);
  121. char *filename = "/";
  122. int ret;
  123. struct part_info *part;
  124. if (argc == 2)
  125. filename = argv[1];
  126. if (0 != (part=jffs2_part_info(part_num))){
  127. /* check partition type for cramfs */
  128. if (cramfs_check(part)) {
  129. ret = cramfs_ls (part, filename);
  130. } else {
  131. /* if this is not cramfs assume jffs2 */
  132. ret = jffs2_1pass_ls(part, filename);
  133. }
  134. return (ret == 1);
  135. }
  136. printf("Active partition not valid\n");
  137. return 0;
  138. }
  139. int
  140. do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  141. {
  142. struct part_info* jffs2_part_info(int);
  143. int jffs2_1pass_info(struct part_info *);
  144. struct part_info *part;
  145. char *fsname;
  146. int ret;
  147. if ((part=jffs2_part_info(part_num))){
  148. /* check partition type for cramfs */
  149. fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
  150. printf("### filesystem type is %s\n", fsname);
  151. if (cramfs_check(part)) {
  152. ret = cramfs_info (part);
  153. } else {
  154. /* if this is not cramfs assume jffs2 */
  155. ret = jffs2_1pass_info(part);
  156. }
  157. return (ret == 1);
  158. }
  159. printf("Active partition not valid\n");
  160. return 0;
  161. }
  162. int
  163. do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  164. {
  165. int tmp_part;
  166. char str_part_num[3];
  167. struct part_info* jffs2_part_info(int);
  168. if (argc >= 2) {
  169. tmp_part = simple_strtoul(argv[1], NULL, 16);
  170. }else{
  171. printf("Need partition number in argument list\n");
  172. return 0;
  173. }
  174. if (jffs2_part_info(tmp_part)){
  175. printf("Partition changed to %d\n",tmp_part);
  176. part_num=tmp_part;
  177. sprintf(str_part_num, "%d", part_num);
  178. setenv("partition", str_part_num);
  179. return 0;
  180. }
  181. printf("Partition %d is not valid partiton\n",tmp_part);
  182. return 0;
  183. }
  184. /***************************************************/
  185. U_BOOT_CMD(
  186. fsload, 3, 0, do_jffs2_fsload,
  187. "fsload - load binary file from a filesystem image\n",
  188. "[ off ] [ filename ]\n"
  189. " - load binary file from flash bank\n"
  190. " with offset 'off'\n"
  191. );
  192. U_BOOT_CMD(
  193. fsinfo, 1, 1, do_jffs2_fsinfo,
  194. "fsinfo - print information about filesystems\n",
  195. " - print information about filesystems\n"
  196. );
  197. U_BOOT_CMD(
  198. ls, 2, 1, do_jffs2_ls,
  199. "ls - list files in a directory (default /)\n",
  200. "[ directory ]\n"
  201. " - list files in a directory.\n"
  202. );
  203. U_BOOT_CMD(
  204. chpart, 2, 0, do_jffs2_chpart,
  205. "chpart - change active partition\n",
  206. " - change active partition\n"
  207. );
  208. #endif /* CFG_CMD_JFFS2 */