cmd_jffs2.c 5.9 KB

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