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_SATA) || \
39 defined(CONFIG_CMD_SCSI) || \
40 defined(CONFIG_CMD_USB) || \
41 defined(CONFIG_MMC) || \
42 defined(CONFIG_SYSTEMACE) )
46 block_dev_desc_t* (*get_dev)(int dev);
49 static const struct block_drvr block_drvr[] = {
50 #if defined(CONFIG_CMD_IDE)
51 { .name = "ide", .get_dev = ide_get_dev, },
53 #if defined(CONFIG_CMD_SATA)
54 {.name = "sata", .get_dev = sata_get_dev, },
56 #if defined(CONFIG_CMD_SCSI)
57 { .name = "scsi", .get_dev = scsi_get_dev, },
59 #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
60 { .name = "usb", .get_dev = usb_stor_get_dev, },
62 #if defined(CONFIG_MMC)
63 { .name = "mmc", .get_dev = mmc_get_dev, },
65 #if defined(CONFIG_SYSTEMACE)
66 { .name = "ace", .get_dev = systemace_get_dev, },
71 DECLARE_GLOBAL_DATA_PTR;
73 block_dev_desc_t *get_dev(char* ifname, int dev)
75 const struct block_drvr *drvr = block_drvr;
76 block_dev_desc_t* (*reloc_get_dev)(int dev);
83 #ifdef CONFIG_NEEDS_MANUAL_RELOC
84 name += gd->reloc_off;
88 reloc_get_dev = drvr->get_dev;
89 #ifdef CONFIG_NEEDS_MANUAL_RELOC
90 name += gd->reloc_off;
91 reloc_get_dev += gd->reloc_off;
93 if (strncmp(ifname, name, strlen(name)) == 0)
94 return reloc_get_dev(dev);
100 block_dev_desc_t *get_dev(char* ifname, int dev)
106 #if (defined(CONFIG_CMD_IDE) || \
107 defined(CONFIG_CMD_SATA) || \
108 defined(CONFIG_CMD_SCSI) || \
109 defined(CONFIG_CMD_USB) || \
110 defined(CONFIG_MMC) || \
111 defined(CONFIG_SYSTEMACE) )
113 /* ------------------------------------------------------------------------- */
115 * reports device info to the user
119 typedef uint64_t lba512_t;
121 typedef lbaint_t lba512_t;
125 * Overflowless variant of (block_count * mul_by / div_by)
126 * when div_by > mul_by
128 static lba512_t lba512_muldiv (lba512_t block_count, lba512_t mul_by, lba512_t div_by)
130 lba512_t bc_quot, bc_rem;
132 /* x * m / d == x / d * m + (x % d) * m / d */
133 bc_quot = block_count / div_by;
134 bc_rem = block_count - div_by * bc_quot;
135 return bc_quot * mul_by + (bc_rem * mul_by) / div_by;
138 void dev_print (block_dev_desc_t *dev_desc)
140 lba512_t lba512; /* number of blocks if 512bytes block size */
142 if (dev_desc->type == DEV_TYPE_UNKNOWN) {
143 puts ("not available\n");
147 switch (dev_desc->if_type) {
149 printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n",
150 dev_desc->target,dev_desc->lun,
158 printf ("Model: %s Firm: %s Ser#: %s\n",
166 printf ("Vendor: %s Rev: %s Prod: %s\n",
172 puts("device type DOC\n");
174 case IF_TYPE_UNKNOWN:
175 puts("device type unknown\n");
178 printf("Unhandled device type: %i\n", dev_desc->if_type);
182 if (dev_desc->removable)
184 switch (dev_desc->type & 0x1F) {
185 case DEV_TYPE_HARDDISK:
191 case DEV_TYPE_OPDISK:
192 puts ("Optical Device");
198 printf ("# %02X #", dev_desc->type & 0x1F);
202 if ((dev_desc->lba * dev_desc->blksz)>0L) {
203 ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;
208 lba512 = (lba * (dev_desc->blksz/512));
209 /* round to 1 digit */
210 mb = lba512_muldiv(lba512, 10, 2048); /* 2048 = (1024 * 1024) / 512 MB */
213 mb_rem = mb - (10 * mb_quot);
217 gb_rem = gb - (10 * gb_quot);
220 printf (" Supports 48-bit addressing\n");
222 #if defined(CONFIG_SYS_64BIT_LBA)
223 printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%Ld x %ld)\n",
229 printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n",
236 puts (" Capacity: not available\n");
241 #if (defined(CONFIG_CMD_IDE) || \
242 defined(CONFIG_CMD_SATA) || \
243 defined(CONFIG_CMD_SCSI) || \
244 defined(CONFIG_CMD_USB) || \
245 defined(CONFIG_MMC) || \
246 defined(CONFIG_SYSTEMACE) )
248 #if defined(CONFIG_MAC_PARTITION) || \
249 defined(CONFIG_DOS_PARTITION) || \
250 defined(CONFIG_ISO_PARTITION) || \
251 defined(CONFIG_AMIGA_PARTITION) || \
252 defined(CONFIG_EFI_PARTITION)
254 void init_part (block_dev_desc_t * dev_desc)
256 #ifdef CONFIG_ISO_PARTITION
257 if (test_part_iso(dev_desc) == 0) {
258 dev_desc->part_type = PART_TYPE_ISO;
263 #ifdef CONFIG_MAC_PARTITION
264 if (test_part_mac(dev_desc) == 0) {
265 dev_desc->part_type = PART_TYPE_MAC;
270 /* must be placed before DOS partition detection */
271 #ifdef CONFIG_EFI_PARTITION
272 if (test_part_efi(dev_desc) == 0) {
273 dev_desc->part_type = PART_TYPE_EFI;
278 #ifdef CONFIG_DOS_PARTITION
279 if (test_part_dos(dev_desc) == 0) {
280 dev_desc->part_type = PART_TYPE_DOS;
285 #ifdef CONFIG_AMIGA_PARTITION
286 if (test_part_amiga(dev_desc) == 0) {
287 dev_desc->part_type = PART_TYPE_AMIGA;
294 int get_partition_info (block_dev_desc_t *dev_desc, int part
295 , disk_partition_t *info)
297 switch (dev_desc->part_type) {
298 #ifdef CONFIG_MAC_PARTITION
300 if (get_partition_info_mac(dev_desc,part,info) == 0) {
301 PRINTF ("## Valid MAC partition found ##\n");
307 #ifdef CONFIG_DOS_PARTITION
309 if (get_partition_info_dos(dev_desc,part,info) == 0) {
310 PRINTF ("## Valid DOS partition found ##\n");
316 #ifdef CONFIG_ISO_PARTITION
318 if (get_partition_info_iso(dev_desc,part,info) == 0) {
319 PRINTF ("## Valid ISO boot partition found ##\n");
325 #ifdef CONFIG_AMIGA_PARTITION
326 case PART_TYPE_AMIGA:
327 if (get_partition_info_amiga(dev_desc, part, info) == 0)
329 PRINTF ("## Valid Amiga partition found ##\n");
335 #ifdef CONFIG_EFI_PARTITION
337 if (get_partition_info_efi(dev_desc,part,info) == 0) {
338 PRINTF ("## Valid EFI partition found ##\n");
349 static void print_part_header (const char *type, block_dev_desc_t * dev_desc)
351 puts ("\nPartition Map for ");
352 switch (dev_desc->if_type) {
378 printf (" device %d -- Partition Type: %s\n\n",
379 dev_desc->dev, type);
382 void print_part (block_dev_desc_t * dev_desc)
385 switch (dev_desc->part_type) {
386 #ifdef CONFIG_MAC_PARTITION
388 PRINTF ("## Testing for valid MAC partition ##\n");
389 print_part_header ("MAC", dev_desc);
390 print_part_mac (dev_desc);
393 #ifdef CONFIG_DOS_PARTITION
395 PRINTF ("## Testing for valid DOS partition ##\n");
396 print_part_header ("DOS", dev_desc);
397 print_part_dos (dev_desc);
401 #ifdef CONFIG_ISO_PARTITION
403 PRINTF ("## Testing for valid ISO Boot partition ##\n");
404 print_part_header ("ISO", dev_desc);
405 print_part_iso (dev_desc);
409 #ifdef CONFIG_AMIGA_PARTITION
410 case PART_TYPE_AMIGA:
411 PRINTF ("## Testing for a valid Amiga partition ##\n");
412 print_part_header ("AMIGA", dev_desc);
413 print_part_amiga (dev_desc);
417 #ifdef CONFIG_EFI_PARTITION
419 PRINTF ("## Testing for valid EFI partition ##\n");
420 print_part_header ("EFI", dev_desc);
421 print_part_efi (dev_desc);
425 puts ("## Unknown partition table\n");
429 #else /* neither MAC nor DOS nor ISO nor AMIGA nor EFI partition configured */
430 # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION
431 # error nor CONFIG_ISO_PARTITION nor CONFIG_AMIGA_PARTITION
432 # error nor CONFIG_EFI_PARTITION configured!