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> 27affae2bfSwdenk 28affae2bfSwdenk #undef PART_DEBUG 29affae2bfSwdenk 30affae2bfSwdenk #ifdef PART_DEBUG 31affae2bfSwdenk #define PRINTF(fmt,args...) printf (fmt ,##args) 32affae2bfSwdenk #else 33affae2bfSwdenk #define PRINTF(fmt,args...) 34affae2bfSwdenk #endif 35affae2bfSwdenk 36149dded2Swdenk #if ((CONFIG_COMMANDS & CFG_CMD_IDE) || \ 37149dded2Swdenk (CONFIG_COMMANDS & CFG_CMD_SCSI) || \ 38c935d3bdSwdenk (CONFIG_COMMANDS & CFG_CMD_USB) || \ 39*1968e615Swdenk defined(CONFIG_MMC) || \ 40*1968e615Swdenk defined(CONFIG_SYSTEMACE) ) 41affae2bfSwdenk 42affae2bfSwdenk /* ------------------------------------------------------------------------- */ 43affae2bfSwdenk /* 44affae2bfSwdenk * reports device info to the user 45affae2bfSwdenk */ 46affae2bfSwdenk void dev_print (block_dev_desc_t *dev_desc) 47affae2bfSwdenk { 4842dfe7a1Swdenk #ifdef CONFIG_LBA48 49c40b2956Swdenk uint64_t lba512; /* number of blocks if 512bytes block size */ 50c40b2956Swdenk #else 51c40b2956Swdenk lbaint_t lba512; 52c40b2956Swdenk #endif 53affae2bfSwdenk 54affae2bfSwdenk if (dev_desc->type==DEV_TYPE_UNKNOWN) { 55affae2bfSwdenk puts ("not available\n"); 56affae2bfSwdenk return; 57affae2bfSwdenk } 58affae2bfSwdenk if (dev_desc->if_type==IF_TYPE_SCSI) { 59affae2bfSwdenk printf ("(%d:%d) ", dev_desc->target,dev_desc->lun); 60affae2bfSwdenk } 61affae2bfSwdenk if (dev_desc->if_type==IF_TYPE_IDE) { 62affae2bfSwdenk printf ("Model: %s Firm: %s Ser#: %s\n", 63affae2bfSwdenk dev_desc->vendor, 64affae2bfSwdenk dev_desc->revision, 65affae2bfSwdenk dev_desc->product); 66affae2bfSwdenk } else { 67affae2bfSwdenk printf ("Vendor: %s Prod.: %s Rev: %s\n", 68affae2bfSwdenk dev_desc->vendor, 69affae2bfSwdenk dev_desc->product, 70affae2bfSwdenk dev_desc->revision); 71affae2bfSwdenk } 72affae2bfSwdenk puts (" Type: "); 73affae2bfSwdenk if (dev_desc->removable) 74affae2bfSwdenk puts ("Removable "); 75affae2bfSwdenk switch (dev_desc->type & 0x1F) { 76affae2bfSwdenk case DEV_TYPE_HARDDISK: puts ("Hard Disk"); 77affae2bfSwdenk break; 78affae2bfSwdenk case DEV_TYPE_CDROM: puts ("CD ROM"); 79affae2bfSwdenk break; 80affae2bfSwdenk case DEV_TYPE_OPDISK: puts ("Optical Device"); 81affae2bfSwdenk break; 82affae2bfSwdenk case DEV_TYPE_TAPE: puts ("Tape"); 83affae2bfSwdenk break; 84affae2bfSwdenk default: printf ("# %02X #", dev_desc->type & 0x1F); 85affae2bfSwdenk break; 86affae2bfSwdenk } 87affae2bfSwdenk puts ("\n"); 88affae2bfSwdenk if ((dev_desc->lba * dev_desc->blksz)>0L) { 89affae2bfSwdenk ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem; 90c40b2956Swdenk lbaint_t lba; 916e592385Swdenk 92c40b2956Swdenk lba = dev_desc->lba; 93affae2bfSwdenk 94c40b2956Swdenk lba512 = (lba * (dev_desc->blksz/512)); 95affae2bfSwdenk mb = (10 * lba512) / 2048; /* 2048 = (1024 * 1024) / 512 MB */ 96affae2bfSwdenk /* round to 1 digit */ 97affae2bfSwdenk mb_quot = mb / 10; 98affae2bfSwdenk mb_rem = mb - (10 * mb_quot); 99affae2bfSwdenk 100affae2bfSwdenk gb = mb / 1024; 101affae2bfSwdenk gb_quot = gb / 10; 102affae2bfSwdenk gb_rem = gb - (10 * gb_quot); 10342dfe7a1Swdenk #ifdef CONFIG_LBA48 1046e592385Swdenk if (dev_desc->lba48) 105c40b2956Swdenk printf (" Supports 48-bit addressing\n"); 106c40b2956Swdenk #endif 10742dfe7a1Swdenk #if defined(CFG_64BIT_LBA) && defined(CFG_64BIT_VSPRINTF) 108c40b2956Swdenk printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%qd x %ld)\n", 109c40b2956Swdenk mb_quot, mb_rem, 110c40b2956Swdenk gb_quot, gb_rem, 111c40b2956Swdenk lba, 112c40b2956Swdenk dev_desc->blksz); 113c40b2956Swdenk #else 114affae2bfSwdenk printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n", 115affae2bfSwdenk mb_quot, mb_rem, 116affae2bfSwdenk gb_quot, gb_rem, 117c40b2956Swdenk (ulong)lba, 118affae2bfSwdenk dev_desc->blksz); 119c40b2956Swdenk #endif 120affae2bfSwdenk } else { 121affae2bfSwdenk puts (" Capacity: not available\n"); 122affae2bfSwdenk } 123affae2bfSwdenk } 124c935d3bdSwdenk #endif /* CFG_CMD_IDE || CFG_CMD_SCSI || CFG_CMD_USB || CONFIG_MMC */ 125affae2bfSwdenk 126c935d3bdSwdenk #if ((CONFIG_COMMANDS & CFG_CMD_IDE) || \ 127c935d3bdSwdenk (CONFIG_COMMANDS & CFG_CMD_SCSI) || \ 1283f85ce27Swdenk (CONFIG_COMMANDS & CFG_CMD_USB) || \ 1293f85ce27Swdenk defined(CONFIG_SYSTEMACE) ) 130affae2bfSwdenk 131affae2bfSwdenk #if defined(CONFIG_MAC_PARTITION) || \ 132affae2bfSwdenk defined(CONFIG_DOS_PARTITION) || \ 133c7de829cSwdenk defined(CONFIG_ISO_PARTITION) || \ 134c7de829cSwdenk defined(CONFIG_AMIGA_PARTITION) 135affae2bfSwdenk 136affae2bfSwdenk void init_part (block_dev_desc_t * dev_desc) 137affae2bfSwdenk { 138affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 139affae2bfSwdenk if (test_part_iso(dev_desc) == 0) { 140affae2bfSwdenk dev_desc->part_type = PART_TYPE_ISO; 141affae2bfSwdenk return; 142affae2bfSwdenk } 143affae2bfSwdenk #endif 144affae2bfSwdenk 145affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 146affae2bfSwdenk if (test_part_mac(dev_desc) == 0) { 147affae2bfSwdenk dev_desc->part_type = PART_TYPE_MAC; 148affae2bfSwdenk return; 149affae2bfSwdenk } 150affae2bfSwdenk #endif 151affae2bfSwdenk 152affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 153affae2bfSwdenk if (test_part_dos(dev_desc) == 0) { 154affae2bfSwdenk dev_desc->part_type = PART_TYPE_DOS; 155affae2bfSwdenk return; 156affae2bfSwdenk } 157affae2bfSwdenk #endif 158c7de829cSwdenk 159c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION 160c7de829cSwdenk if (test_part_amiga(dev_desc) == 0) { 161c7de829cSwdenk dev_desc->part_type = PART_TYPE_AMIGA; 162c7de829cSwdenk return; 163c7de829cSwdenk } 164c7de829cSwdenk #endif 165affae2bfSwdenk } 166affae2bfSwdenk 167affae2bfSwdenk 168affae2bfSwdenk int get_partition_info (block_dev_desc_t *dev_desc, int part, disk_partition_t *info) 169affae2bfSwdenk { 170affae2bfSwdenk switch (dev_desc->part_type) { 171affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 172affae2bfSwdenk case PART_TYPE_MAC: 173affae2bfSwdenk if (get_partition_info_mac(dev_desc,part,info) == 0) { 174affae2bfSwdenk PRINTF ("## Valid MAC partition found ##\n"); 175affae2bfSwdenk return (0); 176affae2bfSwdenk } 177affae2bfSwdenk break; 178affae2bfSwdenk #endif 179affae2bfSwdenk 180affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 181affae2bfSwdenk case PART_TYPE_DOS: 182affae2bfSwdenk if (get_partition_info_dos(dev_desc,part,info) == 0) { 183affae2bfSwdenk PRINTF ("## Valid DOS partition found ##\n"); 184affae2bfSwdenk return (0); 185affae2bfSwdenk } 186affae2bfSwdenk break; 187affae2bfSwdenk #endif 188affae2bfSwdenk 189affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 190affae2bfSwdenk case PART_TYPE_ISO: 191affae2bfSwdenk if (get_partition_info_iso(dev_desc,part,info) == 0) { 192affae2bfSwdenk PRINTF ("## Valid ISO boot partition found ##\n"); 193affae2bfSwdenk return (0); 194affae2bfSwdenk } 195affae2bfSwdenk break; 196affae2bfSwdenk #endif 197c7de829cSwdenk 198c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION 199c7de829cSwdenk case PART_TYPE_AMIGA: 200c7de829cSwdenk if (get_partition_info_amiga(dev_desc, part, info) == 0) 201c7de829cSwdenk { 202c7de829cSwdenk PRINTF ("## Valid Amiga partition found ##\n"); 203c7de829cSwdenk return (0); 204c7de829cSwdenk } 205c7de829cSwdenk break; 206c7de829cSwdenk #endif 207affae2bfSwdenk default: 208affae2bfSwdenk break; 209affae2bfSwdenk } 210affae2bfSwdenk return (-1); 211affae2bfSwdenk } 212affae2bfSwdenk 213affae2bfSwdenk static void print_part_header (const char *type, block_dev_desc_t * dev_desc) 214affae2bfSwdenk { 215affae2bfSwdenk puts ("\nPartition Map for "); 216affae2bfSwdenk switch (dev_desc->if_type) { 217affae2bfSwdenk case IF_TYPE_IDE: puts ("IDE"); 218affae2bfSwdenk break; 219affae2bfSwdenk case IF_TYPE_SCSI: puts ("SCSI"); 220affae2bfSwdenk break; 221affae2bfSwdenk case IF_TYPE_ATAPI: puts ("ATAPI"); 222affae2bfSwdenk break; 223affae2bfSwdenk case IF_TYPE_USB: puts ("USB"); 224affae2bfSwdenk break; 225affae2bfSwdenk case IF_TYPE_DOC: puts ("DOC"); 226affae2bfSwdenk break; 227affae2bfSwdenk default: puts ("UNKNOWN"); 228affae2bfSwdenk break; 229affae2bfSwdenk } 230affae2bfSwdenk printf (" device %d -- Partition Type: %s\n\n", 231affae2bfSwdenk dev_desc->dev, type); 232affae2bfSwdenk } 233affae2bfSwdenk 234affae2bfSwdenk void print_part (block_dev_desc_t * dev_desc) 235affae2bfSwdenk { 236affae2bfSwdenk 237affae2bfSwdenk switch (dev_desc->part_type) { 238affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 239affae2bfSwdenk case PART_TYPE_MAC: 240affae2bfSwdenk PRINTF ("## Testing for valid MAC partition ##\n"); 241affae2bfSwdenk print_part_header ("MAC", dev_desc); 242affae2bfSwdenk print_part_mac (dev_desc); 243affae2bfSwdenk return; 244affae2bfSwdenk #endif 245affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 246affae2bfSwdenk case PART_TYPE_DOS: 247affae2bfSwdenk PRINTF ("## Testing for valid DOS partition ##\n"); 248affae2bfSwdenk print_part_header ("DOS", dev_desc); 249affae2bfSwdenk print_part_dos (dev_desc); 250affae2bfSwdenk return; 251affae2bfSwdenk #endif 252affae2bfSwdenk 253affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 254affae2bfSwdenk case PART_TYPE_ISO: 255affae2bfSwdenk PRINTF ("## Testing for valid ISO Boot partition ##\n"); 256affae2bfSwdenk print_part_header ("ISO", dev_desc); 257affae2bfSwdenk print_part_iso (dev_desc); 258affae2bfSwdenk return; 259affae2bfSwdenk #endif 260c7de829cSwdenk 261c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION 262c7de829cSwdenk case PART_TYPE_AMIGA: 263c7de829cSwdenk PRINTF ("## Testing for a valid Amiga partition ##\n"); 264c7de829cSwdenk print_part_header ("AMIGA", dev_desc); 265c7de829cSwdenk print_part_amiga (dev_desc); 266c7de829cSwdenk return; 267c7de829cSwdenk #endif 268affae2bfSwdenk } 269affae2bfSwdenk puts ("## Unknown partition table\n"); 270affae2bfSwdenk } 271affae2bfSwdenk 272affae2bfSwdenk 273affae2bfSwdenk #else /* neither MAC nor DOS nor ISO partition configured */ 274affae2bfSwdenk # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION nor CONFIG_ISO_PARTITION configured! 275affae2bfSwdenk #endif 276affae2bfSwdenk 277affae2bfSwdenk #endif /* (CONFIG_COMMANDS & CFG_CMD_IDE) || CONFIG_COMMANDS & CFG_CMD_SCSI) */ 278