part.c 8.0 KB

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