part.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. #include <cmd_disk.h>
  27. #undef PART_DEBUG
  28. #ifdef PART_DEBUG
  29. #define PRINTF(fmt,args...) printf (fmt ,##args)
  30. #else
  31. #define PRINTF(fmt,args...)
  32. #endif
  33. #if (CONFIG_COMMANDS & CFG_CMD_IDE) || (CONFIG_COMMANDS & CFG_CMD_SCSI)
  34. /* ------------------------------------------------------------------------- */
  35. /*
  36. * reports device info to the user
  37. */
  38. void dev_print (block_dev_desc_t *dev_desc)
  39. {
  40. ulong lba512; /* number of blocks if 512bytes block size */
  41. if (dev_desc->type==DEV_TYPE_UNKNOWN) {
  42. puts ("not available\n");
  43. return;
  44. }
  45. if (dev_desc->if_type==IF_TYPE_SCSI) {
  46. printf ("(%d:%d) ", dev_desc->target,dev_desc->lun);
  47. }
  48. if (dev_desc->if_type==IF_TYPE_IDE) {
  49. printf ("Model: %s Firm: %s Ser#: %s\n",
  50. dev_desc->vendor,
  51. dev_desc->revision,
  52. dev_desc->product);
  53. } else {
  54. printf ("Vendor: %s Prod.: %s Rev: %s\n",
  55. dev_desc->vendor,
  56. dev_desc->product,
  57. dev_desc->revision);
  58. }
  59. puts (" Type: ");
  60. if (dev_desc->removable)
  61. puts ("Removable ");
  62. switch (dev_desc->type & 0x1F) {
  63. case DEV_TYPE_HARDDISK: puts ("Hard Disk");
  64. break;
  65. case DEV_TYPE_CDROM: puts ("CD ROM");
  66. break;
  67. case DEV_TYPE_OPDISK: puts ("Optical Device");
  68. break;
  69. case DEV_TYPE_TAPE: puts ("Tape");
  70. break;
  71. default: printf ("# %02X #", dev_desc->type & 0x1F);
  72. break;
  73. }
  74. puts ("\n");
  75. if ((dev_desc->lba * dev_desc->blksz)>0L) {
  76. ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;
  77. lba512 = (dev_desc->lba * (dev_desc->blksz/512));
  78. mb = (10 * lba512) / 2048; /* 2048 = (1024 * 1024) / 512 MB */
  79. /* round to 1 digit */
  80. mb_quot = mb / 10;
  81. mb_rem = mb - (10 * mb_quot);
  82. gb = mb / 1024;
  83. gb_quot = gb / 10;
  84. gb_rem = gb - (10 * gb_quot);
  85. printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n",
  86. mb_quot, mb_rem,
  87. gb_quot, gb_rem,
  88. dev_desc->lba,
  89. dev_desc->blksz);
  90. } else {
  91. puts (" Capacity: not available\n");
  92. }
  93. }
  94. #if defined(CONFIG_MAC_PARTITION) || \
  95. defined(CONFIG_DOS_PARTITION) || \
  96. defined(CONFIG_ISO_PARTITION) || \
  97. defined(CONFIG_AMIGA_PARTITION)
  98. void init_part (block_dev_desc_t * dev_desc)
  99. {
  100. #ifdef CONFIG_ISO_PARTITION
  101. if (test_part_iso(dev_desc) == 0) {
  102. dev_desc->part_type = PART_TYPE_ISO;
  103. return;
  104. }
  105. #endif
  106. #ifdef CONFIG_MAC_PARTITION
  107. if (test_part_mac(dev_desc) == 0) {
  108. dev_desc->part_type = PART_TYPE_MAC;
  109. return;
  110. }
  111. #endif
  112. #ifdef CONFIG_DOS_PARTITION
  113. if (test_part_dos(dev_desc) == 0) {
  114. dev_desc->part_type = PART_TYPE_DOS;
  115. return;
  116. }
  117. #endif
  118. #ifdef CONFIG_AMIGA_PARTITION
  119. if (test_part_amiga(dev_desc) == 0) {
  120. dev_desc->part_type = PART_TYPE_AMIGA;
  121. return;
  122. }
  123. #endif
  124. }
  125. int get_partition_info (block_dev_desc_t *dev_desc, int part, disk_partition_t *info)
  126. {
  127. switch (dev_desc->part_type) {
  128. #ifdef CONFIG_MAC_PARTITION
  129. case PART_TYPE_MAC:
  130. if (get_partition_info_mac(dev_desc,part,info) == 0) {
  131. PRINTF ("## Valid MAC partition found ##\n");
  132. return (0);
  133. }
  134. break;
  135. #endif
  136. #ifdef CONFIG_DOS_PARTITION
  137. case PART_TYPE_DOS:
  138. if (get_partition_info_dos(dev_desc,part,info) == 0) {
  139. PRINTF ("## Valid DOS partition found ##\n");
  140. return (0);
  141. }
  142. break;
  143. #endif
  144. #ifdef CONFIG_ISO_PARTITION
  145. case PART_TYPE_ISO:
  146. if (get_partition_info_iso(dev_desc,part,info) == 0) {
  147. PRINTF ("## Valid ISO boot partition found ##\n");
  148. return (0);
  149. }
  150. break;
  151. #endif
  152. #ifdef CONFIG_AMIGA_PARTITION
  153. case PART_TYPE_AMIGA:
  154. if (get_partition_info_amiga(dev_desc, part, info) == 0)
  155. {
  156. PRINTF ("## Valid Amiga partition found ##\n");
  157. return (0);
  158. }
  159. break;
  160. #endif
  161. default:
  162. break;
  163. }
  164. return (-1);
  165. }
  166. static void print_part_header (const char *type, block_dev_desc_t * dev_desc)
  167. {
  168. puts ("\nPartition Map for ");
  169. switch (dev_desc->if_type) {
  170. case IF_TYPE_IDE: puts ("IDE");
  171. break;
  172. case IF_TYPE_SCSI: puts ("SCSI");
  173. break;
  174. case IF_TYPE_ATAPI: puts ("ATAPI");
  175. break;
  176. case IF_TYPE_USB: puts ("USB");
  177. break;
  178. case IF_TYPE_DOC: puts ("DOC");
  179. break;
  180. default: puts ("UNKNOWN");
  181. break;
  182. }
  183. printf (" device %d -- Partition Type: %s\n\n",
  184. dev_desc->dev, type);
  185. }
  186. void print_part (block_dev_desc_t * dev_desc)
  187. {
  188. switch (dev_desc->part_type) {
  189. #ifdef CONFIG_MAC_PARTITION
  190. case PART_TYPE_MAC:
  191. PRINTF ("## Testing for valid MAC partition ##\n");
  192. print_part_header ("MAC", dev_desc);
  193. print_part_mac (dev_desc);
  194. return;
  195. #endif
  196. #ifdef CONFIG_DOS_PARTITION
  197. case PART_TYPE_DOS:
  198. PRINTF ("## Testing for valid DOS partition ##\n");
  199. print_part_header ("DOS", dev_desc);
  200. print_part_dos (dev_desc);
  201. return;
  202. #endif
  203. #ifdef CONFIG_ISO_PARTITION
  204. case PART_TYPE_ISO:
  205. PRINTF ("## Testing for valid ISO Boot partition ##\n");
  206. print_part_header ("ISO", dev_desc);
  207. print_part_iso (dev_desc);
  208. return;
  209. #endif
  210. #ifdef CONFIG_AMIGA_PARTITION
  211. case PART_TYPE_AMIGA:
  212. PRINTF ("## Testing for a valid Amiga partition ##\n");
  213. print_part_header ("AMIGA", dev_desc);
  214. print_part_amiga (dev_desc);
  215. return;
  216. #endif
  217. }
  218. puts ("## Unknown partition table\n");
  219. }
  220. #else /* neither MAC nor DOS nor ISO partition configured */
  221. # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION nor CONFIG_ISO_PARTITION configured!
  222. #endif
  223. #endif /* (CONFIG_COMMANDS & CFG_CMD_IDE) || CONFIG_COMMANDS & CFG_CMD_SCSI) */