3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
32 #define PRINTF(fmt,args...) printf (fmt ,##args)
34 #define PRINTF(fmt,args...)
37 #if (defined(CONFIG_CMD_IDE) || \
38 defined(CONFIG_CMD_MG_DISK) || \
39 defined(CONFIG_CMD_SATA) || \
40 defined(CONFIG_CMD_SCSI) || \
41 defined(CONFIG_CMD_USB) || \
42 defined(CONFIG_MMC) || \
43 defined(CONFIG_SYSTEMACE) )
47 block_dev_desc_t* (*get_dev)(int dev);
50 static const struct block_drvr block_drvr[] = {
51 #if defined(CONFIG_CMD_IDE)
52 { .name = "ide", .get_dev = ide_get_dev, },
54 #if defined(CONFIG_CMD_SATA)
55 {.name = "sata", .get_dev = sata_get_dev, },
57 #if defined(CONFIG_CMD_SCSI)
58 { .name = "scsi", .get_dev = scsi_get_dev, },
60 #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
61 { .name = "usb", .get_dev = usb_stor_get_dev, },
63 #if defined(CONFIG_MMC)
64 { .name = "mmc", .get_dev = mmc_get_dev, },
66 #if defined(CONFIG_SYSTEMACE)
67 { .name = "ace", .get_dev = systemace_get_dev, },
69 #if defined(CONFIG_CMD_MG_DISK)
70 { .name = "mgd", .get_dev = mg_disk_get_dev, },
75 DECLARE_GLOBAL_DATA_PTR;
77 block_dev_desc_t *get_dev(char* ifname, int dev)
79 const struct block_drvr *drvr = block_drvr;
80 block_dev_desc_t* (*reloc_get_dev)(int dev);
87 #ifdef CONFIG_NEEDS_MANUAL_RELOC
88 name += gd->reloc_off;
92 reloc_get_dev = drvr->get_dev;
93 #ifdef CONFIG_NEEDS_MANUAL_RELOC
94 name += gd->reloc_off;
95 reloc_get_dev += gd->reloc_off;
97 if (strncmp(ifname, name, strlen(name)) == 0)
98 return reloc_get_dev(dev);
104 block_dev_desc_t *get_dev(char* ifname, int dev)
110 #if (defined(CONFIG_CMD_IDE) || \
111 defined(CONFIG_CMD_MG_DISK) || \
112 defined(CONFIG_CMD_SATA) || \
113 defined(CONFIG_CMD_SCSI) || \
114 defined(CONFIG_CMD_USB) || \
115 defined(CONFIG_MMC) || \
116 defined(CONFIG_SYSTEMACE) )
118 /* ------------------------------------------------------------------------- */
120 * reports device info to the user
124 typedef uint64_t lba512_t;
126 typedef lbaint_t lba512_t;
130 * Overflowless variant of (block_count * mul_by / div_by)
131 * when div_by > mul_by
133 static lba512_t lba512_muldiv (lba512_t block_count, lba512_t mul_by, lba512_t div_by)
135 lba512_t bc_quot, bc_rem;
137 /* x * m / d == x / d * m + (x % d) * m / d */
138 bc_quot = block_count / div_by;
139 bc_rem = block_count - div_by * bc_quot;
140 return bc_quot * mul_by + (bc_rem * mul_by) / div_by;
143 void dev_print (block_dev_desc_t *dev_desc)
145 lba512_t lba512; /* number of blocks if 512bytes block size */
147 if (dev_desc->type == DEV_TYPE_UNKNOWN) {
148 puts ("not available\n");
152 switch (dev_desc->if_type) {
154 printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n",
155 dev_desc->target,dev_desc->lun,
163 printf ("Model: %s Firm: %s Ser#: %s\n",
171 printf ("Vendor: %s Rev: %s Prod: %s\n",
177 puts("device type DOC\n");
179 case IF_TYPE_UNKNOWN:
180 puts("device type unknown\n");
183 printf("Unhandled device type: %i\n", dev_desc->if_type);
187 if (dev_desc->removable)
189 switch (dev_desc->type & 0x1F) {
190 case DEV_TYPE_HARDDISK:
196 case DEV_TYPE_OPDISK:
197 puts ("Optical Device");
203 printf ("# %02X #", dev_desc->type & 0x1F);
207 if ((dev_desc->lba * dev_desc->blksz)>0L) {
208 ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;
213 lba512 = (lba * (dev_desc->blksz/512));
214 /* round to 1 digit */
215 mb = lba512_muldiv(lba512, 10, 2048); /* 2048 = (1024 * 1024) / 512 MB */
218 mb_rem = mb - (10 * mb_quot);
222 gb_rem = gb - (10 * gb_quot);
225 printf (" Supports 48-bit addressing\n");
227 #if defined(CONFIG_SYS_64BIT_LBA)
228 printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%Ld x %ld)\n",
234 printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n",
241 puts (" Capacity: not available\n");
246 #if (defined(CONFIG_CMD_IDE) || \
247 defined(CONFIG_CMD_MG_DISK) || \
248 defined(CONFIG_CMD_SATA) || \
249 defined(CONFIG_CMD_SCSI) || \
250 defined(CONFIG_CMD_USB) || \
251 defined(CONFIG_MMC) || \
252 defined(CONFIG_SYSTEMACE) )
254 #if defined(CONFIG_MAC_PARTITION) || \
255 defined(CONFIG_DOS_PARTITION) || \
256 defined(CONFIG_ISO_PARTITION) || \
257 defined(CONFIG_AMIGA_PARTITION) || \
258 defined(CONFIG_EFI_PARTITION)
260 void init_part (block_dev_desc_t * dev_desc)
262 #ifdef CONFIG_ISO_PARTITION
263 if (test_part_iso(dev_desc) == 0) {
264 dev_desc->part_type = PART_TYPE_ISO;
269 #ifdef CONFIG_MAC_PARTITION
270 if (test_part_mac(dev_desc) == 0) {
271 dev_desc->part_type = PART_TYPE_MAC;
276 /* must be placed before DOS partition detection */
277 #ifdef CONFIG_EFI_PARTITION
278 if (test_part_efi(dev_desc) == 0) {
279 dev_desc->part_type = PART_TYPE_EFI;
284 #ifdef CONFIG_DOS_PARTITION
285 if (test_part_dos(dev_desc) == 0) {
286 dev_desc->part_type = PART_TYPE_DOS;
291 #ifdef CONFIG_AMIGA_PARTITION
292 if (test_part_amiga(dev_desc) == 0) {
293 dev_desc->part_type = PART_TYPE_AMIGA;
300 int get_partition_info (block_dev_desc_t *dev_desc, int part
301 , disk_partition_t *info)
303 switch (dev_desc->part_type) {
304 #ifdef CONFIG_MAC_PARTITION
306 if (get_partition_info_mac(dev_desc,part,info) == 0) {
307 PRINTF ("## Valid MAC partition found ##\n");
313 #ifdef CONFIG_DOS_PARTITION
315 if (get_partition_info_dos(dev_desc,part,info) == 0) {
316 PRINTF ("## Valid DOS partition found ##\n");
322 #ifdef CONFIG_ISO_PARTITION
324 if (get_partition_info_iso(dev_desc,part,info) == 0) {
325 PRINTF ("## Valid ISO boot partition found ##\n");
331 #ifdef CONFIG_AMIGA_PARTITION
332 case PART_TYPE_AMIGA:
333 if (get_partition_info_amiga(dev_desc, part, info) == 0)
335 PRINTF ("## Valid Amiga partition found ##\n");
341 #ifdef CONFIG_EFI_PARTITION
343 if (get_partition_info_efi(dev_desc,part,info) == 0) {
344 PRINTF ("## Valid EFI partition found ##\n");
355 static void print_part_header (const char *type, block_dev_desc_t * dev_desc)
357 puts ("\nPartition Map for ");
358 switch (dev_desc->if_type) {
384 printf (" device %d -- Partition Type: %s\n\n",
385 dev_desc->dev, type);
388 void print_part (block_dev_desc_t * dev_desc)
391 switch (dev_desc->part_type) {
392 #ifdef CONFIG_MAC_PARTITION
394 PRINTF ("## Testing for valid MAC partition ##\n");
395 print_part_header ("MAC", dev_desc);
396 print_part_mac (dev_desc);
399 #ifdef CONFIG_DOS_PARTITION
401 PRINTF ("## Testing for valid DOS partition ##\n");
402 print_part_header ("DOS", dev_desc);
403 print_part_dos (dev_desc);
407 #ifdef CONFIG_ISO_PARTITION
409 PRINTF ("## Testing for valid ISO Boot partition ##\n");
410 print_part_header ("ISO", dev_desc);
411 print_part_iso (dev_desc);
415 #ifdef CONFIG_AMIGA_PARTITION
416 case PART_TYPE_AMIGA:
417 PRINTF ("## Testing for a valid Amiga partition ##\n");
418 print_part_header ("AMIGA", dev_desc);
419 print_part_amiga (dev_desc);
423 #ifdef CONFIG_EFI_PARTITION
425 PRINTF ("## Testing for valid EFI partition ##\n");
426 print_part_header ("EFI", dev_desc);
427 print_part_efi (dev_desc);
431 puts ("## Unknown partition table\n");
435 #else /* neither MAC nor DOS nor ISO nor AMIGA nor EFI partition configured */
436 # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION
437 # error nor CONFIG_ISO_PARTITION nor CONFIG_AMIGA_PARTITION
438 # error nor CONFIG_EFI_PARTITION configured!