blob: c7774930b8499d2d1f3d83b17484cccddc25b404 [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>
Grant Likely735dd972007-02-20 09:04:34 +010027#include <part.h>
wdenkaffae2b2002-08-17 09:36:01 +000028
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
Jon Loeligercde5c642007-07-09 17:22:37 -050037#if (defined(CONFIG_CMD_IDE) || \
unsik Kim75eb82e2009-02-25 11:31:24 +090038 defined(CONFIG_CMD_MG_DISK) || \
Dave Liuc7057b52008-03-26 22:49:44 +080039 defined(CONFIG_CMD_SATA) || \
Jon Loeligercde5c642007-07-09 17:22:37 -050040 defined(CONFIG_CMD_SCSI) || \
41 defined(CONFIG_CMD_USB) || \
wdenk1968e612005-02-24 23:23:29 +000042 defined(CONFIG_MMC) || \
43 defined(CONFIG_SYSTEMACE) )
wdenkaffae2b2002-08-17 09:36:01 +000044
Grant Likely735dd972007-02-20 09:04:34 +010045struct block_drvr {
46 char *name;
47 block_dev_desc_t* (*get_dev)(int dev);
48};
49
50static const struct block_drvr block_drvr[] = {
Jon Loeligercde5c642007-07-09 17:22:37 -050051#if defined(CONFIG_CMD_IDE)
Grant Likely735dd972007-02-20 09:04:34 +010052 { .name = "ide", .get_dev = ide_get_dev, },
53#endif
Dave Liuc7057b52008-03-26 22:49:44 +080054#if defined(CONFIG_CMD_SATA)
55 {.name = "sata", .get_dev = sata_get_dev, },
56#endif
Jon Loeligercde5c642007-07-09 17:22:37 -050057#if defined(CONFIG_CMD_SCSI)
Grant Likely735dd972007-02-20 09:04:34 +010058 { .name = "scsi", .get_dev = scsi_get_dev, },
59#endif
Jon Loeligercde5c642007-07-09 17:22:37 -050060#if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
Grant Likely735dd972007-02-20 09:04:34 +010061 { .name = "usb", .get_dev = usb_stor_get_dev, },
62#endif
63#if defined(CONFIG_MMC)
64 { .name = "mmc", .get_dev = mmc_get_dev, },
65#endif
66#if defined(CONFIG_SYSTEMACE)
67 { .name = "ace", .get_dev = systemace_get_dev, },
68#endif
unsik Kim75eb82e2009-02-25 11:31:24 +090069#if defined(CONFIG_CMD_MG_DISK)
70 { .name = "mgd", .get_dev = mg_disk_get_dev, },
71#endif
Grant Likely735dd972007-02-20 09:04:34 +010072 { },
73};
74
Stefan Roese751bb572007-02-20 13:21:57 +010075DECLARE_GLOBAL_DATA_PTR;
Stefan Roese751bb572007-02-20 13:21:57 +010076
Grant Likely735dd972007-02-20 09:04:34 +010077block_dev_desc_t *get_dev(char* ifname, int dev)
78{
79 const struct block_drvr *drvr = block_drvr;
Stefan Roese6c7cac82007-02-22 07:43:34 +010080 block_dev_desc_t* (*reloc_get_dev)(int dev);
Grant Likely735dd972007-02-20 09:04:34 +010081
82 while (drvr->name) {
Stefan Roese751bb572007-02-20 13:21:57 +010083 reloc_get_dev = drvr->get_dev + gd->reloc_off;
84 if (strncmp(ifname, drvr->name, strlen(drvr->name)) == 0)
85 return reloc_get_dev(dev);
Grant Likely735dd972007-02-20 09:04:34 +010086 drvr++;
87 }
88 return NULL;
89}
90#else
91block_dev_desc_t *get_dev(char* ifname, int dev)
92{
93 return NULL;
94}
95#endif
96
Jon Loeligercde5c642007-07-09 17:22:37 -050097#if (defined(CONFIG_CMD_IDE) || \
unsik Kim75eb82e2009-02-25 11:31:24 +090098 defined(CONFIG_CMD_MG_DISK) || \
Dave Liuc7057b52008-03-26 22:49:44 +080099 defined(CONFIG_CMD_SATA) || \
Jon Loeligercde5c642007-07-09 17:22:37 -0500100 defined(CONFIG_CMD_SCSI) || \
101 defined(CONFIG_CMD_USB) || \
Grant Likely735dd972007-02-20 09:04:34 +0100102 defined(CONFIG_MMC) || \
103 defined(CONFIG_SYSTEMACE) )
104
wdenkaffae2b2002-08-17 09:36:01 +0000105/* ------------------------------------------------------------------------- */
106/*
107 * reports device info to the user
108 */
109void dev_print (block_dev_desc_t *dev_desc)
110{
wdenk42dfe7a2004-03-14 22:25:36 +0000111#ifdef CONFIG_LBA48
wdenkc40b2952004-03-13 23:29:43 +0000112 uint64_t lba512; /* number of blocks if 512bytes block size */
113#else
114 lbaint_t lba512;
115#endif
wdenkaffae2b2002-08-17 09:36:01 +0000116
Tor Krill8ec6e332008-05-29 11:10:30 +0200117 switch (dev_desc->if_type) {
Detlev Zundel574b3192008-05-05 16:11:21 +0200118 case IF_TYPE_SCSI:
119 printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n",
120 dev_desc->target,dev_desc->lun,
wdenkaffae2b2002-08-17 09:36:01 +0000121 dev_desc->vendor,
122 dev_desc->product,
123 dev_desc->revision);
Detlev Zundel574b3192008-05-05 16:11:21 +0200124 break;
Remy Bohmer6e24a1e2008-09-19 13:30:06 +0200125 case IF_TYPE_ATAPI:
Detlev Zundel574b3192008-05-05 16:11:21 +0200126 case IF_TYPE_IDE:
127 case IF_TYPE_SATA:
128 printf ("Model: %s Firm: %s Ser#: %s\n",
129 dev_desc->vendor,
130 dev_desc->revision,
131 dev_desc->product);
132 break;
Remy Bohmer6e24a1e2008-09-19 13:30:06 +0200133 case IF_TYPE_SD:
134 case IF_TYPE_MMC:
Nícolas Carneiro Lebedenco47bebe32008-09-04 15:35:46 -0300135 case IF_TYPE_USB:
136 printf ("Vendor: %s Rev: %s Prod: %s\n",
137 dev_desc->vendor,
138 dev_desc->revision,
139 dev_desc->product);
140 break;
Remy Bohmer6e24a1e2008-09-19 13:30:06 +0200141 case IF_TYPE_DOC:
142 puts("device type DOC\n");
143 return;
Tor Krill8ec6e332008-05-29 11:10:30 +0200144 case IF_TYPE_UNKNOWN:
Remy Bohmer6e24a1e2008-09-19 13:30:06 +0200145 puts("device type unknown\n");
146 return;
Detlev Zundel574b3192008-05-05 16:11:21 +0200147 default:
Remy Bohmer6e24a1e2008-09-19 13:30:06 +0200148 printf("Unhandled device type: %i\n", dev_desc->if_type);
Detlev Zundel574b3192008-05-05 16:11:21 +0200149 return;
wdenkaffae2b2002-08-17 09:36:01 +0000150 }
151 puts (" Type: ");
152 if (dev_desc->removable)
153 puts ("Removable ");
154 switch (dev_desc->type & 0x1F) {
Detlev Zundel726c0f12008-05-05 16:11:22 +0200155 case DEV_TYPE_HARDDISK:
156 puts ("Hard Disk");
157 break;
158 case DEV_TYPE_CDROM:
159 puts ("CD ROM");
160 break;
161 case DEV_TYPE_OPDISK:
162 puts ("Optical Device");
163 break;
164 case DEV_TYPE_TAPE:
165 puts ("Tape");
166 break;
167 default:
168 printf ("# %02X #", dev_desc->type & 0x1F);
169 break;
wdenkaffae2b2002-08-17 09:36:01 +0000170 }
171 puts ("\n");
172 if ((dev_desc->lba * dev_desc->blksz)>0L) {
173 ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;
wdenkc40b2952004-03-13 23:29:43 +0000174 lbaint_t lba;
wdenk6e592382004-04-18 17:39:38 +0000175
176 lba = dev_desc->lba;
wdenkaffae2b2002-08-17 09:36:01 +0000177
wdenkc40b2952004-03-13 23:29:43 +0000178 lba512 = (lba * (dev_desc->blksz/512));
wdenkaffae2b2002-08-17 09:36:01 +0000179 mb = (10 * lba512) / 2048; /* 2048 = (1024 * 1024) / 512 MB */
180 /* round to 1 digit */
181 mb_quot = mb / 10;
182 mb_rem = mb - (10 * mb_quot);
183
184 gb = mb / 1024;
185 gb_quot = gb / 10;
186 gb_rem = gb - (10 * gb_quot);
wdenk42dfe7a2004-03-14 22:25:36 +0000187#ifdef CONFIG_LBA48
wdenk6e592382004-04-18 17:39:38 +0000188 if (dev_desc->lba48)
wdenkc40b2952004-03-13 23:29:43 +0000189 printf (" Supports 48-bit addressing\n");
190#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200191#if defined(CONFIG_SYS_64BIT_LBA) && defined(CONFIG_SYS_64BIT_VSPRINTF)
Mike Frysinger6c6166f2009-02-16 23:21:36 -0500192 printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%Ld x %ld)\n",
wdenkc40b2952004-03-13 23:29:43 +0000193 mb_quot, mb_rem,
194 gb_quot, gb_rem,
195 lba,
196 dev_desc->blksz);
197#else
wdenkaffae2b2002-08-17 09:36:01 +0000198 printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n",
199 mb_quot, mb_rem,
200 gb_quot, gb_rem,
wdenkc40b2952004-03-13 23:29:43 +0000201 (ulong)lba,
wdenkaffae2b2002-08-17 09:36:01 +0000202 dev_desc->blksz);
wdenkc40b2952004-03-13 23:29:43 +0000203#endif
wdenkaffae2b2002-08-17 09:36:01 +0000204 } else {
205 puts (" Capacity: not available\n");
206 }
207}
Jon Loeligerb3aff0c2007-07-10 11:19:50 -0500208#endif
wdenkaffae2b2002-08-17 09:36:01 +0000209
Jon Loeligercde5c642007-07-09 17:22:37 -0500210#if (defined(CONFIG_CMD_IDE) || \
unsik Kim75eb82e2009-02-25 11:31:24 +0900211 defined(CONFIG_CMD_MG_DISK) || \
Dave Liuc7057b52008-03-26 22:49:44 +0800212 defined(CONFIG_CMD_SATA) || \
Jon Loeligercde5c642007-07-09 17:22:37 -0500213 defined(CONFIG_CMD_SCSI) || \
214 defined(CONFIG_CMD_USB) || \
Haavard Skinnemoen7fac3f62006-12-17 18:53:56 +0100215 defined(CONFIG_MMC) || \
unsik Kim75eb82e2009-02-25 11:31:24 +0900216 defined(CONFIG_SYSTEMACE) )
wdenkaffae2b2002-08-17 09:36:01 +0000217
wdenkaffae2b2002-08-17 09:36:01 +0000218#if defined(CONFIG_MAC_PARTITION) || \
219 defined(CONFIG_DOS_PARTITION) || \
wdenkc7de8292002-11-19 11:04:11 +0000220 defined(CONFIG_ISO_PARTITION) || \
richardretanubun07f3d782008-09-26 11:13:22 -0400221 defined(CONFIG_AMIGA_PARTITION) || \
222 defined(CONFIG_EFI_PARTITION)
wdenkaffae2b2002-08-17 09:36:01 +0000223
224void init_part (block_dev_desc_t * dev_desc)
225{
226#ifdef CONFIG_ISO_PARTITION
227 if (test_part_iso(dev_desc) == 0) {
228 dev_desc->part_type = PART_TYPE_ISO;
229 return;
230 }
231#endif
232
233#ifdef CONFIG_MAC_PARTITION
234 if (test_part_mac(dev_desc) == 0) {
235 dev_desc->part_type = PART_TYPE_MAC;
236 return;
237 }
238#endif
239
richardretanubun07f3d782008-09-26 11:13:22 -0400240/* must be placed before DOS partition detection */
241#ifdef CONFIG_EFI_PARTITION
242 if (test_part_efi(dev_desc) == 0) {
243 dev_desc->part_type = PART_TYPE_EFI;
244 return;
245 }
246#endif
247
wdenkaffae2b2002-08-17 09:36:01 +0000248#ifdef CONFIG_DOS_PARTITION
249 if (test_part_dos(dev_desc) == 0) {
250 dev_desc->part_type = PART_TYPE_DOS;
251 return;
252 }
253#endif
wdenkc7de8292002-11-19 11:04:11 +0000254
255#ifdef CONFIG_AMIGA_PARTITION
256 if (test_part_amiga(dev_desc) == 0) {
257 dev_desc->part_type = PART_TYPE_AMIGA;
258 return;
259 }
260#endif
wdenkaffae2b2002-08-17 09:36:01 +0000261}
262
263
Peter Pearse3e3b9562007-05-18 16:47:03 +0100264int get_partition_info (block_dev_desc_t *dev_desc, int part
265 , disk_partition_t *info)
wdenkaffae2b2002-08-17 09:36:01 +0000266{
Heiko Schocher566a4942007-06-22 19:11:54 +0200267 switch (dev_desc->part_type) {
wdenkaffae2b2002-08-17 09:36:01 +0000268#ifdef CONFIG_MAC_PARTITION
269 case PART_TYPE_MAC:
270 if (get_partition_info_mac(dev_desc,part,info) == 0) {
271 PRINTF ("## Valid MAC partition found ##\n");
272 return (0);
273 }
274 break;
275#endif
276
277#ifdef CONFIG_DOS_PARTITION
278 case PART_TYPE_DOS:
279 if (get_partition_info_dos(dev_desc,part,info) == 0) {
280 PRINTF ("## Valid DOS partition found ##\n");
281 return (0);
282 }
283 break;
284#endif
285
286#ifdef CONFIG_ISO_PARTITION
287 case PART_TYPE_ISO:
288 if (get_partition_info_iso(dev_desc,part,info) == 0) {
289 PRINTF ("## Valid ISO boot partition found ##\n");
290 return (0);
291 }
292 break;
293#endif
wdenkc7de8292002-11-19 11:04:11 +0000294
295#ifdef CONFIG_AMIGA_PARTITION
296 case PART_TYPE_AMIGA:
297 if (get_partition_info_amiga(dev_desc, part, info) == 0)
298 {
299 PRINTF ("## Valid Amiga partition found ##\n");
300 return (0);
301 }
302 break;
303#endif
richardretanubun07f3d782008-09-26 11:13:22 -0400304
305#ifdef CONFIG_EFI_PARTITION
306 case PART_TYPE_EFI:
307 if (get_partition_info_efi(dev_desc,part,info) == 0) {
308 PRINTF ("## Valid EFI partition found ##\n");
309 return (0);
310 }
311 break;
312#endif
wdenkaffae2b2002-08-17 09:36:01 +0000313 default:
314 break;
315 }
316 return (-1);
317}
318
319static void print_part_header (const char *type, block_dev_desc_t * dev_desc)
320{
321 puts ("\nPartition Map for ");
322 switch (dev_desc->if_type) {
Detlev Zundel726c0f12008-05-05 16:11:22 +0200323 case IF_TYPE_IDE:
324 puts ("IDE");
325 break;
326 case IF_TYPE_SATA:
327 puts ("SATA");
328 break;
329 case IF_TYPE_SCSI:
330 puts ("SCSI");
331 break;
332 case IF_TYPE_ATAPI:
333 puts ("ATAPI");
334 break;
335 case IF_TYPE_USB:
336 puts ("USB");
337 break;
338 case IF_TYPE_DOC:
339 puts ("DOC");
340 break;
341 default:
342 puts ("UNKNOWN");
343 break;
wdenkaffae2b2002-08-17 09:36:01 +0000344 }
345 printf (" device %d -- Partition Type: %s\n\n",
346 dev_desc->dev, type);
347}
348
349void print_part (block_dev_desc_t * dev_desc)
350{
351
352 switch (dev_desc->part_type) {
353#ifdef CONFIG_MAC_PARTITION
354 case PART_TYPE_MAC:
355 PRINTF ("## Testing for valid MAC partition ##\n");
356 print_part_header ("MAC", dev_desc);
357 print_part_mac (dev_desc);
358 return;
359#endif
360#ifdef CONFIG_DOS_PARTITION
361 case PART_TYPE_DOS:
362 PRINTF ("## Testing for valid DOS partition ##\n");
363 print_part_header ("DOS", dev_desc);
364 print_part_dos (dev_desc);
365 return;
366#endif
367
368#ifdef CONFIG_ISO_PARTITION
369 case PART_TYPE_ISO:
370 PRINTF ("## Testing for valid ISO Boot partition ##\n");
371 print_part_header ("ISO", dev_desc);
372 print_part_iso (dev_desc);
373 return;
374#endif
wdenkc7de8292002-11-19 11:04:11 +0000375
376#ifdef CONFIG_AMIGA_PARTITION
377 case PART_TYPE_AMIGA:
378 PRINTF ("## Testing for a valid Amiga partition ##\n");
379 print_part_header ("AMIGA", dev_desc);
380 print_part_amiga (dev_desc);
381 return;
382#endif
richardretanubun07f3d782008-09-26 11:13:22 -0400383
384#ifdef CONFIG_EFI_PARTITION
385 case PART_TYPE_EFI:
386 PRINTF ("## Testing for valid EFI partition ##\n");
387 print_part_header ("EFI", dev_desc);
388 print_part_efi (dev_desc);
389 return;
390#endif
wdenkaffae2b2002-08-17 09:36:01 +0000391 }
392 puts ("## Unknown partition table\n");
393}
394
395
richardretanubun07f3d782008-09-26 11:13:22 -0400396#else /* neither MAC nor DOS nor ISO nor AMIGA nor EFI partition configured */
Wolfgang Denk725671c2007-06-06 16:26:56 +0200397# error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION
richardretanubun07f3d782008-09-26 11:13:22 -0400398# error nor CONFIG_ISO_PARTITION nor CONFIG_AMIGA_PARTITION
399# error nor CONFIG_EFI_PARTITION configured!
wdenkaffae2b2002-08-17 09:36:01 +0000400#endif
401
Jon Loeligercde5c642007-07-09 17:22:37 -0500402#endif