part.c 16 KB

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