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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
| 10 | #include <ide.h> |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 11 | #include <malloc.h> |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 12 | #include <part.h> |
Hans de Goede | 690c796 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 13 | #include <ubifs_uboot.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 14 | |
| 15 | #undef PART_DEBUG |
| 16 | |
| 17 | #ifdef PART_DEBUG |
| 18 | #define PRINTF(fmt,args...) printf (fmt ,##args) |
| 19 | #else |
| 20 | #define PRINTF(fmt,args...) |
| 21 | #endif |
| 22 | |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 23 | struct block_drvr { |
| 24 | char *name; |
| 25 | block_dev_desc_t* (*get_dev)(int dev); |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 26 | int (*select_hwpart)(int dev_num, int hwpart); |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | static const struct block_drvr block_drvr[] = { |
Jon Loeliger | f7f54a8 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 30 | #if defined(CONFIG_CMD_IDE) |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 31 | { .name = "ide", .get_dev = ide_get_dev, }, |
| 32 | #endif |
Dave Liu | 76596ba | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 33 | #if defined(CONFIG_CMD_SATA) |
| 34 | {.name = "sata", .get_dev = sata_get_dev, }, |
| 35 | #endif |
Jon Loeliger | f7f54a8 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 36 | #if defined(CONFIG_CMD_SCSI) |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 37 | { .name = "scsi", .get_dev = scsi_get_dev, }, |
| 38 | #endif |
Jon Loeliger | f7f54a8 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 39 | #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE) |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 40 | { .name = "usb", .get_dev = usb_stor_get_dev, }, |
| 41 | #endif |
| 42 | #if defined(CONFIG_MMC) |
Stephen Warren | 52c44e4 | 2014-05-07 12:19:02 -0600 | [diff] [blame] | 43 | { |
| 44 | .name = "mmc", |
| 45 | .get_dev = mmc_get_dev, |
| 46 | .select_hwpart = mmc_select_hwpart, |
| 47 | }, |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 48 | #endif |
| 49 | #if defined(CONFIG_SYSTEMACE) |
| 50 | { .name = "ace", .get_dev = systemace_get_dev, }, |
| 51 | #endif |
Henrik Nordström | 26f9a6c | 2013-11-10 10:26:56 -0700 | [diff] [blame] | 52 | #if defined(CONFIG_SANDBOX) |
| 53 | { .name = "host", .get_dev = host_get_dev, }, |
| 54 | #endif |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 55 | { }, |
| 56 | }; |
| 57 | |
Stefan Roese | 61ddee4 | 2007-02-20 13:21:57 +0100 | [diff] [blame] | 58 | DECLARE_GLOBAL_DATA_PTR; |
Stefan Roese | 61ddee4 | 2007-02-20 13:21:57 +0100 | [diff] [blame] | 59 | |
Gabe Black | 0fc71b5 | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 60 | #ifdef HAVE_BLOCK_DEVICE |
Jeroen Hofstee | 3d96843 | 2014-10-08 22:57:33 +0200 | [diff] [blame] | 61 | static block_dev_desc_t *get_dev_hwpart(const char *ifname, int dev, int hwpart) |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 62 | { |
| 63 | const struct block_drvr *drvr = block_drvr; |
Stefan Roese | 5b084e1 | 2007-02-22 07:43:34 +0100 | [diff] [blame] | 64 | block_dev_desc_t* (*reloc_get_dev)(int dev); |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 65 | int (*select_hwpart)(int dev_num, int hwpart); |
Heiko Schocher | 9b98723 | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 66 | char *name; |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 67 | int ret; |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 68 | |
Tim Kientzle | 47e444c | 2012-03-27 11:43:25 +0200 | [diff] [blame] | 69 | if (!ifname) |
| 70 | return NULL; |
| 71 | |
Heiko Schocher | 9b98723 | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 72 | name = drvr->name; |
Wolfgang Denk | d0813e5 | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 73 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
Heiko Schocher | 9b98723 | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 74 | name += gd->reloc_off; |
| 75 | #endif |
Lei Wen | 2a01067 | 2011-02-15 16:56:40 +0800 | [diff] [blame] | 76 | while (drvr->name) { |
Heiko Schocher | 9b98723 | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 77 | name = drvr->name; |
Peter Tyser | 9057cbf | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 78 | reloc_get_dev = drvr->get_dev; |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 79 | select_hwpart = drvr->select_hwpart; |
Wolfgang Denk | d0813e5 | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 80 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
Heiko Schocher | 9b98723 | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 81 | name += gd->reloc_off; |
Peter Tyser | 9057cbf | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 82 | reloc_get_dev += gd->reloc_off; |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 83 | if (select_hwpart) |
| 84 | select_hwpart += gd->reloc_off; |
Peter Tyser | 9057cbf | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 85 | #endif |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 86 | if (strncmp(ifname, name, strlen(name)) == 0) { |
| 87 | block_dev_desc_t *dev_desc = reloc_get_dev(dev); |
| 88 | if (!dev_desc) |
| 89 | return NULL; |
Stephen Warren | ad17c0f | 2014-05-23 12:48:11 -0600 | [diff] [blame] | 90 | if (hwpart == 0 && !select_hwpart) |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 91 | return dev_desc; |
| 92 | if (!select_hwpart) |
| 93 | return NULL; |
| 94 | ret = select_hwpart(dev_desc->dev, hwpart); |
| 95 | if (ret < 0) |
| 96 | return NULL; |
| 97 | return dev_desc; |
| 98 | } |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 99 | drvr++; |
| 100 | } |
| 101 | return NULL; |
| 102 | } |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 103 | |
| 104 | block_dev_desc_t *get_dev(const char *ifname, int dev) |
| 105 | { |
Stephen Warren | ad17c0f | 2014-05-23 12:48:11 -0600 | [diff] [blame] | 106 | return get_dev_hwpart(ifname, dev, 0); |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 107 | } |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 108 | #else |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 109 | block_dev_desc_t *get_dev_hwpart(const char *ifname, int dev, int hwpart) |
| 110 | { |
| 111 | return NULL; |
| 112 | } |
| 113 | |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 114 | block_dev_desc_t *get_dev(const char *ifname, int dev) |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 115 | { |
| 116 | return NULL; |
| 117 | } |
| 118 | #endif |
| 119 | |
Gabe Black | 0fc71b5 | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 120 | #ifdef HAVE_BLOCK_DEVICE |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 121 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 122 | /* ------------------------------------------------------------------------- */ |
| 123 | /* |
| 124 | * reports device info to the user |
| 125 | */ |
Sergei Trofimovich | 89d935b | 2010-08-08 15:05:39 +0300 | [diff] [blame] | 126 | |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 127 | #ifdef CONFIG_LBA48 |
Sergei Trofimovich | 89d935b | 2010-08-08 15:05:39 +0300 | [diff] [blame] | 128 | typedef uint64_t lba512_t; |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 129 | #else |
Sergei Trofimovich | 89d935b | 2010-08-08 15:05:39 +0300 | [diff] [blame] | 130 | typedef lbaint_t lba512_t; |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 131 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 132 | |
Sergei Trofimovich | 89d935b | 2010-08-08 15:05:39 +0300 | [diff] [blame] | 133 | /* |
| 134 | * Overflowless variant of (block_count * mul_by / div_by) |
| 135 | * when div_by > mul_by |
| 136 | */ |
Pavel Machek | a4264e1 | 2014-09-09 15:19:42 +0200 | [diff] [blame] | 137 | static lba512_t lba512_muldiv(lba512_t block_count, lba512_t mul_by, lba512_t div_by) |
Sergei Trofimovich | 89d935b | 2010-08-08 15:05:39 +0300 | [diff] [blame] | 138 | { |
| 139 | lba512_t bc_quot, bc_rem; |
| 140 | |
| 141 | /* x * m / d == x / d * m + (x % d) * m / d */ |
| 142 | bc_quot = block_count / div_by; |
| 143 | bc_rem = block_count - div_by * bc_quot; |
| 144 | return bc_quot * mul_by + (bc_rem * mul_by) / div_by; |
| 145 | } |
| 146 | |
| 147 | void dev_print (block_dev_desc_t *dev_desc) |
| 148 | { |
| 149 | lba512_t lba512; /* number of blocks if 512bytes block size */ |
| 150 | |
Wolfgang Denk | 8561e71 | 2009-05-15 09:27:58 +0200 | [diff] [blame] | 151 | if (dev_desc->type == DEV_TYPE_UNKNOWN) { |
| 152 | puts ("not available\n"); |
| 153 | return; |
| 154 | } |
| 155 | |
Tor Krill | 03ff330 | 2008-05-29 11:10:30 +0200 | [diff] [blame] | 156 | switch (dev_desc->if_type) { |
Detlev Zundel | bec6b32 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 157 | case IF_TYPE_SCSI: |
| 158 | printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n", |
| 159 | dev_desc->target,dev_desc->lun, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 160 | dev_desc->vendor, |
Detlev Zundel | bec6b32 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 161 | dev_desc->product, |
| 162 | dev_desc->revision); |
| 163 | break; |
Remy Bohmer | f9f718b | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 164 | case IF_TYPE_ATAPI: |
Detlev Zundel | bec6b32 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 165 | case IF_TYPE_IDE: |
| 166 | case IF_TYPE_SATA: |
Dave Liu | 76596ba | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 167 | printf ("Model: %s Firm: %s Ser#: %s\n", |
| 168 | dev_desc->vendor, |
| 169 | dev_desc->revision, |
| 170 | dev_desc->product); |
Detlev Zundel | bec6b32 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 171 | break; |
Remy Bohmer | f9f718b | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 172 | case IF_TYPE_SD: |
| 173 | case IF_TYPE_MMC: |
NÃcolas Carneiro Lebedenco | ef3edd4 | 2008-09-04 15:35:46 -0300 | [diff] [blame] | 174 | case IF_TYPE_USB: |
| 175 | printf ("Vendor: %s Rev: %s Prod: %s\n", |
| 176 | dev_desc->vendor, |
| 177 | dev_desc->revision, |
| 178 | dev_desc->product); |
| 179 | break; |
Remy Bohmer | f9f718b | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 180 | case IF_TYPE_DOC: |
| 181 | puts("device type DOC\n"); |
| 182 | return; |
Tor Krill | 03ff330 | 2008-05-29 11:10:30 +0200 | [diff] [blame] | 183 | case IF_TYPE_UNKNOWN: |
Remy Bohmer | f9f718b | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 184 | puts("device type unknown\n"); |
| 185 | return; |
Detlev Zundel | bec6b32 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 186 | default: |
Remy Bohmer | f9f718b | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 187 | printf("Unhandled device type: %i\n", dev_desc->if_type); |
Detlev Zundel | bec6b32 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 188 | return; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 189 | } |
| 190 | puts (" Type: "); |
| 191 | if (dev_desc->removable) |
| 192 | puts ("Removable "); |
| 193 | switch (dev_desc->type & 0x1F) { |
Detlev Zundel | 0e11cc6 | 2008-05-05 16:11:22 +0200 | [diff] [blame] | 194 | case DEV_TYPE_HARDDISK: |
| 195 | puts ("Hard Disk"); |
| 196 | break; |
| 197 | case DEV_TYPE_CDROM: |
| 198 | puts ("CD ROM"); |
| 199 | break; |
| 200 | case DEV_TYPE_OPDISK: |
| 201 | puts ("Optical Device"); |
| 202 | break; |
| 203 | case DEV_TYPE_TAPE: |
| 204 | puts ("Tape"); |
| 205 | break; |
| 206 | default: |
| 207 | printf ("# %02X #", dev_desc->type & 0x1F); |
| 208 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 209 | } |
| 210 | puts ("\n"); |
Jerry Huang | 6a4feb4 | 2012-11-06 15:33:12 +0000 | [diff] [blame] | 211 | if (dev_desc->lba > 0L && dev_desc->blksz > 0L) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 212 | ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem; |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 213 | lbaint_t lba; |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 214 | |
| 215 | lba = dev_desc->lba; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 216 | |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 217 | lba512 = (lba * (dev_desc->blksz/512)); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 218 | /* round to 1 digit */ |
Pavel Machek | a4264e1 | 2014-09-09 15:19:42 +0200 | [diff] [blame] | 219 | /* 2048 = (1024 * 1024) / 512 MB */ |
| 220 | mb = lba512_muldiv(lba512, 10, 2048); |
Sergei Trofimovich | 89d935b | 2010-08-08 15:05:39 +0300 | [diff] [blame] | 221 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 222 | mb_quot = mb / 10; |
| 223 | mb_rem = mb - (10 * mb_quot); |
| 224 | |
| 225 | gb = mb / 1024; |
| 226 | gb_quot = gb / 10; |
| 227 | gb_rem = gb - (10 * gb_quot); |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 228 | #ifdef CONFIG_LBA48 |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 229 | if (dev_desc->lba48) |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 230 | printf (" Supports 48-bit addressing\n"); |
| 231 | #endif |
Heiko Schocher | 0f602e1 | 2009-12-03 11:21:21 +0100 | [diff] [blame] | 232 | #if defined(CONFIG_SYS_64BIT_LBA) |
Mike Frysinger | 2b745dc | 2009-02-16 23:21:36 -0500 | [diff] [blame] | 233 | printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%Ld x %ld)\n", |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 234 | mb_quot, mb_rem, |
| 235 | gb_quot, gb_rem, |
| 236 | lba, |
| 237 | dev_desc->blksz); |
| 238 | #else |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 239 | printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n", |
| 240 | mb_quot, mb_rem, |
| 241 | gb_quot, gb_rem, |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 242 | (ulong)lba, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 243 | dev_desc->blksz); |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 244 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 245 | } else { |
| 246 | puts (" Capacity: not available\n"); |
| 247 | } |
| 248 | } |
Jon Loeliger | 1670a5b | 2007-07-10 11:19:50 -0500 | [diff] [blame] | 249 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 250 | |
Gabe Black | 0fc71b5 | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 251 | #ifdef HAVE_BLOCK_DEVICE |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 252 | |
Pavel Machek | a4264e1 | 2014-09-09 15:19:42 +0200 | [diff] [blame] | 253 | void init_part(block_dev_desc_t *dev_desc) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 254 | { |
| 255 | #ifdef CONFIG_ISO_PARTITION |
| 256 | if (test_part_iso(dev_desc) == 0) { |
| 257 | dev_desc->part_type = PART_TYPE_ISO; |
| 258 | return; |
| 259 | } |
| 260 | #endif |
| 261 | |
| 262 | #ifdef CONFIG_MAC_PARTITION |
| 263 | if (test_part_mac(dev_desc) == 0) { |
| 264 | dev_desc->part_type = PART_TYPE_MAC; |
| 265 | return; |
| 266 | } |
| 267 | #endif |
| 268 | |
richardretanubun | e674559 | 2008-09-26 11:13:22 -0400 | [diff] [blame] | 269 | /* must be placed before DOS partition detection */ |
| 270 | #ifdef CONFIG_EFI_PARTITION |
| 271 | if (test_part_efi(dev_desc) == 0) { |
| 272 | dev_desc->part_type = PART_TYPE_EFI; |
| 273 | return; |
| 274 | } |
| 275 | #endif |
| 276 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 277 | #ifdef CONFIG_DOS_PARTITION |
| 278 | if (test_part_dos(dev_desc) == 0) { |
| 279 | dev_desc->part_type = PART_TYPE_DOS; |
| 280 | return; |
| 281 | } |
| 282 | #endif |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 283 | |
| 284 | #ifdef CONFIG_AMIGA_PARTITION |
| 285 | if (test_part_amiga(dev_desc) == 0) { |
| 286 | dev_desc->part_type = PART_TYPE_AMIGA; |
| 287 | return; |
| 288 | } |
| 289 | #endif |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 290 | dev_desc->part_type = PART_TYPE_UNKNOWN; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | |
Gabe Black | 0fc71b5 | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 294 | #if defined(CONFIG_MAC_PARTITION) || \ |
| 295 | defined(CONFIG_DOS_PARTITION) || \ |
| 296 | defined(CONFIG_ISO_PARTITION) || \ |
| 297 | defined(CONFIG_AMIGA_PARTITION) || \ |
| 298 | defined(CONFIG_EFI_PARTITION) |
| 299 | |
Pavel Machek | a4264e1 | 2014-09-09 15:19:42 +0200 | [diff] [blame] | 300 | static void print_part_header(const char *type, block_dev_desc_t *dev_desc) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 301 | { |
| 302 | puts ("\nPartition Map for "); |
| 303 | switch (dev_desc->if_type) { |
Detlev Zundel | 0e11cc6 | 2008-05-05 16:11:22 +0200 | [diff] [blame] | 304 | case IF_TYPE_IDE: |
| 305 | puts ("IDE"); |
| 306 | break; |
| 307 | case IF_TYPE_SATA: |
| 308 | puts ("SATA"); |
| 309 | break; |
| 310 | case IF_TYPE_SCSI: |
| 311 | puts ("SCSI"); |
| 312 | break; |
| 313 | case IF_TYPE_ATAPI: |
| 314 | puts ("ATAPI"); |
| 315 | break; |
| 316 | case IF_TYPE_USB: |
| 317 | puts ("USB"); |
| 318 | break; |
| 319 | case IF_TYPE_DOC: |
| 320 | puts ("DOC"); |
| 321 | break; |
Lei Wen | 61dba93 | 2010-09-13 22:07:28 +0800 | [diff] [blame] | 322 | case IF_TYPE_MMC: |
| 323 | puts ("MMC"); |
| 324 | break; |
Henrik Nordström | 26f9a6c | 2013-11-10 10:26:56 -0700 | [diff] [blame] | 325 | case IF_TYPE_HOST: |
| 326 | puts("HOST"); |
| 327 | break; |
Detlev Zundel | 0e11cc6 | 2008-05-05 16:11:22 +0200 | [diff] [blame] | 328 | default: |
| 329 | puts ("UNKNOWN"); |
| 330 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 331 | } |
| 332 | printf (" device %d -- Partition Type: %s\n\n", |
| 333 | dev_desc->dev, type); |
| 334 | } |
| 335 | |
Gabe Black | 0fc71b5 | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 336 | #endif /* any CONFIG_..._PARTITION */ |
| 337 | |
Pavel Machek | 13334e7 | 2014-07-19 23:50:44 +0200 | [diff] [blame] | 338 | void print_part(block_dev_desc_t * dev_desc) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 339 | { |
| 340 | |
| 341 | switch (dev_desc->part_type) { |
| 342 | #ifdef CONFIG_MAC_PARTITION |
| 343 | case PART_TYPE_MAC: |
| 344 | PRINTF ("## Testing for valid MAC partition ##\n"); |
| 345 | print_part_header ("MAC", dev_desc); |
| 346 | print_part_mac (dev_desc); |
| 347 | return; |
| 348 | #endif |
| 349 | #ifdef CONFIG_DOS_PARTITION |
| 350 | case PART_TYPE_DOS: |
| 351 | PRINTF ("## Testing for valid DOS partition ##\n"); |
| 352 | print_part_header ("DOS", dev_desc); |
| 353 | print_part_dos (dev_desc); |
| 354 | return; |
| 355 | #endif |
| 356 | |
| 357 | #ifdef CONFIG_ISO_PARTITION |
| 358 | case PART_TYPE_ISO: |
| 359 | PRINTF ("## Testing for valid ISO Boot partition ##\n"); |
| 360 | print_part_header ("ISO", dev_desc); |
| 361 | print_part_iso (dev_desc); |
| 362 | return; |
| 363 | #endif |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 364 | |
| 365 | #ifdef CONFIG_AMIGA_PARTITION |
| 366 | case PART_TYPE_AMIGA: |
| 367 | PRINTF ("## Testing for a valid Amiga partition ##\n"); |
| 368 | print_part_header ("AMIGA", dev_desc); |
| 369 | print_part_amiga (dev_desc); |
| 370 | return; |
| 371 | #endif |
richardretanubun | e674559 | 2008-09-26 11:13:22 -0400 | [diff] [blame] | 372 | |
| 373 | #ifdef CONFIG_EFI_PARTITION |
| 374 | case PART_TYPE_EFI: |
| 375 | PRINTF ("## Testing for valid EFI partition ##\n"); |
| 376 | print_part_header ("EFI", dev_desc); |
| 377 | print_part_efi (dev_desc); |
| 378 | return; |
| 379 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 380 | } |
| 381 | puts ("## Unknown partition table\n"); |
| 382 | } |
| 383 | |
Gabe Black | 0fc71b5 | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 384 | #endif /* HAVE_BLOCK_DEVICE */ |
Stephen Warren | 07c5bff | 2012-09-21 12:46:54 +0000 | [diff] [blame] | 385 | |
Pavel Machek | 13334e7 | 2014-07-19 23:50:44 +0200 | [diff] [blame] | 386 | int get_partition_info(block_dev_desc_t *dev_desc, int part, |
| 387 | disk_partition_t *info) |
Stephen Warren | 07c5bff | 2012-09-21 12:46:54 +0000 | [diff] [blame] | 388 | { |
Gabe Black | 0fc71b5 | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 389 | #ifdef HAVE_BLOCK_DEVICE |
Stephen Warren | 07c5bff | 2012-09-21 12:46:54 +0000 | [diff] [blame] | 390 | |
Stephen Warren | c6c7b7a | 2012-09-21 09:50:59 +0000 | [diff] [blame] | 391 | #ifdef CONFIG_PARTITION_UUIDS |
| 392 | /* The common case is no UUID support */ |
| 393 | info->uuid[0] = 0; |
| 394 | #endif |
| 395 | |
Stephen Warren | 07c5bff | 2012-09-21 12:46:54 +0000 | [diff] [blame] | 396 | switch (dev_desc->part_type) { |
| 397 | #ifdef CONFIG_MAC_PARTITION |
| 398 | case PART_TYPE_MAC: |
| 399 | if (get_partition_info_mac(dev_desc, part, info) == 0) { |
| 400 | PRINTF("## Valid MAC partition found ##\n"); |
| 401 | return 0; |
| 402 | } |
| 403 | break; |
| 404 | #endif |
| 405 | |
| 406 | #ifdef CONFIG_DOS_PARTITION |
| 407 | case PART_TYPE_DOS: |
| 408 | if (get_partition_info_dos(dev_desc, part, info) == 0) { |
| 409 | PRINTF("## Valid DOS partition found ##\n"); |
| 410 | return 0; |
| 411 | } |
| 412 | break; |
| 413 | #endif |
| 414 | |
| 415 | #ifdef CONFIG_ISO_PARTITION |
| 416 | case PART_TYPE_ISO: |
| 417 | if (get_partition_info_iso(dev_desc, part, info) == 0) { |
| 418 | PRINTF("## Valid ISO boot partition found ##\n"); |
| 419 | return 0; |
| 420 | } |
| 421 | break; |
| 422 | #endif |
| 423 | |
| 424 | #ifdef CONFIG_AMIGA_PARTITION |
| 425 | case PART_TYPE_AMIGA: |
| 426 | if (get_partition_info_amiga(dev_desc, part, info) == 0) { |
| 427 | PRINTF("## Valid Amiga partition found ##\n"); |
| 428 | return 0; |
| 429 | } |
| 430 | break; |
| 431 | #endif |
| 432 | |
| 433 | #ifdef CONFIG_EFI_PARTITION |
| 434 | case PART_TYPE_EFI: |
| 435 | if (get_partition_info_efi(dev_desc, part, info) == 0) { |
| 436 | PRINTF("## Valid EFI partition found ##\n"); |
| 437 | return 0; |
| 438 | } |
| 439 | break; |
| 440 | #endif |
| 441 | default: |
| 442 | break; |
| 443 | } |
Gabe Black | 0fc71b5 | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 444 | #endif /* HAVE_BLOCK_DEVICE */ |
Stephen Warren | 07c5bff | 2012-09-21 12:46:54 +0000 | [diff] [blame] | 445 | |
| 446 | return -1; |
| 447 | } |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 448 | |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 449 | int get_device(const char *ifname, const char *dev_hwpart_str, |
Stephen Warren | afd909c | 2012-09-21 09:50:56 +0000 | [diff] [blame] | 450 | block_dev_desc_t **dev_desc) |
| 451 | { |
| 452 | char *ep; |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 453 | char *dup_str = NULL; |
| 454 | const char *dev_str, *hwpart_str; |
| 455 | int dev, hwpart; |
| 456 | |
| 457 | hwpart_str = strchr(dev_hwpart_str, '.'); |
| 458 | if (hwpart_str) { |
| 459 | dup_str = strdup(dev_hwpart_str); |
| 460 | dup_str[hwpart_str - dev_hwpart_str] = 0; |
| 461 | dev_str = dup_str; |
| 462 | hwpart_str++; |
| 463 | } else { |
| 464 | dev_str = dev_hwpart_str; |
Stephen Warren | ad17c0f | 2014-05-23 12:48:11 -0600 | [diff] [blame] | 465 | hwpart = 0; |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 466 | } |
Stephen Warren | afd909c | 2012-09-21 09:50:56 +0000 | [diff] [blame] | 467 | |
| 468 | dev = simple_strtoul(dev_str, &ep, 16); |
| 469 | if (*ep) { |
| 470 | printf("** Bad device specification %s %s **\n", |
| 471 | ifname, dev_str); |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 472 | dev = -1; |
| 473 | goto cleanup; |
| 474 | } |
| 475 | |
| 476 | if (hwpart_str) { |
| 477 | hwpart = simple_strtoul(hwpart_str, &ep, 16); |
| 478 | if (*ep) { |
| 479 | printf("** Bad HW partition specification %s %s **\n", |
| 480 | ifname, hwpart_str); |
| 481 | dev = -1; |
| 482 | goto cleanup; |
| 483 | } |
Stephen Warren | afd909c | 2012-09-21 09:50:56 +0000 | [diff] [blame] | 484 | } |
| 485 | |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 486 | *dev_desc = get_dev_hwpart(ifname, dev, hwpart); |
Stephen Warren | afd909c | 2012-09-21 09:50:56 +0000 | [diff] [blame] | 487 | if (!(*dev_desc) || ((*dev_desc)->type == DEV_TYPE_UNKNOWN)) { |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 488 | printf("** Bad device %s %s **\n", ifname, dev_hwpart_str); |
| 489 | dev = -1; |
| 490 | goto cleanup; |
Stephen Warren | afd909c | 2012-09-21 09:50:56 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Stephen Warren | aeca52f | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 493 | cleanup: |
| 494 | free(dup_str); |
Stephen Warren | afd909c | 2012-09-21 09:50:56 +0000 | [diff] [blame] | 495 | return dev; |
| 496 | } |
| 497 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 498 | #define PART_UNSPECIFIED -2 |
| 499 | #define PART_AUTO -1 |
| 500 | #define MAX_SEARCH_PARTITIONS 16 |
| 501 | int get_device_and_partition(const char *ifname, const char *dev_part_str, |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 502 | block_dev_desc_t **dev_desc, |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 503 | disk_partition_t *info, int allow_whole_dev) |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 504 | { |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 505 | int ret = -1; |
| 506 | const char *part_str; |
| 507 | char *dup_str = NULL; |
| 508 | const char *dev_str; |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 509 | int dev; |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 510 | char *ep; |
| 511 | int p; |
| 512 | int part; |
| 513 | disk_partition_t tmpinfo; |
| 514 | |
Hans de Goede | 690c796 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 515 | #if defined CONFIG_SANDBOX && defined CONFIG_CMD_UBIFS |
| 516 | #error Only one of CONFIG_SANDBOX and CONFIG_CMD_UBIFS may be selected |
| 517 | #endif |
| 518 | |
Hans de Goede | 4763ee3 | 2015-09-17 18:46:55 -0400 | [diff] [blame] | 519 | #ifdef CONFIG_SANDBOX |
Stephen Warren | bff6c31 | 2014-06-12 10:28:32 -0600 | [diff] [blame] | 520 | /* |
Pavel Machek | 13334e7 | 2014-07-19 23:50:44 +0200 | [diff] [blame] | 521 | * Special-case a pseudo block device "hostfs", to allow access to the |
Stephen Warren | bff6c31 | 2014-06-12 10:28:32 -0600 | [diff] [blame] | 522 | * host's own filesystem. |
| 523 | */ |
| 524 | if (0 == strcmp(ifname, "hostfs")) { |
| 525 | *dev_desc = NULL; |
| 526 | info->start = 0; |
| 527 | info->size = 0; |
| 528 | info->blksz = 0; |
| 529 | info->bootable = 0; |
| 530 | strcpy((char *)info->type, BOOT_PART_TYPE); |
| 531 | strcpy((char *)info->name, "Sandbox host"); |
| 532 | #ifdef CONFIG_PARTITION_UUIDS |
| 533 | info->uuid[0] = 0; |
| 534 | #endif |
| 535 | |
Hans de Goede | 690c796 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 536 | return 0; |
| 537 | } |
| 538 | #endif |
| 539 | |
| 540 | #ifdef CONFIG_CMD_UBIFS |
| 541 | /* |
| 542 | * Special-case ubi, ubi goes through a mtd, rathen then through |
| 543 | * a regular block device. |
| 544 | */ |
| 545 | if (0 == strcmp(ifname, "ubi")) { |
| 546 | if (!ubifs_is_mounted()) { |
| 547 | printf("UBIFS not mounted, use ubifsmount to mount volume first!\n"); |
| 548 | return -1; |
| 549 | } |
| 550 | |
| 551 | *dev_desc = NULL; |
| 552 | memset(info, 0, sizeof(*info)); |
| 553 | strcpy((char *)info->type, BOOT_PART_TYPE); |
| 554 | strcpy((char *)info->name, "UBI"); |
| 555 | #ifdef CONFIG_PARTITION_UUIDS |
| 556 | info->uuid[0] = 0; |
| 557 | #endif |
Stephen Warren | bff6c31 | 2014-06-12 10:28:32 -0600 | [diff] [blame] | 558 | return 0; |
| 559 | } |
Hans de Goede | 4763ee3 | 2015-09-17 18:46:55 -0400 | [diff] [blame] | 560 | #endif |
Stephen Warren | bff6c31 | 2014-06-12 10:28:32 -0600 | [diff] [blame] | 561 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 562 | /* If no dev_part_str, use bootdevice environment variable */ |
Stephen Warren | a95af94 | 2012-09-28 05:34:09 +0000 | [diff] [blame] | 563 | if (!dev_part_str || !strlen(dev_part_str) || |
| 564 | !strcmp(dev_part_str, "-")) |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 565 | dev_part_str = getenv("bootdevice"); |
| 566 | |
| 567 | /* If still no dev_part_str, it's an error */ |
| 568 | if (!dev_part_str) { |
| 569 | printf("** No device specified **\n"); |
| 570 | goto cleanup; |
| 571 | } |
| 572 | |
| 573 | /* Separate device and partition ID specification */ |
| 574 | part_str = strchr(dev_part_str, ':'); |
| 575 | if (part_str) { |
| 576 | dup_str = strdup(dev_part_str); |
| 577 | dup_str[part_str - dev_part_str] = 0; |
| 578 | dev_str = dup_str; |
| 579 | part_str++; |
| 580 | } else { |
| 581 | dev_str = dev_part_str; |
| 582 | } |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 583 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 584 | /* Look up the device */ |
| 585 | dev = get_device(ifname, dev_str, dev_desc); |
| 586 | if (dev < 0) |
| 587 | goto cleanup; |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 588 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 589 | /* Convert partition ID string to number */ |
| 590 | if (!part_str || !*part_str) { |
| 591 | part = PART_UNSPECIFIED; |
| 592 | } else if (!strcmp(part_str, "auto")) { |
| 593 | part = PART_AUTO; |
| 594 | } else { |
| 595 | /* Something specified -> use exactly that */ |
| 596 | part = (int)simple_strtoul(part_str, &ep, 16); |
| 597 | /* |
| 598 | * Less than whole string converted, |
| 599 | * or request for whole device, but caller requires partition. |
| 600 | */ |
| 601 | if (*ep || (part == 0 && !allow_whole_dev)) { |
| 602 | printf("** Bad partition specification %s %s **\n", |
| 603 | ifname, dev_part_str); |
| 604 | goto cleanup; |
| 605 | } |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 608 | /* |
| 609 | * No partition table on device, |
| 610 | * or user requested partition 0 (entire device). |
| 611 | */ |
| 612 | if (((*dev_desc)->part_type == PART_TYPE_UNKNOWN) || |
| 613 | (part == 0)) { |
| 614 | if (!(*dev_desc)->lba) { |
| 615 | printf("** Bad device size - %s %s **\n", ifname, |
| 616 | dev_str); |
| 617 | goto cleanup; |
| 618 | } |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 619 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 620 | /* |
| 621 | * If user specified a partition ID other than 0, |
| 622 | * or the calling command only accepts partitions, |
| 623 | * it's an error. |
| 624 | */ |
| 625 | if ((part > 0) || (!allow_whole_dev)) { |
| 626 | printf("** No partition table - %s %s **\n", ifname, |
| 627 | dev_str); |
| 628 | goto cleanup; |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 629 | } |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 630 | |
Lan Yixun (dlan) | 138914e | 2013-07-20 08:17:59 +0800 | [diff] [blame] | 631 | (*dev_desc)->log2blksz = LOG2((*dev_desc)->blksz); |
| 632 | |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 633 | info->start = 0; |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 634 | info->size = (*dev_desc)->lba; |
| 635 | info->blksz = (*dev_desc)->blksz; |
| 636 | info->bootable = 0; |
Stephen Warren | 65be849 | 2012-10-10 07:57:51 +0000 | [diff] [blame] | 637 | strcpy((char *)info->type, BOOT_PART_TYPE); |
| 638 | strcpy((char *)info->name, "Whole Disk"); |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 639 | #ifdef CONFIG_PARTITION_UUIDS |
| 640 | info->uuid[0] = 0; |
| 641 | #endif |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 642 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 643 | ret = 0; |
| 644 | goto cleanup; |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 647 | /* |
| 648 | * Now there's known to be a partition table, |
| 649 | * not specifying a partition means to pick partition 1. |
| 650 | */ |
| 651 | if (part == PART_UNSPECIFIED) |
| 652 | part = 1; |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 653 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 654 | /* |
| 655 | * If user didn't specify a partition number, or did specify something |
| 656 | * other than "auto", use that partition number directly. |
| 657 | */ |
| 658 | if (part != PART_AUTO) { |
| 659 | ret = get_partition_info(*dev_desc, part, info); |
| 660 | if (ret) { |
| 661 | printf("** Invalid partition %d **\n", part); |
| 662 | goto cleanup; |
| 663 | } |
| 664 | } else { |
| 665 | /* |
| 666 | * Find the first bootable partition. |
| 667 | * If none are bootable, fall back to the first valid partition. |
| 668 | */ |
| 669 | part = 0; |
| 670 | for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) { |
| 671 | ret = get_partition_info(*dev_desc, p, info); |
| 672 | if (ret) |
| 673 | continue; |
| 674 | |
| 675 | /* |
| 676 | * First valid partition, or new better partition? |
| 677 | * If so, save partition ID. |
| 678 | */ |
| 679 | if (!part || info->bootable) |
| 680 | part = p; |
| 681 | |
| 682 | /* Best possible partition? Stop searching. */ |
| 683 | if (info->bootable) |
| 684 | break; |
| 685 | |
| 686 | /* |
| 687 | * We now need to search further for best possible. |
| 688 | * If we what we just queried was the best so far, |
| 689 | * save the info since we over-write it next loop. |
| 690 | */ |
| 691 | if (part == p) |
| 692 | tmpinfo = *info; |
| 693 | } |
| 694 | /* If we found any acceptable partition */ |
| 695 | if (part) { |
| 696 | /* |
| 697 | * If we searched all possible partition IDs, |
| 698 | * return the first valid partition we found. |
| 699 | */ |
| 700 | if (p == MAX_SEARCH_PARTITIONS + 1) |
| 701 | *info = tmpinfo; |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 702 | } else { |
| 703 | printf("** No valid partitions found **\n"); |
Stephen Warren | 3c28be9 | 2012-10-08 07:45:54 +0000 | [diff] [blame] | 704 | ret = -1; |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 705 | goto cleanup; |
| 706 | } |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 707 | } |
| 708 | if (strncmp((char *)info->type, BOOT_PART_TYPE, sizeof(info->type)) != 0) { |
| 709 | printf("** Invalid partition type \"%.32s\"" |
| 710 | " (expect \"" BOOT_PART_TYPE "\")\n", |
| 711 | info->type); |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 712 | ret = -1; |
| 713 | goto cleanup; |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 714 | } |
| 715 | |
Lan Yixun (dlan) | 138914e | 2013-07-20 08:17:59 +0800 | [diff] [blame] | 716 | (*dev_desc)->log2blksz = LOG2((*dev_desc)->blksz); |
| 717 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 718 | ret = part; |
| 719 | goto cleanup; |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 720 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 721 | cleanup: |
| 722 | free(dup_str); |
| 723 | return ret; |
Rob Herring | d586cec | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 724 | } |