Commit 2ae67aec5e283e6ccdc43b9432a6077c8af2c27e

Authored by Nishanth Menon
Committed by Simon Glass
1 parent c3ab985362

dm: part: fix missing driver name in debug print

Fixes the following warning with PART_DEBUG enabled:
disk/part.c: In function ‘get_partition_info’:
disk/part.c:372:3: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat]

Signed-off-by: Nishanth Menon <nm@ti.com>

Showing 1 changed file with 2 additions and 1 deletions Inline Diff

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