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