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