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 37149dded2Swdenk #if ((CONFIG_COMMANDS & CFG_CMD_IDE) || \ 38149dded2Swdenk (CONFIG_COMMANDS & CFG_CMD_SCSI) || \ 39c935d3bdSwdenk (CONFIG_COMMANDS & CFG_CMD_USB) || \ 401968e615Swdenk defined(CONFIG_MMC) || \ 411968e615Swdenk defined(CONFIG_SYSTEMACE) ) 42affae2bfSwdenk 43735dd97bSGrant Likely struct block_drvr { 44735dd97bSGrant Likely char *name; 45735dd97bSGrant Likely block_dev_desc_t* (*get_dev)(int dev); 46735dd97bSGrant Likely }; 47735dd97bSGrant Likely 48735dd97bSGrant Likely static const struct block_drvr block_drvr[] = { 49735dd97bSGrant Likely #if (CONFIG_COMMANDS & CFG_CMD_IDE) 50735dd97bSGrant Likely { .name = "ide", .get_dev = ide_get_dev, }, 51735dd97bSGrant Likely #endif 52735dd97bSGrant Likely #if (CONFIG_COMMANDS & CFG_CMD_SCSI) 53735dd97bSGrant Likely { .name = "scsi", .get_dev = scsi_get_dev, }, 54735dd97bSGrant Likely #endif 55735dd97bSGrant Likely #if ((CONFIG_COMMANDS & CFG_CMD_USB) && defined(CONFIG_USB_STORAGE)) 56735dd97bSGrant Likely { .name = "usb", .get_dev = usb_stor_get_dev, }, 57735dd97bSGrant Likely #endif 58735dd97bSGrant Likely #if defined(CONFIG_MMC) 59735dd97bSGrant Likely { .name = "mmc", .get_dev = mmc_get_dev, }, 60735dd97bSGrant Likely #endif 61735dd97bSGrant Likely #if defined(CONFIG_SYSTEMACE) 62735dd97bSGrant Likely { .name = "ace", .get_dev = systemace_get_dev, }, 63735dd97bSGrant Likely #endif 64735dd97bSGrant Likely { }, 65735dd97bSGrant Likely }; 66735dd97bSGrant Likely 67751bb571SStefan Roese DECLARE_GLOBAL_DATA_PTR; 68751bb571SStefan Roese 69735dd97bSGrant Likely block_dev_desc_t *get_dev(char* ifname, int dev) 70735dd97bSGrant Likely { 71735dd97bSGrant Likely const struct block_drvr *drvr = block_drvr; 72751bb571SStefan Roese block_dev_desc_t* (*reloc_get_dev)(int dev); 73751bb571SStefan Roese 746c7cac8cSStefan Roese while (drvr->name) { 75751bb571SStefan Roese reloc_get_dev = drvr->get_dev + gd->reloc_off; 76751bb571SStefan Roese if (strncmp(ifname, drvr->name, strlen(drvr->name)) == 0) 77751bb571SStefan Roese return reloc_get_dev(dev); 78735dd97bSGrant Likely drvr++; 79735dd97bSGrant Likely } 80735dd97bSGrant Likely return NULL; 81735dd97bSGrant Likely } 82735dd97bSGrant Likely #else 83735dd97bSGrant Likely block_dev_desc_t *get_dev(char* ifname, int dev) 84735dd97bSGrant Likely { 85735dd97bSGrant Likely return NULL; 86735dd97bSGrant Likely } 87735dd97bSGrant Likely #endif 88735dd97bSGrant Likely 89735dd97bSGrant Likely #if ((CONFIG_COMMANDS & CFG_CMD_IDE) || \ 90735dd97bSGrant Likely (CONFIG_COMMANDS & CFG_CMD_SCSI) || \ 91735dd97bSGrant Likely (CONFIG_COMMANDS & CFG_CMD_USB) || \ 92735dd97bSGrant Likely defined(CONFIG_MMC) || \ 93735dd97bSGrant Likely defined(CONFIG_SYSTEMACE) ) 94735dd97bSGrant Likely 95affae2bfSwdenk /* ------------------------------------------------------------------------- */ 96affae2bfSwdenk /* 97affae2bfSwdenk * reports device info to the user 98affae2bfSwdenk */ 99affae2bfSwdenk void dev_print (block_dev_desc_t *dev_desc) 100affae2bfSwdenk { 10142dfe7a1Swdenk #ifdef CONFIG_LBA48 102c40b2956Swdenk uint64_t lba512; /* number of blocks if 512bytes block size */ 103c40b2956Swdenk #else 104c40b2956Swdenk lbaint_t lba512; 105c40b2956Swdenk #endif 106affae2bfSwdenk 107affae2bfSwdenk if (dev_desc->type==DEV_TYPE_UNKNOWN) { 108affae2bfSwdenk puts ("not available\n"); 109affae2bfSwdenk return; 110affae2bfSwdenk } 111affae2bfSwdenk if (dev_desc->if_type==IF_TYPE_SCSI) { 112affae2bfSwdenk printf ("(%d:%d) ", dev_desc->target,dev_desc->lun); 113affae2bfSwdenk } 114affae2bfSwdenk if (dev_desc->if_type==IF_TYPE_IDE) { 115affae2bfSwdenk printf ("Model: %s Firm: %s Ser#: %s\n", 116affae2bfSwdenk dev_desc->vendor, 117affae2bfSwdenk dev_desc->revision, 118affae2bfSwdenk dev_desc->product); 119affae2bfSwdenk } else { 120affae2bfSwdenk printf ("Vendor: %s Prod.: %s Rev: %s\n", 121affae2bfSwdenk dev_desc->vendor, 122affae2bfSwdenk dev_desc->product, 123affae2bfSwdenk dev_desc->revision); 124affae2bfSwdenk } 125affae2bfSwdenk puts (" Type: "); 126affae2bfSwdenk if (dev_desc->removable) 127affae2bfSwdenk puts ("Removable "); 128affae2bfSwdenk switch (dev_desc->type & 0x1F) { 129affae2bfSwdenk case DEV_TYPE_HARDDISK: puts ("Hard Disk"); 130affae2bfSwdenk break; 131affae2bfSwdenk case DEV_TYPE_CDROM: puts ("CD ROM"); 132affae2bfSwdenk break; 133affae2bfSwdenk case DEV_TYPE_OPDISK: puts ("Optical Device"); 134affae2bfSwdenk break; 135affae2bfSwdenk case DEV_TYPE_TAPE: puts ("Tape"); 136affae2bfSwdenk break; 137affae2bfSwdenk default: printf ("# %02X #", dev_desc->type & 0x1F); 138affae2bfSwdenk break; 139affae2bfSwdenk } 140affae2bfSwdenk puts ("\n"); 141affae2bfSwdenk if ((dev_desc->lba * dev_desc->blksz)>0L) { 142affae2bfSwdenk ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem; 143c40b2956Swdenk lbaint_t lba; 1446e592385Swdenk 145c40b2956Swdenk lba = dev_desc->lba; 146affae2bfSwdenk 147c40b2956Swdenk lba512 = (lba * (dev_desc->blksz/512)); 148affae2bfSwdenk mb = (10 * lba512) / 2048; /* 2048 = (1024 * 1024) / 512 MB */ 149affae2bfSwdenk /* round to 1 digit */ 150affae2bfSwdenk mb_quot = mb / 10; 151affae2bfSwdenk mb_rem = mb - (10 * mb_quot); 152affae2bfSwdenk 153affae2bfSwdenk gb = mb / 1024; 154affae2bfSwdenk gb_quot = gb / 10; 155affae2bfSwdenk gb_rem = gb - (10 * gb_quot); 15642dfe7a1Swdenk #ifdef CONFIG_LBA48 1576e592385Swdenk if (dev_desc->lba48) 158c40b2956Swdenk printf (" Supports 48-bit addressing\n"); 159c40b2956Swdenk #endif 16042dfe7a1Swdenk #if defined(CFG_64BIT_LBA) && defined(CFG_64BIT_VSPRINTF) 161c40b2956Swdenk printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%qd x %ld)\n", 162c40b2956Swdenk mb_quot, mb_rem, 163c40b2956Swdenk gb_quot, gb_rem, 164c40b2956Swdenk lba, 165c40b2956Swdenk dev_desc->blksz); 166c40b2956Swdenk #else 167affae2bfSwdenk printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n", 168affae2bfSwdenk mb_quot, mb_rem, 169affae2bfSwdenk gb_quot, gb_rem, 170c40b2956Swdenk (ulong)lba, 171affae2bfSwdenk dev_desc->blksz); 172c40b2956Swdenk #endif 173affae2bfSwdenk } else { 174affae2bfSwdenk puts (" Capacity: not available\n"); 175affae2bfSwdenk } 176affae2bfSwdenk } 177c935d3bdSwdenk #endif /* CFG_CMD_IDE || CFG_CMD_SCSI || CFG_CMD_USB || CONFIG_MMC */ 178affae2bfSwdenk 179c935d3bdSwdenk #if ((CONFIG_COMMANDS & CFG_CMD_IDE) || \ 180c935d3bdSwdenk (CONFIG_COMMANDS & CFG_CMD_SCSI) || \ 1813f85ce27Swdenk (CONFIG_COMMANDS & CFG_CMD_USB) || \ 182*7fac3f69SHaavard Skinnemoen defined(CONFIG_MMC) || \ 1833f85ce27Swdenk defined(CONFIG_SYSTEMACE) ) 184affae2bfSwdenk 185affae2bfSwdenk #if defined(CONFIG_MAC_PARTITION) || \ 186affae2bfSwdenk defined(CONFIG_DOS_PARTITION) || \ 187c7de829cSwdenk defined(CONFIG_ISO_PARTITION) || \ 188c7de829cSwdenk defined(CONFIG_AMIGA_PARTITION) 189affae2bfSwdenk 190affae2bfSwdenk void init_part (block_dev_desc_t * dev_desc) 191affae2bfSwdenk { 192affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 193affae2bfSwdenk if (test_part_iso(dev_desc) == 0) { 194affae2bfSwdenk dev_desc->part_type = PART_TYPE_ISO; 195affae2bfSwdenk return; 196affae2bfSwdenk } 197affae2bfSwdenk #endif 198affae2bfSwdenk 199affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 200affae2bfSwdenk if (test_part_mac(dev_desc) == 0) { 201affae2bfSwdenk dev_desc->part_type = PART_TYPE_MAC; 202affae2bfSwdenk return; 203affae2bfSwdenk } 204affae2bfSwdenk #endif 205affae2bfSwdenk 206affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 207affae2bfSwdenk if (test_part_dos(dev_desc) == 0) { 208affae2bfSwdenk dev_desc->part_type = PART_TYPE_DOS; 209affae2bfSwdenk return; 210affae2bfSwdenk } 211affae2bfSwdenk #endif 212c7de829cSwdenk 213c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION 214c7de829cSwdenk if (test_part_amiga(dev_desc) == 0) { 215c7de829cSwdenk dev_desc->part_type = PART_TYPE_AMIGA; 216c7de829cSwdenk return; 217c7de829cSwdenk } 218c7de829cSwdenk #endif 219affae2bfSwdenk } 220affae2bfSwdenk 221affae2bfSwdenk 222affae2bfSwdenk int get_partition_info (block_dev_desc_t *dev_desc, int part, disk_partition_t *info) 223affae2bfSwdenk { 224affae2bfSwdenk switch (dev_desc->part_type) { 225affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 226affae2bfSwdenk case PART_TYPE_MAC: 227affae2bfSwdenk if (get_partition_info_mac(dev_desc,part,info) == 0) { 228affae2bfSwdenk PRINTF ("## Valid MAC partition found ##\n"); 229affae2bfSwdenk return (0); 230affae2bfSwdenk } 231affae2bfSwdenk break; 232affae2bfSwdenk #endif 233affae2bfSwdenk 234affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 235affae2bfSwdenk case PART_TYPE_DOS: 236affae2bfSwdenk if (get_partition_info_dos(dev_desc,part,info) == 0) { 237affae2bfSwdenk PRINTF ("## Valid DOS partition found ##\n"); 238affae2bfSwdenk return (0); 239affae2bfSwdenk } 240affae2bfSwdenk break; 241affae2bfSwdenk #endif 242affae2bfSwdenk 243affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 244affae2bfSwdenk case PART_TYPE_ISO: 245affae2bfSwdenk if (get_partition_info_iso(dev_desc,part,info) == 0) { 246affae2bfSwdenk PRINTF ("## Valid ISO boot partition found ##\n"); 247affae2bfSwdenk return (0); 248affae2bfSwdenk } 249affae2bfSwdenk break; 250affae2bfSwdenk #endif 251c7de829cSwdenk 252c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION 253c7de829cSwdenk case PART_TYPE_AMIGA: 254c7de829cSwdenk if (get_partition_info_amiga(dev_desc, part, info) == 0) 255c7de829cSwdenk { 256c7de829cSwdenk PRINTF ("## Valid Amiga partition found ##\n"); 257c7de829cSwdenk return (0); 258c7de829cSwdenk } 259c7de829cSwdenk break; 260c7de829cSwdenk #endif 261affae2bfSwdenk default: 262affae2bfSwdenk break; 263affae2bfSwdenk } 264affae2bfSwdenk return (-1); 265affae2bfSwdenk } 266affae2bfSwdenk 267affae2bfSwdenk static void print_part_header (const char *type, block_dev_desc_t * dev_desc) 268affae2bfSwdenk { 269affae2bfSwdenk puts ("\nPartition Map for "); 270affae2bfSwdenk switch (dev_desc->if_type) { 271affae2bfSwdenk case IF_TYPE_IDE: puts ("IDE"); 272affae2bfSwdenk break; 273affae2bfSwdenk case IF_TYPE_SCSI: puts ("SCSI"); 274affae2bfSwdenk break; 275affae2bfSwdenk case IF_TYPE_ATAPI: puts ("ATAPI"); 276affae2bfSwdenk break; 277affae2bfSwdenk case IF_TYPE_USB: puts ("USB"); 278affae2bfSwdenk break; 279affae2bfSwdenk case IF_TYPE_DOC: puts ("DOC"); 280affae2bfSwdenk break; 281affae2bfSwdenk default: puts ("UNKNOWN"); 282affae2bfSwdenk break; 283affae2bfSwdenk } 284affae2bfSwdenk printf (" device %d -- Partition Type: %s\n\n", 285affae2bfSwdenk dev_desc->dev, type); 286affae2bfSwdenk } 287affae2bfSwdenk 288affae2bfSwdenk void print_part (block_dev_desc_t * dev_desc) 289affae2bfSwdenk { 290affae2bfSwdenk 291affae2bfSwdenk switch (dev_desc->part_type) { 292affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 293affae2bfSwdenk case PART_TYPE_MAC: 294affae2bfSwdenk PRINTF ("## Testing for valid MAC partition ##\n"); 295affae2bfSwdenk print_part_header ("MAC", dev_desc); 296affae2bfSwdenk print_part_mac (dev_desc); 297affae2bfSwdenk return; 298affae2bfSwdenk #endif 299affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 300affae2bfSwdenk case PART_TYPE_DOS: 301affae2bfSwdenk PRINTF ("## Testing for valid DOS partition ##\n"); 302affae2bfSwdenk print_part_header ("DOS", dev_desc); 303affae2bfSwdenk print_part_dos (dev_desc); 304affae2bfSwdenk return; 305affae2bfSwdenk #endif 306affae2bfSwdenk 307affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 308affae2bfSwdenk case PART_TYPE_ISO: 309affae2bfSwdenk PRINTF ("## Testing for valid ISO Boot partition ##\n"); 310affae2bfSwdenk print_part_header ("ISO", dev_desc); 311affae2bfSwdenk print_part_iso (dev_desc); 312affae2bfSwdenk return; 313affae2bfSwdenk #endif 314c7de829cSwdenk 315c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION 316c7de829cSwdenk case PART_TYPE_AMIGA: 317c7de829cSwdenk PRINTF ("## Testing for a valid Amiga partition ##\n"); 318c7de829cSwdenk print_part_header ("AMIGA", dev_desc); 319c7de829cSwdenk print_part_amiga (dev_desc); 320c7de829cSwdenk return; 321c7de829cSwdenk #endif 322affae2bfSwdenk } 323affae2bfSwdenk puts ("## Unknown partition table\n"); 324affae2bfSwdenk } 325affae2bfSwdenk 326affae2bfSwdenk 327affae2bfSwdenk #else /* neither MAC nor DOS nor ISO partition configured */ 328affae2bfSwdenk # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION nor CONFIG_ISO_PARTITION configured! 329affae2bfSwdenk #endif 330affae2bfSwdenk 331affae2bfSwdenk #endif /* (CONFIG_COMMANDS & CFG_CMD_IDE) || CONFIG_COMMANDS & CFG_CMD_SCSI) */ 332