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