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