part.c 6.7 KB

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