part.c 7.9 KB

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