part.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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_SYSTEMACE) )
  167. #if defined(CONFIG_MAC_PARTITION) || \
  168. defined(CONFIG_DOS_PARTITION) || \
  169. defined(CONFIG_ISO_PARTITION) || \
  170. defined(CONFIG_AMIGA_PARTITION)
  171. void init_part (block_dev_desc_t * dev_desc)
  172. {
  173. #ifdef CONFIG_ISO_PARTITION
  174. if (test_part_iso(dev_desc) == 0) {
  175. dev_desc->part_type = PART_TYPE_ISO;
  176. return;
  177. }
  178. #endif
  179. #ifdef CONFIG_MAC_PARTITION
  180. if (test_part_mac(dev_desc) == 0) {
  181. dev_desc->part_type = PART_TYPE_MAC;
  182. return;
  183. }
  184. #endif
  185. #ifdef CONFIG_DOS_PARTITION
  186. if (test_part_dos(dev_desc) == 0) {
  187. dev_desc->part_type = PART_TYPE_DOS;
  188. return;
  189. }
  190. #endif
  191. #ifdef CONFIG_AMIGA_PARTITION
  192. if (test_part_amiga(dev_desc) == 0) {
  193. dev_desc->part_type = PART_TYPE_AMIGA;
  194. return;
  195. }
  196. #endif
  197. }
  198. int get_partition_info (block_dev_desc_t *dev_desc, int part, disk_partition_t *info)
  199. {
  200. switch (dev_desc->part_type) {
  201. #ifdef CONFIG_MAC_PARTITION
  202. case PART_TYPE_MAC:
  203. if (get_partition_info_mac(dev_desc,part,info) == 0) {
  204. PRINTF ("## Valid MAC partition found ##\n");
  205. return (0);
  206. }
  207. break;
  208. #endif
  209. #ifdef CONFIG_DOS_PARTITION
  210. case PART_TYPE_DOS:
  211. if (get_partition_info_dos(dev_desc,part,info) == 0) {
  212. PRINTF ("## Valid DOS partition found ##\n");
  213. return (0);
  214. }
  215. break;
  216. #endif
  217. #ifdef CONFIG_ISO_PARTITION
  218. case PART_TYPE_ISO:
  219. if (get_partition_info_iso(dev_desc,part,info) == 0) {
  220. PRINTF ("## Valid ISO boot partition found ##\n");
  221. return (0);
  222. }
  223. break;
  224. #endif
  225. #ifdef CONFIG_AMIGA_PARTITION
  226. case PART_TYPE_AMIGA:
  227. if (get_partition_info_amiga(dev_desc, part, info) == 0)
  228. {
  229. PRINTF ("## Valid Amiga partition found ##\n");
  230. return (0);
  231. }
  232. break;
  233. #endif
  234. default:
  235. break;
  236. }
  237. return (-1);
  238. }
  239. static void print_part_header (const char *type, block_dev_desc_t * dev_desc)
  240. {
  241. puts ("\nPartition Map for ");
  242. switch (dev_desc->if_type) {
  243. case IF_TYPE_IDE: puts ("IDE");
  244. break;
  245. case IF_TYPE_SCSI: puts ("SCSI");
  246. break;
  247. case IF_TYPE_ATAPI: puts ("ATAPI");
  248. break;
  249. case IF_TYPE_USB: puts ("USB");
  250. break;
  251. case IF_TYPE_DOC: puts ("DOC");
  252. break;
  253. default: puts ("UNKNOWN");
  254. break;
  255. }
  256. printf (" device %d -- Partition Type: %s\n\n",
  257. dev_desc->dev, type);
  258. }
  259. void print_part (block_dev_desc_t * dev_desc)
  260. {
  261. switch (dev_desc->part_type) {
  262. #ifdef CONFIG_MAC_PARTITION
  263. case PART_TYPE_MAC:
  264. PRINTF ("## Testing for valid MAC partition ##\n");
  265. print_part_header ("MAC", dev_desc);
  266. print_part_mac (dev_desc);
  267. return;
  268. #endif
  269. #ifdef CONFIG_DOS_PARTITION
  270. case PART_TYPE_DOS:
  271. PRINTF ("## Testing for valid DOS partition ##\n");
  272. print_part_header ("DOS", dev_desc);
  273. print_part_dos (dev_desc);
  274. return;
  275. #endif
  276. #ifdef CONFIG_ISO_PARTITION
  277. case PART_TYPE_ISO:
  278. PRINTF ("## Testing for valid ISO Boot partition ##\n");
  279. print_part_header ("ISO", dev_desc);
  280. print_part_iso (dev_desc);
  281. return;
  282. #endif
  283. #ifdef CONFIG_AMIGA_PARTITION
  284. case PART_TYPE_AMIGA:
  285. PRINTF ("## Testing for a valid Amiga partition ##\n");
  286. print_part_header ("AMIGA", dev_desc);
  287. print_part_amiga (dev_desc);
  288. return;
  289. #endif
  290. }
  291. puts ("## Unknown partition table\n");
  292. }
  293. #else /* neither MAC nor DOS nor ISO partition configured */
  294. # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION nor CONFIG_ISO_PARTITION configured!
  295. #endif
  296. #endif /* (CONFIG_COMMANDS & CFG_CMD_IDE) || CONFIG_COMMANDS & CFG_CMD_SCSI) */