part.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * (C) Copyright 2001
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <command.h>
  25. #include <ide.h>
  26. #undef PART_DEBUG
  27. #ifdef PART_DEBUG
  28. #define PRINTF(fmt,args...) printf (fmt ,##args)
  29. #else
  30. #define PRINTF(fmt,args...)
  31. #endif
  32. #if ((CONFIG_COMMANDS & CFG_CMD_IDE) || \
  33. (CONFIG_COMMANDS & CFG_CMD_SCSI) || \
  34. (CONFIG_COMMANDS & CFG_CMD_USB) || \
  35. (CONFIG_MMC) )
  36. /* ------------------------------------------------------------------------- */
  37. /*
  38. * reports device info to the user
  39. */
  40. void dev_print (block_dev_desc_t *dev_desc)
  41. {
  42. ulong lba512; /* number of blocks if 512bytes block size */
  43. if (dev_desc->type==DEV_TYPE_UNKNOWN) {
  44. puts ("not available\n");
  45. return;
  46. }
  47. if (dev_desc->if_type==IF_TYPE_SCSI) {
  48. printf ("(%d:%d) ", dev_desc->target,dev_desc->lun);
  49. }
  50. if (dev_desc->if_type==IF_TYPE_IDE) {
  51. printf ("Model: %s Firm: %s Ser#: %s\n",
  52. dev_desc->vendor,
  53. dev_desc->revision,
  54. dev_desc->product);
  55. } else {
  56. printf ("Vendor: %s Prod.: %s Rev: %s\n",
  57. dev_desc->vendor,
  58. dev_desc->product,
  59. dev_desc->revision);
  60. }
  61. puts (" Type: ");
  62. if (dev_desc->removable)
  63. puts ("Removable ");
  64. switch (dev_desc->type & 0x1F) {
  65. case DEV_TYPE_HARDDISK: puts ("Hard Disk");
  66. break;
  67. case DEV_TYPE_CDROM: puts ("CD ROM");
  68. break;
  69. case DEV_TYPE_OPDISK: puts ("Optical Device");
  70. break;
  71. case DEV_TYPE_TAPE: puts ("Tape");
  72. break;
  73. default: printf ("# %02X #", dev_desc->type & 0x1F);
  74. break;
  75. }
  76. puts ("\n");
  77. if ((dev_desc->lba * dev_desc->blksz)>0L) {
  78. ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;
  79. lba512 = (dev_desc->lba * (dev_desc->blksz/512));
  80. mb = (10 * lba512) / 2048; /* 2048 = (1024 * 1024) / 512 MB */
  81. /* round to 1 digit */
  82. mb_quot = mb / 10;
  83. mb_rem = mb - (10 * mb_quot);
  84. gb = mb / 1024;
  85. gb_quot = gb / 10;
  86. gb_rem = gb - (10 * gb_quot);
  87. printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n",
  88. mb_quot, mb_rem,
  89. gb_quot, gb_rem,
  90. dev_desc->lba,
  91. dev_desc->blksz);
  92. } else {
  93. puts (" Capacity: not available\n");
  94. }
  95. }
  96. #endif /* CFG_CMD_IDE || CFG_CMD_SCSI || CFG_CMD_USB || CONFIG_MMC */
  97. #if ((CONFIG_COMMANDS & CFG_CMD_IDE) || \
  98. (CONFIG_COMMANDS & CFG_CMD_SCSI) || \
  99. (CONFIG_COMMANDS & CFG_CMD_USB) )
  100. #if defined(CONFIG_MAC_PARTITION) || \
  101. defined(CONFIG_DOS_PARTITION) || \
  102. defined(CONFIG_ISO_PARTITION) || \
  103. defined(CONFIG_AMIGA_PARTITION)
  104. void init_part (block_dev_desc_t * dev_desc)
  105. {
  106. #ifdef CONFIG_ISO_PARTITION
  107. if (test_part_iso(dev_desc) == 0) {
  108. dev_desc->part_type = PART_TYPE_ISO;
  109. return;
  110. }
  111. #endif
  112. #ifdef CONFIG_MAC_PARTITION
  113. if (test_part_mac(dev_desc) == 0) {
  114. dev_desc->part_type = PART_TYPE_MAC;
  115. return;
  116. }
  117. #endif
  118. #ifdef CONFIG_DOS_PARTITION
  119. if (test_part_dos(dev_desc) == 0) {
  120. dev_desc->part_type = PART_TYPE_DOS;
  121. return;
  122. }
  123. #endif
  124. #ifdef CONFIG_AMIGA_PARTITION
  125. if (test_part_amiga(dev_desc) == 0) {
  126. dev_desc->part_type = PART_TYPE_AMIGA;
  127. return;
  128. }
  129. #endif
  130. }
  131. int get_partition_info (block_dev_desc_t *dev_desc, int part, disk_partition_t *info)
  132. {
  133. switch (dev_desc->part_type) {
  134. #ifdef CONFIG_MAC_PARTITION
  135. case PART_TYPE_MAC:
  136. if (get_partition_info_mac(dev_desc,part,info) == 0) {
  137. PRINTF ("## Valid MAC partition found ##\n");
  138. return (0);
  139. }
  140. break;
  141. #endif
  142. #ifdef CONFIG_DOS_PARTITION
  143. case PART_TYPE_DOS:
  144. if (get_partition_info_dos(dev_desc,part,info) == 0) {
  145. PRINTF ("## Valid DOS partition found ##\n");
  146. return (0);
  147. }
  148. break;
  149. #endif
  150. #ifdef CONFIG_ISO_PARTITION
  151. case PART_TYPE_ISO:
  152. if (get_partition_info_iso(dev_desc,part,info) == 0) {
  153. PRINTF ("## Valid ISO boot partition found ##\n");
  154. return (0);
  155. }
  156. break;
  157. #endif
  158. #ifdef CONFIG_AMIGA_PARTITION
  159. case PART_TYPE_AMIGA:
  160. if (get_partition_info_amiga(dev_desc, part, info) == 0)
  161. {
  162. PRINTF ("## Valid Amiga partition found ##\n");
  163. return (0);
  164. }
  165. break;
  166. #endif
  167. default:
  168. break;
  169. }
  170. return (-1);
  171. }
  172. static void print_part_header (const char *type, block_dev_desc_t * dev_desc)
  173. {
  174. puts ("\nPartition Map for ");
  175. switch (dev_desc->if_type) {
  176. case IF_TYPE_IDE: puts ("IDE");
  177. break;
  178. case IF_TYPE_SCSI: puts ("SCSI");
  179. break;
  180. case IF_TYPE_ATAPI: puts ("ATAPI");
  181. break;
  182. case IF_TYPE_USB: puts ("USB");
  183. break;
  184. case IF_TYPE_DOC: puts ("DOC");
  185. break;
  186. default: puts ("UNKNOWN");
  187. break;
  188. }
  189. printf (" device %d -- Partition Type: %s\n\n",
  190. dev_desc->dev, type);
  191. }
  192. void print_part (block_dev_desc_t * dev_desc)
  193. {
  194. switch (dev_desc->part_type) {
  195. #ifdef CONFIG_MAC_PARTITION
  196. case PART_TYPE_MAC:
  197. PRINTF ("## Testing for valid MAC partition ##\n");
  198. print_part_header ("MAC", dev_desc);
  199. print_part_mac (dev_desc);
  200. return;
  201. #endif
  202. #ifdef CONFIG_DOS_PARTITION
  203. case PART_TYPE_DOS:
  204. PRINTF ("## Testing for valid DOS partition ##\n");
  205. print_part_header ("DOS", dev_desc);
  206. print_part_dos (dev_desc);
  207. return;
  208. #endif
  209. #ifdef CONFIG_ISO_PARTITION
  210. case PART_TYPE_ISO:
  211. PRINTF ("## Testing for valid ISO Boot partition ##\n");
  212. print_part_header ("ISO", dev_desc);
  213. print_part_iso (dev_desc);
  214. return;
  215. #endif
  216. #ifdef CONFIG_AMIGA_PARTITION
  217. case PART_TYPE_AMIGA:
  218. PRINTF ("## Testing for a valid Amiga partition ##\n");
  219. print_part_header ("AMIGA", dev_desc);
  220. print_part_amiga (dev_desc);
  221. return;
  222. #endif
  223. }
  224. puts ("## Unknown partition table\n");
  225. }
  226. #else /* neither MAC nor DOS nor ISO partition configured */
  227. # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION nor CONFIG_ISO_PARTITION configured!
  228. #endif
  229. #endif /* (CONFIG_COMMANDS & CFG_CMD_IDE) || CONFIG_COMMANDS & CFG_CMD_SCSI) */