wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | /* |
| 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 Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 27 | #include <part.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 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 | |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 37 | #if (defined(CONFIG_CMD_IDE) || \ |
Dave Liu | c7057b5 | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 38 | defined(CONFIG_CMD_SATA) || \ |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 39 | defined(CONFIG_CMD_SCSI) || \ |
| 40 | defined(CONFIG_CMD_USB) || \ |
wdenk | 1968e61 | 2005-02-24 23:23:29 +0000 | [diff] [blame] | 41 | defined(CONFIG_MMC) || \ |
| 42 | defined(CONFIG_SYSTEMACE) ) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 43 | |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 44 | struct block_drvr { |
| 45 | char *name; |
| 46 | block_dev_desc_t* (*get_dev)(int dev); |
| 47 | }; |
| 48 | |
| 49 | static const struct block_drvr block_drvr[] = { |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 50 | #if defined(CONFIG_CMD_IDE) |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 51 | { .name = "ide", .get_dev = ide_get_dev, }, |
| 52 | #endif |
Dave Liu | c7057b5 | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 53 | #if defined(CONFIG_CMD_SATA) |
| 54 | {.name = "sata", .get_dev = sata_get_dev, }, |
| 55 | #endif |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 56 | #if defined(CONFIG_CMD_SCSI) |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 57 | { .name = "scsi", .get_dev = scsi_get_dev, }, |
| 58 | #endif |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 59 | #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE) |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 60 | { .name = "usb", .get_dev = usb_stor_get_dev, }, |
| 61 | #endif |
| 62 | #if defined(CONFIG_MMC) |
| 63 | { .name = "mmc", .get_dev = mmc_get_dev, }, |
| 64 | #endif |
| 65 | #if defined(CONFIG_SYSTEMACE) |
| 66 | { .name = "ace", .get_dev = systemace_get_dev, }, |
| 67 | #endif |
| 68 | { }, |
| 69 | }; |
| 70 | |
Stefan Roese | 751bb57 | 2007-02-20 13:21:57 +0100 | [diff] [blame] | 71 | DECLARE_GLOBAL_DATA_PTR; |
Stefan Roese | 751bb57 | 2007-02-20 13:21:57 +0100 | [diff] [blame] | 72 | |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 73 | block_dev_desc_t *get_dev(const char *ifname, int dev) |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 74 | { |
| 75 | const struct block_drvr *drvr = block_drvr; |
Stefan Roese | 6c7cac8 | 2007-02-22 07:43:34 +0100 | [diff] [blame] | 76 | block_dev_desc_t* (*reloc_get_dev)(int dev); |
Heiko Schocher | 23090da | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 77 | char *name; |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 78 | |
Tim Kientzle | 7e71dc6 | 2012-03-27 11:43:25 +0200 | [diff] [blame] | 79 | if (!ifname) |
| 80 | return NULL; |
| 81 | |
Heiko Schocher | 23090da | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 82 | name = drvr->name; |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 83 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
Heiko Schocher | 23090da | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 84 | name += gd->reloc_off; |
| 85 | #endif |
Lei Wen | b16aadf | 2011-02-15 16:56:40 +0800 | [diff] [blame] | 86 | while (drvr->name) { |
Heiko Schocher | 23090da | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 87 | name = drvr->name; |
Peter Tyser | 521af04 | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 88 | reloc_get_dev = drvr->get_dev; |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 89 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
Heiko Schocher | 23090da | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 90 | name += gd->reloc_off; |
Peter Tyser | 521af04 | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 91 | reloc_get_dev += gd->reloc_off; |
| 92 | #endif |
Heiko Schocher | 23090da | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 93 | if (strncmp(ifname, name, strlen(name)) == 0) |
Stefan Roese | 751bb57 | 2007-02-20 13:21:57 +0100 | [diff] [blame] | 94 | return reloc_get_dev(dev); |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 95 | drvr++; |
| 96 | } |
| 97 | return NULL; |
| 98 | } |
| 99 | #else |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 100 | block_dev_desc_t *get_dev(const char *ifname, int dev) |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 101 | { |
| 102 | return NULL; |
| 103 | } |
| 104 | #endif |
| 105 | |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 106 | #if (defined(CONFIG_CMD_IDE) || \ |
Dave Liu | c7057b5 | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 107 | defined(CONFIG_CMD_SATA) || \ |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 108 | defined(CONFIG_CMD_SCSI) || \ |
| 109 | defined(CONFIG_CMD_USB) || \ |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 110 | defined(CONFIG_MMC) || \ |
| 111 | defined(CONFIG_SYSTEMACE) ) |
| 112 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 113 | /* ------------------------------------------------------------------------- */ |
| 114 | /* |
| 115 | * reports device info to the user |
| 116 | */ |
Sergei Trofimovich | 69a2a4d | 2010-08-08 15:05:39 +0300 | [diff] [blame] | 117 | |
| 118 | #ifdef CONFIG_LBA48 |
| 119 | typedef uint64_t lba512_t; |
| 120 | #else |
| 121 | typedef lbaint_t lba512_t; |
| 122 | #endif |
| 123 | |
| 124 | /* |
| 125 | * Overflowless variant of (block_count * mul_by / div_by) |
| 126 | * when div_by > mul_by |
| 127 | */ |
| 128 | static lba512_t lba512_muldiv (lba512_t block_count, lba512_t mul_by, lba512_t div_by) |
| 129 | { |
| 130 | lba512_t bc_quot, bc_rem; |
| 131 | |
| 132 | /* x * m / d == x / d * m + (x % d) * m / d */ |
| 133 | bc_quot = block_count / div_by; |
| 134 | bc_rem = block_count - div_by * bc_quot; |
| 135 | return bc_quot * mul_by + (bc_rem * mul_by) / div_by; |
| 136 | } |
| 137 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 138 | void dev_print (block_dev_desc_t *dev_desc) |
| 139 | { |
Sergei Trofimovich | 69a2a4d | 2010-08-08 15:05:39 +0300 | [diff] [blame] | 140 | lba512_t lba512; /* number of blocks if 512bytes block size */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 141 | |
Wolfgang Denk | af75a45 | 2009-05-15 09:27:58 +0200 | [diff] [blame] | 142 | if (dev_desc->type == DEV_TYPE_UNKNOWN) { |
| 143 | puts ("not available\n"); |
| 144 | return; |
| 145 | } |
| 146 | |
Tor Krill | 8ec6e33 | 2008-05-29 11:10:30 +0200 | [diff] [blame] | 147 | switch (dev_desc->if_type) { |
Detlev Zundel | 574b319 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 148 | case IF_TYPE_SCSI: |
| 149 | printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n", |
| 150 | dev_desc->target,dev_desc->lun, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 151 | dev_desc->vendor, |
| 152 | dev_desc->product, |
| 153 | dev_desc->revision); |
Detlev Zundel | 574b319 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 154 | break; |
Remy Bohmer | 6e24a1e | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 155 | case IF_TYPE_ATAPI: |
Detlev Zundel | 574b319 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 156 | case IF_TYPE_IDE: |
| 157 | case IF_TYPE_SATA: |
| 158 | printf ("Model: %s Firm: %s Ser#: %s\n", |
| 159 | dev_desc->vendor, |
| 160 | dev_desc->revision, |
| 161 | dev_desc->product); |
| 162 | break; |
Remy Bohmer | 6e24a1e | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 163 | case IF_TYPE_SD: |
| 164 | case IF_TYPE_MMC: |
NÃcolas Carneiro Lebedenco | 47bebe3 | 2008-09-04 15:35:46 -0300 | [diff] [blame] | 165 | case IF_TYPE_USB: |
| 166 | printf ("Vendor: %s Rev: %s Prod: %s\n", |
| 167 | dev_desc->vendor, |
| 168 | dev_desc->revision, |
| 169 | dev_desc->product); |
| 170 | break; |
Remy Bohmer | 6e24a1e | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 171 | case IF_TYPE_DOC: |
| 172 | puts("device type DOC\n"); |
| 173 | return; |
Tor Krill | 8ec6e33 | 2008-05-29 11:10:30 +0200 | [diff] [blame] | 174 | case IF_TYPE_UNKNOWN: |
Remy Bohmer | 6e24a1e | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 175 | puts("device type unknown\n"); |
| 176 | return; |
Detlev Zundel | 574b319 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 177 | default: |
Remy Bohmer | 6e24a1e | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 178 | printf("Unhandled device type: %i\n", dev_desc->if_type); |
Detlev Zundel | 574b319 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 179 | return; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 180 | } |
| 181 | puts (" Type: "); |
| 182 | if (dev_desc->removable) |
| 183 | puts ("Removable "); |
| 184 | switch (dev_desc->type & 0x1F) { |
Detlev Zundel | 726c0f1 | 2008-05-05 16:11:22 +0200 | [diff] [blame] | 185 | case DEV_TYPE_HARDDISK: |
| 186 | puts ("Hard Disk"); |
| 187 | break; |
| 188 | case DEV_TYPE_CDROM: |
| 189 | puts ("CD ROM"); |
| 190 | break; |
| 191 | case DEV_TYPE_OPDISK: |
| 192 | puts ("Optical Device"); |
| 193 | break; |
| 194 | case DEV_TYPE_TAPE: |
| 195 | puts ("Tape"); |
| 196 | break; |
| 197 | default: |
| 198 | printf ("# %02X #", dev_desc->type & 0x1F); |
| 199 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 200 | } |
| 201 | puts ("\n"); |
| 202 | if ((dev_desc->lba * dev_desc->blksz)>0L) { |
| 203 | ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem; |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 204 | lbaint_t lba; |
wdenk | 6e59238 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 205 | |
| 206 | lba = dev_desc->lba; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 207 | |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 208 | lba512 = (lba * (dev_desc->blksz/512)); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 209 | /* round to 1 digit */ |
Sergei Trofimovich | 69a2a4d | 2010-08-08 15:05:39 +0300 | [diff] [blame] | 210 | mb = lba512_muldiv(lba512, 10, 2048); /* 2048 = (1024 * 1024) / 512 MB */ |
| 211 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 212 | mb_quot = mb / 10; |
| 213 | mb_rem = mb - (10 * mb_quot); |
| 214 | |
| 215 | gb = mb / 1024; |
| 216 | gb_quot = gb / 10; |
| 217 | gb_rem = gb - (10 * gb_quot); |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 218 | #ifdef CONFIG_LBA48 |
wdenk | 6e59238 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 219 | if (dev_desc->lba48) |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 220 | printf (" Supports 48-bit addressing\n"); |
| 221 | #endif |
Heiko Schocher | 4b142fe | 2009-12-03 11:21:21 +0100 | [diff] [blame] | 222 | #if defined(CONFIG_SYS_64BIT_LBA) |
Mike Frysinger | 6c6166f | 2009-02-16 23:21:36 -0500 | [diff] [blame] | 223 | printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%Ld x %ld)\n", |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 224 | mb_quot, mb_rem, |
| 225 | gb_quot, gb_rem, |
| 226 | lba, |
| 227 | dev_desc->blksz); |
| 228 | #else |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 229 | printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n", |
| 230 | mb_quot, mb_rem, |
| 231 | gb_quot, gb_rem, |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 232 | (ulong)lba, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 233 | dev_desc->blksz); |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 234 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 235 | } else { |
| 236 | puts (" Capacity: not available\n"); |
| 237 | } |
| 238 | } |
Jon Loeliger | b3aff0c | 2007-07-10 11:19:50 -0500 | [diff] [blame] | 239 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 240 | |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 241 | #if (defined(CONFIG_CMD_IDE) || \ |
Dave Liu | c7057b5 | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 242 | defined(CONFIG_CMD_SATA) || \ |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 243 | defined(CONFIG_CMD_SCSI) || \ |
| 244 | defined(CONFIG_CMD_USB) || \ |
Haavard Skinnemoen | 7fac3f6 | 2006-12-17 18:53:56 +0100 | [diff] [blame] | 245 | defined(CONFIG_MMC) || \ |
unsik Kim | 75eb82e | 2009-02-25 11:31:24 +0900 | [diff] [blame] | 246 | defined(CONFIG_SYSTEMACE) ) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 247 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 248 | #if defined(CONFIG_MAC_PARTITION) || \ |
| 249 | defined(CONFIG_DOS_PARTITION) || \ |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 250 | defined(CONFIG_ISO_PARTITION) || \ |
richardretanubun | 07f3d78 | 2008-09-26 11:13:22 -0400 | [diff] [blame] | 251 | defined(CONFIG_AMIGA_PARTITION) || \ |
| 252 | defined(CONFIG_EFI_PARTITION) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 253 | |
| 254 | void init_part (block_dev_desc_t * dev_desc) |
| 255 | { |
| 256 | #ifdef CONFIG_ISO_PARTITION |
| 257 | if (test_part_iso(dev_desc) == 0) { |
| 258 | dev_desc->part_type = PART_TYPE_ISO; |
| 259 | return; |
| 260 | } |
| 261 | #endif |
| 262 | |
| 263 | #ifdef CONFIG_MAC_PARTITION |
| 264 | if (test_part_mac(dev_desc) == 0) { |
| 265 | dev_desc->part_type = PART_TYPE_MAC; |
| 266 | return; |
| 267 | } |
| 268 | #endif |
| 269 | |
richardretanubun | 07f3d78 | 2008-09-26 11:13:22 -0400 | [diff] [blame] | 270 | /* must be placed before DOS partition detection */ |
| 271 | #ifdef CONFIG_EFI_PARTITION |
| 272 | if (test_part_efi(dev_desc) == 0) { |
| 273 | dev_desc->part_type = PART_TYPE_EFI; |
| 274 | return; |
| 275 | } |
| 276 | #endif |
| 277 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 278 | #ifdef CONFIG_DOS_PARTITION |
| 279 | if (test_part_dos(dev_desc) == 0) { |
| 280 | dev_desc->part_type = PART_TYPE_DOS; |
| 281 | return; |
| 282 | } |
| 283 | #endif |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 284 | |
| 285 | #ifdef CONFIG_AMIGA_PARTITION |
| 286 | if (test_part_amiga(dev_desc) == 0) { |
| 287 | dev_desc->part_type = PART_TYPE_AMIGA; |
| 288 | return; |
| 289 | } |
| 290 | #endif |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 291 | dev_desc->part_type = PART_TYPE_UNKNOWN; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 295 | static void print_part_header (const char *type, block_dev_desc_t * dev_desc) |
| 296 | { |
| 297 | puts ("\nPartition Map for "); |
| 298 | switch (dev_desc->if_type) { |
Detlev Zundel | 726c0f1 | 2008-05-05 16:11:22 +0200 | [diff] [blame] | 299 | case IF_TYPE_IDE: |
| 300 | puts ("IDE"); |
| 301 | break; |
| 302 | case IF_TYPE_SATA: |
| 303 | puts ("SATA"); |
| 304 | break; |
| 305 | case IF_TYPE_SCSI: |
| 306 | puts ("SCSI"); |
| 307 | break; |
| 308 | case IF_TYPE_ATAPI: |
| 309 | puts ("ATAPI"); |
| 310 | break; |
| 311 | case IF_TYPE_USB: |
| 312 | puts ("USB"); |
| 313 | break; |
| 314 | case IF_TYPE_DOC: |
| 315 | puts ("DOC"); |
| 316 | break; |
Lei Wen | 8f3b964 | 2010-09-13 22:07:28 +0800 | [diff] [blame] | 317 | case IF_TYPE_MMC: |
| 318 | puts ("MMC"); |
| 319 | break; |
Detlev Zundel | 726c0f1 | 2008-05-05 16:11:22 +0200 | [diff] [blame] | 320 | default: |
| 321 | puts ("UNKNOWN"); |
| 322 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 323 | } |
| 324 | printf (" device %d -- Partition Type: %s\n\n", |
| 325 | dev_desc->dev, type); |
| 326 | } |
| 327 | |
| 328 | void print_part (block_dev_desc_t * dev_desc) |
| 329 | { |
| 330 | |
| 331 | switch (dev_desc->part_type) { |
| 332 | #ifdef CONFIG_MAC_PARTITION |
| 333 | case PART_TYPE_MAC: |
| 334 | PRINTF ("## Testing for valid MAC partition ##\n"); |
| 335 | print_part_header ("MAC", dev_desc); |
| 336 | print_part_mac (dev_desc); |
| 337 | return; |
| 338 | #endif |
| 339 | #ifdef CONFIG_DOS_PARTITION |
| 340 | case PART_TYPE_DOS: |
| 341 | PRINTF ("## Testing for valid DOS partition ##\n"); |
| 342 | print_part_header ("DOS", dev_desc); |
| 343 | print_part_dos (dev_desc); |
| 344 | return; |
| 345 | #endif |
| 346 | |
| 347 | #ifdef CONFIG_ISO_PARTITION |
| 348 | case PART_TYPE_ISO: |
| 349 | PRINTF ("## Testing for valid ISO Boot partition ##\n"); |
| 350 | print_part_header ("ISO", dev_desc); |
| 351 | print_part_iso (dev_desc); |
| 352 | return; |
| 353 | #endif |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 354 | |
| 355 | #ifdef CONFIG_AMIGA_PARTITION |
| 356 | case PART_TYPE_AMIGA: |
| 357 | PRINTF ("## Testing for a valid Amiga partition ##\n"); |
| 358 | print_part_header ("AMIGA", dev_desc); |
| 359 | print_part_amiga (dev_desc); |
| 360 | return; |
| 361 | #endif |
richardretanubun | 07f3d78 | 2008-09-26 11:13:22 -0400 | [diff] [blame] | 362 | |
| 363 | #ifdef CONFIG_EFI_PARTITION |
| 364 | case PART_TYPE_EFI: |
| 365 | PRINTF ("## Testing for valid EFI partition ##\n"); |
| 366 | print_part_header ("EFI", dev_desc); |
| 367 | print_part_efi (dev_desc); |
| 368 | return; |
| 369 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 370 | } |
| 371 | puts ("## Unknown partition table\n"); |
| 372 | } |
| 373 | |
| 374 | |
richardretanubun | 07f3d78 | 2008-09-26 11:13:22 -0400 | [diff] [blame] | 375 | #else /* neither MAC nor DOS nor ISO nor AMIGA nor EFI partition configured */ |
Wolfgang Denk | 725671c | 2007-06-06 16:26:56 +0200 | [diff] [blame] | 376 | # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION |
richardretanubun | 07f3d78 | 2008-09-26 11:13:22 -0400 | [diff] [blame] | 377 | # error nor CONFIG_ISO_PARTITION nor CONFIG_AMIGA_PARTITION |
| 378 | # error nor CONFIG_EFI_PARTITION configured! |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 379 | #endif |
| 380 | |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 381 | #endif |
Stephen Warren | 2f50164 | 2012-09-21 12:46:54 +0000 | [diff] [blame] | 382 | |
| 383 | int get_partition_info(block_dev_desc_t *dev_desc, int part |
| 384 | , disk_partition_t *info) |
| 385 | { |
| 386 | #if defined(CONFIG_CMD_IDE) || \ |
| 387 | defined(CONFIG_CMD_SATA) || \ |
| 388 | defined(CONFIG_CMD_SCSI) || \ |
| 389 | defined(CONFIG_CMD_USB) || \ |
| 390 | defined(CONFIG_MMC) || \ |
| 391 | defined(CONFIG_SYSTEMACE) |
| 392 | |
| 393 | switch (dev_desc->part_type) { |
| 394 | #ifdef CONFIG_MAC_PARTITION |
| 395 | case PART_TYPE_MAC: |
| 396 | if (get_partition_info_mac(dev_desc, part, info) == 0) { |
| 397 | PRINTF("## Valid MAC partition found ##\n"); |
| 398 | return 0; |
| 399 | } |
| 400 | break; |
| 401 | #endif |
| 402 | |
| 403 | #ifdef CONFIG_DOS_PARTITION |
| 404 | case PART_TYPE_DOS: |
| 405 | if (get_partition_info_dos(dev_desc, part, info) == 0) { |
| 406 | PRINTF("## Valid DOS partition found ##\n"); |
| 407 | return 0; |
| 408 | } |
| 409 | break; |
| 410 | #endif |
| 411 | |
| 412 | #ifdef CONFIG_ISO_PARTITION |
| 413 | case PART_TYPE_ISO: |
| 414 | if (get_partition_info_iso(dev_desc, part, info) == 0) { |
| 415 | PRINTF("## Valid ISO boot partition found ##\n"); |
| 416 | return 0; |
| 417 | } |
| 418 | break; |
| 419 | #endif |
| 420 | |
| 421 | #ifdef CONFIG_AMIGA_PARTITION |
| 422 | case PART_TYPE_AMIGA: |
| 423 | if (get_partition_info_amiga(dev_desc, part, info) == 0) { |
| 424 | PRINTF("## Valid Amiga partition found ##\n"); |
| 425 | return 0; |
| 426 | } |
| 427 | break; |
| 428 | #endif |
| 429 | |
| 430 | #ifdef CONFIG_EFI_PARTITION |
| 431 | case PART_TYPE_EFI: |
| 432 | if (get_partition_info_efi(dev_desc, part, info) == 0) { |
| 433 | PRINTF("## Valid EFI partition found ##\n"); |
| 434 | return 0; |
| 435 | } |
| 436 | break; |
| 437 | #endif |
| 438 | default: |
| 439 | break; |
| 440 | } |
| 441 | #endif |
| 442 | |
| 443 | return -1; |
| 444 | } |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 445 | |
Stephen Warren | 2023e60 | 2012-09-21 09:50:56 +0000 | [diff] [blame^] | 446 | int get_device(const char *ifname, const char *dev_str, |
| 447 | block_dev_desc_t **dev_desc) |
| 448 | { |
| 449 | char *ep; |
| 450 | int dev; |
| 451 | |
| 452 | dev = simple_strtoul(dev_str, &ep, 16); |
| 453 | if (*ep) { |
| 454 | printf("** Bad device specification %s %s **\n", |
| 455 | ifname, dev_str); |
| 456 | return -1; |
| 457 | } |
| 458 | |
| 459 | *dev_desc = get_dev(ifname, dev); |
| 460 | if (!(*dev_desc) || ((*dev_desc)->type == DEV_TYPE_UNKNOWN)) { |
| 461 | printf("** Bad device %s %s **\n", ifname, dev_str); |
| 462 | return -1; |
| 463 | } |
| 464 | |
| 465 | return dev; |
| 466 | } |
| 467 | |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 468 | int get_device_and_partition(const char *ifname, const char *dev_str, |
| 469 | block_dev_desc_t **dev_desc, |
| 470 | disk_partition_t *info) |
| 471 | { |
| 472 | int ret; |
| 473 | char *ep; |
| 474 | int dev; |
| 475 | block_dev_desc_t *desc; |
| 476 | int part = 0; |
| 477 | char *part_str; |
| 478 | |
| 479 | if (dev_str) |
| 480 | dev = simple_strtoul(dev_str, &ep, 16); |
| 481 | |
| 482 | if (!dev_str || (dev_str == ep)) { |
| 483 | dev_str = getenv("bootdevice"); |
| 484 | if (dev_str) |
| 485 | dev = simple_strtoul(dev_str, &ep, 16); |
| 486 | if (!dev_str || (dev_str == ep)) |
| 487 | goto err; |
| 488 | } |
| 489 | |
| 490 | desc = get_dev(ifname, dev); |
| 491 | if (!desc || (desc->type == DEV_TYPE_UNKNOWN)) |
| 492 | goto err; |
| 493 | |
| 494 | if (desc->part_type == PART_TYPE_UNKNOWN) { |
| 495 | /* disk doesn't use partition table */ |
| 496 | if (!desc->lba) { |
| 497 | printf("**Bad disk size - %s %d:0 **\n", ifname, dev); |
| 498 | return -1; |
| 499 | } |
| 500 | info->start = 0; |
| 501 | info->size = desc->lba; |
| 502 | info->blksz = desc->blksz; |
| 503 | |
| 504 | *dev_desc = desc; |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | part_str = strchr(dev_str, ':'); |
| 509 | if (part_str) |
| 510 | part = (int)simple_strtoul(++part_str, NULL, 16); |
| 511 | |
| 512 | ret = get_partition_info(desc, part, info); |
| 513 | if (ret) { |
| 514 | printf("** Invalid partition %d, use `dev[:part]' **\n", part); |
| 515 | return -1; |
| 516 | } |
| 517 | if (strncmp((char *)info->type, BOOT_PART_TYPE, sizeof(info->type)) != 0) { |
| 518 | printf("** Invalid partition type \"%.32s\"" |
| 519 | " (expect \"" BOOT_PART_TYPE "\")\n", |
| 520 | info->type); |
| 521 | return -1; |
| 522 | } |
| 523 | |
| 524 | *dev_desc = desc; |
| 525 | return part; |
| 526 | |
| 527 | err: |
| 528 | puts("** Invalid boot device, use `dev[:part]' **\n"); |
| 529 | return -1; |
| 530 | } |