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