1affae2bfSwdenk /* 2affae2bfSwdenk * (C) Copyright 2001 3affae2bfSwdenk * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4affae2bfSwdenk * 5affae2bfSwdenk * See file CREDITS for list of people who contributed to this 6affae2bfSwdenk * project. 7affae2bfSwdenk * 8affae2bfSwdenk * This program is free software; you can redistribute it and/or 9affae2bfSwdenk * modify it under the terms of the GNU General Public License as 10affae2bfSwdenk * published by the Free Software Foundation; either version 2 of 11affae2bfSwdenk * the License, or (at your option) any later version. 12affae2bfSwdenk * 13affae2bfSwdenk * This program is distributed in the hope that it will be useful, 14affae2bfSwdenk * but WITHOUT ANY WARRANTY; without even the implied warranty of 15affae2bfSwdenk * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16affae2bfSwdenk * GNU General Public License for more details. 17affae2bfSwdenk * 18affae2bfSwdenk * You should have received a copy of the GNU General Public License 19affae2bfSwdenk * along with this program; if not, write to the Free Software 20affae2bfSwdenk * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21affae2bfSwdenk * MA 02111-1307 USA 22affae2bfSwdenk */ 23affae2bfSwdenk 24affae2bfSwdenk #include <common.h> 25affae2bfSwdenk #include <command.h> 26affae2bfSwdenk #include <ide.h> 27735dd97bSGrant Likely #include <part.h> 28affae2bfSwdenk 29affae2bfSwdenk #undef PART_DEBUG 30affae2bfSwdenk 31affae2bfSwdenk #ifdef PART_DEBUG 32affae2bfSwdenk #define PRINTF(fmt,args...) printf (fmt ,##args) 33affae2bfSwdenk #else 34affae2bfSwdenk #define PRINTF(fmt,args...) 35affae2bfSwdenk #endif 36affae2bfSwdenk 37cde5c64dSJon Loeliger #if (defined(CONFIG_CMD_IDE) || \ 38c7057b52SDave Liu defined(CONFIG_CMD_SATA) || \ 39cde5c64dSJon Loeliger defined(CONFIG_CMD_SCSI) || \ 40cde5c64dSJon Loeliger defined(CONFIG_CMD_USB) || \ 411968e615Swdenk defined(CONFIG_MMC) || \ 421968e615Swdenk defined(CONFIG_SYSTEMACE) ) 43affae2bfSwdenk 44735dd97bSGrant Likely struct block_drvr { 45735dd97bSGrant Likely char *name; 46735dd97bSGrant Likely block_dev_desc_t* (*get_dev)(int dev); 47735dd97bSGrant Likely }; 48735dd97bSGrant Likely 49735dd97bSGrant Likely static const struct block_drvr block_drvr[] = { 50cde5c64dSJon Loeliger #if defined(CONFIG_CMD_IDE) 51735dd97bSGrant Likely { .name = "ide", .get_dev = ide_get_dev, }, 52735dd97bSGrant Likely #endif 53c7057b52SDave Liu #if defined(CONFIG_CMD_SATA) 54c7057b52SDave Liu {.name = "sata", .get_dev = sata_get_dev, }, 55c7057b52SDave Liu #endif 56cde5c64dSJon Loeliger #if defined(CONFIG_CMD_SCSI) 57735dd97bSGrant Likely { .name = "scsi", .get_dev = scsi_get_dev, }, 58735dd97bSGrant Likely #endif 59cde5c64dSJon Loeliger #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE) 60735dd97bSGrant Likely { .name = "usb", .get_dev = usb_stor_get_dev, }, 61735dd97bSGrant Likely #endif 62735dd97bSGrant Likely #if defined(CONFIG_MMC) 63735dd97bSGrant Likely { .name = "mmc", .get_dev = mmc_get_dev, }, 64735dd97bSGrant Likely #endif 65735dd97bSGrant Likely #if defined(CONFIG_SYSTEMACE) 66735dd97bSGrant Likely { .name = "ace", .get_dev = systemace_get_dev, }, 67735dd97bSGrant Likely #endif 68735dd97bSGrant Likely { }, 69735dd97bSGrant Likely }; 70735dd97bSGrant Likely 71751bb571SStefan Roese DECLARE_GLOBAL_DATA_PTR; 72751bb571SStefan Roese 73735dd97bSGrant Likely block_dev_desc_t *get_dev(char* ifname, int dev) 74735dd97bSGrant Likely { 75735dd97bSGrant Likely const struct block_drvr *drvr = block_drvr; 76751bb571SStefan Roese block_dev_desc_t* (*reloc_get_dev)(int dev); 77751bb571SStefan Roese 786c7cac8cSStefan Roese while (drvr->name) { 79751bb571SStefan Roese reloc_get_dev = drvr->get_dev + gd->reloc_off; 80751bb571SStefan Roese if (strncmp(ifname, drvr->name, strlen(drvr->name)) == 0) 81751bb571SStefan Roese return reloc_get_dev(dev); 82735dd97bSGrant Likely drvr++; 83735dd97bSGrant Likely } 84735dd97bSGrant Likely return NULL; 85735dd97bSGrant Likely } 86735dd97bSGrant Likely #else 87735dd97bSGrant Likely block_dev_desc_t *get_dev(char* ifname, int dev) 88735dd97bSGrant Likely { 89735dd97bSGrant Likely return NULL; 90735dd97bSGrant Likely } 91735dd97bSGrant Likely #endif 92735dd97bSGrant Likely 93cde5c64dSJon Loeliger #if (defined(CONFIG_CMD_IDE) || \ 94c7057b52SDave Liu defined(CONFIG_CMD_SATA) || \ 95cde5c64dSJon Loeliger defined(CONFIG_CMD_SCSI) || \ 96cde5c64dSJon Loeliger defined(CONFIG_CMD_USB) || \ 97735dd97bSGrant Likely defined(CONFIG_MMC) || \ 98735dd97bSGrant Likely defined(CONFIG_SYSTEMACE) ) 99735dd97bSGrant Likely 100affae2bfSwdenk /* ------------------------------------------------------------------------- */ 101affae2bfSwdenk /* 102affae2bfSwdenk * reports device info to the user 103affae2bfSwdenk */ 104affae2bfSwdenk void dev_print (block_dev_desc_t *dev_desc) 105affae2bfSwdenk { 10642dfe7a1Swdenk #ifdef CONFIG_LBA48 107c40b2956Swdenk uint64_t lba512; /* number of blocks if 512bytes block size */ 108c40b2956Swdenk #else 109c40b2956Swdenk lbaint_t lba512; 110c40b2956Swdenk #endif 111affae2bfSwdenk 112*574b3195SDetlev Zundel switch (dev_desc->type) { 113*574b3195SDetlev Zundel case IF_TYPE_SCSI: 114*574b3195SDetlev Zundel printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n", 115*574b3195SDetlev Zundel dev_desc->target,dev_desc->lun, 116affae2bfSwdenk dev_desc->vendor, 117affae2bfSwdenk dev_desc->product, 118affae2bfSwdenk dev_desc->revision); 119*574b3195SDetlev Zundel break; 120*574b3195SDetlev Zundel case IF_TYPE_IDE: 121*574b3195SDetlev Zundel case IF_TYPE_SATA: 122*574b3195SDetlev Zundel printf ("Model: %s Firm: %s Ser#: %s\n", 123*574b3195SDetlev Zundel dev_desc->vendor, 124*574b3195SDetlev Zundel dev_desc->revision, 125*574b3195SDetlev Zundel dev_desc->product); 126*574b3195SDetlev Zundel break; 127*574b3195SDetlev Zundel case DEV_TYPE_UNKNOWN: 128*574b3195SDetlev Zundel default: 129*574b3195SDetlev Zundel puts ("not available\n"); 130*574b3195SDetlev Zundel return; 131affae2bfSwdenk } 132affae2bfSwdenk puts (" Type: "); 133affae2bfSwdenk if (dev_desc->removable) 134affae2bfSwdenk puts ("Removable "); 135affae2bfSwdenk switch (dev_desc->type & 0x1F) { 136affae2bfSwdenk case DEV_TYPE_HARDDISK: puts ("Hard Disk"); 137affae2bfSwdenk break; 138affae2bfSwdenk case DEV_TYPE_CDROM: puts ("CD ROM"); 139affae2bfSwdenk break; 140affae2bfSwdenk case DEV_TYPE_OPDISK: puts ("Optical Device"); 141affae2bfSwdenk break; 142affae2bfSwdenk case DEV_TYPE_TAPE: puts ("Tape"); 143affae2bfSwdenk break; 144affae2bfSwdenk default: printf ("# %02X #", dev_desc->type & 0x1F); 145affae2bfSwdenk break; 146affae2bfSwdenk } 147affae2bfSwdenk puts ("\n"); 148affae2bfSwdenk if ((dev_desc->lba * dev_desc->blksz)>0L) { 149affae2bfSwdenk ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem; 150c40b2956Swdenk lbaint_t lba; 1516e592385Swdenk 152c40b2956Swdenk lba = dev_desc->lba; 153affae2bfSwdenk 154c40b2956Swdenk lba512 = (lba * (dev_desc->blksz/512)); 155affae2bfSwdenk mb = (10 * lba512) / 2048; /* 2048 = (1024 * 1024) / 512 MB */ 156affae2bfSwdenk /* round to 1 digit */ 157affae2bfSwdenk mb_quot = mb / 10; 158affae2bfSwdenk mb_rem = mb - (10 * mb_quot); 159affae2bfSwdenk 160affae2bfSwdenk gb = mb / 1024; 161affae2bfSwdenk gb_quot = gb / 10; 162affae2bfSwdenk gb_rem = gb - (10 * gb_quot); 16342dfe7a1Swdenk #ifdef CONFIG_LBA48 1646e592385Swdenk if (dev_desc->lba48) 165c40b2956Swdenk printf (" Supports 48-bit addressing\n"); 166c40b2956Swdenk #endif 16742dfe7a1Swdenk #if defined(CFG_64BIT_LBA) && defined(CFG_64BIT_VSPRINTF) 168c40b2956Swdenk printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%qd x %ld)\n", 169c40b2956Swdenk mb_quot, mb_rem, 170c40b2956Swdenk gb_quot, gb_rem, 171c40b2956Swdenk lba, 172c40b2956Swdenk dev_desc->blksz); 173c40b2956Swdenk #else 174affae2bfSwdenk printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n", 175affae2bfSwdenk mb_quot, mb_rem, 176affae2bfSwdenk gb_quot, gb_rem, 177c40b2956Swdenk (ulong)lba, 178affae2bfSwdenk dev_desc->blksz); 179c40b2956Swdenk #endif 180affae2bfSwdenk } else { 181affae2bfSwdenk puts (" Capacity: not available\n"); 182affae2bfSwdenk } 183affae2bfSwdenk } 184b3aff0cbSJon Loeliger #endif 185affae2bfSwdenk 186cde5c64dSJon Loeliger #if (defined(CONFIG_CMD_IDE) || \ 187c7057b52SDave Liu defined(CONFIG_CMD_SATA) || \ 188cde5c64dSJon Loeliger defined(CONFIG_CMD_SCSI) || \ 189cde5c64dSJon Loeliger defined(CONFIG_CMD_USB) || \ 1907fac3f69SHaavard Skinnemoen defined(CONFIG_MMC) || \ 1913f85ce27Swdenk defined(CONFIG_SYSTEMACE) ) 192affae2bfSwdenk 193affae2bfSwdenk #if defined(CONFIG_MAC_PARTITION) || \ 194affae2bfSwdenk defined(CONFIG_DOS_PARTITION) || \ 195c7de829cSwdenk defined(CONFIG_ISO_PARTITION) || \ 196c7de829cSwdenk defined(CONFIG_AMIGA_PARTITION) 197affae2bfSwdenk 198affae2bfSwdenk void init_part (block_dev_desc_t * dev_desc) 199affae2bfSwdenk { 200affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 201affae2bfSwdenk if (test_part_iso(dev_desc) == 0) { 202affae2bfSwdenk dev_desc->part_type = PART_TYPE_ISO; 203affae2bfSwdenk return; 204affae2bfSwdenk } 205affae2bfSwdenk #endif 206affae2bfSwdenk 207affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 208affae2bfSwdenk if (test_part_mac(dev_desc) == 0) { 209affae2bfSwdenk dev_desc->part_type = PART_TYPE_MAC; 210affae2bfSwdenk return; 211affae2bfSwdenk } 212affae2bfSwdenk #endif 213affae2bfSwdenk 214affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 215affae2bfSwdenk if (test_part_dos(dev_desc) == 0) { 216affae2bfSwdenk dev_desc->part_type = PART_TYPE_DOS; 217affae2bfSwdenk return; 218affae2bfSwdenk } 219affae2bfSwdenk #endif 220c7de829cSwdenk 221c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION 222c7de829cSwdenk if (test_part_amiga(dev_desc) == 0) { 223c7de829cSwdenk dev_desc->part_type = PART_TYPE_AMIGA; 224c7de829cSwdenk return; 225c7de829cSwdenk } 226c7de829cSwdenk #endif 227affae2bfSwdenk } 228affae2bfSwdenk 229affae2bfSwdenk 2303e3b9569SPeter Pearse int get_partition_info (block_dev_desc_t *dev_desc, int part 2313e3b9569SPeter Pearse , disk_partition_t *info) 232affae2bfSwdenk { 233affae2bfSwdenk switch (dev_desc->part_type) { 234affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 235affae2bfSwdenk case PART_TYPE_MAC: 236affae2bfSwdenk if (get_partition_info_mac(dev_desc,part,info) == 0) { 237affae2bfSwdenk PRINTF ("## Valid MAC partition found ##\n"); 238affae2bfSwdenk return (0); 239affae2bfSwdenk } 240affae2bfSwdenk break; 241affae2bfSwdenk #endif 242affae2bfSwdenk 243affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 244affae2bfSwdenk case PART_TYPE_DOS: 245affae2bfSwdenk if (get_partition_info_dos(dev_desc,part,info) == 0) { 246affae2bfSwdenk PRINTF ("## Valid DOS partition found ##\n"); 247affae2bfSwdenk return (0); 248affae2bfSwdenk } 249affae2bfSwdenk break; 250affae2bfSwdenk #endif 251affae2bfSwdenk 252affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 253affae2bfSwdenk case PART_TYPE_ISO: 254affae2bfSwdenk if (get_partition_info_iso(dev_desc,part,info) == 0) { 255affae2bfSwdenk PRINTF ("## Valid ISO boot partition found ##\n"); 256affae2bfSwdenk return (0); 257affae2bfSwdenk } 258affae2bfSwdenk break; 259affae2bfSwdenk #endif 260c7de829cSwdenk 261c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION 262c7de829cSwdenk case PART_TYPE_AMIGA: 263c7de829cSwdenk if (get_partition_info_amiga(dev_desc, part, info) == 0) 264c7de829cSwdenk { 265c7de829cSwdenk PRINTF ("## Valid Amiga partition found ##\n"); 266c7de829cSwdenk return (0); 267c7de829cSwdenk } 268c7de829cSwdenk break; 269c7de829cSwdenk #endif 270affae2bfSwdenk default: 271affae2bfSwdenk break; 272affae2bfSwdenk } 273affae2bfSwdenk return (-1); 274affae2bfSwdenk } 275affae2bfSwdenk 276affae2bfSwdenk static void print_part_header (const char *type, block_dev_desc_t * dev_desc) 277affae2bfSwdenk { 278affae2bfSwdenk puts ("\nPartition Map for "); 279affae2bfSwdenk switch (dev_desc->if_type) { 280affae2bfSwdenk case IF_TYPE_IDE: puts ("IDE"); 281affae2bfSwdenk break; 282c7057b52SDave Liu case IF_TYPE_SATA: puts ("SATA"); 283c7057b52SDave Liu break; 284affae2bfSwdenk case IF_TYPE_SCSI: puts ("SCSI"); 285affae2bfSwdenk break; 286affae2bfSwdenk case IF_TYPE_ATAPI: puts ("ATAPI"); 287affae2bfSwdenk break; 288affae2bfSwdenk case IF_TYPE_USB: puts ("USB"); 289affae2bfSwdenk break; 290affae2bfSwdenk case IF_TYPE_DOC: puts ("DOC"); 291affae2bfSwdenk break; 292affae2bfSwdenk default: puts ("UNKNOWN"); 293affae2bfSwdenk break; 294affae2bfSwdenk } 295affae2bfSwdenk printf (" device %d -- Partition Type: %s\n\n", 296affae2bfSwdenk dev_desc->dev, type); 297affae2bfSwdenk } 298affae2bfSwdenk 299affae2bfSwdenk void print_part (block_dev_desc_t * dev_desc) 300affae2bfSwdenk { 301affae2bfSwdenk 302affae2bfSwdenk switch (dev_desc->part_type) { 303affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 304affae2bfSwdenk case PART_TYPE_MAC: 305affae2bfSwdenk PRINTF ("## Testing for valid MAC partition ##\n"); 306affae2bfSwdenk print_part_header ("MAC", dev_desc); 307affae2bfSwdenk print_part_mac (dev_desc); 308affae2bfSwdenk return; 309affae2bfSwdenk #endif 310affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 311affae2bfSwdenk case PART_TYPE_DOS: 312affae2bfSwdenk PRINTF ("## Testing for valid DOS partition ##\n"); 313affae2bfSwdenk print_part_header ("DOS", dev_desc); 314affae2bfSwdenk print_part_dos (dev_desc); 315affae2bfSwdenk return; 316affae2bfSwdenk #endif 317affae2bfSwdenk 318affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 319affae2bfSwdenk case PART_TYPE_ISO: 320affae2bfSwdenk PRINTF ("## Testing for valid ISO Boot partition ##\n"); 321affae2bfSwdenk print_part_header ("ISO", dev_desc); 322affae2bfSwdenk print_part_iso (dev_desc); 323affae2bfSwdenk return; 324affae2bfSwdenk #endif 325c7de829cSwdenk 326c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION 327c7de829cSwdenk case PART_TYPE_AMIGA: 328c7de829cSwdenk PRINTF ("## Testing for a valid Amiga partition ##\n"); 329c7de829cSwdenk print_part_header ("AMIGA", dev_desc); 330c7de829cSwdenk print_part_amiga (dev_desc); 331c7de829cSwdenk return; 332c7de829cSwdenk #endif 333affae2bfSwdenk } 334affae2bfSwdenk puts ("## Unknown partition table\n"); 335affae2bfSwdenk } 336affae2bfSwdenk 337affae2bfSwdenk 338affae2bfSwdenk #else /* neither MAC nor DOS nor ISO partition configured */ 3393e3b9569SPeter Pearse # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION 3403e3b9569SPeter Pearse # error nor CONFIG_ISO_PARTITION configured! 341affae2bfSwdenk #endif 342affae2bfSwdenk 343cde5c64dSJon Loeliger #endif 344