part: Use desc instead of dev_desc
[pandora-u-boot.git] / disk / part.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2001
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  */
6
7 #include <common.h>
8 #include <blk.h>
9 #include <command.h>
10 #include <env.h>
11 #include <errno.h>
12 #include <ide.h>
13 #include <log.h>
14 #include <malloc.h>
15 #include <part.h>
16 #include <ubifs_uboot.h>
17
18 #undef  PART_DEBUG
19
20 #ifdef  PART_DEBUG
21 #define PRINTF(fmt,args...)     printf (fmt ,##args)
22 #else
23 #define PRINTF(fmt,args...)
24 #endif
25
26 /* Check all partition types */
27 #define PART_TYPE_ALL           -1
28
29 static struct part_driver *part_driver_get_type(int part_type)
30 {
31         struct part_driver *drv =
32                 ll_entry_start(struct part_driver, part_driver);
33         const int n_ents = ll_entry_count(struct part_driver, part_driver);
34         struct part_driver *entry;
35
36         for (entry = drv; entry != drv + n_ents; entry++) {
37                 if (part_type == entry->part_type)
38                         return entry;
39         }
40
41         /* Not found */
42         return NULL;
43 }
44
45 static struct part_driver *part_driver_lookup_type(struct blk_desc *desc)
46 {
47         struct part_driver *drv =
48                 ll_entry_start(struct part_driver, part_driver);
49         const int n_ents = ll_entry_count(struct part_driver, part_driver);
50         struct part_driver *entry;
51
52         if (desc->part_type == PART_TYPE_UNKNOWN) {
53                 for (entry = drv; entry != drv + n_ents; entry++) {
54                         int ret;
55
56                         ret = entry->test(desc);
57                         if (!ret) {
58                                 desc->part_type = entry->part_type;
59                                 return entry;
60                         }
61                 }
62         } else {
63                 return part_driver_get_type(desc->part_type);
64         }
65
66         /* Not found */
67         return NULL;
68 }
69
70 int part_get_type_by_name(const char *name)
71 {
72         struct part_driver *drv =
73                 ll_entry_start(struct part_driver, part_driver);
74         const int n_ents = ll_entry_count(struct part_driver, part_driver);
75         struct part_driver *entry;
76
77         for (entry = drv; entry != drv + n_ents; entry++) {
78                 if (!strcasecmp(name, entry->name))
79                         return entry->part_type;
80         }
81
82         /* Not found */
83         return PART_TYPE_UNKNOWN;
84 }
85
86 static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
87 {
88         struct blk_desc *desc;
89         int ret;
90
91         if (!blk_enabled())
92                 return NULL;
93         desc = blk_get_devnum_by_uclass_idname(ifname, dev);
94         if (!desc) {
95                 debug("%s: No device for iface '%s', dev %d\n", __func__,
96                       ifname, dev);
97                 return NULL;
98         }
99         ret = blk_dselect_hwpart(desc, hwpart);
100         if (ret) {
101                 debug("%s: Failed to select h/w partition: err-%d\n", __func__,
102                       ret);
103                 return NULL;
104         }
105
106         return desc;
107 }
108
109 struct blk_desc *blk_get_dev(const char *ifname, int dev)
110 {
111         if (!blk_enabled())
112                 return NULL;
113
114         return get_dev_hwpart(ifname, dev, 0);
115 }
116
117 /* ------------------------------------------------------------------------- */
118 /*
119  * reports device info to the user
120  */
121
122 #ifdef CONFIG_LBA48
123 typedef uint64_t lba512_t;
124 #else
125 typedef lbaint_t lba512_t;
126 #endif
127
128 /*
129  * Overflowless variant of (block_count * mul_by / 2**right_shift)
130  * when 2**right_shift > mul_by
131  */
132 static lba512_t lba512_muldiv(lba512_t block_count, lba512_t mul_by,
133                               int right_shift)
134 {
135         lba512_t bc_quot, bc_rem;
136
137         /* x * m / d == x / d * m + (x % d) * m / d */
138         bc_quot = block_count >> right_shift;
139         bc_rem  = block_count - (bc_quot << right_shift);
140         return bc_quot * mul_by + ((bc_rem * mul_by) >> right_shift);
141 }
142
143 void dev_print(struct blk_desc *desc)
144 {
145         lba512_t lba512; /* number of blocks if 512bytes block size */
146
147         if (desc->type == DEV_TYPE_UNKNOWN) {
148                 puts ("not available\n");
149                 return;
150         }
151
152         switch (desc->uclass_id) {
153         case UCLASS_SCSI:
154                 printf("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n", desc->target,
155                        desc->lun, desc->vendor, desc->product, desc->revision);
156                 break;
157         case UCLASS_IDE:
158         case UCLASS_AHCI:
159                 printf("Model: %s Firm: %s Ser#: %s\n", desc->vendor,
160                        desc->revision, desc->product);
161                 break;
162         case UCLASS_MMC:
163         case UCLASS_USB:
164         case UCLASS_NVME:
165         case UCLASS_PVBLOCK:
166         case UCLASS_HOST:
167         case UCLASS_BLKMAP:
168                 printf ("Vendor: %s Rev: %s Prod: %s\n",
169                         desc->vendor,
170                         desc->revision,
171                         desc->product);
172                 break;
173         case UCLASS_VIRTIO:
174                 printf("%s VirtIO Block Device\n", desc->vendor);
175                 break;
176         case UCLASS_EFI_MEDIA:
177                 printf("EFI media Block Device %d\n", desc->devnum);
178                 break;
179         case UCLASS_INVALID:
180                 puts("device type unknown\n");
181                 return;
182         default:
183                 printf("Unhandled device type: %i\n", desc->uclass_id);
184                 return;
185         }
186         puts ("            Type: ");
187         if (desc->removable)
188                 puts ("Removable ");
189         switch (desc->type & 0x1F) {
190         case DEV_TYPE_HARDDISK:
191                 puts ("Hard Disk");
192                 break;
193         case DEV_TYPE_CDROM:
194                 puts ("CD ROM");
195                 break;
196         case DEV_TYPE_OPDISK:
197                 puts ("Optical Device");
198                 break;
199         case DEV_TYPE_TAPE:
200                 puts ("Tape");
201                 break;
202         default:
203                 printf("# %02X #", desc->type & 0x1F);
204                 break;
205         }
206         puts ("\n");
207         if (desc->lba > 0L && desc->blksz > 0L) {
208                 ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;
209                 lbaint_t lba;
210
211                 lba = desc->lba;
212
213                 lba512 = lba * (desc->blksz / 512);
214                 /* round to 1 digit */
215                 /* 2048 = (1024 * 1024) / 512 MB */
216                 mb = lba512_muldiv(lba512, 10, 11);
217
218                 mb_quot = mb / 10;
219                 mb_rem  = mb - (10 * mb_quot);
220
221                 gb = mb / 1024;
222                 gb_quot = gb / 10;
223                 gb_rem  = gb - (10 * gb_quot);
224 #ifdef CONFIG_LBA48
225                 if (desc->lba48)
226                         printf ("            Supports 48-bit addressing\n");
227 #endif
228 #if defined(CONFIG_SYS_64BIT_LBA)
229                 printf ("            Capacity: %lu.%lu MB = %lu.%lu GB (%llu x %lu)\n",
230                         mb_quot, mb_rem,
231                         gb_quot, gb_rem,
232                         lba,
233                         desc->blksz);
234 #else
235                 printf ("            Capacity: %lu.%lu MB = %lu.%lu GB (%lu x %lu)\n",
236                         mb_quot, mb_rem,
237                         gb_quot, gb_rem,
238                         (ulong)lba,
239                         desc->blksz);
240 #endif
241         } else {
242                 puts ("            Capacity: not available\n");
243         }
244 }
245
246 void part_init(struct blk_desc *desc)
247 {
248         struct part_driver *drv =
249                 ll_entry_start(struct part_driver, part_driver);
250         const int n_ents = ll_entry_count(struct part_driver, part_driver);
251         struct part_driver *entry;
252
253         blkcache_invalidate(desc->uclass_id, desc->devnum);
254
255         desc->part_type = PART_TYPE_UNKNOWN;
256         for (entry = drv; entry != drv + n_ents; entry++) {
257                 int ret;
258
259                 ret = entry->test(desc);
260                 debug("%s: try '%s': ret=%d\n", __func__, entry->name, ret);
261                 if (!ret) {
262                         desc->part_type = entry->part_type;
263                         break;
264                 }
265         }
266 }
267
268 static void print_part_header(const char *type, struct blk_desc *desc)
269 {
270 #if CONFIG_IS_ENABLED(MAC_PARTITION) || \
271         CONFIG_IS_ENABLED(DOS_PARTITION) || \
272         CONFIG_IS_ENABLED(ISO_PARTITION) || \
273         CONFIG_IS_ENABLED(AMIGA_PARTITION) || \
274         CONFIG_IS_ENABLED(EFI_PARTITION)
275         puts ("\nPartition Map for ");
276         switch (desc->uclass_id) {
277         case UCLASS_IDE:
278                 puts ("IDE");
279                 break;
280         case UCLASS_AHCI:
281                 puts ("SATA");
282                 break;
283         case UCLASS_SCSI:
284                 puts ("SCSI");
285                 break;
286         case UCLASS_USB:
287                 puts ("USB");
288                 break;
289         case UCLASS_MMC:
290                 puts ("MMC");
291                 break;
292         case UCLASS_HOST:
293                 puts ("HOST");
294                 break;
295         case UCLASS_NVME:
296                 puts ("NVMe");
297                 break;
298         case UCLASS_PVBLOCK:
299                 puts("PV BLOCK");
300                 break;
301         case UCLASS_VIRTIO:
302                 puts("VirtIO");
303                 break;
304         case UCLASS_EFI_MEDIA:
305                 puts("EFI");
306                 break;
307         default:
308                 puts("UNKNOWN");
309                 break;
310         }
311         printf (" device %d  --   Partition Type: %s\n\n",
312                         desc->devnum, type);
313 #endif /* any CONFIG_..._PARTITION */
314 }
315
316 void part_print(struct blk_desc *desc)
317 {
318         struct part_driver *drv;
319
320         drv = part_driver_lookup_type(desc);
321         if (!drv) {
322                 printf("## Unknown partition table type %x\n",
323                        desc->part_type);
324                 return;
325         }
326
327         PRINTF("## Testing for valid %s partition ##\n", drv->name);
328         print_part_header(drv->name, desc);
329         if (drv->print)
330                 drv->print(desc);
331 }
332
333 int part_get_info_by_type(struct blk_desc *desc, int part, int part_type,
334                           struct disk_partition *info)
335 {
336         struct part_driver *drv;
337
338         if (blk_enabled()) {
339 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
340                 /* The common case is no UUID support */
341                 info->uuid[0] = 0;
342 #endif
343 #ifdef CONFIG_PARTITION_TYPE_GUID
344                 info->type_guid[0] = 0;
345 #endif
346
347                 if (part_type == PART_TYPE_UNKNOWN) {
348                         drv = part_driver_lookup_type(desc);
349                 } else {
350                         drv = part_driver_get_type(part_type);
351                 }
352
353                 if (!drv) {
354                         debug("## Unknown partition table type %x\n",
355                               desc->part_type);
356                         return -EPROTONOSUPPORT;
357                 }
358                 if (!drv->get_info) {
359                         PRINTF("## Driver %s does not have the get_info() method\n",
360                                drv->name);
361                         return -ENOSYS;
362                 }
363                 if (drv->get_info(desc, part, info) == 0) {
364                         PRINTF("## Valid %s partition found ##\n", drv->name);
365                         return 0;
366                 }
367         }
368
369         return -ENOENT;
370 }
371
372 int part_get_info(struct blk_desc *desc, int part,
373                   struct disk_partition *info)
374 {
375         return part_get_info_by_type(desc, part, PART_TYPE_UNKNOWN, info);
376 }
377
378 int part_get_info_whole_disk(struct blk_desc *desc,
379                              struct disk_partition *info)
380 {
381         info->start = 0;
382         info->size = desc->lba;
383         info->blksz = desc->blksz;
384         info->bootable = 0;
385         strcpy((char *)info->type, BOOT_PART_TYPE);
386         strcpy((char *)info->name, "Whole Disk");
387 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
388         info->uuid[0] = 0;
389 #endif
390 #ifdef CONFIG_PARTITION_TYPE_GUID
391         info->type_guid[0] = 0;
392 #endif
393
394         return 0;
395 }
396
397 int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str,
398                           struct blk_desc **desc)
399 {
400         char *ep;
401         char *dup_str = NULL;
402         const char *dev_str, *hwpart_str;
403         int dev, hwpart;
404
405         hwpart_str = strchr(dev_hwpart_str, '.');
406         if (hwpart_str) {
407                 dup_str = strdup(dev_hwpart_str);
408                 dup_str[hwpart_str - dev_hwpart_str] = 0;
409                 dev_str = dup_str;
410                 hwpart_str++;
411         } else {
412                 dev_str = dev_hwpart_str;
413                 hwpart = 0;
414         }
415
416         dev = hextoul(dev_str, &ep);
417         if (*ep) {
418                 printf("** Bad device specification %s %s **\n",
419                        ifname, dev_str);
420                 dev = -EINVAL;
421                 goto cleanup;
422         }
423
424         if (hwpart_str) {
425                 hwpart = hextoul(hwpart_str, &ep);
426                 if (*ep) {
427                         printf("** Bad HW partition specification %s %s **\n",
428                             ifname, hwpart_str);
429                         dev = -EINVAL;
430                         goto cleanup;
431                 }
432         }
433
434         *desc = get_dev_hwpart(ifname, dev, hwpart);
435         if (!(*desc) || ((*desc)->type == DEV_TYPE_UNKNOWN)) {
436                 debug("** Bad device %s %s **\n", ifname, dev_hwpart_str);
437                 dev = -ENODEV;
438                 goto cleanup;
439         }
440
441         if (blk_enabled()) {
442                 /*
443                  * Updates the partition table for the specified hw partition.
444                  * Always should be done, otherwise hw partition 0 will return
445                  * stale data after displaying a non-zero hw partition.
446                  */
447                 if ((*desc)->uclass_id == UCLASS_MMC)
448                         part_init(*desc);
449         }
450
451 cleanup:
452         free(dup_str);
453         return dev;
454 }
455
456 #define PART_UNSPECIFIED -2
457 #define PART_AUTO -1
458 int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
459                              struct blk_desc **desc,
460                              struct disk_partition *info, int allow_whole_dev)
461 {
462         int ret;
463         const char *part_str;
464         char *dup_str = NULL;
465         const char *dev_str;
466         int dev;
467         char *ep;
468         int p;
469         int part;
470         struct disk_partition tmpinfo;
471
472         *desc = NULL;
473         memset(info, 0, sizeof(*info));
474
475 #if IS_ENABLED(CONFIG_SANDBOX) || IS_ENABLED(CONFIG_SEMIHOSTING)
476         /*
477          * Special-case a pseudo block device "hostfs", to allow access to the
478          * host's own filesystem.
479          */
480         if (!strcmp(ifname, "hostfs")) {
481                 strcpy((char *)info->type, BOOT_PART_TYPE);
482                 strcpy((char *)info->name, "Host filesystem");
483
484                 return 0;
485         }
486 #endif
487
488 #if IS_ENABLED(CONFIG_CMD_UBIFS) && !IS_ENABLED(CONFIG_SPL_BUILD)
489         /*
490          * Special-case ubi, ubi goes through a mtd, rather than through
491          * a regular block device.
492          */
493         if (!strcmp(ifname, "ubi")) {
494                 if (!ubifs_is_mounted()) {
495                         printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
496                         return -EINVAL;
497                 }
498
499                 strcpy((char *)info->type, BOOT_PART_TYPE);
500                 strcpy((char *)info->name, "UBI");
501                 return 0;
502         }
503 #endif
504
505         /* If no dev_part_str, use bootdevice environment variable */
506         if (CONFIG_IS_ENABLED(ENV_SUPPORT)) {
507                 if (!dev_part_str || !strlen(dev_part_str) ||
508                     !strcmp(dev_part_str, "-"))
509                         dev_part_str = env_get("bootdevice");
510         }
511
512         /* If still no dev_part_str, it's an error */
513         if (!dev_part_str) {
514                 printf("** No device specified **\n");
515                 ret = -ENODEV;
516                 goto cleanup;
517         }
518
519         /* Separate device and partition ID specification */
520         part_str = strchr(dev_part_str, ':');
521         if (part_str) {
522                 dup_str = strdup(dev_part_str);
523                 dup_str[part_str - dev_part_str] = 0;
524                 dev_str = dup_str;
525                 part_str++;
526         } else {
527                 dev_str = dev_part_str;
528         }
529
530         /* Look up the device */
531         dev = blk_get_device_by_str(ifname, dev_str, desc);
532         if (dev < 0) {
533                 printf("** Bad device specification %s %s **\n",
534                        ifname, dev_str);
535                 ret = dev;
536                 goto cleanup;
537         }
538
539         /* Convert partition ID string to number */
540         if (!part_str || !*part_str) {
541                 part = PART_UNSPECIFIED;
542         } else if (!strcmp(part_str, "auto")) {
543                 part = PART_AUTO;
544         } else {
545                 /* Something specified -> use exactly that */
546                 part = (int)hextoul(part_str, &ep);
547                 /*
548                  * Less than whole string converted,
549                  * or request for whole device, but caller requires partition.
550                  */
551                 if (*ep || (part == 0 && !allow_whole_dev)) {
552                         printf("** Bad partition specification %s %s **\n",
553                             ifname, dev_part_str);
554                         ret = -ENOENT;
555                         goto cleanup;
556                 }
557         }
558
559         /*
560          * No partition table on device,
561          * or user requested partition 0 (entire device).
562          */
563         if (((*desc)->part_type == PART_TYPE_UNKNOWN) || !part) {
564                 if (!(*desc)->lba) {
565                         printf("** Bad device size - %s %s **\n", ifname,
566                                dev_str);
567                         ret = -EINVAL;
568                         goto cleanup;
569                 }
570
571                 /*
572                  * If user specified a partition ID other than 0,
573                  * or the calling command only accepts partitions,
574                  * it's an error.
575                  */
576                 if ((part > 0) || (!allow_whole_dev)) {
577                         printf("** No partition table - %s %s **\n", ifname,
578                                dev_str);
579                         ret = -EPROTONOSUPPORT;
580                         goto cleanup;
581                 }
582
583                 (*desc)->log2blksz = LOG2((*desc)->blksz);
584
585                 part_get_info_whole_disk(*desc, info);
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) {
603                 ret = part_get_info(*desc, part, info);
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++) {
615                         ret = part_get_info(*desc, p, info);
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;
646                 } else {
647                         printf("** No valid partitions found **\n");
648                         goto cleanup;
649                 }
650         }
651         if (strncmp((char *)info->type, BOOT_PART_TYPE, sizeof(info->type)) != 0) {
652                 printf("** Invalid partition type \"%.32s\""
653                         " (expect \"" BOOT_PART_TYPE "\")\n",
654                         info->type);
655                 ret  = -EINVAL;
656                 goto cleanup;
657         }
658
659         (*desc)->log2blksz = LOG2((*desc)->blksz);
660
661         ret = part;
662         goto cleanup;
663
664 cleanup:
665         free(dup_str);
666         return ret;
667 }
668
669 int part_get_info_by_name(struct blk_desc *desc, const char *name,
670                           struct disk_partition *info)
671 {
672         struct part_driver *part_drv;
673         int ret;
674         int i;
675
676         part_drv = part_driver_lookup_type(desc);
677         if (!part_drv)
678                 return -1;
679
680         if (!part_drv->get_info) {
681                 log_debug("## Driver %s does not have the get_info() method\n",
682                           part_drv->name);
683                 return -ENOSYS;
684         }
685
686         for (i = 1; i < part_drv->max_entries; i++) {
687                 ret = part_drv->get_info(desc, i, info);
688                 if (ret != 0) {
689                         /* no more entries in table */
690                         break;
691                 }
692                 if (strcmp(name, (const char *)info->name) == 0) {
693                         /* matched */
694                         return i;
695                 }
696         }
697
698         return -ENOENT;
699 }
700
701 /**
702  * Get partition info from device number and partition name.
703  *
704  * Parse a device number and partition name string in the form of
705  * "devicenum.hwpartnum#partition_name", for example "0.1#misc". devicenum and
706  * hwpartnum are both optional, defaulting to 0. If the partition is found,
707  * sets desc and part_info accordingly with the information of the
708  * partition with the given partition_name.
709  *
710  * @param[in] dev_iface Device interface
711  * @param[in] dev_part_str Input string argument, like "0.1#misc"
712  * @param[out] desc Place to store the device description pointer
713  * @param[out] part_info Place to store the partition information
714  * Return: 0 on success, or a negative on error
715  */
716 static int part_get_info_by_dev_and_name(const char *dev_iface,
717                                          const char *dev_part_str,
718                                          struct blk_desc **desc,
719                                          struct disk_partition *part_info)
720 {
721         char *dup_str = NULL;
722         const char *dev_str, *part_str;
723         int ret;
724
725         /* Separate device and partition name specification */
726         if (dev_part_str)
727                 part_str = strchr(dev_part_str, '#');
728         else
729                 part_str = NULL;
730
731         if (part_str) {
732                 dup_str = strdup(dev_part_str);
733                 dup_str[part_str - dev_part_str] = 0;
734                 dev_str = dup_str;
735                 part_str++;
736         } else {
737                 return -EINVAL;
738         }
739
740         ret = blk_get_device_by_str(dev_iface, dev_str, desc);
741         if (ret < 0)
742                 goto cleanup;
743
744         ret = part_get_info_by_name(*desc, part_str, part_info);
745         if (ret < 0)
746                 printf("Could not find \"%s\" partition\n", part_str);
747
748 cleanup:
749         free(dup_str);
750         return ret;
751 }
752
753 int part_get_info_by_dev_and_name_or_num(const char *dev_iface,
754                                          const char *dev_part_str,
755                                          struct blk_desc **desc,
756                                          struct disk_partition *part_info,
757                                          int allow_whole_dev)
758 {
759         int ret;
760
761         /* Split the part_name if passed as "$dev_num#part_name". */
762         ret = part_get_info_by_dev_and_name(dev_iface, dev_part_str, desc,
763                                             part_info);
764         if (ret >= 0)
765                 return ret;
766         /*
767          * Couldn't lookup by name, try looking up the partition description
768          * directly.
769          */
770         ret = blk_get_device_part_str(dev_iface, dev_part_str, desc, part_info,
771                                       allow_whole_dev);
772         if (ret < 0)
773                 printf("Couldn't find partition %s %s\n",
774                        dev_iface, dev_part_str);
775         return ret;
776 }
777
778 void part_set_generic_name(const struct blk_desc *desc, int part_num,
779                            char *name)
780 {
781         char *devtype;
782
783         switch (desc->uclass_id) {
784         case UCLASS_IDE:
785         case UCLASS_AHCI:
786                 devtype = "hd";
787                 break;
788         case UCLASS_SCSI:
789                 devtype = "sd";
790                 break;
791         case UCLASS_USB:
792                 devtype = "usbd";
793                 break;
794         case UCLASS_MMC:
795                 devtype = "mmcsd";
796                 break;
797         default:
798                 devtype = "xx";
799                 break;
800         }
801
802         sprintf(name, "%s%c%d", devtype, 'a' + desc->devnum, part_num);
803 }
804
805 int part_get_bootable(struct blk_desc *desc)
806 {
807         struct disk_partition info;
808         int p;
809
810         for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
811                 int ret;
812
813                 ret = part_get_info(desc, p, &info);
814                 if (!ret && info.bootable)
815                         return p;
816         }
817
818         return 0;
819 }