cmd_reiser.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * (C) Copyright 2003 - 2004
  3. * Sysgo Real-Time Solutions, AG <www.elinos.com>
  4. * Pavel Bartusek <pba@sysgo.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. *
  24. */
  25. /*
  26. * Reiserfs support
  27. */
  28. #include <common.h>
  29. #if (CONFIG_COMMANDS & CFG_CMD_REISER)
  30. #include <config.h>
  31. #include <command.h>
  32. #include <image.h>
  33. #include <linux/ctype.h>
  34. #include <asm/byteorder.h>
  35. #include <reiserfs.h>
  36. #ifndef CONFIG_DOS_PARTITION
  37. #error DOS partition support must be selected
  38. #endif
  39. /* #define REISER_DEBUG */
  40. #ifdef REISER_DEBUG
  41. #define PRINTF(fmt,args...) printf (fmt ,##args)
  42. #else
  43. #define PRINTF(fmt,args...)
  44. #endif
  45. static block_dev_desc_t *get_dev (char* ifname, int dev)
  46. {
  47. #if (CONFIG_COMMANDS & CFG_CMD_IDE)
  48. if (strncmp(ifname,"ide",3)==0) {
  49. extern block_dev_desc_t * ide_get_dev(int dev);
  50. return((dev >= CFG_IDE_MAXDEVICE) ? NULL : ide_get_dev(dev));
  51. }
  52. #endif
  53. #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
  54. if (strncmp(ifname,"scsi",4)==0) {
  55. extern block_dev_desc_t * scsi_get_dev(int dev);
  56. return((dev >= CFG_SCSI_MAXDEVICE) ? NULL : scsi_get_dev(dev));
  57. }
  58. #endif
  59. #if ((CONFIG_COMMANDS & CFG_CMD_USB) && defined(CONFIG_USB_STORAGE))
  60. if (strncmp(ifname,"usb",3)==0) {
  61. extern block_dev_desc_t * usb_stor_get_dev(int dev);
  62. return((dev >= USB_MAX_STOR_DEV) ? NULL : usb_stor_get_dev(dev));
  63. }
  64. #endif
  65. #if defined(CONFIG_MMC)
  66. if (strncmp(ifname,"mmc",3)==0) {
  67. extern block_dev_desc_t * mmc_get_dev(int dev);
  68. return((dev >= 1) ? NULL : mmc_get_dev(dev));
  69. }
  70. #endif
  71. #if defined(CONFIG_SYSTEMACE)
  72. if (strcmp(ifname,"ace")==0) {
  73. extern block_dev_desc_t * systemace_get_dev(int dev);
  74. return((dev >= 1) ? NULL : systemace_get_dev(dev));
  75. }
  76. #endif
  77. return NULL;
  78. }
  79. int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  80. {
  81. char *filename = "/";
  82. int dev=0;
  83. int part=1;
  84. char *ep;
  85. block_dev_desc_t *dev_desc=NULL;
  86. int part_length;
  87. if (argc < 3) {
  88. printf ("Usage:\n%s\n", cmdtp->usage);
  89. return 1;
  90. }
  91. dev = (int)simple_strtoul (argv[2], &ep, 16);
  92. dev_desc=get_dev(argv[1],dev);
  93. if (dev_desc == NULL) {
  94. printf ("\n** Block device %s %d not supported\n", argv[1], dev);
  95. return 1;
  96. }
  97. if (*ep) {
  98. if (*ep != ':') {
  99. puts ("\n** Invalid boot device, use `dev[:part]' **\n");
  100. return 1;
  101. }
  102. part = (int)simple_strtoul(++ep, NULL, 16);
  103. }
  104. if (argc == 4) {
  105. filename = argv[3];
  106. }
  107. PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
  108. if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
  109. printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
  110. return 1;
  111. }
  112. if (!reiserfs_mount(part_length)) {
  113. printf ("** Bad Reisefs partition or disk - %s %d:%d **\n", argv[1], dev, part);
  114. return 1;
  115. }
  116. if (reiserfs_ls (filename)) {
  117. printf ("** Error reiserfs_ls() **\n");
  118. return 1;
  119. };
  120. return 0;
  121. }
  122. U_BOOT_CMD(
  123. reiserls, 4, 1, do_reiserls,
  124. "reiserls- list files in a directory (default /)\n",
  125. "<interface> <dev[:part]> [directory]\n"
  126. " - list files from 'dev' on 'interface' in a 'directory'\n"
  127. );
  128. /******************************************************************************
  129. * Reiserfs boot command intepreter. Derived from diskboot
  130. */
  131. int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  132. {
  133. char *filename = NULL;
  134. char *ep;
  135. int dev, part = 0;
  136. ulong addr = 0, part_length, filelen;
  137. disk_partition_t info;
  138. block_dev_desc_t *dev_desc = NULL;
  139. char buf [12];
  140. unsigned long count;
  141. char *addr_str;
  142. switch (argc) {
  143. case 3:
  144. addr_str = getenv("loadaddr");
  145. if (addr_str != NULL) {
  146. addr = simple_strtoul (addr_str, NULL, 16);
  147. } else {
  148. addr = CFG_LOAD_ADDR;
  149. }
  150. filename = getenv ("bootfile");
  151. count = 0;
  152. break;
  153. case 4:
  154. addr = simple_strtoul (argv[3], NULL, 16);
  155. filename = getenv ("bootfile");
  156. count = 0;
  157. break;
  158. case 5:
  159. addr = simple_strtoul (argv[3], NULL, 16);
  160. filename = argv[4];
  161. count = 0;
  162. break;
  163. case 6:
  164. addr = simple_strtoul (argv[3], NULL, 16);
  165. filename = argv[4];
  166. count = simple_strtoul (argv[5], NULL, 16);
  167. break;
  168. default:
  169. printf ("Usage:\n%s\n", cmdtp->usage);
  170. return 1;
  171. }
  172. if (!filename) {
  173. puts ("\n** No boot file defined **\n");
  174. return 1;
  175. }
  176. dev = (int)simple_strtoul (argv[2], &ep, 16);
  177. dev_desc=get_dev(argv[1],dev);
  178. if (dev_desc==NULL) {
  179. printf ("\n** Block device %s %d not supported\n", argv[1], dev);
  180. return 1;
  181. }
  182. if (*ep) {
  183. if (*ep != ':') {
  184. puts ("\n** Invalid boot device, use `dev[:part]' **\n");
  185. return 1;
  186. }
  187. part = (int)simple_strtoul(++ep, NULL, 16);
  188. }
  189. PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part);
  190. if (part != 0) {
  191. if (get_partition_info (dev_desc, part, &info)) {
  192. printf ("** Bad partition %d **\n", part);
  193. return 1;
  194. }
  195. if (strncmp(info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
  196. printf ("\n** Invalid partition type \"%.32s\""
  197. " (expect \"" BOOT_PART_TYPE "\")\n",
  198. info.type);
  199. return 1;
  200. }
  201. PRINTF ("\nLoading from block device %s device %d, partition %d: "
  202. "Name: %.32s Type: %.32s File:%s\n",
  203. argv[1], dev, part, info.name, info.type, filename);
  204. } else {
  205. PRINTF ("\nLoading from block device %s device %d, File:%s\n",
  206. argv[1], dev, filename);
  207. }
  208. if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
  209. printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
  210. return 1;
  211. }
  212. if (!reiserfs_mount(part_length)) {
  213. printf ("** Bad Reisefs partition or disk - %s %d:%d **\n", argv[1], dev, part);
  214. return 1;
  215. }
  216. filelen = reiserfs_open(filename);
  217. if (filelen < 0) {
  218. printf("** File not found %s\n", filename);
  219. return 1;
  220. }
  221. if ((count < filelen) && (count != 0)) {
  222. filelen = count;
  223. }
  224. if (reiserfs_read((char *)addr, filelen) != filelen) {
  225. printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
  226. return 1;
  227. }
  228. /* Loading ok, update default load address */
  229. load_addr = addr;
  230. printf ("\n%ld bytes read\n", filelen);
  231. sprintf(buf, "%lX", filelen);
  232. setenv("filesize", buf);
  233. return filelen;
  234. }
  235. U_BOOT_CMD(
  236. reiserload, 6, 0, do_reiserload,
  237. "reiserload- load binary file from a Reiser filesystem\n",
  238. "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
  239. " - load binary file 'filename' from 'dev' on 'interface'\n"
  240. " to address 'addr' from dos filesystem\n"
  241. );
  242. #endif /* CONFIG_COMMANDS & CFG_CMD_REISER */