part.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. void init_part (block_dev_desc_t * dev_desc)
  98. {
  99. #ifdef CONFIG_ISO_PARTITION
  100. if (test_part_iso(dev_desc) == 0) {
  101. dev_desc->part_type = PART_TYPE_ISO;
  102. return;
  103. }
  104. #endif
  105. #ifdef CONFIG_MAC_PARTITION
  106. if (test_part_mac(dev_desc) == 0) {
  107. dev_desc->part_type = PART_TYPE_MAC;
  108. return;
  109. }
  110. #endif
  111. #ifdef CONFIG_DOS_PARTITION
  112. if (test_part_dos(dev_desc) == 0) {
  113. dev_desc->part_type = PART_TYPE_DOS;
  114. return;
  115. }
  116. #endif
  117. }
  118. int get_partition_info (block_dev_desc_t *dev_desc, int part, disk_partition_t *info)
  119. {
  120. switch (dev_desc->part_type) {
  121. #ifdef CONFIG_MAC_PARTITION
  122. case PART_TYPE_MAC:
  123. if (get_partition_info_mac(dev_desc,part,info) == 0) {
  124. PRINTF ("## Valid MAC partition found ##\n");
  125. return (0);
  126. }
  127. break;
  128. #endif
  129. #ifdef CONFIG_DOS_PARTITION
  130. case PART_TYPE_DOS:
  131. if (get_partition_info_dos(dev_desc,part,info) == 0) {
  132. PRINTF ("## Valid DOS partition found ##\n");
  133. return (0);
  134. }
  135. break;
  136. #endif
  137. #ifdef CONFIG_ISO_PARTITION
  138. case PART_TYPE_ISO:
  139. if (get_partition_info_iso(dev_desc,part,info) == 0) {
  140. PRINTF ("## Valid ISO boot partition found ##\n");
  141. return (0);
  142. }
  143. break;
  144. #endif
  145. default:
  146. break;
  147. }
  148. return (-1);
  149. }
  150. static void print_part_header (const char *type, block_dev_desc_t * dev_desc)
  151. {
  152. puts ("\nPartition Map for ");
  153. switch (dev_desc->if_type) {
  154. case IF_TYPE_IDE: puts ("IDE");
  155. break;
  156. case IF_TYPE_SCSI: puts ("SCSI");
  157. break;
  158. case IF_TYPE_ATAPI: puts ("ATAPI");
  159. break;
  160. case IF_TYPE_USB: puts ("USB");
  161. break;
  162. case IF_TYPE_DOC: puts ("DOC");
  163. break;
  164. default: puts ("UNKNOWN");
  165. break;
  166. }
  167. printf (" device %d -- Partition Type: %s\n\n",
  168. dev_desc->dev, type);
  169. }
  170. void print_part (block_dev_desc_t * dev_desc)
  171. {
  172. switch (dev_desc->part_type) {
  173. #ifdef CONFIG_MAC_PARTITION
  174. case PART_TYPE_MAC:
  175. PRINTF ("## Testing for valid MAC partition ##\n");
  176. print_part_header ("MAC", dev_desc);
  177. print_part_mac (dev_desc);
  178. return;
  179. #endif
  180. #ifdef CONFIG_DOS_PARTITION
  181. case PART_TYPE_DOS:
  182. PRINTF ("## Testing for valid DOS partition ##\n");
  183. print_part_header ("DOS", dev_desc);
  184. print_part_dos (dev_desc);
  185. return;
  186. #endif
  187. #ifdef CONFIG_ISO_PARTITION
  188. case PART_TYPE_ISO:
  189. PRINTF ("## Testing for valid ISO Boot partition ##\n");
  190. print_part_header ("ISO", dev_desc);
  191. print_part_iso (dev_desc);
  192. return;
  193. #endif
  194. }
  195. puts ("## Unknown partition table\n");
  196. }
  197. #else /* neither MAC nor DOS nor ISO partition configured */
  198. # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION nor CONFIG_ISO_PARTITION configured!
  199. #endif
  200. #endif /* (CONFIG_COMMANDS & CFG_CMD_IDE) || CONFIG_COMMANDS & CFG_CMD_SCSI) */