cmd_reiser.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. #include <config.h>
  30. #include <command.h>
  31. #include <image.h>
  32. #include <linux/ctype.h>
  33. #include <asm/byteorder.h>
  34. #include <reiserfs.h>
  35. #include <part.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. int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  46. {
  47. char *filename = "/";
  48. int dev, part;
  49. block_dev_desc_t *dev_desc=NULL;
  50. disk_partition_t info;
  51. if (argc < 3)
  52. return CMD_RET_USAGE;
  53. part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
  54. if (part < 0)
  55. return 1;
  56. if (argc == 4) {
  57. filename = argv[3];
  58. }
  59. dev = dev_desc->dev;
  60. PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
  61. reiserfs_set_blk_dev(dev_desc, &info);
  62. if (!reiserfs_mount(info.size)) {
  63. printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
  64. return 1;
  65. }
  66. if (reiserfs_ls (filename)) {
  67. printf ("** Error reiserfs_ls() **\n");
  68. return 1;
  69. };
  70. return 0;
  71. }
  72. U_BOOT_CMD(
  73. reiserls, 4, 1, do_reiserls,
  74. "list files in a directory (default /)",
  75. "<interface> <dev[:part]> [directory]\n"
  76. " - list files from 'dev' on 'interface' in a 'directory'"
  77. );
  78. /******************************************************************************
  79. * Reiserfs boot command intepreter. Derived from diskboot
  80. */
  81. int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  82. {
  83. char *filename = NULL;
  84. int dev, part;
  85. ulong addr = 0, filelen;
  86. disk_partition_t info;
  87. block_dev_desc_t *dev_desc = NULL;
  88. unsigned long count;
  89. char *addr_str;
  90. switch (argc) {
  91. case 3:
  92. addr_str = getenv("loadaddr");
  93. if (addr_str != NULL) {
  94. addr = simple_strtoul (addr_str, NULL, 16);
  95. } else {
  96. addr = CONFIG_SYS_LOAD_ADDR;
  97. }
  98. filename = getenv ("bootfile");
  99. count = 0;
  100. break;
  101. case 4:
  102. addr = simple_strtoul (argv[3], NULL, 16);
  103. filename = getenv ("bootfile");
  104. count = 0;
  105. break;
  106. case 5:
  107. addr = simple_strtoul (argv[3], NULL, 16);
  108. filename = argv[4];
  109. count = 0;
  110. break;
  111. case 6:
  112. addr = simple_strtoul (argv[3], NULL, 16);
  113. filename = argv[4];
  114. count = simple_strtoul (argv[5], NULL, 16);
  115. break;
  116. default:
  117. return CMD_RET_USAGE;
  118. }
  119. if (!filename) {
  120. puts ("\n** No boot file defined **\n");
  121. return 1;
  122. }
  123. part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
  124. if (part < 0)
  125. return 1;
  126. dev = dev_desc->dev;
  127. printf("Loading file \"%s\" from %s device %d%c%c\n",
  128. filename, argv[1], dev,
  129. part ? ':' : ' ', part ? part + '0' : ' ');
  130. reiserfs_set_blk_dev(dev_desc, &info);
  131. if (!reiserfs_mount(info.size)) {
  132. printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
  133. return 1;
  134. }
  135. filelen = reiserfs_open(filename);
  136. if (filelen < 0) {
  137. printf("** File not found %s\n", filename);
  138. return 1;
  139. }
  140. if ((count < filelen) && (count != 0)) {
  141. filelen = count;
  142. }
  143. if (reiserfs_read((char *)addr, filelen) != filelen) {
  144. printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
  145. return 1;
  146. }
  147. /* Loading ok, update default load address */
  148. load_addr = addr;
  149. printf ("\n%ld bytes read\n", filelen);
  150. setenv_hex("filesize", filelen);
  151. return filelen;
  152. }
  153. U_BOOT_CMD(
  154. reiserload, 6, 0, do_reiserload,
  155. "load binary file from a Reiser filesystem",
  156. "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
  157. " - load binary file 'filename' from 'dev' on 'interface'\n"
  158. " to address 'addr' from dos filesystem"
  159. );