blob: b92fb45b8616c79ed0de0350d45a6bbb8a292729 [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
Wolfgang Denkaf75a452009-05-15 09:27:58 +0200117 if (dev_desc->type == DEV_TYPE_UNKNOWN) {
118 puts ("not available\n");
119 return;
120 }
121
Tor Krill8ec6e332008-05-29 11:10:30 +0200122 switch (dev_desc->if_type) {
Detlev Zundel574b3192008-05-05 16:11:21 +0200123 case IF_TYPE_SCSI:
124 printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n",
125 dev_desc->target,dev_desc->lun,
wdenkaffae2b2002-08-17 09:36:01 +0000126 dev_desc->vendor,
127 dev_desc->product,
128 dev_desc->revision);
Detlev Zundel574b3192008-05-05 16:11:21 +0200129 break;
Remy Bohmer6e24a1e2008-09-19 13:30:06 +0200130 case IF_TYPE_ATAPI:
Detlev Zundel574b3192008-05-05 16:11:21 +0200131 case IF_TYPE_IDE:
132 case IF_TYPE_SATA:
133 printf ("Model: %s Firm: %s Ser#: %s\n",
134 dev_desc->vendor,
135 dev_desc->revision,
136 dev_desc->product);
137 break;
Remy Bohmer6e24a1e2008-09-19 13:30:06 +0200138 case IF_TYPE_SD:
139 case IF_TYPE_MMC:
Nícolas Carneiro Lebedenco47bebe32008-09-04 15:35:46 -0300140 case IF_TYPE_USB:
141 printf ("Vendor: %s Rev: %s Prod: %s\n",
142 dev_desc->vendor,
143 dev_desc->revision,
144 dev_desc->product);
145 break;
Remy Bohmer6e24a1e2008-09-19 13:30:06 +0200146 case IF_TYPE_DOC:
147 puts("device type DOC\n");
148 return;
Tor Krill8ec6e332008-05-29 11:10:30 +0200149 case IF_TYPE_UNKNOWN:
Remy Bohmer6e24a1e2008-09-19 13:30:06 +0200150 puts("device type unknown\n");
151 return;
Detlev Zundel574b3192008-05-05 16:11:21 +0200152 default:
Remy Bohmer6e24a1e2008-09-19 13:30:06 +0200153 printf("Unhandled device type: %i\n", dev_desc->if_type);
Detlev Zundel574b3192008-05-05 16:11:21 +0200154 return;
wdenkaffae2b2002-08-17 09:36:01 +0000155 }
156 puts (" Type: ");
157 if (dev_desc->removable)
158 puts ("Removable ");
159 switch (dev_desc->type & 0x1F) {
Detlev Zundel726c0f12008-05-05 16:11:22 +0200160 case DEV_TYPE_HARDDISK:
161 puts ("Hard Disk");
162 break;
163 case DEV_TYPE_CDROM:
164 puts ("CD ROM");
165 break;
166 case DEV_TYPE_OPDISK:
167 puts ("Optical Device");
168 break;
169 case DEV_TYPE_TAPE:
170 puts ("Tape");
171 break;
172 default:
173 printf ("# %02X #", dev_desc->type & 0x1F);
174 break;
wdenkaffae2b2002-08-17 09:36:01 +0000175 }
176 puts ("\n");
177 if ((dev_desc->lba * dev_desc->blksz)>0L) {
178 ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;
wdenkc40b2952004-03-13 23:29:43 +0000179 lbaint_t lba;
wdenk6e592382004-04-18 17:39:38 +0000180
181 lba = dev_desc->lba;
wdenkaffae2b2002-08-17 09:36:01 +0000182
wdenkc40b2952004-03-13 23:29:43 +0000183 lba512 = (lba * (dev_desc->blksz/512));
wdenkaffae2b2002-08-17 09:36:01 +0000184 mb = (10 * lba512) / 2048; /* 2048 = (1024 * 1024) / 512 MB */
185 /* round to 1 digit */
186 mb_quot = mb / 10;
187 mb_rem = mb - (10 * mb_quot);
188
189 gb = mb / 1024;
190 gb_quot = gb / 10;
191 gb_rem = gb - (10 * gb_quot);
wdenk42dfe7a2004-03-14 22:25:36 +0000192#ifdef CONFIG_LBA48
wdenk6e592382004-04-18 17:39:38 +0000193 if (dev_desc->lba48)
wdenkc40b2952004-03-13 23:29:43 +0000194 printf (" Supports 48-bit addressing\n");
195#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200196#if defined(CONFIG_SYS_64BIT_LBA) && defined(CONFIG_SYS_64BIT_VSPRINTF)
Mike Frysinger6c6166f2009-02-16 23:21:36 -0500197 printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%Ld x %ld)\n",
wdenkc40b2952004-03-13 23:29:43 +0000198 mb_quot, mb_rem,
199 gb_quot, gb_rem,
200 lba,
201 dev_desc->blksz);
202#else
wdenkaffae2b2002-08-17 09:36:01 +0000203 printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n",
204 mb_quot, mb_rem,
205 gb_quot, gb_rem,
wdenkc40b2952004-03-13 23:29:43 +0000206 (ulong)lba,
wdenkaffae2b2002-08-17 09:36:01 +0000207 dev_desc->blksz);
wdenkc40b2952004-03-13 23:29:43 +0000208#endif
wdenkaffae2b2002-08-17 09:36:01 +0000209 } else {
210 puts (" Capacity: not available\n");
211 }
212}
Jon Loeligerb3aff0c2007-07-10 11:19:50 -0500213#endif
wdenkaffae2b2002-08-17 09:36:01 +0000214
Jon Loeligercde5c642007-07-09 17:22:37 -0500215#if (defined(CONFIG_CMD_IDE) || \
unsik Kim75eb82e2009-02-25 11:31:24 +0900216 defined(CONFIG_CMD_MG_DISK) || \
Dave Liuc7057b52008-03-26 22:49:44 +0800217 defined(CONFIG_CMD_SATA) || \
Jon Loeligercde5c642007-07-09 17:22:37 -0500218 defined(CONFIG_CMD_SCSI) || \
219 defined(CONFIG_CMD_USB) || \
Haavard Skinnemoen7fac3f62006-12-17 18:53:56 +0100220 defined(CONFIG_MMC) || \
unsik Kim75eb82e2009-02-25 11:31:24 +0900221 defined(CONFIG_SYSTEMACE) )
wdenkaffae2b2002-08-17 09:36:01 +0000222
wdenkaffae2b2002-08-17 09:36:01 +0000223#if defined(CONFIG_MAC_PARTITION) || \
224 defined(CONFIG_DOS_PARTITION) || \
wdenkc7de8292002-11-19 11:04:11 +0000225 defined(CONFIG_ISO_PARTITION) || \
richardretanubun07f3d782008-09-26 11:13:22 -0400226 defined(CONFIG_AMIGA_PARTITION) || \
227 defined(CONFIG_EFI_PARTITION)
wdenkaffae2b2002-08-17 09:36:01 +0000228
229void init_part (block_dev_desc_t * dev_desc)
230{
231#ifdef CONFIG_ISO_PARTITION
232 if (test_part_iso(dev_desc) == 0) {
233 dev_desc->part_type = PART_TYPE_ISO;
234 return;
235 }
236#endif
237
238#ifdef CONFIG_MAC_PARTITION
239 if (test_part_mac(dev_desc) == 0) {
240 dev_desc->part_type = PART_TYPE_MAC;
241 return;
242 }
243#endif
244
richardretanubun07f3d782008-09-26 11:13:22 -0400245/* must be placed before DOS partition detection */
246#ifdef CONFIG_EFI_PARTITION
247 if (test_part_efi(dev_desc) == 0) {
248 dev_desc->part_type = PART_TYPE_EFI;
249 return;
250 }
251#endif
252
wdenkaffae2b2002-08-17 09:36:01 +0000253#ifdef CONFIG_DOS_PARTITION
254 if (test_part_dos(dev_desc) == 0) {
255 dev_desc->part_type = PART_TYPE_DOS;
256 return;
257 }
258#endif
wdenkc7de8292002-11-19 11:04:11 +0000259
260#ifdef CONFIG_AMIGA_PARTITION
261 if (test_part_amiga(dev_desc) == 0) {
262 dev_desc->part_type = PART_TYPE_AMIGA;
263 return;
264 }
265#endif
wdenkaffae2b2002-08-17 09:36:01 +0000266}
267
268
Peter Pearse3e3b9562007-05-18 16:47:03 +0100269int get_partition_info (block_dev_desc_t *dev_desc, int part
270 , disk_partition_t *info)
wdenkaffae2b2002-08-17 09:36:01 +0000271{
Heiko Schocher566a4942007-06-22 19:11:54 +0200272 switch (dev_desc->part_type) {
wdenkaffae2b2002-08-17 09:36:01 +0000273#ifdef CONFIG_MAC_PARTITION
274 case PART_TYPE_MAC:
275 if (get_partition_info_mac(dev_desc,part,info) == 0) {
276 PRINTF ("## Valid MAC partition found ##\n");
277 return (0);
278 }
279 break;
280#endif
281
282#ifdef CONFIG_DOS_PARTITION
283 case PART_TYPE_DOS:
284 if (get_partition_info_dos(dev_desc,part,info) == 0) {
285 PRINTF ("## Valid DOS partition found ##\n");
286 return (0);
287 }
288 break;
289#endif
290
291#ifdef CONFIG_ISO_PARTITION
292 case PART_TYPE_ISO:
293 if (get_partition_info_iso(dev_desc,part,info) == 0) {
294 PRINTF ("## Valid ISO boot partition found ##\n");
295 return (0);
296 }
297 break;
298#endif
wdenkc7de8292002-11-19 11:04:11 +0000299
300#ifdef CONFIG_AMIGA_PARTITION
301 case PART_TYPE_AMIGA:
302 if (get_partition_info_amiga(dev_desc, part, info) == 0)
303 {
304 PRINTF ("## Valid Amiga partition found ##\n");
305 return (0);
306 }
307 break;
308#endif
richardretanubun07f3d782008-09-26 11:13:22 -0400309
310#ifdef CONFIG_EFI_PARTITION
311 case PART_TYPE_EFI:
312 if (get_partition_info_efi(dev_desc,part,info) == 0) {
313 PRINTF ("## Valid EFI partition found ##\n");
314 return (0);
315 }
316 break;
317#endif
wdenkaffae2b2002-08-17 09:36:01 +0000318 default:
319 break;
320 }
321 return (-1);
322}
323
324static void print_part_header (const char *type, block_dev_desc_t * dev_desc)
325{
326 puts ("\nPartition Map for ");
327 switch (dev_desc->if_type) {
Detlev Zundel726c0f12008-05-05 16:11:22 +0200328 case IF_TYPE_IDE:
329 puts ("IDE");
330 break;
331 case IF_TYPE_SATA:
332 puts ("SATA");
333 break;
334 case IF_TYPE_SCSI:
335 puts ("SCSI");
336 break;
337 case IF_TYPE_ATAPI:
338 puts ("ATAPI");
339 break;
340 case IF_TYPE_USB:
341 puts ("USB");
342 break;
343 case IF_TYPE_DOC:
344 puts ("DOC");
345 break;
346 default:
347 puts ("UNKNOWN");
348 break;
wdenkaffae2b2002-08-17 09:36:01 +0000349 }
350 printf (" device %d -- Partition Type: %s\n\n",
351 dev_desc->dev, type);
352}
353
354void print_part (block_dev_desc_t * dev_desc)
355{
356
357 switch (dev_desc->part_type) {
358#ifdef CONFIG_MAC_PARTITION
359 case PART_TYPE_MAC:
360 PRINTF ("## Testing for valid MAC partition ##\n");
361 print_part_header ("MAC", dev_desc);
362 print_part_mac (dev_desc);
363 return;
364#endif
365#ifdef CONFIG_DOS_PARTITION
366 case PART_TYPE_DOS:
367 PRINTF ("## Testing for valid DOS partition ##\n");
368 print_part_header ("DOS", dev_desc);
369 print_part_dos (dev_desc);
370 return;
371#endif
372
373#ifdef CONFIG_ISO_PARTITION
374 case PART_TYPE_ISO:
375 PRINTF ("## Testing for valid ISO Boot partition ##\n");
376 print_part_header ("ISO", dev_desc);
377 print_part_iso (dev_desc);
378 return;
379#endif
wdenkc7de8292002-11-19 11:04:11 +0000380
381#ifdef CONFIG_AMIGA_PARTITION
382 case PART_TYPE_AMIGA:
383 PRINTF ("## Testing for a valid Amiga partition ##\n");
384 print_part_header ("AMIGA", dev_desc);
385 print_part_amiga (dev_desc);
386 return;
387#endif
richardretanubun07f3d782008-09-26 11:13:22 -0400388
389#ifdef CONFIG_EFI_PARTITION
390 case PART_TYPE_EFI:
391 PRINTF ("## Testing for valid EFI partition ##\n");
392 print_part_header ("EFI", dev_desc);
393 print_part_efi (dev_desc);
394 return;
395#endif
wdenkaffae2b2002-08-17 09:36:01 +0000396 }
397 puts ("## Unknown partition table\n");
398}
399
400
richardretanubun07f3d782008-09-26 11:13:22 -0400401#else /* neither MAC nor DOS nor ISO nor AMIGA nor EFI partition configured */
Wolfgang Denk725671c2007-06-06 16:26:56 +0200402# error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION
richardretanubun07f3d782008-09-26 11:13:22 -0400403# error nor CONFIG_ISO_PARTITION nor CONFIG_AMIGA_PARTITION
404# error nor CONFIG_EFI_PARTITION configured!
wdenkaffae2b2002-08-17 09:36:01 +0000405#endif
406
Jon Loeligercde5c642007-07-09 17:22:37 -0500407#endif