1*affae2bfSwdenk /* 2*affae2bfSwdenk * (C) Copyright 2001 3*affae2bfSwdenk * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4*affae2bfSwdenk * 5*affae2bfSwdenk * See file CREDITS for list of people who contributed to this 6*affae2bfSwdenk * project. 7*affae2bfSwdenk * 8*affae2bfSwdenk * This program is free software; you can redistribute it and/or 9*affae2bfSwdenk * modify it under the terms of the GNU General Public License as 10*affae2bfSwdenk * published by the Free Software Foundation; either version 2 of 11*affae2bfSwdenk * the License, or (at your option) any later version. 12*affae2bfSwdenk * 13*affae2bfSwdenk * This program is distributed in the hope that it will be useful, 14*affae2bfSwdenk * but WITHOUT ANY WARRANTY; without even the implied warranty of 15*affae2bfSwdenk * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*affae2bfSwdenk * GNU General Public License for more details. 17*affae2bfSwdenk * 18*affae2bfSwdenk * You should have received a copy of the GNU General Public License 19*affae2bfSwdenk * along with this program; if not, write to the Free Software 20*affae2bfSwdenk * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21*affae2bfSwdenk * MA 02111-1307 USA 22*affae2bfSwdenk */ 23*affae2bfSwdenk 24*affae2bfSwdenk #include <common.h> 25*affae2bfSwdenk #include <command.h> 26*affae2bfSwdenk #include <ide.h> 27*affae2bfSwdenk #include <cmd_disk.h> 28*affae2bfSwdenk 29*affae2bfSwdenk #undef PART_DEBUG 30*affae2bfSwdenk 31*affae2bfSwdenk #ifdef PART_DEBUG 32*affae2bfSwdenk #define PRINTF(fmt,args...) printf (fmt ,##args) 33*affae2bfSwdenk #else 34*affae2bfSwdenk #define PRINTF(fmt,args...) 35*affae2bfSwdenk #endif 36*affae2bfSwdenk 37*affae2bfSwdenk #if (CONFIG_COMMANDS & CFG_CMD_IDE) || (CONFIG_COMMANDS & CFG_CMD_SCSI) 38*affae2bfSwdenk 39*affae2bfSwdenk /* ------------------------------------------------------------------------- */ 40*affae2bfSwdenk /* 41*affae2bfSwdenk * reports device info to the user 42*affae2bfSwdenk */ 43*affae2bfSwdenk void dev_print (block_dev_desc_t *dev_desc) 44*affae2bfSwdenk { 45*affae2bfSwdenk ulong lba512; /* number of blocks if 512bytes block size */ 46*affae2bfSwdenk 47*affae2bfSwdenk if (dev_desc->type==DEV_TYPE_UNKNOWN) { 48*affae2bfSwdenk puts ("not available\n"); 49*affae2bfSwdenk return; 50*affae2bfSwdenk } 51*affae2bfSwdenk if (dev_desc->if_type==IF_TYPE_SCSI) { 52*affae2bfSwdenk printf ("(%d:%d) ", dev_desc->target,dev_desc->lun); 53*affae2bfSwdenk } 54*affae2bfSwdenk if (dev_desc->if_type==IF_TYPE_IDE) { 55*affae2bfSwdenk printf ("Model: %s Firm: %s Ser#: %s\n", 56*affae2bfSwdenk dev_desc->vendor, 57*affae2bfSwdenk dev_desc->revision, 58*affae2bfSwdenk dev_desc->product); 59*affae2bfSwdenk } else { 60*affae2bfSwdenk printf ("Vendor: %s Prod.: %s Rev: %s\n", 61*affae2bfSwdenk dev_desc->vendor, 62*affae2bfSwdenk dev_desc->product, 63*affae2bfSwdenk dev_desc->revision); 64*affae2bfSwdenk } 65*affae2bfSwdenk puts (" Type: "); 66*affae2bfSwdenk if (dev_desc->removable) 67*affae2bfSwdenk puts ("Removable "); 68*affae2bfSwdenk switch (dev_desc->type & 0x1F) { 69*affae2bfSwdenk case DEV_TYPE_HARDDISK: puts ("Hard Disk"); 70*affae2bfSwdenk break; 71*affae2bfSwdenk case DEV_TYPE_CDROM: puts ("CD ROM"); 72*affae2bfSwdenk break; 73*affae2bfSwdenk case DEV_TYPE_OPDISK: puts ("Optical Device"); 74*affae2bfSwdenk break; 75*affae2bfSwdenk case DEV_TYPE_TAPE: puts ("Tape"); 76*affae2bfSwdenk break; 77*affae2bfSwdenk default: printf ("# %02X #", dev_desc->type & 0x1F); 78*affae2bfSwdenk break; 79*affae2bfSwdenk } 80*affae2bfSwdenk puts ("\n"); 81*affae2bfSwdenk if ((dev_desc->lba * dev_desc->blksz)>0L) { 82*affae2bfSwdenk ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem; 83*affae2bfSwdenk 84*affae2bfSwdenk lba512 = (dev_desc->lba * (dev_desc->blksz/512)); 85*affae2bfSwdenk 86*affae2bfSwdenk mb = (10 * lba512) / 2048; /* 2048 = (1024 * 1024) / 512 MB */ 87*affae2bfSwdenk /* round to 1 digit */ 88*affae2bfSwdenk mb_quot = mb / 10; 89*affae2bfSwdenk mb_rem = mb - (10 * mb_quot); 90*affae2bfSwdenk 91*affae2bfSwdenk gb = mb / 1024; 92*affae2bfSwdenk gb_quot = gb / 10; 93*affae2bfSwdenk gb_rem = gb - (10 * gb_quot); 94*affae2bfSwdenk 95*affae2bfSwdenk printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n", 96*affae2bfSwdenk mb_quot, mb_rem, 97*affae2bfSwdenk gb_quot, gb_rem, 98*affae2bfSwdenk dev_desc->lba, 99*affae2bfSwdenk dev_desc->blksz); 100*affae2bfSwdenk } else { 101*affae2bfSwdenk puts (" Capacity: not available\n"); 102*affae2bfSwdenk } 103*affae2bfSwdenk } 104*affae2bfSwdenk 105*affae2bfSwdenk 106*affae2bfSwdenk 107*affae2bfSwdenk #if defined(CONFIG_MAC_PARTITION) || \ 108*affae2bfSwdenk defined(CONFIG_DOS_PARTITION) || \ 109*affae2bfSwdenk defined(CONFIG_ISO_PARTITION) 110*affae2bfSwdenk 111*affae2bfSwdenk void init_part (block_dev_desc_t * dev_desc) 112*affae2bfSwdenk { 113*affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 114*affae2bfSwdenk if (test_part_iso(dev_desc) == 0) { 115*affae2bfSwdenk dev_desc->part_type = PART_TYPE_ISO; 116*affae2bfSwdenk return; 117*affae2bfSwdenk } 118*affae2bfSwdenk #endif 119*affae2bfSwdenk 120*affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 121*affae2bfSwdenk if (test_part_mac(dev_desc) == 0) { 122*affae2bfSwdenk dev_desc->part_type = PART_TYPE_MAC; 123*affae2bfSwdenk return; 124*affae2bfSwdenk } 125*affae2bfSwdenk #endif 126*affae2bfSwdenk 127*affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 128*affae2bfSwdenk if (test_part_dos(dev_desc) == 0) { 129*affae2bfSwdenk dev_desc->part_type = PART_TYPE_DOS; 130*affae2bfSwdenk return; 131*affae2bfSwdenk } 132*affae2bfSwdenk #endif 133*affae2bfSwdenk } 134*affae2bfSwdenk 135*affae2bfSwdenk 136*affae2bfSwdenk int get_partition_info (block_dev_desc_t *dev_desc, int part, disk_partition_t *info) 137*affae2bfSwdenk { 138*affae2bfSwdenk switch (dev_desc->part_type) { 139*affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 140*affae2bfSwdenk case PART_TYPE_MAC: 141*affae2bfSwdenk if (get_partition_info_mac(dev_desc,part,info) == 0) { 142*affae2bfSwdenk PRINTF ("## Valid MAC partition found ##\n"); 143*affae2bfSwdenk return (0); 144*affae2bfSwdenk } 145*affae2bfSwdenk break; 146*affae2bfSwdenk #endif 147*affae2bfSwdenk 148*affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 149*affae2bfSwdenk case PART_TYPE_DOS: 150*affae2bfSwdenk if (get_partition_info_dos(dev_desc,part,info) == 0) { 151*affae2bfSwdenk PRINTF ("## Valid DOS partition found ##\n"); 152*affae2bfSwdenk return (0); 153*affae2bfSwdenk } 154*affae2bfSwdenk break; 155*affae2bfSwdenk #endif 156*affae2bfSwdenk 157*affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 158*affae2bfSwdenk case PART_TYPE_ISO: 159*affae2bfSwdenk if (get_partition_info_iso(dev_desc,part,info) == 0) { 160*affae2bfSwdenk PRINTF ("## Valid ISO boot partition found ##\n"); 161*affae2bfSwdenk return (0); 162*affae2bfSwdenk } 163*affae2bfSwdenk break; 164*affae2bfSwdenk #endif 165*affae2bfSwdenk default: 166*affae2bfSwdenk break; 167*affae2bfSwdenk } 168*affae2bfSwdenk return (-1); 169*affae2bfSwdenk } 170*affae2bfSwdenk 171*affae2bfSwdenk static void print_part_header (const char *type, block_dev_desc_t * dev_desc) 172*affae2bfSwdenk { 173*affae2bfSwdenk puts ("\nPartition Map for "); 174*affae2bfSwdenk switch (dev_desc->if_type) { 175*affae2bfSwdenk case IF_TYPE_IDE: puts ("IDE"); 176*affae2bfSwdenk break; 177*affae2bfSwdenk case IF_TYPE_SCSI: puts ("SCSI"); 178*affae2bfSwdenk break; 179*affae2bfSwdenk case IF_TYPE_ATAPI: puts ("ATAPI"); 180*affae2bfSwdenk break; 181*affae2bfSwdenk case IF_TYPE_USB: puts ("USB"); 182*affae2bfSwdenk break; 183*affae2bfSwdenk case IF_TYPE_DOC: puts ("DOC"); 184*affae2bfSwdenk break; 185*affae2bfSwdenk default: puts ("UNKNOWN"); 186*affae2bfSwdenk break; 187*affae2bfSwdenk } 188*affae2bfSwdenk printf (" device %d -- Partition Type: %s\n\n", 189*affae2bfSwdenk dev_desc->dev, type); 190*affae2bfSwdenk } 191*affae2bfSwdenk 192*affae2bfSwdenk void print_part (block_dev_desc_t * dev_desc) 193*affae2bfSwdenk { 194*affae2bfSwdenk 195*affae2bfSwdenk switch (dev_desc->part_type) { 196*affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION 197*affae2bfSwdenk case PART_TYPE_MAC: 198*affae2bfSwdenk PRINTF ("## Testing for valid MAC partition ##\n"); 199*affae2bfSwdenk print_part_header ("MAC", dev_desc); 200*affae2bfSwdenk print_part_mac (dev_desc); 201*affae2bfSwdenk return; 202*affae2bfSwdenk #endif 203*affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION 204*affae2bfSwdenk case PART_TYPE_DOS: 205*affae2bfSwdenk PRINTF ("## Testing for valid DOS partition ##\n"); 206*affae2bfSwdenk print_part_header ("DOS", dev_desc); 207*affae2bfSwdenk print_part_dos (dev_desc); 208*affae2bfSwdenk return; 209*affae2bfSwdenk #endif 210*affae2bfSwdenk 211*affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION 212*affae2bfSwdenk case PART_TYPE_ISO: 213*affae2bfSwdenk PRINTF ("## Testing for valid ISO Boot partition ##\n"); 214*affae2bfSwdenk print_part_header ("ISO", dev_desc); 215*affae2bfSwdenk print_part_iso (dev_desc); 216*affae2bfSwdenk return; 217*affae2bfSwdenk #endif 218*affae2bfSwdenk } 219*affae2bfSwdenk puts ("## Unknown partition table\n"); 220*affae2bfSwdenk } 221*affae2bfSwdenk 222*affae2bfSwdenk 223*affae2bfSwdenk #else /* neither MAC nor DOS nor ISO partition configured */ 224*affae2bfSwdenk # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION nor CONFIG_ISO_PARTITION configured! 225*affae2bfSwdenk #endif 226*affae2bfSwdenk 227*affae2bfSwdenk #endif /* (CONFIG_COMMANDS & CFG_CMD_IDE) || CONFIG_COMMANDS & CFG_CMD_SCSI) */ 228