efi_device_path.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * EFI device path from u-boot device-model mapping
  4. *
  5. * (C) Copyright 2017 Rob Clark
  6. */
  7. #define LOG_CATEGORY LOGC_EFI
  8. #include <common.h>
  9. #include <blk.h>
  10. #include <dm.h>
  11. #include <log.h>
  12. #include <net.h>
  13. #include <usb.h>
  14. #include <mmc.h>
  15. #include <nvme.h>
  16. #include <efi_loader.h>
  17. #include <part.h>
  18. #include <sandboxblockdev.h>
  19. #include <uuid.h>
  20. #include <asm-generic/unaligned.h>
  21. #include <linux/compat.h> /* U16_MAX */
  22. #ifdef CONFIG_SANDBOX
  23. const efi_guid_t efi_guid_host_dev = U_BOOT_HOST_DEV_GUID;
  24. #endif
  25. #ifdef CONFIG_VIRTIO_BLK
  26. const efi_guid_t efi_guid_virtio_dev = U_BOOT_VIRTIO_DEV_GUID;
  27. #endif
  28. /* template END node: */
  29. static const struct efi_device_path END = {
  30. .type = DEVICE_PATH_TYPE_END,
  31. .sub_type = DEVICE_PATH_SUB_TYPE_END,
  32. .length = sizeof(END),
  33. };
  34. /* template ROOT node: */
  35. static const struct efi_device_path_vendor ROOT = {
  36. .dp = {
  37. .type = DEVICE_PATH_TYPE_HARDWARE_DEVICE,
  38. .sub_type = DEVICE_PATH_SUB_TYPE_VENDOR,
  39. .length = sizeof(ROOT),
  40. },
  41. .guid = U_BOOT_GUID,
  42. };
  43. #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
  44. /*
  45. * Determine if an MMC device is an SD card.
  46. *
  47. * @desc block device descriptor
  48. * @return true if the device is an SD card
  49. */
  50. static bool is_sd(struct blk_desc *desc)
  51. {
  52. struct mmc *mmc = find_mmc_device(desc->devnum);
  53. if (!mmc)
  54. return false;
  55. return IS_SD(mmc) != 0U;
  56. }
  57. #endif
  58. static void *dp_alloc(size_t sz)
  59. {
  60. void *buf;
  61. if (efi_allocate_pool(EFI_BOOT_SERVICES_DATA, sz, &buf) !=
  62. EFI_SUCCESS) {
  63. debug("EFI: ERROR: out of memory in %s\n", __func__);
  64. return NULL;
  65. }
  66. memset(buf, 0, sz);
  67. return buf;
  68. }
  69. /*
  70. * Iterate to next block in device-path, terminating (returning NULL)
  71. * at /End* node.
  72. */
  73. struct efi_device_path *efi_dp_next(const struct efi_device_path *dp)
  74. {
  75. if (dp == NULL)
  76. return NULL;
  77. if (dp->type == DEVICE_PATH_TYPE_END)
  78. return NULL;
  79. dp = ((void *)dp) + dp->length;
  80. if (dp->type == DEVICE_PATH_TYPE_END)
  81. return NULL;
  82. return (struct efi_device_path *)dp;
  83. }
  84. /*
  85. * Compare two device-paths, stopping when the shorter of the two hits
  86. * an End* node. This is useful to, for example, compare a device-path
  87. * representing a device with one representing a file on the device, or
  88. * a device with a parent device.
  89. */
  90. int efi_dp_match(const struct efi_device_path *a,
  91. const struct efi_device_path *b)
  92. {
  93. while (1) {
  94. int ret;
  95. ret = memcmp(&a->length, &b->length, sizeof(a->length));
  96. if (ret)
  97. return ret;
  98. ret = memcmp(a, b, a->length);
  99. if (ret)
  100. return ret;
  101. a = efi_dp_next(a);
  102. b = efi_dp_next(b);
  103. if (!a || !b)
  104. return 0;
  105. }
  106. }
  107. /*
  108. * We can have device paths that start with a USB WWID or a USB Class node,
  109. * and a few other cases which don't encode the full device path with bus
  110. * hierarchy:
  111. *
  112. * - MESSAGING:USB_WWID
  113. * - MESSAGING:USB_CLASS
  114. * - MEDIA:FILE_PATH
  115. * - MEDIA:HARD_DRIVE
  116. * - MESSAGING:URI
  117. *
  118. * See UEFI spec (section 3.1.2, about short-form device-paths)
  119. */
  120. static struct efi_device_path *shorten_path(struct efi_device_path *dp)
  121. {
  122. while (dp) {
  123. /*
  124. * TODO: Add MESSAGING:USB_WWID and MESSAGING:URI..
  125. * in practice fallback.efi just uses MEDIA:HARD_DRIVE
  126. * so not sure when we would see these other cases.
  127. */
  128. if (EFI_DP_TYPE(dp, MESSAGING_DEVICE, MSG_USB_CLASS) ||
  129. EFI_DP_TYPE(dp, MEDIA_DEVICE, HARD_DRIVE_PATH) ||
  130. EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH))
  131. return dp;
  132. dp = efi_dp_next(dp);
  133. }
  134. return dp;
  135. }
  136. static struct efi_object *find_obj(struct efi_device_path *dp, bool short_path,
  137. struct efi_device_path **rem)
  138. {
  139. struct efi_object *efiobj;
  140. efi_uintn_t dp_size = efi_dp_instance_size(dp);
  141. list_for_each_entry(efiobj, &efi_obj_list, link) {
  142. struct efi_handler *handler;
  143. struct efi_device_path *obj_dp;
  144. efi_status_t ret;
  145. ret = efi_search_protocol(efiobj,
  146. &efi_guid_device_path, &handler);
  147. if (ret != EFI_SUCCESS)
  148. continue;
  149. obj_dp = handler->protocol_interface;
  150. do {
  151. if (efi_dp_match(dp, obj_dp) == 0) {
  152. if (rem) {
  153. /*
  154. * Allow partial matches, but inform
  155. * the caller.
  156. */
  157. *rem = ((void *)dp) +
  158. efi_dp_instance_size(obj_dp);
  159. return efiobj;
  160. } else {
  161. /* Only return on exact matches */
  162. if (efi_dp_instance_size(obj_dp) ==
  163. dp_size)
  164. return efiobj;
  165. }
  166. }
  167. obj_dp = shorten_path(efi_dp_next(obj_dp));
  168. } while (short_path && obj_dp);
  169. }
  170. return NULL;
  171. }
  172. /*
  173. * Find an efiobj from device-path, if 'rem' is not NULL, returns the
  174. * remaining part of the device path after the matched object.
  175. */
  176. struct efi_object *efi_dp_find_obj(struct efi_device_path *dp,
  177. struct efi_device_path **rem)
  178. {
  179. struct efi_object *efiobj;
  180. /* Search for an exact match first */
  181. efiobj = find_obj(dp, false, NULL);
  182. /* Then for a fuzzy match */
  183. if (!efiobj)
  184. efiobj = find_obj(dp, false, rem);
  185. /* And now for a fuzzy short match */
  186. if (!efiobj)
  187. efiobj = find_obj(dp, true, rem);
  188. return efiobj;
  189. }
  190. /*
  191. * Determine the last device path node that is not the end node.
  192. *
  193. * @dp device path
  194. * @return last node before the end node if it exists
  195. * otherwise NULL
  196. */
  197. const struct efi_device_path *efi_dp_last_node(const struct efi_device_path *dp)
  198. {
  199. struct efi_device_path *ret;
  200. if (!dp || dp->type == DEVICE_PATH_TYPE_END)
  201. return NULL;
  202. while (dp) {
  203. ret = (struct efi_device_path *)dp;
  204. dp = efi_dp_next(dp);
  205. }
  206. return ret;
  207. }
  208. /* get size of the first device path instance excluding end node */
  209. efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp)
  210. {
  211. efi_uintn_t sz = 0;
  212. if (!dp || dp->type == DEVICE_PATH_TYPE_END)
  213. return 0;
  214. while (dp) {
  215. sz += dp->length;
  216. dp = efi_dp_next(dp);
  217. }
  218. return sz;
  219. }
  220. /* get size of multi-instance device path excluding end node */
  221. efi_uintn_t efi_dp_size(const struct efi_device_path *dp)
  222. {
  223. const struct efi_device_path *p = dp;
  224. if (!p)
  225. return 0;
  226. while (p->type != DEVICE_PATH_TYPE_END ||
  227. p->sub_type != DEVICE_PATH_SUB_TYPE_END)
  228. p = (void *)p + p->length;
  229. return (void *)p - (void *)dp;
  230. }
  231. /* copy multi-instance device path */
  232. struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp)
  233. {
  234. struct efi_device_path *ndp;
  235. size_t sz = efi_dp_size(dp) + sizeof(END);
  236. if (!dp)
  237. return NULL;
  238. ndp = dp_alloc(sz);
  239. if (!ndp)
  240. return NULL;
  241. memcpy(ndp, dp, sz);
  242. return ndp;
  243. }
  244. /**
  245. * efi_dp_append_or_concatenate() - Append or concatenate two device paths.
  246. * Concatenated device path will be separated
  247. * by a sub-type 0xff end node
  248. *
  249. * @dp1: First device path
  250. * @dp2: Second device path
  251. * @concat: If true the two device paths will be concatenated and separated
  252. * by an end of entrire device path sub-type 0xff end node.
  253. * If true the second device path will be appended to the first and
  254. * terminated by an end node
  255. *
  256. * Return:
  257. * concatenated device path or NULL. Caller must free the returned value
  258. */
  259. static struct
  260. efi_device_path *efi_dp_append_or_concatenate(const struct efi_device_path *dp1,
  261. const struct efi_device_path *dp2,
  262. bool concat)
  263. {
  264. struct efi_device_path *ret;
  265. size_t end_size = sizeof(END);
  266. if (concat)
  267. end_size = 2 * sizeof(END);
  268. if (!dp1 && !dp2) {
  269. /* return an end node */
  270. ret = efi_dp_dup(&END);
  271. } else if (!dp1) {
  272. ret = efi_dp_dup(dp2);
  273. } else if (!dp2) {
  274. ret = efi_dp_dup(dp1);
  275. } else {
  276. /* both dp1 and dp2 are non-null */
  277. unsigned sz1 = efi_dp_size(dp1);
  278. unsigned sz2 = efi_dp_size(dp2);
  279. void *p = dp_alloc(sz1 + sz2 + end_size);
  280. if (!p)
  281. return NULL;
  282. ret = p;
  283. memcpy(p, dp1, sz1);
  284. p += sz1;
  285. if (concat) {
  286. memcpy(p, &END, sizeof(END));
  287. p += sizeof(END);
  288. }
  289. /* the end node of the second device path has to be retained */
  290. memcpy(p, dp2, sz2);
  291. p += sz2;
  292. memcpy(p, &END, sizeof(END));
  293. }
  294. return ret;
  295. }
  296. /**
  297. * efi_dp_append() - Append a device to an existing device path.
  298. *
  299. * @dp1: First device path
  300. * @dp2: Second device path
  301. *
  302. * Return:
  303. * concatenated device path or NULL. Caller must free the returned value
  304. */
  305. struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,
  306. const struct efi_device_path *dp2)
  307. {
  308. return efi_dp_append_or_concatenate(dp1, dp2, false);
  309. }
  310. /**
  311. * efi_dp_concat() - Concatenate 2 device paths. The final device path will
  312. * contain two device paths separated by and end node (0xff).
  313. *
  314. * @dp1: First device path
  315. * @dp2: Second device path
  316. *
  317. * Return:
  318. * concatenated device path or NULL. Caller must free the returned value
  319. */
  320. struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1,
  321. const struct efi_device_path *dp2)
  322. {
  323. return efi_dp_append_or_concatenate(dp1, dp2, true);
  324. }
  325. struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp,
  326. const struct efi_device_path *node)
  327. {
  328. struct efi_device_path *ret;
  329. if (!node && !dp) {
  330. ret = efi_dp_dup(&END);
  331. } else if (!node) {
  332. ret = efi_dp_dup(dp);
  333. } else if (!dp) {
  334. size_t sz = node->length;
  335. void *p = dp_alloc(sz + sizeof(END));
  336. if (!p)
  337. return NULL;
  338. memcpy(p, node, sz);
  339. memcpy(p + sz, &END, sizeof(END));
  340. ret = p;
  341. } else {
  342. /* both dp and node are non-null */
  343. size_t sz = efi_dp_size(dp);
  344. void *p = dp_alloc(sz + node->length + sizeof(END));
  345. if (!p)
  346. return NULL;
  347. memcpy(p, dp, sz);
  348. memcpy(p + sz, node, node->length);
  349. memcpy(p + sz + node->length, &END, sizeof(END));
  350. ret = p;
  351. }
  352. return ret;
  353. }
  354. struct efi_device_path *efi_dp_create_device_node(const u8 type,
  355. const u8 sub_type,
  356. const u16 length)
  357. {
  358. struct efi_device_path *ret;
  359. if (length < sizeof(struct efi_device_path))
  360. return NULL;
  361. ret = dp_alloc(length);
  362. if (!ret)
  363. return ret;
  364. ret->type = type;
  365. ret->sub_type = sub_type;
  366. ret->length = length;
  367. return ret;
  368. }
  369. struct efi_device_path *efi_dp_append_instance(
  370. const struct efi_device_path *dp,
  371. const struct efi_device_path *dpi)
  372. {
  373. size_t sz, szi;
  374. struct efi_device_path *p, *ret;
  375. if (!dpi)
  376. return NULL;
  377. if (!dp)
  378. return efi_dp_dup(dpi);
  379. sz = efi_dp_size(dp);
  380. szi = efi_dp_instance_size(dpi);
  381. p = dp_alloc(sz + szi + 2 * sizeof(END));
  382. if (!p)
  383. return NULL;
  384. ret = p;
  385. memcpy(p, dp, sz + sizeof(END));
  386. p = (void *)p + sz;
  387. p->sub_type = DEVICE_PATH_SUB_TYPE_INSTANCE_END;
  388. p = (void *)p + sizeof(END);
  389. memcpy(p, dpi, szi);
  390. p = (void *)p + szi;
  391. memcpy(p, &END, sizeof(END));
  392. return ret;
  393. }
  394. struct efi_device_path *efi_dp_get_next_instance(struct efi_device_path **dp,
  395. efi_uintn_t *size)
  396. {
  397. size_t sz;
  398. struct efi_device_path *p;
  399. if (size)
  400. *size = 0;
  401. if (!dp || !*dp)
  402. return NULL;
  403. sz = efi_dp_instance_size(*dp);
  404. p = dp_alloc(sz + sizeof(END));
  405. if (!p)
  406. return NULL;
  407. memcpy(p, *dp, sz + sizeof(END));
  408. *dp = (void *)*dp + sz;
  409. if ((*dp)->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END)
  410. *dp = (void *)*dp + sizeof(END);
  411. else
  412. *dp = NULL;
  413. if (size)
  414. *size = sz + sizeof(END);
  415. return p;
  416. }
  417. bool efi_dp_is_multi_instance(const struct efi_device_path *dp)
  418. {
  419. const struct efi_device_path *p = dp;
  420. if (!p)
  421. return false;
  422. while (p->type != DEVICE_PATH_TYPE_END)
  423. p = (void *)p + p->length;
  424. return p->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END;
  425. }
  426. #ifdef CONFIG_DM
  427. /* size of device-path not including END node for device and all parents
  428. * up to the root device.
  429. */
  430. __maybe_unused static unsigned int dp_size(struct udevice *dev)
  431. {
  432. if (!dev || !dev->driver)
  433. return sizeof(ROOT);
  434. switch (dev->driver->id) {
  435. case UCLASS_ROOT:
  436. case UCLASS_SIMPLE_BUS:
  437. /* stop traversing parents at this point: */
  438. return sizeof(ROOT);
  439. case UCLASS_ETH:
  440. return dp_size(dev->parent) +
  441. sizeof(struct efi_device_path_mac_addr);
  442. #ifdef CONFIG_BLK
  443. case UCLASS_BLK:
  444. switch (dev->parent->uclass->uc_drv->id) {
  445. #ifdef CONFIG_IDE
  446. case UCLASS_IDE:
  447. return dp_size(dev->parent) +
  448. sizeof(struct efi_device_path_atapi);
  449. #endif
  450. #if defined(CONFIG_SCSI) && defined(CONFIG_DM_SCSI)
  451. case UCLASS_SCSI:
  452. return dp_size(dev->parent) +
  453. sizeof(struct efi_device_path_scsi);
  454. #endif
  455. #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
  456. case UCLASS_MMC:
  457. return dp_size(dev->parent) +
  458. sizeof(struct efi_device_path_sd_mmc_path);
  459. #endif
  460. #if defined(CONFIG_AHCI) || defined(CONFIG_SATA)
  461. case UCLASS_AHCI:
  462. return dp_size(dev->parent) +
  463. sizeof(struct efi_device_path_sata);
  464. #endif
  465. #if defined(CONFIG_NVME)
  466. case UCLASS_NVME:
  467. return dp_size(dev->parent) +
  468. sizeof(struct efi_device_path_nvme);
  469. #endif
  470. #ifdef CONFIG_SANDBOX
  471. case UCLASS_ROOT:
  472. /*
  473. * Sandbox's host device will be represented
  474. * as vendor device with extra one byte for
  475. * device number
  476. */
  477. return dp_size(dev->parent)
  478. + sizeof(struct efi_device_path_vendor) + 1;
  479. #endif
  480. #ifdef CONFIG_VIRTIO_BLK
  481. case UCLASS_VIRTIO:
  482. /*
  483. * Virtio devices will be represented as a vendor
  484. * device node with an extra byte for the device
  485. * number.
  486. */
  487. return dp_size(dev->parent)
  488. + sizeof(struct efi_device_path_vendor) + 1;
  489. #endif
  490. default:
  491. return dp_size(dev->parent);
  492. }
  493. #endif
  494. #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
  495. case UCLASS_MMC:
  496. return dp_size(dev->parent) +
  497. sizeof(struct efi_device_path_sd_mmc_path);
  498. #endif
  499. case UCLASS_MASS_STORAGE:
  500. case UCLASS_USB_HUB:
  501. return dp_size(dev->parent) +
  502. sizeof(struct efi_device_path_usb_class);
  503. default:
  504. /* just skip over unknown classes: */
  505. return dp_size(dev->parent);
  506. }
  507. }
  508. /*
  509. * Recursively build a device path.
  510. *
  511. * @buf pointer to the end of the device path
  512. * @dev device
  513. * @return pointer to the end of the device path
  514. */
  515. __maybe_unused static void *dp_fill(void *buf, struct udevice *dev)
  516. {
  517. if (!dev || !dev->driver)
  518. return buf;
  519. switch (dev->driver->id) {
  520. case UCLASS_ROOT:
  521. case UCLASS_SIMPLE_BUS: {
  522. /* stop traversing parents at this point: */
  523. struct efi_device_path_vendor *vdp = buf;
  524. *vdp = ROOT;
  525. return &vdp[1];
  526. }
  527. #ifdef CONFIG_DM_ETH
  528. case UCLASS_ETH: {
  529. struct efi_device_path_mac_addr *dp =
  530. dp_fill(buf, dev->parent);
  531. struct eth_pdata *pdata = dev_get_plat(dev);
  532. dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
  533. dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR;
  534. dp->dp.length = sizeof(*dp);
  535. memset(&dp->mac, 0, sizeof(dp->mac));
  536. /* We only support IPv4 */
  537. memcpy(&dp->mac, &pdata->enetaddr, ARP_HLEN);
  538. /* Ethernet */
  539. dp->if_type = 1;
  540. return &dp[1];
  541. }
  542. #endif
  543. #ifdef CONFIG_BLK
  544. case UCLASS_BLK:
  545. switch (dev->parent->uclass->uc_drv->id) {
  546. #ifdef CONFIG_SANDBOX
  547. case UCLASS_ROOT: {
  548. /* stop traversing parents at this point: */
  549. struct efi_device_path_vendor *dp;
  550. struct blk_desc *desc = dev_get_uclass_plat(dev);
  551. dp_fill(buf, dev->parent);
  552. dp = buf;
  553. ++dp;
  554. dp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
  555. dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR;
  556. dp->dp.length = sizeof(*dp) + 1;
  557. memcpy(&dp->guid, &efi_guid_host_dev,
  558. sizeof(efi_guid_t));
  559. dp->vendor_data[0] = desc->devnum;
  560. return &dp->vendor_data[1];
  561. }
  562. #endif
  563. #ifdef CONFIG_VIRTIO_BLK
  564. case UCLASS_VIRTIO: {
  565. struct efi_device_path_vendor *dp;
  566. struct blk_desc *desc = dev_get_uclass_plat(dev);
  567. dp_fill(buf, dev->parent);
  568. dp = buf;
  569. ++dp;
  570. dp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
  571. dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR;
  572. dp->dp.length = sizeof(*dp) + 1;
  573. memcpy(&dp->guid, &efi_guid_virtio_dev,
  574. sizeof(efi_guid_t));
  575. dp->vendor_data[0] = desc->devnum;
  576. return &dp->vendor_data[1];
  577. }
  578. #endif
  579. #ifdef CONFIG_IDE
  580. case UCLASS_IDE: {
  581. struct efi_device_path_atapi *dp =
  582. dp_fill(buf, dev->parent);
  583. struct blk_desc *desc = dev_get_uclass_plat(dev);
  584. dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
  585. dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_ATAPI;
  586. dp->dp.length = sizeof(*dp);
  587. dp->logical_unit_number = desc->devnum;
  588. dp->primary_secondary = IDE_BUS(desc->devnum);
  589. dp->slave_master = desc->devnum %
  590. (CONFIG_SYS_IDE_MAXDEVICE /
  591. CONFIG_SYS_IDE_MAXBUS);
  592. return &dp[1];
  593. }
  594. #endif
  595. #if defined(CONFIG_SCSI) && defined(CONFIG_DM_SCSI)
  596. case UCLASS_SCSI: {
  597. struct efi_device_path_scsi *dp =
  598. dp_fill(buf, dev->parent);
  599. struct blk_desc *desc = dev_get_uclass_plat(dev);
  600. dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
  601. dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SCSI;
  602. dp->dp.length = sizeof(*dp);
  603. dp->logical_unit_number = desc->lun;
  604. dp->target_id = desc->target;
  605. return &dp[1];
  606. }
  607. #endif
  608. #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
  609. case UCLASS_MMC: {
  610. struct efi_device_path_sd_mmc_path *sddp =
  611. dp_fill(buf, dev->parent);
  612. struct blk_desc *desc = dev_get_uclass_plat(dev);
  613. sddp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
  614. sddp->dp.sub_type = is_sd(desc) ?
  615. DEVICE_PATH_SUB_TYPE_MSG_SD :
  616. DEVICE_PATH_SUB_TYPE_MSG_MMC;
  617. sddp->dp.length = sizeof(*sddp);
  618. sddp->slot_number = dev_seq(dev);
  619. return &sddp[1];
  620. }
  621. #endif
  622. #if defined(CONFIG_AHCI) || defined(CONFIG_SATA)
  623. case UCLASS_AHCI: {
  624. struct efi_device_path_sata *dp =
  625. dp_fill(buf, dev->parent);
  626. struct blk_desc *desc = dev_get_uclass_plat(dev);
  627. dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
  628. dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SATA;
  629. dp->dp.length = sizeof(*dp);
  630. dp->hba_port = desc->devnum;
  631. /* default 0xffff implies no port multiplier */
  632. dp->port_multiplier_port = 0xffff;
  633. dp->logical_unit_number = desc->lun;
  634. return &dp[1];
  635. }
  636. #endif
  637. #if defined(CONFIG_NVME)
  638. case UCLASS_NVME: {
  639. struct efi_device_path_nvme *dp =
  640. dp_fill(buf, dev->parent);
  641. u32 ns_id;
  642. dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
  643. dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_NVME;
  644. dp->dp.length = sizeof(*dp);
  645. nvme_get_namespace_id(dev, &ns_id, dp->eui64);
  646. memcpy(&dp->ns_id, &ns_id, sizeof(ns_id));
  647. return &dp[1];
  648. }
  649. #endif
  650. default:
  651. debug("%s(%u) %s: unhandled parent class: %s (%u)\n",
  652. __FILE__, __LINE__, __func__,
  653. dev->name, dev->parent->uclass->uc_drv->id);
  654. return dp_fill(buf, dev->parent);
  655. }
  656. #endif
  657. #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
  658. case UCLASS_MMC: {
  659. struct efi_device_path_sd_mmc_path *sddp =
  660. dp_fill(buf, dev->parent);
  661. struct mmc *mmc = mmc_get_mmc_dev(dev);
  662. struct blk_desc *desc = mmc_get_blk_desc(mmc);
  663. sddp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
  664. sddp->dp.sub_type = is_sd(desc) ?
  665. DEVICE_PATH_SUB_TYPE_MSG_SD :
  666. DEVICE_PATH_SUB_TYPE_MSG_MMC;
  667. sddp->dp.length = sizeof(*sddp);
  668. sddp->slot_number = dev_seq(dev);
  669. return &sddp[1];
  670. }
  671. #endif
  672. case UCLASS_MASS_STORAGE:
  673. case UCLASS_USB_HUB: {
  674. struct efi_device_path_usb_class *udp =
  675. dp_fill(buf, dev->parent);
  676. struct usb_device *udev = dev_get_parent_priv(dev);
  677. struct usb_device_descriptor *desc = &udev->descriptor;
  678. udp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
  679. udp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS;
  680. udp->dp.length = sizeof(*udp);
  681. udp->vendor_id = desc->idVendor;
  682. udp->product_id = desc->idProduct;
  683. udp->device_class = desc->bDeviceClass;
  684. udp->device_subclass = desc->bDeviceSubClass;
  685. udp->device_protocol = desc->bDeviceProtocol;
  686. return &udp[1];
  687. }
  688. default:
  689. debug("%s(%u) %s: unhandled device class: %s (%u)\n",
  690. __FILE__, __LINE__, __func__,
  691. dev->name, dev->driver->id);
  692. return dp_fill(buf, dev->parent);
  693. }
  694. }
  695. #endif
  696. static unsigned dp_part_size(struct blk_desc *desc, int part)
  697. {
  698. unsigned dpsize;
  699. #ifdef CONFIG_BLK
  700. {
  701. struct udevice *dev;
  702. int ret = blk_find_device(desc->if_type, desc->devnum, &dev);
  703. if (ret)
  704. dev = desc->bdev->parent;
  705. dpsize = dp_size(dev);
  706. }
  707. #else
  708. dpsize = sizeof(ROOT) + sizeof(struct efi_device_path_usb);
  709. #endif
  710. if (part == 0) /* the actual disk, not a partition */
  711. return dpsize;
  712. if (desc->part_type == PART_TYPE_ISO)
  713. dpsize += sizeof(struct efi_device_path_cdrom_path);
  714. else
  715. dpsize += sizeof(struct efi_device_path_hard_drive_path);
  716. return dpsize;
  717. }
  718. /*
  719. * Create a device node for a block device partition.
  720. *
  721. * @buf buffer to which the device path is written
  722. * @desc block device descriptor
  723. * @part partition number, 0 identifies a block device
  724. */
  725. static void *dp_part_node(void *buf, struct blk_desc *desc, int part)
  726. {
  727. struct disk_partition info;
  728. part_get_info(desc, part, &info);
  729. if (desc->part_type == PART_TYPE_ISO) {
  730. struct efi_device_path_cdrom_path *cddp = buf;
  731. cddp->boot_entry = part;
  732. cddp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
  733. cddp->dp.sub_type = DEVICE_PATH_SUB_TYPE_CDROM_PATH;
  734. cddp->dp.length = sizeof(*cddp);
  735. cddp->partition_start = info.start;
  736. cddp->partition_size = info.size;
  737. buf = &cddp[1];
  738. } else {
  739. struct efi_device_path_hard_drive_path *hddp = buf;
  740. hddp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
  741. hddp->dp.sub_type = DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH;
  742. hddp->dp.length = sizeof(*hddp);
  743. hddp->partition_number = part;
  744. hddp->partition_start = info.start;
  745. hddp->partition_end = info.size;
  746. if (desc->part_type == PART_TYPE_EFI)
  747. hddp->partmap_type = 2;
  748. else
  749. hddp->partmap_type = 1;
  750. switch (desc->sig_type) {
  751. case SIG_TYPE_NONE:
  752. default:
  753. hddp->signature_type = 0;
  754. memset(hddp->partition_signature, 0,
  755. sizeof(hddp->partition_signature));
  756. break;
  757. case SIG_TYPE_MBR:
  758. hddp->signature_type = 1;
  759. memset(hddp->partition_signature, 0,
  760. sizeof(hddp->partition_signature));
  761. memcpy(hddp->partition_signature, &desc->mbr_sig,
  762. sizeof(desc->mbr_sig));
  763. break;
  764. case SIG_TYPE_GUID:
  765. hddp->signature_type = 2;
  766. if (uuid_str_to_bin(info.uuid,
  767. hddp->partition_signature, 1))
  768. log_warning(
  769. "Partition no. %d: invalid guid: %s\n",
  770. part, info.uuid);
  771. break;
  772. }
  773. buf = &hddp[1];
  774. }
  775. return buf;
  776. }
  777. /*
  778. * Create a device path for a block device or one of its partitions.
  779. *
  780. * @buf buffer to which the device path is written
  781. * @desc block device descriptor
  782. * @part partition number, 0 identifies a block device
  783. */
  784. static void *dp_part_fill(void *buf, struct blk_desc *desc, int part)
  785. {
  786. #ifdef CONFIG_BLK
  787. {
  788. struct udevice *dev;
  789. int ret = blk_find_device(desc->if_type, desc->devnum, &dev);
  790. if (ret)
  791. dev = desc->bdev->parent;
  792. buf = dp_fill(buf, dev);
  793. }
  794. #else
  795. /*
  796. * We *could* make a more accurate path, by looking at if_type
  797. * and handling all the different cases like we do for non-
  798. * legacy (i.e. CONFIG_BLK=y) case. But most important thing
  799. * is just to have a unique device-path for if_type+devnum.
  800. * So map things to a fictitious USB device.
  801. */
  802. struct efi_device_path_usb *udp;
  803. memcpy(buf, &ROOT, sizeof(ROOT));
  804. buf += sizeof(ROOT);
  805. udp = buf;
  806. udp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
  807. udp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_USB;
  808. udp->dp.length = sizeof(*udp);
  809. udp->parent_port_number = desc->if_type;
  810. udp->usb_interface = desc->devnum;
  811. buf = &udp[1];
  812. #endif
  813. if (part == 0) /* the actual disk, not a partition */
  814. return buf;
  815. return dp_part_node(buf, desc, part);
  816. }
  817. /* Construct a device-path from a partition on a block device: */
  818. struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part)
  819. {
  820. void *buf, *start;
  821. start = buf = dp_alloc(dp_part_size(desc, part) + sizeof(END));
  822. if (!buf)
  823. return NULL;
  824. buf = dp_part_fill(buf, desc, part);
  825. *((struct efi_device_path *)buf) = END;
  826. return start;
  827. }
  828. /*
  829. * Create a device node for a block device partition.
  830. *
  831. * @buf buffer to which the device path is written
  832. * @desc block device descriptor
  833. * @part partition number, 0 identifies a block device
  834. */
  835. struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part)
  836. {
  837. efi_uintn_t dpsize;
  838. void *buf;
  839. if (desc->part_type == PART_TYPE_ISO)
  840. dpsize = sizeof(struct efi_device_path_cdrom_path);
  841. else
  842. dpsize = sizeof(struct efi_device_path_hard_drive_path);
  843. buf = dp_alloc(dpsize);
  844. dp_part_node(buf, desc, part);
  845. return buf;
  846. }
  847. /**
  848. * path_to_uefi() - convert UTF-8 path to an UEFI style path
  849. *
  850. * Convert UTF-8 path to a UEFI style path (i.e. with backslashes as path
  851. * separators and UTF-16).
  852. *
  853. * @src: source buffer
  854. * @uefi: target buffer, possibly unaligned
  855. */
  856. static void path_to_uefi(void *uefi, const char *src)
  857. {
  858. u16 *pos = uefi;
  859. /*
  860. * efi_set_bootdev() calls this routine indirectly before the UEFI
  861. * subsystem is initialized. So we cannot assume unaligned access to be
  862. * enabled.
  863. */
  864. allow_unaligned();
  865. while (*src) {
  866. s32 code = utf8_get(&src);
  867. if (code < 0)
  868. code = '?';
  869. else if (code == '/')
  870. code = '\\';
  871. utf16_put(code, &pos);
  872. }
  873. *pos = 0;
  874. }
  875. /*
  876. * If desc is NULL, this creates a path with only the file component,
  877. * otherwise it creates a full path with both device and file components
  878. */
  879. struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
  880. const char *path)
  881. {
  882. struct efi_device_path_file_path *fp;
  883. void *buf, *start;
  884. size_t dpsize = 0, fpsize;
  885. if (desc)
  886. dpsize = dp_part_size(desc, part);
  887. fpsize = sizeof(struct efi_device_path) +
  888. 2 * (utf8_utf16_strlen(path) + 1);
  889. if (fpsize > U16_MAX)
  890. return NULL;
  891. dpsize += fpsize;
  892. start = buf = dp_alloc(dpsize + sizeof(END));
  893. if (!buf)
  894. return NULL;
  895. if (desc)
  896. buf = dp_part_fill(buf, desc, part);
  897. /* add file-path: */
  898. fp = buf;
  899. fp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
  900. fp->dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH;
  901. fp->dp.length = (u16)fpsize;
  902. path_to_uefi(fp->str, path);
  903. buf += fpsize;
  904. *((struct efi_device_path *)buf) = END;
  905. return start;
  906. }
  907. struct efi_device_path *efi_dp_from_uart(void)
  908. {
  909. void *buf, *pos;
  910. struct efi_device_path_uart *uart;
  911. size_t dpsize = sizeof(ROOT) + sizeof(*uart) + sizeof(END);
  912. buf = dp_alloc(dpsize);
  913. if (!buf)
  914. return NULL;
  915. pos = buf;
  916. memcpy(pos, &ROOT, sizeof(ROOT));
  917. pos += sizeof(ROOT);
  918. uart = pos;
  919. uart->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
  920. uart->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_UART;
  921. uart->dp.length = sizeof(*uart);
  922. pos += sizeof(*uart);
  923. memcpy(pos, &END, sizeof(END));
  924. return buf;
  925. }
  926. #ifdef CONFIG_NET
  927. struct efi_device_path *efi_dp_from_eth(void)
  928. {
  929. #ifndef CONFIG_DM_ETH
  930. struct efi_device_path_mac_addr *ndp;
  931. #endif
  932. void *buf, *start;
  933. unsigned dpsize = 0;
  934. assert(eth_get_dev());
  935. #ifdef CONFIG_DM_ETH
  936. dpsize += dp_size(eth_get_dev());
  937. #else
  938. dpsize += sizeof(ROOT);
  939. dpsize += sizeof(*ndp);
  940. #endif
  941. start = buf = dp_alloc(dpsize + sizeof(END));
  942. if (!buf)
  943. return NULL;
  944. #ifdef CONFIG_DM_ETH
  945. buf = dp_fill(buf, eth_get_dev());
  946. #else
  947. memcpy(buf, &ROOT, sizeof(ROOT));
  948. buf += sizeof(ROOT);
  949. ndp = buf;
  950. ndp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
  951. ndp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR;
  952. ndp->dp.length = sizeof(*ndp);
  953. ndp->if_type = 1; /* Ethernet */
  954. memcpy(ndp->mac.addr, eth_get_ethaddr(), ARP_HLEN);
  955. buf = &ndp[1];
  956. #endif
  957. *((struct efi_device_path *)buf) = END;
  958. return start;
  959. }
  960. #endif
  961. /* Construct a device-path for memory-mapped image */
  962. struct efi_device_path *efi_dp_from_mem(uint32_t memory_type,
  963. uint64_t start_address,
  964. uint64_t end_address)
  965. {
  966. struct efi_device_path_memory *mdp;
  967. void *buf, *start;
  968. start = buf = dp_alloc(sizeof(*mdp) + sizeof(END));
  969. if (!buf)
  970. return NULL;
  971. mdp = buf;
  972. mdp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
  973. mdp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MEMORY;
  974. mdp->dp.length = sizeof(*mdp);
  975. mdp->memory_type = memory_type;
  976. mdp->start_address = start_address;
  977. mdp->end_address = end_address;
  978. buf = &mdp[1];
  979. *((struct efi_device_path *)buf) = END;
  980. return start;
  981. }
  982. /**
  983. * efi_dp_split_file_path() - split of relative file path from device path
  984. *
  985. * Given a device path indicating a file on a device, separate the device
  986. * path in two: the device path of the actual device and the file path
  987. * relative to this device.
  988. *
  989. * @full_path: device path including device and file path
  990. * @device_path: path of the device
  991. * @file_path: relative path of the file or NULL if there is none
  992. * Return: status code
  993. */
  994. efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path,
  995. struct efi_device_path **device_path,
  996. struct efi_device_path **file_path)
  997. {
  998. struct efi_device_path *p, *dp, *fp = NULL;
  999. *device_path = NULL;
  1000. *file_path = NULL;
  1001. dp = efi_dp_dup(full_path);
  1002. if (!dp)
  1003. return EFI_OUT_OF_RESOURCES;
  1004. p = dp;
  1005. while (!EFI_DP_TYPE(p, MEDIA_DEVICE, FILE_PATH)) {
  1006. p = efi_dp_next(p);
  1007. if (!p)
  1008. goto out;
  1009. }
  1010. fp = efi_dp_dup(p);
  1011. if (!fp)
  1012. return EFI_OUT_OF_RESOURCES;
  1013. p->type = DEVICE_PATH_TYPE_END;
  1014. p->sub_type = DEVICE_PATH_SUB_TYPE_END;
  1015. p->length = sizeof(*p);
  1016. out:
  1017. *device_path = dp;
  1018. *file_path = fp;
  1019. return EFI_SUCCESS;
  1020. }
  1021. /**
  1022. * efi_dp_from_name() - convert U-Boot device and file path to device path
  1023. *
  1024. * @dev: U-Boot device, e.g. 'mmc'
  1025. * @devnr: U-Boot device number, e.g. 1 for 'mmc:1'
  1026. * @path: file path relative to U-Boot device, may be NULL
  1027. * @device: pointer to receive device path of the device
  1028. * @file: pointer to receive device path for the file
  1029. * Return: status code
  1030. */
  1031. efi_status_t efi_dp_from_name(const char *dev, const char *devnr,
  1032. const char *path,
  1033. struct efi_device_path **device,
  1034. struct efi_device_path **file)
  1035. {
  1036. struct blk_desc *desc = NULL;
  1037. struct disk_partition fs_partition;
  1038. int part = 0;
  1039. char *filename;
  1040. char *s;
  1041. if (path && !file)
  1042. return EFI_INVALID_PARAMETER;
  1043. if (!strcmp(dev, "Net")) {
  1044. #ifdef CONFIG_NET
  1045. if (device)
  1046. *device = efi_dp_from_eth();
  1047. #endif
  1048. } else if (!strcmp(dev, "Uart")) {
  1049. if (device)
  1050. *device = efi_dp_from_uart();
  1051. } else {
  1052. part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition,
  1053. 1);
  1054. if (part < 0 || !desc)
  1055. return EFI_INVALID_PARAMETER;
  1056. if (device)
  1057. *device = efi_dp_from_part(desc, part);
  1058. }
  1059. if (!path)
  1060. return EFI_SUCCESS;
  1061. filename = calloc(1, strlen(path) + 1);
  1062. if (!filename)
  1063. return EFI_OUT_OF_RESOURCES;
  1064. sprintf(filename, "%s", path);
  1065. /* DOS style file path: */
  1066. s = filename;
  1067. while ((s = strchr(s, '/')))
  1068. *s++ = '\\';
  1069. *file = efi_dp_from_file(desc, part, filename);
  1070. free(filename);
  1071. if (!*file)
  1072. return EFI_INVALID_PARAMETER;
  1073. return EFI_SUCCESS;
  1074. }
  1075. /**
  1076. * efi_dp_check_length() - check length of a device path
  1077. *
  1078. * @dp: pointer to device path
  1079. * @maxlen: maximum length of the device path
  1080. * Return:
  1081. * * length of the device path if it is less or equal @maxlen
  1082. * * -1 if the device path is longer then @maxlen
  1083. * * -1 if a device path node has a length of less than 4
  1084. * * -EINVAL if maxlen exceeds SSIZE_MAX
  1085. */
  1086. ssize_t efi_dp_check_length(const struct efi_device_path *dp,
  1087. const size_t maxlen)
  1088. {
  1089. ssize_t ret = 0;
  1090. u16 len;
  1091. if (maxlen > SSIZE_MAX)
  1092. return -EINVAL;
  1093. for (;;) {
  1094. len = dp->length;
  1095. if (len < 4)
  1096. return -1;
  1097. ret += len;
  1098. if (ret > maxlen)
  1099. return -1;
  1100. if (dp->type == DEVICE_PATH_TYPE_END &&
  1101. dp->sub_type == DEVICE_PATH_SUB_TYPE_END)
  1102. return ret;
  1103. dp = (const struct efi_device_path *)((const u8 *)dp + len);
  1104. }
  1105. }
  1106. /**
  1107. * efi_dp_from_lo() - Get the instance of a VenMedia node in a
  1108. * multi-instance device path that matches
  1109. * a specific GUID. This kind of device paths
  1110. * is found in Boot#### options describing an
  1111. * initrd location
  1112. *
  1113. * @lo: EFI_LOAD_OPTION containing a valid device path
  1114. * @size: size of the discovered device path
  1115. * @guid: guid to search for
  1116. *
  1117. * Return:
  1118. * device path including the VenMedia node or NULL.
  1119. * Caller must free the returned value.
  1120. */
  1121. struct
  1122. efi_device_path *efi_dp_from_lo(struct efi_load_option *lo,
  1123. efi_uintn_t *size, efi_guid_t guid)
  1124. {
  1125. struct efi_device_path *fp = lo->file_path;
  1126. struct efi_device_path_vendor *vendor;
  1127. int lo_len = lo->file_path_length;
  1128. for (; lo_len >= sizeof(struct efi_device_path);
  1129. lo_len -= fp->length, fp = (void *)fp + fp->length) {
  1130. if (lo_len < 0 || efi_dp_check_length(fp, lo_len) < 0)
  1131. break;
  1132. if (fp->type != DEVICE_PATH_TYPE_MEDIA_DEVICE ||
  1133. fp->sub_type != DEVICE_PATH_SUB_TYPE_VENDOR_PATH)
  1134. continue;
  1135. vendor = (struct efi_device_path_vendor *)fp;
  1136. if (!guidcmp(&vendor->guid, &guid))
  1137. return efi_dp_dup(fp);
  1138. }
  1139. log_debug("VenMedia(%pUl) not found in %ls\n", &guid, lo->label);
  1140. return NULL;
  1141. }