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 | 1a45966 | 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> |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 10 | #include <errno.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 11 | #include <ide.h> |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 12 | #include <malloc.h> |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 13 | #include <part.h> |
Hans de Goede | 251cee0 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 14 | #include <ubifs_uboot.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 15 | |
| 16 | #undef PART_DEBUG |
| 17 | |
| 18 | #ifdef PART_DEBUG |
| 19 | #define PRINTF(fmt,args...) printf (fmt ,##args) |
| 20 | #else |
| 21 | #define PRINTF(fmt,args...) |
| 22 | #endif |
| 23 | |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 24 | struct block_drvr { |
| 25 | char *name; |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 26 | struct blk_desc* (*get_dev)(int dev); |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 27 | int (*select_hwpart)(int dev_num, int hwpart); |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | static const struct block_drvr block_drvr[] = { |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 31 | #if defined(CONFIG_CMD_IDE) |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 32 | { .name = "ide", .get_dev = ide_get_dev, }, |
| 33 | #endif |
Dave Liu | c7057b5 | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 34 | #if defined(CONFIG_CMD_SATA) |
| 35 | {.name = "sata", .get_dev = sata_get_dev, }, |
| 36 | #endif |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 37 | #if defined(CONFIG_CMD_SCSI) |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 38 | { .name = "scsi", .get_dev = scsi_get_dev, }, |
| 39 | #endif |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 40 | #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE) |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 41 | { .name = "usb", .get_dev = usb_stor_get_dev, }, |
| 42 | #endif |
| 43 | #if defined(CONFIG_MMC) |
Stephen Warren | d235628 | 2014-05-07 12:19:02 -0600 | [diff] [blame] | 44 | { |
| 45 | .name = "mmc", |
| 46 | .get_dev = mmc_get_dev, |
| 47 | .select_hwpart = mmc_select_hwpart, |
| 48 | }, |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 49 | #endif |
| 50 | #if defined(CONFIG_SYSTEMACE) |
| 51 | { .name = "ace", .get_dev = systemace_get_dev, }, |
| 52 | #endif |
Henrik Nordström | f4d8de4 | 2013-11-10 10:26:56 -0700 | [diff] [blame] | 53 | #if defined(CONFIG_SANDBOX) |
| 54 | { .name = "host", .get_dev = host_get_dev, }, |
| 55 | #endif |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 56 | { }, |
| 57 | }; |
| 58 | |
Stefan Roese | 751bb57 | 2007-02-20 13:21:57 +0100 | [diff] [blame] | 59 | DECLARE_GLOBAL_DATA_PTR; |
Stefan Roese | 751bb57 | 2007-02-20 13:21:57 +0100 | [diff] [blame] | 60 | |
Gabe Black | 0c9c8fb | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 61 | #ifdef HAVE_BLOCK_DEVICE |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 62 | static struct part_driver *part_driver_lookup_type(int part_type) |
| 63 | { |
| 64 | struct part_driver *drv = |
| 65 | ll_entry_start(struct part_driver, part_driver); |
| 66 | const int n_ents = ll_entry_count(struct part_driver, part_driver); |
| 67 | struct part_driver *entry; |
| 68 | |
| 69 | for (entry = drv; entry != drv + n_ents; entry++) { |
| 70 | if (part_type == entry->part_type) |
| 71 | return entry; |
| 72 | } |
| 73 | |
| 74 | /* Not found */ |
| 75 | return NULL; |
| 76 | } |
| 77 | |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 78 | static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart) |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 79 | { |
| 80 | const struct block_drvr *drvr = block_drvr; |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 81 | struct blk_desc* (*reloc_get_dev)(int dev); |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 82 | int (*select_hwpart)(int dev_num, int hwpart); |
Heiko Schocher | 23090da | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 83 | char *name; |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 84 | int ret; |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 85 | |
Tim Kientzle | 7e71dc6 | 2012-03-27 11:43:25 +0200 | [diff] [blame] | 86 | if (!ifname) |
| 87 | return NULL; |
| 88 | |
Heiko Schocher | 23090da | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 89 | name = drvr->name; |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 90 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
Heiko Schocher | 23090da | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 91 | name += gd->reloc_off; |
| 92 | #endif |
Lei Wen | b16aadf | 2011-02-15 16:56:40 +0800 | [diff] [blame] | 93 | while (drvr->name) { |
Heiko Schocher | 23090da | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 94 | name = drvr->name; |
Peter Tyser | 521af04 | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 95 | reloc_get_dev = drvr->get_dev; |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 96 | select_hwpart = drvr->select_hwpart; |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 97 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
Heiko Schocher | 23090da | 2010-09-17 13:10:36 +0200 | [diff] [blame] | 98 | name += gd->reloc_off; |
Peter Tyser | 521af04 | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 99 | reloc_get_dev += gd->reloc_off; |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 100 | if (select_hwpart) |
| 101 | select_hwpart += gd->reloc_off; |
Peter Tyser | 521af04 | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 102 | #endif |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 103 | if (strncmp(ifname, name, strlen(name)) == 0) { |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 104 | struct blk_desc *dev_desc = reloc_get_dev(dev); |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 105 | if (!dev_desc) |
| 106 | return NULL; |
Stephen Warren | ecdd57e | 2014-05-23 12:48:11 -0600 | [diff] [blame] | 107 | if (hwpart == 0 && !select_hwpart) |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 108 | return dev_desc; |
| 109 | if (!select_hwpart) |
| 110 | return NULL; |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 111 | ret = select_hwpart(dev_desc->devnum, hwpart); |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 112 | if (ret < 0) |
| 113 | return NULL; |
| 114 | return dev_desc; |
| 115 | } |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 116 | drvr++; |
| 117 | } |
| 118 | return NULL; |
| 119 | } |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 120 | |
Simon Glass | db1d9e7 | 2016-02-29 15:25:42 -0700 | [diff] [blame] | 121 | struct blk_desc *blk_get_dev(const char *ifname, int dev) |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 122 | { |
Stephen Warren | ecdd57e | 2014-05-23 12:48:11 -0600 | [diff] [blame] | 123 | return get_dev_hwpart(ifname, dev, 0); |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 124 | } |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 125 | #else |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 126 | struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart) |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 127 | { |
| 128 | return NULL; |
| 129 | } |
| 130 | |
Simon Glass | db1d9e7 | 2016-02-29 15:25:42 -0700 | [diff] [blame] | 131 | struct blk_desc *blk_get_dev(const char *ifname, int dev) |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 132 | { |
| 133 | return NULL; |
| 134 | } |
| 135 | #endif |
| 136 | |
Gabe Black | 0c9c8fb | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 137 | #ifdef HAVE_BLOCK_DEVICE |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 138 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 139 | /* ------------------------------------------------------------------------- */ |
| 140 | /* |
| 141 | * reports device info to the user |
| 142 | */ |
Sergei Trofimovich | 69a2a4d | 2010-08-08 15:05:39 +0300 | [diff] [blame] | 143 | |
| 144 | #ifdef CONFIG_LBA48 |
| 145 | typedef uint64_t lba512_t; |
| 146 | #else |
| 147 | typedef lbaint_t lba512_t; |
| 148 | #endif |
| 149 | |
| 150 | /* |
| 151 | * Overflowless variant of (block_count * mul_by / div_by) |
| 152 | * when div_by > mul_by |
| 153 | */ |
Pavel Machek | 214b3f3 | 2014-09-09 15:19:42 +0200 | [diff] [blame] | 154 | static lba512_t lba512_muldiv(lba512_t block_count, lba512_t mul_by, lba512_t div_by) |
Sergei Trofimovich | 69a2a4d | 2010-08-08 15:05:39 +0300 | [diff] [blame] | 155 | { |
| 156 | lba512_t bc_quot, bc_rem; |
| 157 | |
| 158 | /* x * m / d == x / d * m + (x % d) * m / d */ |
| 159 | bc_quot = block_count / div_by; |
| 160 | bc_rem = block_count - div_by * bc_quot; |
| 161 | return bc_quot * mul_by + (bc_rem * mul_by) / div_by; |
| 162 | } |
| 163 | |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 164 | void dev_print (struct blk_desc *dev_desc) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 165 | { |
Sergei Trofimovich | 69a2a4d | 2010-08-08 15:05:39 +0300 | [diff] [blame] | 166 | lba512_t lba512; /* number of blocks if 512bytes block size */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 167 | |
Wolfgang Denk | af75a45 | 2009-05-15 09:27:58 +0200 | [diff] [blame] | 168 | if (dev_desc->type == DEV_TYPE_UNKNOWN) { |
| 169 | puts ("not available\n"); |
| 170 | return; |
| 171 | } |
| 172 | |
Tor Krill | 8ec6e33 | 2008-05-29 11:10:30 +0200 | [diff] [blame] | 173 | switch (dev_desc->if_type) { |
Detlev Zundel | 574b319 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 174 | case IF_TYPE_SCSI: |
| 175 | printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n", |
| 176 | dev_desc->target,dev_desc->lun, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 177 | dev_desc->vendor, |
| 178 | dev_desc->product, |
| 179 | dev_desc->revision); |
Detlev Zundel | 574b319 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 180 | break; |
Remy Bohmer | 6e24a1e | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 181 | case IF_TYPE_ATAPI: |
Detlev Zundel | 574b319 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 182 | case IF_TYPE_IDE: |
| 183 | case IF_TYPE_SATA: |
| 184 | printf ("Model: %s Firm: %s Ser#: %s\n", |
| 185 | dev_desc->vendor, |
| 186 | dev_desc->revision, |
| 187 | dev_desc->product); |
| 188 | break; |
Remy Bohmer | 6e24a1e | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 189 | case IF_TYPE_SD: |
| 190 | case IF_TYPE_MMC: |
NÃcolas Carneiro Lebedenco | 47bebe3 | 2008-09-04 15:35:46 -0300 | [diff] [blame] | 191 | case IF_TYPE_USB: |
| 192 | printf ("Vendor: %s Rev: %s Prod: %s\n", |
| 193 | dev_desc->vendor, |
| 194 | dev_desc->revision, |
| 195 | dev_desc->product); |
| 196 | break; |
Remy Bohmer | 6e24a1e | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 197 | case IF_TYPE_DOC: |
| 198 | puts("device type DOC\n"); |
| 199 | return; |
Tor Krill | 8ec6e33 | 2008-05-29 11:10:30 +0200 | [diff] [blame] | 200 | case IF_TYPE_UNKNOWN: |
Remy Bohmer | 6e24a1e | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 201 | puts("device type unknown\n"); |
| 202 | return; |
Detlev Zundel | 574b319 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 203 | default: |
Remy Bohmer | 6e24a1e | 2008-09-19 13:30:06 +0200 | [diff] [blame] | 204 | printf("Unhandled device type: %i\n", dev_desc->if_type); |
Detlev Zundel | 574b319 | 2008-05-05 16:11:21 +0200 | [diff] [blame] | 205 | return; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 206 | } |
| 207 | puts (" Type: "); |
| 208 | if (dev_desc->removable) |
| 209 | puts ("Removable "); |
| 210 | switch (dev_desc->type & 0x1F) { |
Detlev Zundel | 726c0f1 | 2008-05-05 16:11:22 +0200 | [diff] [blame] | 211 | case DEV_TYPE_HARDDISK: |
| 212 | puts ("Hard Disk"); |
| 213 | break; |
| 214 | case DEV_TYPE_CDROM: |
| 215 | puts ("CD ROM"); |
| 216 | break; |
| 217 | case DEV_TYPE_OPDISK: |
| 218 | puts ("Optical Device"); |
| 219 | break; |
| 220 | case DEV_TYPE_TAPE: |
| 221 | puts ("Tape"); |
| 222 | break; |
| 223 | default: |
| 224 | printf ("# %02X #", dev_desc->type & 0x1F); |
| 225 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 226 | } |
| 227 | puts ("\n"); |
Jerry Huang | 33699df | 2012-11-06 15:33:12 +0000 | [diff] [blame] | 228 | if (dev_desc->lba > 0L && dev_desc->blksz > 0L) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 229 | ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem; |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 230 | lbaint_t lba; |
wdenk | 6e59238 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 231 | |
| 232 | lba = dev_desc->lba; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 233 | |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 234 | lba512 = (lba * (dev_desc->blksz/512)); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 235 | /* round to 1 digit */ |
Pavel Machek | 214b3f3 | 2014-09-09 15:19:42 +0200 | [diff] [blame] | 236 | /* 2048 = (1024 * 1024) / 512 MB */ |
| 237 | mb = lba512_muldiv(lba512, 10, 2048); |
Sergei Trofimovich | 69a2a4d | 2010-08-08 15:05:39 +0300 | [diff] [blame] | 238 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 239 | mb_quot = mb / 10; |
| 240 | mb_rem = mb - (10 * mb_quot); |
| 241 | |
| 242 | gb = mb / 1024; |
| 243 | gb_quot = gb / 10; |
| 244 | gb_rem = gb - (10 * gb_quot); |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 245 | #ifdef CONFIG_LBA48 |
wdenk | 6e59238 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 246 | if (dev_desc->lba48) |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 247 | printf (" Supports 48-bit addressing\n"); |
| 248 | #endif |
Heiko Schocher | 4b142fe | 2009-12-03 11:21:21 +0100 | [diff] [blame] | 249 | #if defined(CONFIG_SYS_64BIT_LBA) |
Mike Frysinger | 6c6166f | 2009-02-16 23:21:36 -0500 | [diff] [blame] | 250 | printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%Ld x %ld)\n", |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 251 | mb_quot, mb_rem, |
| 252 | gb_quot, gb_rem, |
| 253 | lba, |
| 254 | dev_desc->blksz); |
| 255 | #else |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 256 | printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n", |
| 257 | mb_quot, mb_rem, |
| 258 | gb_quot, gb_rem, |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 259 | (ulong)lba, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 260 | dev_desc->blksz); |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 261 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 262 | } else { |
| 263 | puts (" Capacity: not available\n"); |
| 264 | } |
| 265 | } |
Jon Loeliger | b3aff0c | 2007-07-10 11:19:50 -0500 | [diff] [blame] | 266 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 267 | |
Gabe Black | 0c9c8fb | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 268 | #ifdef HAVE_BLOCK_DEVICE |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 269 | |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 270 | void part_init(struct blk_desc *dev_desc) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 271 | { |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 272 | struct part_driver *drv = |
| 273 | ll_entry_start(struct part_driver, part_driver); |
| 274 | const int n_ents = ll_entry_count(struct part_driver, part_driver); |
| 275 | struct part_driver *entry; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 276 | |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 277 | dev_desc->part_type = PART_TYPE_UNKNOWN; |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 278 | for (entry = drv; entry != drv + n_ents; entry++) { |
| 279 | int ret; |
| 280 | |
| 281 | ret = entry->test(dev_desc); |
| 282 | debug("%s: try '%s': ret=%d\n", __func__, entry->name, ret); |
| 283 | if (!ret) { |
| 284 | dev_desc->part_type = entry->part_type; |
| 285 | break; |
| 286 | } |
| 287 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 290 | static void print_part_header(const char *type, struct blk_desc *dev_desc) |
| 291 | { |
Gabe Black | 0c9c8fb | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 292 | #if defined(CONFIG_MAC_PARTITION) || \ |
| 293 | defined(CONFIG_DOS_PARTITION) || \ |
| 294 | defined(CONFIG_ISO_PARTITION) || \ |
| 295 | defined(CONFIG_AMIGA_PARTITION) || \ |
| 296 | defined(CONFIG_EFI_PARTITION) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 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; |
Henrik Nordström | f4d8de4 | 2013-11-10 10:26:56 -0700 | [diff] [blame] | 320 | case IF_TYPE_HOST: |
| 321 | puts("HOST"); |
| 322 | break; |
Detlev Zundel | 726c0f1 | 2008-05-05 16:11:22 +0200 | [diff] [blame] | 323 | default: |
| 324 | puts ("UNKNOWN"); |
| 325 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 326 | } |
| 327 | printf (" device %d -- Partition Type: %s\n\n", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 328 | dev_desc->devnum, type); |
Gabe Black | 0c9c8fb | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 329 | #endif /* any CONFIG_..._PARTITION */ |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 330 | } |
Gabe Black | 0c9c8fb | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 331 | |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 332 | void part_print(struct blk_desc *dev_desc) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 333 | { |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 334 | struct part_driver *drv; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 335 | |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 336 | drv = part_driver_lookup_type(dev_desc->part_type); |
| 337 | if (!drv) { |
| 338 | printf("## Unknown partition table type %x\n", |
| 339 | dev_desc->part_type); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 340 | return; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 341 | } |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 342 | |
| 343 | PRINTF("## Testing for valid %s partition ##\n", drv->name); |
| 344 | print_part_header(drv->name, dev_desc); |
| 345 | if (drv->print) |
| 346 | drv->print(dev_desc); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Gabe Black | 0c9c8fb | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 349 | #endif /* HAVE_BLOCK_DEVICE */ |
Stephen Warren | 2f50164 | 2012-09-21 12:46:54 +0000 | [diff] [blame] | 350 | |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 351 | int part_get_info(struct blk_desc *dev_desc, int part, |
Pavel Machek | 3f9eb6e | 2014-07-19 23:50:44 +0200 | [diff] [blame] | 352 | disk_partition_t *info) |
Stephen Warren | 2f50164 | 2012-09-21 12:46:54 +0000 | [diff] [blame] | 353 | { |
Gabe Black | 0c9c8fb | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 354 | #ifdef HAVE_BLOCK_DEVICE |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 355 | struct part_driver *drv; |
Stephen Warren | 2f50164 | 2012-09-21 12:46:54 +0000 | [diff] [blame] | 356 | |
Stephen Warren | 894bfbb | 2012-09-21 09:50:59 +0000 | [diff] [blame] | 357 | #ifdef CONFIG_PARTITION_UUIDS |
| 358 | /* The common case is no UUID support */ |
| 359 | info->uuid[0] = 0; |
| 360 | #endif |
Patrick Delaunay | 7561b25 | 2015-10-27 11:00:27 +0100 | [diff] [blame] | 361 | #ifdef CONFIG_PARTITION_TYPE_GUID |
| 362 | info->type_guid[0] = 0; |
| 363 | #endif |
Stephen Warren | 894bfbb | 2012-09-21 09:50:59 +0000 | [diff] [blame] | 364 | |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 365 | drv = part_driver_lookup_type(dev_desc->part_type); |
| 366 | if (!drv) { |
| 367 | debug("## Unknown partition table type %x\n", |
| 368 | dev_desc->part_type); |
| 369 | return -EPROTONOSUPPORT; |
| 370 | } |
| 371 | if (!drv->get_info) { |
| 372 | PRINTF("## Driver %s does not have the get_info() method\n"); |
| 373 | return -ENOSYS; |
| 374 | } |
| 375 | if (drv->get_info(dev_desc, part, info) == 0) { |
| 376 | PRINTF("## Valid %s partition found ##\n", drv->name); |
| 377 | return 0; |
Stephen Warren | 2f50164 | 2012-09-21 12:46:54 +0000 | [diff] [blame] | 378 | } |
Gabe Black | 0c9c8fb | 2012-10-12 14:26:08 +0000 | [diff] [blame] | 379 | #endif /* HAVE_BLOCK_DEVICE */ |
Stephen Warren | 2f50164 | 2012-09-21 12:46:54 +0000 | [diff] [blame] | 380 | |
| 381 | return -1; |
| 382 | } |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 383 | |
Simon Glass | ebac37c | 2016-02-29 15:25:43 -0700 | [diff] [blame] | 384 | int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str, |
| 385 | struct blk_desc **dev_desc) |
Stephen Warren | 2023e60 | 2012-09-21 09:50:56 +0000 | [diff] [blame] | 386 | { |
| 387 | char *ep; |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 388 | char *dup_str = NULL; |
| 389 | const char *dev_str, *hwpart_str; |
| 390 | int dev, hwpart; |
| 391 | |
| 392 | hwpart_str = strchr(dev_hwpart_str, '.'); |
| 393 | if (hwpart_str) { |
| 394 | dup_str = strdup(dev_hwpart_str); |
| 395 | dup_str[hwpart_str - dev_hwpart_str] = 0; |
| 396 | dev_str = dup_str; |
| 397 | hwpart_str++; |
| 398 | } else { |
| 399 | dev_str = dev_hwpart_str; |
Stephen Warren | ecdd57e | 2014-05-23 12:48:11 -0600 | [diff] [blame] | 400 | hwpart = 0; |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 401 | } |
Stephen Warren | 2023e60 | 2012-09-21 09:50:56 +0000 | [diff] [blame] | 402 | |
| 403 | dev = simple_strtoul(dev_str, &ep, 16); |
| 404 | if (*ep) { |
| 405 | printf("** Bad device specification %s %s **\n", |
| 406 | ifname, dev_str); |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 407 | dev = -1; |
| 408 | goto cleanup; |
Stephen Warren | 2023e60 | 2012-09-21 09:50:56 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 411 | if (hwpart_str) { |
| 412 | hwpart = simple_strtoul(hwpart_str, &ep, 16); |
| 413 | if (*ep) { |
| 414 | printf("** Bad HW partition specification %s %s **\n", |
| 415 | ifname, hwpart_str); |
| 416 | dev = -1; |
| 417 | goto cleanup; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | *dev_desc = get_dev_hwpart(ifname, dev, hwpart); |
Stephen Warren | 2023e60 | 2012-09-21 09:50:56 +0000 | [diff] [blame] | 422 | if (!(*dev_desc) || ((*dev_desc)->type == DEV_TYPE_UNKNOWN)) { |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 423 | printf("** Bad device %s %s **\n", ifname, dev_hwpart_str); |
| 424 | dev = -1; |
| 425 | goto cleanup; |
Stephen Warren | 2023e60 | 2012-09-21 09:50:56 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Erik Tideman | 99e7fc8 | 2016-01-11 13:39:07 +0000 | [diff] [blame] | 428 | #ifdef HAVE_BLOCK_DEVICE |
| 429 | /* |
| 430 | * Updates the partition table for the specified hw partition. |
| 431 | * Does not need to be done for hwpart 0 since it is default and |
| 432 | * already loaded. |
| 433 | */ |
| 434 | if(hwpart != 0) |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 435 | part_init(*dev_desc); |
Erik Tideman | 99e7fc8 | 2016-01-11 13:39:07 +0000 | [diff] [blame] | 436 | #endif |
| 437 | |
Stephen Warren | 336b6f9 | 2014-05-07 12:19:01 -0600 | [diff] [blame] | 438 | cleanup: |
| 439 | free(dup_str); |
Stephen Warren | 2023e60 | 2012-09-21 09:50:56 +0000 | [diff] [blame] | 440 | return dev; |
| 441 | } |
| 442 | |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 443 | #define PART_UNSPECIFIED -2 |
| 444 | #define PART_AUTO -1 |
| 445 | #define MAX_SEARCH_PARTITIONS 16 |
Simon Glass | e35929e | 2016-02-29 15:25:44 -0700 | [diff] [blame] | 446 | int blk_get_device_part_str(const char *ifname, const char *dev_part_str, |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 447 | struct blk_desc **dev_desc, |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 448 | disk_partition_t *info, int allow_whole_dev) |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 449 | { |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 450 | int ret = -1; |
| 451 | const char *part_str; |
| 452 | char *dup_str = NULL; |
| 453 | const char *dev_str; |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 454 | int dev; |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 455 | char *ep; |
| 456 | int p; |
| 457 | int part; |
| 458 | disk_partition_t tmpinfo; |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 459 | |
Hans de Goede | afc1744 | 2015-09-17 18:46:55 -0400 | [diff] [blame] | 460 | #ifdef CONFIG_SANDBOX |
Stephen Warren | 4d90702 | 2014-06-12 10:28:32 -0600 | [diff] [blame] | 461 | /* |
Pavel Machek | 3f9eb6e | 2014-07-19 23:50:44 +0200 | [diff] [blame] | 462 | * Special-case a pseudo block device "hostfs", to allow access to the |
Stephen Warren | 4d90702 | 2014-06-12 10:28:32 -0600 | [diff] [blame] | 463 | * host's own filesystem. |
| 464 | */ |
| 465 | if (0 == strcmp(ifname, "hostfs")) { |
| 466 | *dev_desc = NULL; |
| 467 | info->start = 0; |
| 468 | info->size = 0; |
| 469 | info->blksz = 0; |
| 470 | info->bootable = 0; |
| 471 | strcpy((char *)info->type, BOOT_PART_TYPE); |
| 472 | strcpy((char *)info->name, "Sandbox host"); |
| 473 | #ifdef CONFIG_PARTITION_UUIDS |
| 474 | info->uuid[0] = 0; |
| 475 | #endif |
Patrick Delaunay | 7561b25 | 2015-10-27 11:00:27 +0100 | [diff] [blame] | 476 | #ifdef CONFIG_PARTITION_TYPE_GUID |
| 477 | info->type_guid[0] = 0; |
| 478 | #endif |
Stephen Warren | 4d90702 | 2014-06-12 10:28:32 -0600 | [diff] [blame] | 479 | |
| 480 | return 0; |
| 481 | } |
Hans de Goede | afc1744 | 2015-09-17 18:46:55 -0400 | [diff] [blame] | 482 | #endif |
Stephen Warren | 4d90702 | 2014-06-12 10:28:32 -0600 | [diff] [blame] | 483 | |
Hans de Goede | 251cee0 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 484 | #ifdef CONFIG_CMD_UBIFS |
| 485 | /* |
| 486 | * Special-case ubi, ubi goes through a mtd, rathen then through |
| 487 | * a regular block device. |
| 488 | */ |
| 489 | if (0 == strcmp(ifname, "ubi")) { |
| 490 | if (!ubifs_is_mounted()) { |
| 491 | printf("UBIFS not mounted, use ubifsmount to mount volume first!\n"); |
| 492 | return -1; |
| 493 | } |
| 494 | |
| 495 | *dev_desc = NULL; |
| 496 | memset(info, 0, sizeof(*info)); |
| 497 | strcpy((char *)info->type, BOOT_PART_TYPE); |
| 498 | strcpy((char *)info->name, "UBI"); |
| 499 | #ifdef CONFIG_PARTITION_UUIDS |
| 500 | info->uuid[0] = 0; |
| 501 | #endif |
| 502 | return 0; |
| 503 | } |
| 504 | #endif |
| 505 | |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 506 | /* If no dev_part_str, use bootdevice environment variable */ |
Stephen Warren | a10973e | 2012-09-28 05:34:09 +0000 | [diff] [blame] | 507 | if (!dev_part_str || !strlen(dev_part_str) || |
| 508 | !strcmp(dev_part_str, "-")) |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 509 | dev_part_str = getenv("bootdevice"); |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 510 | |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 511 | /* If still no dev_part_str, it's an error */ |
| 512 | if (!dev_part_str) { |
| 513 | printf("** No device specified **\n"); |
| 514 | goto cleanup; |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 517 | /* Separate device and partition ID specification */ |
| 518 | part_str = strchr(dev_part_str, ':'); |
| 519 | if (part_str) { |
| 520 | dup_str = strdup(dev_part_str); |
| 521 | dup_str[part_str - dev_part_str] = 0; |
| 522 | dev_str = dup_str; |
| 523 | part_str++; |
| 524 | } else { |
| 525 | dev_str = dev_part_str; |
| 526 | } |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 527 | |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 528 | /* Look up the device */ |
Simon Glass | ebac37c | 2016-02-29 15:25:43 -0700 | [diff] [blame] | 529 | dev = blk_get_device_by_str(ifname, dev_str, dev_desc); |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 530 | if (dev < 0) |
| 531 | goto cleanup; |
| 532 | |
| 533 | /* Convert partition ID string to number */ |
| 534 | if (!part_str || !*part_str) { |
| 535 | part = PART_UNSPECIFIED; |
| 536 | } else if (!strcmp(part_str, "auto")) { |
| 537 | part = PART_AUTO; |
| 538 | } else { |
| 539 | /* Something specified -> use exactly that */ |
| 540 | part = (int)simple_strtoul(part_str, &ep, 16); |
| 541 | /* |
| 542 | * Less than whole string converted, |
| 543 | * or request for whole device, but caller requires partition. |
| 544 | */ |
| 545 | if (*ep || (part == 0 && !allow_whole_dev)) { |
| 546 | printf("** Bad partition specification %s %s **\n", |
| 547 | ifname, dev_part_str); |
| 548 | goto cleanup; |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 549 | } |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 552 | /* |
| 553 | * No partition table on device, |
| 554 | * or user requested partition 0 (entire device). |
| 555 | */ |
| 556 | if (((*dev_desc)->part_type == PART_TYPE_UNKNOWN) || |
| 557 | (part == 0)) { |
| 558 | if (!(*dev_desc)->lba) { |
| 559 | printf("** Bad device size - %s %s **\n", ifname, |
| 560 | dev_str); |
| 561 | goto cleanup; |
| 562 | } |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 563 | |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 564 | /* |
| 565 | * If user specified a partition ID other than 0, |
| 566 | * or the calling command only accepts partitions, |
| 567 | * it's an error. |
| 568 | */ |
| 569 | if ((part > 0) || (!allow_whole_dev)) { |
| 570 | printf("** No partition table - %s %s **\n", ifname, |
| 571 | dev_str); |
| 572 | goto cleanup; |
| 573 | } |
| 574 | |
Lan Yixun (dlan) | 50ffc3b | 2013-07-20 08:17:59 +0800 | [diff] [blame] | 575 | (*dev_desc)->log2blksz = LOG2((*dev_desc)->blksz); |
| 576 | |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 577 | info->start = 0; |
| 578 | info->size = (*dev_desc)->lba; |
| 579 | info->blksz = (*dev_desc)->blksz; |
| 580 | info->bootable = 0; |
Stephen Warren | 6ab6a65 | 2012-10-10 07:57:51 +0000 | [diff] [blame] | 581 | strcpy((char *)info->type, BOOT_PART_TYPE); |
| 582 | strcpy((char *)info->name, "Whole Disk"); |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 583 | #ifdef CONFIG_PARTITION_UUIDS |
| 584 | info->uuid[0] = 0; |
| 585 | #endif |
Patrick Delaunay | 7561b25 | 2015-10-27 11:00:27 +0100 | [diff] [blame] | 586 | #ifdef CONFIG_PARTITION_TYPE_GUID |
| 587 | info->type_guid[0] = 0; |
| 588 | #endif |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 589 | |
| 590 | ret = 0; |
| 591 | goto cleanup; |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * Now there's known to be a partition table, |
| 596 | * not specifying a partition means to pick partition 1. |
| 597 | */ |
| 598 | if (part == PART_UNSPECIFIED) |
| 599 | part = 1; |
| 600 | |
| 601 | /* |
| 602 | * If user didn't specify a partition number, or did specify something |
| 603 | * other than "auto", use that partition number directly. |
| 604 | */ |
| 605 | if (part != PART_AUTO) { |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 606 | ret = part_get_info(*dev_desc, part, info); |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 607 | if (ret) { |
| 608 | printf("** Invalid partition %d **\n", part); |
| 609 | goto cleanup; |
| 610 | } |
| 611 | } else { |
| 612 | /* |
| 613 | * Find the first bootable partition. |
| 614 | * If none are bootable, fall back to the first valid partition. |
| 615 | */ |
| 616 | part = 0; |
| 617 | for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) { |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 618 | ret = part_get_info(*dev_desc, p, info); |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 619 | if (ret) |
| 620 | continue; |
| 621 | |
| 622 | /* |
| 623 | * First valid partition, or new better partition? |
| 624 | * If so, save partition ID. |
| 625 | */ |
| 626 | if (!part || info->bootable) |
| 627 | part = p; |
| 628 | |
| 629 | /* Best possible partition? Stop searching. */ |
| 630 | if (info->bootable) |
| 631 | break; |
| 632 | |
| 633 | /* |
| 634 | * We now need to search further for best possible. |
| 635 | * If we what we just queried was the best so far, |
| 636 | * save the info since we over-write it next loop. |
| 637 | */ |
| 638 | if (part == p) |
| 639 | tmpinfo = *info; |
| 640 | } |
| 641 | /* If we found any acceptable partition */ |
| 642 | if (part) { |
| 643 | /* |
| 644 | * If we searched all possible partition IDs, |
| 645 | * return the first valid partition we found. |
| 646 | */ |
| 647 | if (p == MAX_SEARCH_PARTITIONS + 1) |
| 648 | *info = tmpinfo; |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 649 | } else { |
| 650 | printf("** No valid partitions found **\n"); |
Stephen Warren | 71bba42 | 2012-10-08 07:45:54 +0000 | [diff] [blame] | 651 | ret = -1; |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 652 | goto cleanup; |
| 653 | } |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 654 | } |
| 655 | if (strncmp((char *)info->type, BOOT_PART_TYPE, sizeof(info->type)) != 0) { |
| 656 | printf("** Invalid partition type \"%.32s\"" |
| 657 | " (expect \"" BOOT_PART_TYPE "\")\n", |
| 658 | info->type); |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 659 | ret = -1; |
| 660 | goto cleanup; |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Lan Yixun (dlan) | 50ffc3b | 2013-07-20 08:17:59 +0800 | [diff] [blame] | 663 | (*dev_desc)->log2blksz = LOG2((*dev_desc)->blksz); |
| 664 | |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 665 | ret = part; |
| 666 | goto cleanup; |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 667 | |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 668 | cleanup: |
| 669 | free(dup_str); |
| 670 | return ret; |
Rob Herring | 99d2c20 | 2012-09-21 04:08:17 +0000 | [diff] [blame] | 671 | } |