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 74*6c7cac8cSStefan 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) || \ 1823f85ce27Swdenk defined(CONFIG_SYSTEMACE) ) 183affae2bfSwdenk 184affae2bfSwdenk #if defined(CONFIG_MAC_PARTITION) || \ 185affae2bfSwdenk defined(CONFIG_DOS_PARTITION) || \ 186c7de829cSwdenk defined(CONFIG_ISO_PARTITION) || \ 187c7de829cSwdenk defined(CONFIG_AMIGA_PARTITION) 188affae2bfSwdenk 189affae2bfSwdenk void init_part (block_dev_desc_t * dev_desc) 190affae2bfSwdenk { 191affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 192affae2bfSwdenk if (test_part_iso(dev_desc) == 0) { 193affae2bfSwdenk dev_desc->part_type = PART_TYPE_ISO; 194affae2bfSwdenk return; 195affae2bfSwdenk } 196affae2bfSwdenk #endif 197affae2bfSwdenk 198affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 199affae2bfSwdenk if (test_part_mac(dev_desc) == 0) { 200affae2bfSwdenk dev_desc->part_type = PART_TYPE_MAC; 201affae2bfSwdenk return; 202affae2bfSwdenk } 203affae2bfSwdenk #endif 204affae2bfSwdenk 205affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 206affae2bfSwdenk if (test_part_dos(dev_desc) == 0) { 207affae2bfSwdenk dev_desc->part_type = PART_TYPE_DOS; 208affae2bfSwdenk return; 209affae2bfSwdenk } 210affae2bfSwdenk #endif 211c7de829cSwdenk 212c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION 213c7de829cSwdenk if (test_part_amiga(dev_desc) == 0) { 214c7de829cSwdenk dev_desc->part_type = PART_TYPE_AMIGA; 215c7de829cSwdenk return; 216c7de829cSwdenk } 217c7de829cSwdenk #endif 218affae2bfSwdenk } 219affae2bfSwdenk 220affae2bfSwdenk 221affae2bfSwdenk int get_partition_info (block_dev_desc_t *dev_desc, int part, disk_partition_t *info) 222affae2bfSwdenk { 223affae2bfSwdenk switch (dev_desc->part_type) { 224affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 225affae2bfSwdenk case PART_TYPE_MAC: 226affae2bfSwdenk if (get_partition_info_mac(dev_desc,part,info) == 0) { 227affae2bfSwdenk PRINTF ("## Valid MAC partition found ##\n"); 228affae2bfSwdenk return (0); 229affae2bfSwdenk } 230affae2bfSwdenk break; 231affae2bfSwdenk #endif 232affae2bfSwdenk 233affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 234affae2bfSwdenk case PART_TYPE_DOS: 235affae2bfSwdenk if (get_partition_info_dos(dev_desc,part,info) == 0) { 236affae2bfSwdenk PRINTF ("## Valid DOS partition found ##\n"); 237affae2bfSwdenk return (0); 238affae2bfSwdenk } 239affae2bfSwdenk break; 240affae2bfSwdenk #endif 241affae2bfSwdenk 242affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 243affae2bfSwdenk case PART_TYPE_ISO: 244affae2bfSwdenk if (get_partition_info_iso(dev_desc,part,info) == 0) { 245affae2bfSwdenk PRINTF ("## Valid ISO boot partition found ##\n"); 246affae2bfSwdenk return (0); 247affae2bfSwdenk } 248affae2bfSwdenk break; 249affae2bfSwdenk #endif 250c7de829cSwdenk 251c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION 252c7de829cSwdenk case PART_TYPE_AMIGA: 253c7de829cSwdenk if (get_partition_info_amiga(dev_desc, part, info) == 0) 254c7de829cSwdenk { 255c7de829cSwdenk PRINTF ("## Valid Amiga partition found ##\n"); 256c7de829cSwdenk return (0); 257c7de829cSwdenk } 258c7de829cSwdenk break; 259c7de829cSwdenk #endif 260affae2bfSwdenk default: 261affae2bfSwdenk break; 262affae2bfSwdenk } 263affae2bfSwdenk return (-1); 264affae2bfSwdenk } 265affae2bfSwdenk 266affae2bfSwdenk static void print_part_header (const char *type, block_dev_desc_t * dev_desc) 267affae2bfSwdenk { 268affae2bfSwdenk puts ("\nPartition Map for "); 269affae2bfSwdenk switch (dev_desc->if_type) { 270affae2bfSwdenk case IF_TYPE_IDE: puts ("IDE"); 271affae2bfSwdenk break; 272affae2bfSwdenk case IF_TYPE_SCSI: puts ("SCSI"); 273affae2bfSwdenk break; 274affae2bfSwdenk case IF_TYPE_ATAPI: puts ("ATAPI"); 275affae2bfSwdenk break; 276affae2bfSwdenk case IF_TYPE_USB: puts ("USB"); 277affae2bfSwdenk break; 278affae2bfSwdenk case IF_TYPE_DOC: puts ("DOC"); 279affae2bfSwdenk break; 280affae2bfSwdenk default: puts ("UNKNOWN"); 281affae2bfSwdenk break; 282affae2bfSwdenk } 283affae2bfSwdenk printf (" device %d -- Partition Type: %s\n\n", 284affae2bfSwdenk dev_desc->dev, type); 285affae2bfSwdenk } 286affae2bfSwdenk 287affae2bfSwdenk void print_part (block_dev_desc_t * dev_desc) 288affae2bfSwdenk { 289affae2bfSwdenk 290affae2bfSwdenk switch (dev_desc->part_type) { 291affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 292affae2bfSwdenk case PART_TYPE_MAC: 293affae2bfSwdenk PRINTF ("## Testing for valid MAC partition ##\n"); 294affae2bfSwdenk print_part_header ("MAC", dev_desc); 295affae2bfSwdenk print_part_mac (dev_desc); 296affae2bfSwdenk return; 297affae2bfSwdenk #endif 298affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 299affae2bfSwdenk case PART_TYPE_DOS: 300affae2bfSwdenk PRINTF ("## Testing for valid DOS partition ##\n"); 301affae2bfSwdenk print_part_header ("DOS", dev_desc); 302affae2bfSwdenk print_part_dos (dev_desc); 303affae2bfSwdenk return; 304affae2bfSwdenk #endif 305affae2bfSwdenk 306affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 307affae2bfSwdenk case PART_TYPE_ISO: 308affae2bfSwdenk PRINTF ("## Testing for valid ISO Boot partition ##\n"); 309affae2bfSwdenk print_part_header ("ISO", dev_desc); 310affae2bfSwdenk print_part_iso (dev_desc); 311affae2bfSwdenk return; 312affae2bfSwdenk #endif 313c7de829cSwdenk 314c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION 315c7de829cSwdenk case PART_TYPE_AMIGA: 316c7de829cSwdenk PRINTF ("## Testing for a valid Amiga partition ##\n"); 317c7de829cSwdenk print_part_header ("AMIGA", dev_desc); 318c7de829cSwdenk print_part_amiga (dev_desc); 319c7de829cSwdenk return; 320c7de829cSwdenk #endif 321affae2bfSwdenk } 322affae2bfSwdenk puts ("## Unknown partition table\n"); 323affae2bfSwdenk } 324affae2bfSwdenk 325affae2bfSwdenk 326affae2bfSwdenk #else /* neither MAC nor DOS nor ISO partition configured */ 327affae2bfSwdenk # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION nor CONFIG_ISO_PARTITION configured! 328affae2bfSwdenk #endif 329affae2bfSwdenk 330affae2bfSwdenk #endif /* (CONFIG_COMMANDS & CFG_CMD_IDE) || CONFIG_COMMANDS & CFG_CMD_SCSI) */ 331