Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 2 | /* |
| 3 | * EFI device path from u-boot device-model mapping |
| 4 | * |
| 5 | * (C) Copyright 2017 Rob Clark |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 6 | */ |
| 7 | |
Alfonso Sánchez-Beato | f007a37 | 2021-07-15 15:31:42 +0200 | [diff] [blame] | 8 | #define LOG_CATEGORY LOGC_EFI |
| 9 | |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 10 | #include <blk.h> |
| 11 | #include <dm.h> |
Heinrich Schuchardt | 39568fd | 2023-07-19 06:43:08 +0200 | [diff] [blame] | 12 | #include <dm/root.h> |
Simon Glass | 37972f4 | 2025-05-24 11:28:21 -0600 | [diff] [blame^] | 13 | #include <efi_device_path.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 14 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 15 | #include <net.h> |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 16 | #include <usb.h> |
| 17 | #include <mmc.h> |
Patrick Wildt | a3ca37e | 2019-10-03 16:24:17 +0200 | [diff] [blame] | 18 | #include <nvme.h> |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 19 | #include <efi_loader.h> |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 20 | #include <part.h> |
Caleb Connolly | 29cab7c | 2024-08-30 13:34:37 +0100 | [diff] [blame] | 21 | #include <u-boot/uuid.h> |
Heinrich Schuchardt | 8d80af8 | 2019-07-14 19:26:47 +0200 | [diff] [blame] | 22 | #include <asm-generic/unaligned.h> |
AKASHI Takahiro | f1dbbae | 2019-10-09 16:19:52 +0900 | [diff] [blame] | 23 | #include <linux/compat.h> /* U16_MAX */ |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 24 | |
| 25 | /* template END node: */ |
Masahisa Kojima | 97bd9da | 2022-06-19 13:55:59 +0900 | [diff] [blame] | 26 | const struct efi_device_path END = { |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 27 | .type = DEVICE_PATH_TYPE_END, |
| 28 | .sub_type = DEVICE_PATH_SUB_TYPE_END, |
| 29 | .length = sizeof(END), |
| 30 | }; |
| 31 | |
Simon Glass | 222f3cb | 2021-09-24 18:30:17 -0600 | [diff] [blame] | 32 | #if defined(CONFIG_MMC) |
Heinrich Schuchardt | 7d569db | 2017-12-11 12:56:39 +0100 | [diff] [blame] | 33 | /* |
| 34 | * Determine if an MMC device is an SD card. |
| 35 | * |
| 36 | * @desc block device descriptor |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 37 | * Return: true if the device is an SD card |
Heinrich Schuchardt | 7d569db | 2017-12-11 12:56:39 +0100 | [diff] [blame] | 38 | */ |
| 39 | static bool is_sd(struct blk_desc *desc) |
| 40 | { |
| 41 | struct mmc *mmc = find_mmc_device(desc->devnum); |
| 42 | |
| 43 | if (!mmc) |
| 44 | return false; |
| 45 | |
| 46 | return IS_SD(mmc) != 0U; |
| 47 | } |
| 48 | #endif |
| 49 | |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 50 | struct efi_device_path *efi_dp_next(const struct efi_device_path *dp) |
| 51 | { |
| 52 | if (dp == NULL) |
| 53 | return NULL; |
| 54 | if (dp->type == DEVICE_PATH_TYPE_END) |
| 55 | return NULL; |
| 56 | dp = ((void *)dp) + dp->length; |
| 57 | if (dp->type == DEVICE_PATH_TYPE_END) |
| 58 | return NULL; |
| 59 | return (struct efi_device_path *)dp; |
| 60 | } |
| 61 | |
Heinrich Schuchardt | 753e248 | 2017-10-26 19:25:48 +0200 | [diff] [blame] | 62 | int efi_dp_match(const struct efi_device_path *a, |
| 63 | const struct efi_device_path *b) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 64 | { |
| 65 | while (1) { |
| 66 | int ret; |
| 67 | |
| 68 | ret = memcmp(&a->length, &b->length, sizeof(a->length)); |
| 69 | if (ret) |
| 70 | return ret; |
| 71 | |
| 72 | ret = memcmp(a, b, a->length); |
| 73 | if (ret) |
| 74 | return ret; |
| 75 | |
| 76 | a = efi_dp_next(a); |
| 77 | b = efi_dp_next(b); |
| 78 | |
| 79 | if (!a || !b) |
| 80 | return 0; |
| 81 | } |
| 82 | } |
| 83 | |
Heinrich Schuchardt | 24f0e6a | 2022-02-26 12:10:10 +0100 | [diff] [blame] | 84 | struct efi_device_path *efi_dp_shorten(struct efi_device_path *dp) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 85 | { |
| 86 | while (dp) { |
Heinrich Schuchardt | a7ffd90 | 2023-03-26 12:22:40 +0200 | [diff] [blame] | 87 | if (EFI_DP_TYPE(dp, MESSAGING_DEVICE, MSG_USB_WWI) || |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 88 | EFI_DP_TYPE(dp, MEDIA_DEVICE, HARD_DRIVE_PATH) || |
| 89 | EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH)) |
| 90 | return dp; |
| 91 | |
| 92 | dp = efi_dp_next(dp); |
| 93 | } |
| 94 | |
| 95 | return dp; |
| 96 | } |
| 97 | |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 98 | /** |
Heinrich Schuchardt | 0a04a41 | 2022-03-19 06:35:43 +0100 | [diff] [blame] | 99 | * find_handle() - find handle by device path and installed protocol |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 100 | * |
| 101 | * If @rem is provided, the handle with the longest partial match is returned. |
| 102 | * |
| 103 | * @dp: device path to search |
Heinrich Schuchardt | 0a04a41 | 2022-03-19 06:35:43 +0100 | [diff] [blame] | 104 | * @guid: GUID of protocol that must be installed on path or NULL |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 105 | * @short_path: use short form device path for matching |
| 106 | * @rem: pointer to receive remaining device path |
| 107 | * Return: matching handle |
| 108 | */ |
Heinrich Schuchardt | 0a04a41 | 2022-03-19 06:35:43 +0100 | [diff] [blame] | 109 | static efi_handle_t find_handle(struct efi_device_path *dp, |
| 110 | const efi_guid_t *guid, bool short_path, |
| 111 | struct efi_device_path **rem) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 112 | { |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 113 | efi_handle_t handle, best_handle = NULL; |
| 114 | efi_uintn_t len, best_len = 0; |
| 115 | |
| 116 | len = efi_dp_instance_size(dp); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 117 | |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 118 | list_for_each_entry(handle, &efi_obj_list, link) { |
Heinrich Schuchardt | 6953c10 | 2017-11-26 14:05:16 +0100 | [diff] [blame] | 119 | struct efi_handler *handler; |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 120 | struct efi_device_path *dp_current; |
| 121 | efi_uintn_t len_current; |
Heinrich Schuchardt | 6953c10 | 2017-11-26 14:05:16 +0100 | [diff] [blame] | 122 | efi_status_t ret; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 123 | |
Heinrich Schuchardt | 0a04a41 | 2022-03-19 06:35:43 +0100 | [diff] [blame] | 124 | if (guid) { |
| 125 | ret = efi_search_protocol(handle, guid, &handler); |
| 126 | if (ret != EFI_SUCCESS) |
| 127 | continue; |
| 128 | } |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 129 | ret = efi_search_protocol(handle, &efi_guid_device_path, |
| 130 | &handler); |
Heinrich Schuchardt | 6953c10 | 2017-11-26 14:05:16 +0100 | [diff] [blame] | 131 | if (ret != EFI_SUCCESS) |
| 132 | continue; |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 133 | dp_current = handler->protocol_interface; |
| 134 | if (short_path) { |
| 135 | dp_current = efi_dp_shorten(dp_current); |
| 136 | if (!dp_current) |
| 137 | continue; |
| 138 | } |
| 139 | len_current = efi_dp_instance_size(dp_current); |
| 140 | if (rem) { |
Heinrich Schuchardt | 0a04a41 | 2022-03-19 06:35:43 +0100 | [diff] [blame] | 141 | if (len_current > len) |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 142 | continue; |
| 143 | } else { |
| 144 | if (len_current != len) |
| 145 | continue; |
| 146 | } |
Heinrich Schuchardt | 0a04a41 | 2022-03-19 06:35:43 +0100 | [diff] [blame] | 147 | if (memcmp(dp_current, dp, len_current)) |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 148 | continue; |
| 149 | if (!rem) |
| 150 | return handle; |
| 151 | if (len_current > best_len) { |
| 152 | best_len = len_current; |
| 153 | best_handle = handle; |
| 154 | *rem = (void*)((u8 *)dp + len_current); |
| 155 | } |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 156 | } |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 157 | return best_handle; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 158 | } |
| 159 | |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 160 | efi_handle_t efi_dp_find_obj(struct efi_device_path *dp, |
Heinrich Schuchardt | 0a04a41 | 2022-03-19 06:35:43 +0100 | [diff] [blame] | 161 | const efi_guid_t *guid, |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 162 | struct efi_device_path **rem) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 163 | { |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 164 | efi_handle_t handle; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 165 | |
Heinrich Schuchardt | 0a04a41 | 2022-03-19 06:35:43 +0100 | [diff] [blame] | 166 | handle = find_handle(dp, guid, false, rem); |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 167 | if (!handle) |
| 168 | /* Match short form device path */ |
Heinrich Schuchardt | 0a04a41 | 2022-03-19 06:35:43 +0100 | [diff] [blame] | 169 | handle = find_handle(dp, guid, true, rem); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 170 | |
Heinrich Schuchardt | ad6d5a4 | 2022-03-04 08:20:00 +0100 | [diff] [blame] | 171 | return handle; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 172 | } |
| 173 | |
Heinrich Schuchardt | 0976f8b | 2018-01-19 20:24:49 +0100 | [diff] [blame] | 174 | const struct efi_device_path *efi_dp_last_node(const struct efi_device_path *dp) |
| 175 | { |
| 176 | struct efi_device_path *ret; |
| 177 | |
| 178 | if (!dp || dp->type == DEVICE_PATH_TYPE_END) |
| 179 | return NULL; |
| 180 | while (dp) { |
| 181 | ret = (struct efi_device_path *)dp; |
| 182 | dp = efi_dp_next(dp); |
| 183 | } |
| 184 | return ret; |
| 185 | } |
| 186 | |
Heinrich Schuchardt | 51ca4f5 | 2018-04-16 07:59:08 +0200 | [diff] [blame] | 187 | efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 188 | { |
Heinrich Schuchardt | 51ca4f5 | 2018-04-16 07:59:08 +0200 | [diff] [blame] | 189 | efi_uintn_t sz = 0; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 190 | |
Heinrich Schuchardt | 01d48ed | 2018-04-16 07:59:07 +0200 | [diff] [blame] | 191 | if (!dp || dp->type == DEVICE_PATH_TYPE_END) |
| 192 | return 0; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 193 | while (dp) { |
| 194 | sz += dp->length; |
| 195 | dp = efi_dp_next(dp); |
| 196 | } |
| 197 | |
| 198 | return sz; |
| 199 | } |
| 200 | |
Heinrich Schuchardt | 51ca4f5 | 2018-04-16 07:59:08 +0200 | [diff] [blame] | 201 | efi_uintn_t efi_dp_size(const struct efi_device_path *dp) |
| 202 | { |
| 203 | const struct efi_device_path *p = dp; |
| 204 | |
| 205 | if (!p) |
| 206 | return 0; |
| 207 | while (p->type != DEVICE_PATH_TYPE_END || |
| 208 | p->sub_type != DEVICE_PATH_SUB_TYPE_END) |
| 209 | p = (void *)p + p->length; |
| 210 | |
| 211 | return (void *)p - (void *)dp; |
| 212 | } |
| 213 | |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 214 | struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp) |
| 215 | { |
| 216 | struct efi_device_path *ndp; |
Heinrich Schuchardt | 51ca4f5 | 2018-04-16 07:59:08 +0200 | [diff] [blame] | 217 | size_t sz = efi_dp_size(dp) + sizeof(END); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 218 | |
| 219 | if (!dp) |
| 220 | return NULL; |
| 221 | |
Heinrich Schuchardt | 4564025 | 2023-03-19 09:20:22 +0100 | [diff] [blame] | 222 | ndp = efi_alloc(sz); |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 223 | if (!ndp) |
| 224 | return NULL; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 225 | memcpy(ndp, dp, sz); |
| 226 | |
| 227 | return ndp; |
| 228 | } |
| 229 | |
Ilias Apalodimas | 5dcefa7 | 2024-01-08 10:55:33 +0200 | [diff] [blame] | 230 | struct |
| 231 | efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, |
| 232 | const struct efi_device_path *dp2, |
Heinrich Schuchardt | f8de009 | 2024-05-24 14:54:26 +0200 | [diff] [blame] | 233 | size_t split_end_node) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 234 | { |
| 235 | struct efi_device_path *ret; |
Ilias Apalodimas | 5dcefa7 | 2024-01-08 10:55:33 +0200 | [diff] [blame] | 236 | size_t end_size; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 237 | |
Heinrich Schuchardt | 60b5ab2 | 2018-04-16 07:59:06 +0200 | [diff] [blame] | 238 | if (!dp1 && !dp2) { |
| 239 | /* return an end node */ |
| 240 | ret = efi_dp_dup(&END); |
| 241 | } else if (!dp1) { |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 242 | ret = efi_dp_dup(dp2); |
| 243 | } else if (!dp2) { |
| 244 | ret = efi_dp_dup(dp1); |
| 245 | } else { |
| 246 | /* both dp1 and dp2 are non-null */ |
Heinrich Schuchardt | f8de009 | 2024-05-24 14:54:26 +0200 | [diff] [blame] | 247 | size_t sz1; |
| 248 | size_t sz2 = efi_dp_size(dp2); |
Ilias Apalodimas | 5dcefa7 | 2024-01-08 10:55:33 +0200 | [diff] [blame] | 249 | void *p; |
| 250 | |
Heinrich Schuchardt | f8de009 | 2024-05-24 14:54:26 +0200 | [diff] [blame] | 251 | if (split_end_node < sizeof(struct efi_device_path)) |
| 252 | sz1 = efi_dp_size(dp1); |
| 253 | else |
| 254 | sz1 = split_end_node; |
| 255 | |
Ilias Apalodimas | 5dcefa7 | 2024-01-08 10:55:33 +0200 | [diff] [blame] | 256 | if (split_end_node) |
| 257 | end_size = 2 * sizeof(END); |
| 258 | else |
| 259 | end_size = sizeof(END); |
| 260 | p = efi_alloc(sz1 + sz2 + end_size); |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 261 | if (!p) |
| 262 | return NULL; |
Ilias Apalodimas | 483d28e | 2021-03-17 21:54:58 +0200 | [diff] [blame] | 263 | ret = p; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 264 | memcpy(p, dp1, sz1); |
Ilias Apalodimas | 483d28e | 2021-03-17 21:54:58 +0200 | [diff] [blame] | 265 | p += sz1; |
| 266 | |
Ilias Apalodimas | 5dcefa7 | 2024-01-08 10:55:33 +0200 | [diff] [blame] | 267 | if (split_end_node) { |
Ilias Apalodimas | 483d28e | 2021-03-17 21:54:58 +0200 | [diff] [blame] | 268 | memcpy(p, &END, sizeof(END)); |
| 269 | p += sizeof(END); |
| 270 | } |
| 271 | |
Heinrich Schuchardt | 60b5ab2 | 2018-04-16 07:59:06 +0200 | [diff] [blame] | 272 | /* the end node of the second device path has to be retained */ |
Ilias Apalodimas | 483d28e | 2021-03-17 21:54:58 +0200 | [diff] [blame] | 273 | memcpy(p, dp2, sz2); |
| 274 | p += sz2; |
| 275 | memcpy(p, &END, sizeof(END)); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp, |
| 282 | const struct efi_device_path *node) |
| 283 | { |
| 284 | struct efi_device_path *ret; |
| 285 | |
| 286 | if (!node && !dp) { |
| 287 | ret = efi_dp_dup(&END); |
| 288 | } else if (!node) { |
| 289 | ret = efi_dp_dup(dp); |
| 290 | } else if (!dp) { |
Heinrich Schuchardt | 51ca4f5 | 2018-04-16 07:59:08 +0200 | [diff] [blame] | 291 | size_t sz = node->length; |
Heinrich Schuchardt | 4564025 | 2023-03-19 09:20:22 +0100 | [diff] [blame] | 292 | void *p = efi_alloc(sz + sizeof(END)); |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 293 | if (!p) |
| 294 | return NULL; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 295 | memcpy(p, node, sz); |
| 296 | memcpy(p + sz, &END, sizeof(END)); |
| 297 | ret = p; |
| 298 | } else { |
| 299 | /* both dp and node are non-null */ |
Heinrich Schuchardt | 51ca4f5 | 2018-04-16 07:59:08 +0200 | [diff] [blame] | 300 | size_t sz = efi_dp_size(dp); |
Heinrich Schuchardt | 4564025 | 2023-03-19 09:20:22 +0100 | [diff] [blame] | 301 | void *p = efi_alloc(sz + node->length + sizeof(END)); |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 302 | if (!p) |
| 303 | return NULL; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 304 | memcpy(p, dp, sz); |
| 305 | memcpy(p + sz, node, node->length); |
| 306 | memcpy(p + sz + node->length, &END, sizeof(END)); |
| 307 | ret = p; |
| 308 | } |
| 309 | |
| 310 | return ret; |
| 311 | } |
| 312 | |
Heinrich Schuchardt | b41c8e2 | 2018-04-16 07:59:05 +0200 | [diff] [blame] | 313 | struct efi_device_path *efi_dp_create_device_node(const u8 type, |
| 314 | const u8 sub_type, |
| 315 | const u16 length) |
| 316 | { |
| 317 | struct efi_device_path *ret; |
| 318 | |
Heinrich Schuchardt | c96c594 | 2019-04-23 00:51:01 +0200 | [diff] [blame] | 319 | if (length < sizeof(struct efi_device_path)) |
| 320 | return NULL; |
| 321 | |
Heinrich Schuchardt | 4564025 | 2023-03-19 09:20:22 +0100 | [diff] [blame] | 322 | ret = efi_alloc(length); |
Heinrich Schuchardt | b41c8e2 | 2018-04-16 07:59:05 +0200 | [diff] [blame] | 323 | if (!ret) |
| 324 | return ret; |
| 325 | ret->type = type; |
| 326 | ret->sub_type = sub_type; |
| 327 | ret->length = length; |
| 328 | return ret; |
| 329 | } |
| 330 | |
Heinrich Schuchardt | cb0f7ce | 2018-04-16 07:59:09 +0200 | [diff] [blame] | 331 | struct efi_device_path *efi_dp_append_instance( |
| 332 | const struct efi_device_path *dp, |
| 333 | const struct efi_device_path *dpi) |
| 334 | { |
| 335 | size_t sz, szi; |
| 336 | struct efi_device_path *p, *ret; |
| 337 | |
| 338 | if (!dpi) |
| 339 | return NULL; |
| 340 | if (!dp) |
| 341 | return efi_dp_dup(dpi); |
| 342 | sz = efi_dp_size(dp); |
| 343 | szi = efi_dp_instance_size(dpi); |
Heinrich Schuchardt | 4564025 | 2023-03-19 09:20:22 +0100 | [diff] [blame] | 344 | p = efi_alloc(sz + szi + 2 * sizeof(END)); |
Heinrich Schuchardt | cb0f7ce | 2018-04-16 07:59:09 +0200 | [diff] [blame] | 345 | if (!p) |
| 346 | return NULL; |
| 347 | ret = p; |
| 348 | memcpy(p, dp, sz + sizeof(END)); |
| 349 | p = (void *)p + sz; |
| 350 | p->sub_type = DEVICE_PATH_SUB_TYPE_INSTANCE_END; |
| 351 | p = (void *)p + sizeof(END); |
| 352 | memcpy(p, dpi, szi); |
| 353 | p = (void *)p + szi; |
| 354 | memcpy(p, &END, sizeof(END)); |
| 355 | return ret; |
| 356 | } |
| 357 | |
| 358 | struct efi_device_path *efi_dp_get_next_instance(struct efi_device_path **dp, |
| 359 | efi_uintn_t *size) |
| 360 | { |
| 361 | size_t sz; |
| 362 | struct efi_device_path *p; |
| 363 | |
| 364 | if (size) |
| 365 | *size = 0; |
| 366 | if (!dp || !*dp) |
| 367 | return NULL; |
Heinrich Schuchardt | cb0f7ce | 2018-04-16 07:59:09 +0200 | [diff] [blame] | 368 | sz = efi_dp_instance_size(*dp); |
Heinrich Schuchardt | 4564025 | 2023-03-19 09:20:22 +0100 | [diff] [blame] | 369 | p = efi_alloc(sz + sizeof(END)); |
Heinrich Schuchardt | cb0f7ce | 2018-04-16 07:59:09 +0200 | [diff] [blame] | 370 | if (!p) |
| 371 | return NULL; |
| 372 | memcpy(p, *dp, sz + sizeof(END)); |
| 373 | *dp = (void *)*dp + sz; |
| 374 | if ((*dp)->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END) |
| 375 | *dp = (void *)*dp + sizeof(END); |
| 376 | else |
| 377 | *dp = NULL; |
| 378 | if (size) |
| 379 | *size = sz + sizeof(END); |
| 380 | return p; |
| 381 | } |
| 382 | |
| 383 | bool efi_dp_is_multi_instance(const struct efi_device_path *dp) |
| 384 | { |
| 385 | const struct efi_device_path *p = dp; |
| 386 | |
| 387 | if (!p) |
| 388 | return false; |
| 389 | while (p->type != DEVICE_PATH_TYPE_END) |
| 390 | p = (void *)p + p->length; |
| 391 | return p->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END; |
| 392 | } |
| 393 | |
Heinrich Schuchardt | c22d9e3 | 2019-11-10 02:16:33 +0100 | [diff] [blame] | 394 | __maybe_unused static unsigned int dp_size(struct udevice *dev) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 395 | { |
| 396 | if (!dev || !dev->driver) |
Heinrich Schuchardt | 39568fd | 2023-07-19 06:43:08 +0200 | [diff] [blame] | 397 | return sizeof(struct efi_device_path_udevice); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 398 | |
Simon Glass | 56ada7b | 2022-01-29 14:58:38 -0700 | [diff] [blame] | 399 | switch (device_get_uclass_id(dev)) { |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 400 | case UCLASS_ROOT: |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 401 | /* stop traversing parents at this point: */ |
Heinrich Schuchardt | 39568fd | 2023-07-19 06:43:08 +0200 | [diff] [blame] | 402 | return sizeof(struct efi_device_path_udevice); |
Heinrich Schuchardt | 1f1d49d | 2018-01-20 21:02:18 +0100 | [diff] [blame] | 403 | case UCLASS_ETH: |
| 404 | return dp_size(dev->parent) + |
| 405 | sizeof(struct efi_device_path_mac_addr); |
Heinrich Schuchardt | e2dcb9a | 2017-12-11 12:56:44 +0100 | [diff] [blame] | 406 | case UCLASS_BLK: |
| 407 | switch (dev->parent->uclass->uc_drv->id) { |
| 408 | #ifdef CONFIG_IDE |
| 409 | case UCLASS_IDE: |
| 410 | return dp_size(dev->parent) + |
| 411 | sizeof(struct efi_device_path_atapi); |
| 412 | #endif |
Simon Glass | 222f3cb | 2021-09-24 18:30:17 -0600 | [diff] [blame] | 413 | #if defined(CONFIG_SCSI) |
Heinrich Schuchardt | e2dcb9a | 2017-12-11 12:56:44 +0100 | [diff] [blame] | 414 | case UCLASS_SCSI: |
| 415 | return dp_size(dev->parent) + |
| 416 | sizeof(struct efi_device_path_scsi); |
| 417 | #endif |
Simon Glass | 222f3cb | 2021-09-24 18:30:17 -0600 | [diff] [blame] | 418 | #if defined(CONFIG_MMC) |
Heinrich Schuchardt | 1f1d49d | 2018-01-20 21:02:18 +0100 | [diff] [blame] | 419 | case UCLASS_MMC: |
| 420 | return dp_size(dev->parent) + |
| 421 | sizeof(struct efi_device_path_sd_mmc_path); |
| 422 | #endif |
Heinrich Schuchardt | 7bdb602 | 2020-05-20 23:12:02 +0200 | [diff] [blame] | 423 | #if defined(CONFIG_AHCI) || defined(CONFIG_SATA) |
| 424 | case UCLASS_AHCI: |
| 425 | return dp_size(dev->parent) + |
| 426 | sizeof(struct efi_device_path_sata); |
| 427 | #endif |
Patrick Wildt | a3ca37e | 2019-10-03 16:24:17 +0200 | [diff] [blame] | 428 | #if defined(CONFIG_NVME) |
| 429 | case UCLASS_NVME: |
| 430 | return dp_size(dev->parent) + |
| 431 | sizeof(struct efi_device_path_nvme); |
| 432 | #endif |
Heinrich Schuchardt | 25b18d6 | 2023-03-19 16:18:09 +0100 | [diff] [blame] | 433 | #ifdef CONFIG_USB |
| 434 | case UCLASS_MASS_STORAGE: |
| 435 | return dp_size(dev->parent) |
| 436 | + sizeof(struct efi_device_path_controller); |
| 437 | #endif |
Heinrich Schuchardt | e2dcb9a | 2017-12-11 12:56:44 +0100 | [diff] [blame] | 438 | default: |
Heinrich Schuchardt | 8433a5d | 2023-07-21 00:03:46 +0200 | [diff] [blame] | 439 | /* UCLASS_BLKMAP, UCLASS_HOST, UCLASS_VIRTIO */ |
| 440 | return dp_size(dev->parent) + |
| 441 | sizeof(struct efi_device_path_udevice); |
Heinrich Schuchardt | e2dcb9a | 2017-12-11 12:56:44 +0100 | [diff] [blame] | 442 | } |
Simon Glass | 222f3cb | 2021-09-24 18:30:17 -0600 | [diff] [blame] | 443 | #if defined(CONFIG_MMC) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 444 | case UCLASS_MMC: |
| 445 | return dp_size(dev->parent) + |
| 446 | sizeof(struct efi_device_path_sd_mmc_path); |
Heinrich Schuchardt | 1f1d49d | 2018-01-20 21:02:18 +0100 | [diff] [blame] | 447 | #endif |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 448 | case UCLASS_MASS_STORAGE: |
| 449 | case UCLASS_USB_HUB: |
| 450 | return dp_size(dev->parent) + |
Heinrich Schuchardt | 25b18d6 | 2023-03-19 16:18:09 +0100 | [diff] [blame] | 451 | sizeof(struct efi_device_path_usb); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 452 | default: |
Heinrich Schuchardt | 39568fd | 2023-07-19 06:43:08 +0200 | [diff] [blame] | 453 | return dp_size(dev->parent) + |
| 454 | sizeof(struct efi_device_path_udevice); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
Heinrich Schuchardt | e2dcb9a | 2017-12-11 12:56:44 +0100 | [diff] [blame] | 458 | /* |
| 459 | * Recursively build a device path. |
| 460 | * |
| 461 | * @buf pointer to the end of the device path |
| 462 | * @dev device |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 463 | * Return: pointer to the end of the device path |
Heinrich Schuchardt | e2dcb9a | 2017-12-11 12:56:44 +0100 | [diff] [blame] | 464 | */ |
Heinrich Schuchardt | c22d9e3 | 2019-11-10 02:16:33 +0100 | [diff] [blame] | 465 | __maybe_unused static void *dp_fill(void *buf, struct udevice *dev) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 466 | { |
Heinrich Schuchardt | 3d34763 | 2023-07-21 08:34:18 +0200 | [diff] [blame] | 467 | enum uclass_id uclass_id; |
| 468 | |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 469 | if (!dev || !dev->driver) |
| 470 | return buf; |
| 471 | |
Heinrich Schuchardt | 3d34763 | 2023-07-21 08:34:18 +0200 | [diff] [blame] | 472 | uclass_id = device_get_uclass_id(dev); |
| 473 | if (uclass_id != UCLASS_ROOT) |
| 474 | buf = dp_fill(buf, dev->parent); |
| 475 | |
| 476 | switch (uclass_id) { |
Jan Kiszka | f138982 | 2022-10-14 18:10:06 +0200 | [diff] [blame] | 477 | #ifdef CONFIG_NETDEVICES |
Heinrich Schuchardt | 1f1d49d | 2018-01-20 21:02:18 +0100 | [diff] [blame] | 478 | case UCLASS_ETH: { |
Heinrich Schuchardt | 3d34763 | 2023-07-21 08:34:18 +0200 | [diff] [blame] | 479 | struct efi_device_path_mac_addr *dp = buf; |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 480 | struct eth_pdata *pdata = dev_get_plat(dev); |
Heinrich Schuchardt | 1f1d49d | 2018-01-20 21:02:18 +0100 | [diff] [blame] | 481 | |
| 482 | dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; |
| 483 | dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR; |
| 484 | dp->dp.length = sizeof(*dp); |
| 485 | memset(&dp->mac, 0, sizeof(dp->mac)); |
| 486 | /* We only support IPv4 */ |
| 487 | memcpy(&dp->mac, &pdata->enetaddr, ARP_HLEN); |
| 488 | /* Ethernet */ |
| 489 | dp->if_type = 1; |
| 490 | return &dp[1]; |
| 491 | } |
| 492 | #endif |
Heinrich Schuchardt | e2dcb9a | 2017-12-11 12:56:44 +0100 | [diff] [blame] | 493 | case UCLASS_BLK: |
Heinrich Schuchardt | 8433a5d | 2023-07-21 00:03:46 +0200 | [diff] [blame] | 494 | switch (device_get_uclass_id(dev->parent)) { |
Heinrich Schuchardt | e2dcb9a | 2017-12-11 12:56:44 +0100 | [diff] [blame] | 495 | #ifdef CONFIG_IDE |
| 496 | case UCLASS_IDE: { |
Heinrich Schuchardt | 3d34763 | 2023-07-21 08:34:18 +0200 | [diff] [blame] | 497 | struct efi_device_path_atapi *dp = buf; |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 498 | struct blk_desc *desc = dev_get_uclass_plat(dev); |
Heinrich Schuchardt | e2dcb9a | 2017-12-11 12:56:44 +0100 | [diff] [blame] | 499 | |
| 500 | dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; |
| 501 | dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_ATAPI; |
| 502 | dp->dp.length = sizeof(*dp); |
| 503 | dp->logical_unit_number = desc->devnum; |
| 504 | dp->primary_secondary = IDE_BUS(desc->devnum); |
| 505 | dp->slave_master = desc->devnum % |
| 506 | (CONFIG_SYS_IDE_MAXDEVICE / |
| 507 | CONFIG_SYS_IDE_MAXBUS); |
| 508 | return &dp[1]; |
| 509 | } |
| 510 | #endif |
Simon Glass | 222f3cb | 2021-09-24 18:30:17 -0600 | [diff] [blame] | 511 | #if defined(CONFIG_SCSI) |
Heinrich Schuchardt | e2dcb9a | 2017-12-11 12:56:44 +0100 | [diff] [blame] | 512 | case UCLASS_SCSI: { |
Heinrich Schuchardt | 3d34763 | 2023-07-21 08:34:18 +0200 | [diff] [blame] | 513 | struct efi_device_path_scsi *dp = buf; |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 514 | struct blk_desc *desc = dev_get_uclass_plat(dev); |
Heinrich Schuchardt | e2dcb9a | 2017-12-11 12:56:44 +0100 | [diff] [blame] | 515 | |
| 516 | dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; |
| 517 | dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SCSI; |
| 518 | dp->dp.length = sizeof(*dp); |
| 519 | dp->logical_unit_number = desc->lun; |
| 520 | dp->target_id = desc->target; |
| 521 | return &dp[1]; |
| 522 | } |
| 523 | #endif |
Simon Glass | 222f3cb | 2021-09-24 18:30:17 -0600 | [diff] [blame] | 524 | #if defined(CONFIG_MMC) |
Heinrich Schuchardt | 1f1d49d | 2018-01-20 21:02:18 +0100 | [diff] [blame] | 525 | case UCLASS_MMC: { |
Heinrich Schuchardt | 3d34763 | 2023-07-21 08:34:18 +0200 | [diff] [blame] | 526 | struct efi_device_path_sd_mmc_path *sddp = buf; |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 527 | struct blk_desc *desc = dev_get_uclass_plat(dev); |
Heinrich Schuchardt | 1f1d49d | 2018-01-20 21:02:18 +0100 | [diff] [blame] | 528 | |
| 529 | sddp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; |
| 530 | sddp->dp.sub_type = is_sd(desc) ? |
| 531 | DEVICE_PATH_SUB_TYPE_MSG_SD : |
| 532 | DEVICE_PATH_SUB_TYPE_MSG_MMC; |
| 533 | sddp->dp.length = sizeof(*sddp); |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 534 | sddp->slot_number = dev_seq(dev); |
Heinrich Schuchardt | 1f1d49d | 2018-01-20 21:02:18 +0100 | [diff] [blame] | 535 | return &sddp[1]; |
| 536 | } |
| 537 | #endif |
Heinrich Schuchardt | 7bdb602 | 2020-05-20 23:12:02 +0200 | [diff] [blame] | 538 | #if defined(CONFIG_AHCI) || defined(CONFIG_SATA) |
| 539 | case UCLASS_AHCI: { |
Heinrich Schuchardt | 3d34763 | 2023-07-21 08:34:18 +0200 | [diff] [blame] | 540 | struct efi_device_path_sata *dp = buf; |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 541 | struct blk_desc *desc = dev_get_uclass_plat(dev); |
Heinrich Schuchardt | 7bdb602 | 2020-05-20 23:12:02 +0200 | [diff] [blame] | 542 | |
| 543 | dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; |
| 544 | dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SATA; |
| 545 | dp->dp.length = sizeof(*dp); |
| 546 | dp->hba_port = desc->devnum; |
| 547 | /* default 0xffff implies no port multiplier */ |
| 548 | dp->port_multiplier_port = 0xffff; |
| 549 | dp->logical_unit_number = desc->lun; |
| 550 | return &dp[1]; |
| 551 | } |
| 552 | #endif |
Patrick Wildt | a3ca37e | 2019-10-03 16:24:17 +0200 | [diff] [blame] | 553 | #if defined(CONFIG_NVME) |
| 554 | case UCLASS_NVME: { |
Heinrich Schuchardt | 3d34763 | 2023-07-21 08:34:18 +0200 | [diff] [blame] | 555 | struct efi_device_path_nvme *dp = buf; |
Patrick Wildt | a3ca37e | 2019-10-03 16:24:17 +0200 | [diff] [blame] | 556 | u32 ns_id; |
| 557 | |
| 558 | dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; |
| 559 | dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_NVME; |
| 560 | dp->dp.length = sizeof(*dp); |
| 561 | nvme_get_namespace_id(dev, &ns_id, dp->eui64); |
| 562 | memcpy(&dp->ns_id, &ns_id, sizeof(ns_id)); |
| 563 | return &dp[1]; |
| 564 | } |
| 565 | #endif |
Heinrich Schuchardt | 25b18d6 | 2023-03-19 16:18:09 +0100 | [diff] [blame] | 566 | #if defined(CONFIG_USB) |
| 567 | case UCLASS_MASS_STORAGE: { |
Heinrich Schuchardt | 232c9db | 2023-04-01 07:21:55 +0200 | [diff] [blame] | 568 | struct blk_desc *desc = dev_get_uclass_plat(dev); |
Heinrich Schuchardt | 3d34763 | 2023-07-21 08:34:18 +0200 | [diff] [blame] | 569 | struct efi_device_path_controller *dp = buf; |
Heinrich Schuchardt | 25b18d6 | 2023-03-19 16:18:09 +0100 | [diff] [blame] | 570 | |
| 571 | dp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE; |
| 572 | dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_CONTROLLER; |
| 573 | dp->dp.length = sizeof(*dp); |
| 574 | dp->controller_number = desc->lun; |
| 575 | return &dp[1]; |
| 576 | } |
| 577 | #endif |
Heinrich Schuchardt | 8433a5d | 2023-07-21 00:03:46 +0200 | [diff] [blame] | 578 | default: { |
| 579 | /* UCLASS_BLKMAP, UCLASS_HOST, UCLASS_VIRTIO */ |
Heinrich Schuchardt | 3d34763 | 2023-07-21 08:34:18 +0200 | [diff] [blame] | 580 | struct efi_device_path_udevice *dp = buf; |
Heinrich Schuchardt | 8433a5d | 2023-07-21 00:03:46 +0200 | [diff] [blame] | 581 | struct blk_desc *desc = dev_get_uclass_plat(dev); |
| 582 | |
Heinrich Schuchardt | 8433a5d | 2023-07-21 00:03:46 +0200 | [diff] [blame] | 583 | dp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE; |
| 584 | dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR; |
| 585 | dp->dp.length = sizeof(*dp); |
| 586 | memcpy(&dp->guid, &efi_u_boot_guid, |
| 587 | sizeof(efi_guid_t)); |
| 588 | dp->uclass_id = (UCLASS_BLK & 0xffff) | |
| 589 | (desc->uclass_id << 16); |
| 590 | dp->dev_number = desc->devnum; |
| 591 | |
| 592 | return &dp[1]; |
Heinrich Schuchardt | e2dcb9a | 2017-12-11 12:56:44 +0100 | [diff] [blame] | 593 | } |
Heinrich Schuchardt | 8433a5d | 2023-07-21 00:03:46 +0200 | [diff] [blame] | 594 | } |
Simon Glass | 222f3cb | 2021-09-24 18:30:17 -0600 | [diff] [blame] | 595 | #if defined(CONFIG_MMC) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 596 | case UCLASS_MMC: { |
Heinrich Schuchardt | 3d34763 | 2023-07-21 08:34:18 +0200 | [diff] [blame] | 597 | struct efi_device_path_sd_mmc_path *sddp = buf; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 598 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
| 599 | struct blk_desc *desc = mmc_get_blk_desc(mmc); |
| 600 | |
| 601 | sddp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; |
Heinrich Schuchardt | 7d569db | 2017-12-11 12:56:39 +0100 | [diff] [blame] | 602 | sddp->dp.sub_type = is_sd(desc) ? |
| 603 | DEVICE_PATH_SUB_TYPE_MSG_SD : |
| 604 | DEVICE_PATH_SUB_TYPE_MSG_MMC; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 605 | sddp->dp.length = sizeof(*sddp); |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 606 | sddp->slot_number = dev_seq(dev); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 607 | |
| 608 | return &sddp[1]; |
| 609 | } |
| 610 | #endif |
| 611 | case UCLASS_MASS_STORAGE: |
| 612 | case UCLASS_USB_HUB: { |
Heinrich Schuchardt | 3d34763 | 2023-07-21 08:34:18 +0200 | [diff] [blame] | 613 | struct efi_device_path_usb *udp = buf; |
Heinrich Schuchardt | 25b18d6 | 2023-03-19 16:18:09 +0100 | [diff] [blame] | 614 | |
| 615 | switch (device_get_uclass_id(dev->parent)) { |
| 616 | case UCLASS_USB_HUB: { |
| 617 | struct usb_device *udev = dev_get_parent_priv(dev); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 618 | |
Heinrich Schuchardt | 25b18d6 | 2023-03-19 16:18:09 +0100 | [diff] [blame] | 619 | udp->parent_port_number = udev->portnr; |
| 620 | break; |
| 621 | } |
| 622 | default: |
| 623 | udp->parent_port_number = 0; |
| 624 | } |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 625 | udp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; |
Heinrich Schuchardt | 25b18d6 | 2023-03-19 16:18:09 +0100 | [diff] [blame] | 626 | udp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_USB; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 627 | udp->dp.length = sizeof(*udp); |
Heinrich Schuchardt | 25b18d6 | 2023-03-19 16:18:09 +0100 | [diff] [blame] | 628 | udp->usb_interface = 0; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 629 | |
| 630 | return &udp[1]; |
| 631 | } |
Heinrich Schuchardt | 39568fd | 2023-07-19 06:43:08 +0200 | [diff] [blame] | 632 | default: { |
Heinrich Schuchardt | 3d34763 | 2023-07-21 08:34:18 +0200 | [diff] [blame] | 633 | struct efi_device_path_udevice *vdp = buf; |
Heinrich Schuchardt | 39568fd | 2023-07-19 06:43:08 +0200 | [diff] [blame] | 634 | |
| 635 | vdp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE; |
| 636 | vdp->dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR; |
| 637 | vdp->dp.length = sizeof(*vdp); |
| 638 | memcpy(&vdp->guid, &efi_u_boot_guid, sizeof(efi_guid_t)); |
| 639 | vdp->uclass_id = uclass_id; |
| 640 | vdp->dev_number = dev->seq_; |
| 641 | |
| 642 | return &vdp[1]; |
| 643 | } |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 644 | } |
| 645 | } |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 646 | |
| 647 | static unsigned dp_part_size(struct blk_desc *desc, int part) |
| 648 | { |
| 649 | unsigned dpsize; |
Simon Glass | ec209a7 | 2022-01-29 14:58:39 -0700 | [diff] [blame] | 650 | struct udevice *dev = desc->bdev; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 651 | |
Simon Glass | 222f3cb | 2021-09-24 18:30:17 -0600 | [diff] [blame] | 652 | dpsize = dp_size(dev); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 653 | |
| 654 | if (part == 0) /* the actual disk, not a partition */ |
| 655 | return dpsize; |
| 656 | |
| 657 | if (desc->part_type == PART_TYPE_ISO) |
| 658 | dpsize += sizeof(struct efi_device_path_cdrom_path); |
| 659 | else |
| 660 | dpsize += sizeof(struct efi_device_path_hard_drive_path); |
| 661 | |
| 662 | return dpsize; |
| 663 | } |
| 664 | |
Heinrich Schuchardt | 8983ffd | 2017-12-11 12:56:42 +0100 | [diff] [blame] | 665 | /* |
Heinrich Schuchardt | 6c6307c | 2018-01-19 20:24:46 +0100 | [diff] [blame] | 666 | * Create a device node for a block device partition. |
Heinrich Schuchardt | 8983ffd | 2017-12-11 12:56:42 +0100 | [diff] [blame] | 667 | * |
Heinrich Schuchardt | b21f839 | 2018-10-17 21:55:24 +0200 | [diff] [blame] | 668 | * @buf buffer to which the device path is written |
Heinrich Schuchardt | 8983ffd | 2017-12-11 12:56:42 +0100 | [diff] [blame] | 669 | * @desc block device descriptor |
| 670 | * @part partition number, 0 identifies a block device |
Heinrich Schuchardt | ee69ae1 | 2023-05-27 08:18:28 +0200 | [diff] [blame] | 671 | * |
| 672 | * Return: pointer to position after the node |
Heinrich Schuchardt | 8983ffd | 2017-12-11 12:56:42 +0100 | [diff] [blame] | 673 | */ |
Heinrich Schuchardt | 6c6307c | 2018-01-19 20:24:46 +0100 | [diff] [blame] | 674 | static void *dp_part_node(void *buf, struct blk_desc *desc, int part) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 675 | { |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 676 | struct disk_partition info; |
Heinrich Schuchardt | ee69ae1 | 2023-05-27 08:18:28 +0200 | [diff] [blame] | 677 | int ret; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 678 | |
Heinrich Schuchardt | ee69ae1 | 2023-05-27 08:18:28 +0200 | [diff] [blame] | 679 | ret = part_get_info(desc, part, &info); |
| 680 | if (ret < 0) |
| 681 | return buf; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 682 | |
| 683 | if (desc->part_type == PART_TYPE_ISO) { |
| 684 | struct efi_device_path_cdrom_path *cddp = buf; |
| 685 | |
Heinrich Schuchardt | 2aae6db | 2017-12-11 12:56:40 +0100 | [diff] [blame] | 686 | cddp->boot_entry = part; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 687 | cddp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE; |
| 688 | cddp->dp.sub_type = DEVICE_PATH_SUB_TYPE_CDROM_PATH; |
| 689 | cddp->dp.length = sizeof(*cddp); |
| 690 | cddp->partition_start = info.start; |
Heinrich Schuchardt | 28dfd1a | 2019-09-04 13:56:01 +0200 | [diff] [blame] | 691 | cddp->partition_size = info.size; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 692 | |
| 693 | buf = &cddp[1]; |
| 694 | } else { |
| 695 | struct efi_device_path_hard_drive_path *hddp = buf; |
| 696 | |
| 697 | hddp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE; |
| 698 | hddp->dp.sub_type = DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH; |
| 699 | hddp->dp.length = sizeof(*hddp); |
Heinrich Schuchardt | 2aae6db | 2017-12-11 12:56:40 +0100 | [diff] [blame] | 700 | hddp->partition_number = part; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 701 | hddp->partition_start = info.start; |
| 702 | hddp->partition_end = info.size; |
| 703 | if (desc->part_type == PART_TYPE_EFI) |
| 704 | hddp->partmap_type = 2; |
| 705 | else |
| 706 | hddp->partmap_type = 1; |
Jonathan Gray | 84b4d70 | 2017-11-22 14:18:59 +1100 | [diff] [blame] | 707 | |
| 708 | switch (desc->sig_type) { |
| 709 | case SIG_TYPE_NONE: |
| 710 | default: |
| 711 | hddp->signature_type = 0; |
| 712 | memset(hddp->partition_signature, 0, |
| 713 | sizeof(hddp->partition_signature)); |
| 714 | break; |
| 715 | case SIG_TYPE_MBR: |
| 716 | hddp->signature_type = 1; |
| 717 | memset(hddp->partition_signature, 0, |
| 718 | sizeof(hddp->partition_signature)); |
| 719 | memcpy(hddp->partition_signature, &desc->mbr_sig, |
| 720 | sizeof(desc->mbr_sig)); |
| 721 | break; |
| 722 | case SIG_TYPE_GUID: |
| 723 | hddp->signature_type = 2; |
AKASHI Takahiro | ae18a67 | 2022-04-19 10:01:56 +0900 | [diff] [blame] | 724 | #if CONFIG_IS_ENABLED(PARTITION_UUIDS) |
| 725 | /* info.uuid exists only with PARTITION_UUIDS */ |
Alfonso Sánchez-Beato | f007a37 | 2021-07-15 15:31:42 +0200 | [diff] [blame] | 726 | if (uuid_str_to_bin(info.uuid, |
AKASHI Takahiro | ae18a67 | 2022-04-19 10:01:56 +0900 | [diff] [blame] | 727 | hddp->partition_signature, |
| 728 | UUID_STR_FORMAT_GUID)) { |
Alfonso Sánchez-Beato | f007a37 | 2021-07-15 15:31:42 +0200 | [diff] [blame] | 729 | log_warning( |
AKASHI Takahiro | ae18a67 | 2022-04-19 10:01:56 +0900 | [diff] [blame] | 730 | "Partition %d: invalid GUID %s\n", |
Alfonso Sánchez-Beato | f007a37 | 2021-07-15 15:31:42 +0200 | [diff] [blame] | 731 | part, info.uuid); |
AKASHI Takahiro | ae18a67 | 2022-04-19 10:01:56 +0900 | [diff] [blame] | 732 | } |
| 733 | #endif |
Jonathan Gray | 84b4d70 | 2017-11-22 14:18:59 +1100 | [diff] [blame] | 734 | break; |
| 735 | } |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 736 | |
| 737 | buf = &hddp[1]; |
| 738 | } |
| 739 | |
| 740 | return buf; |
| 741 | } |
| 742 | |
Heinrich Schuchardt | 6c6307c | 2018-01-19 20:24:46 +0100 | [diff] [blame] | 743 | /* |
| 744 | * Create a device path for a block device or one of its partitions. |
| 745 | * |
Heinrich Schuchardt | b21f839 | 2018-10-17 21:55:24 +0200 | [diff] [blame] | 746 | * @buf buffer to which the device path is written |
Heinrich Schuchardt | 6c6307c | 2018-01-19 20:24:46 +0100 | [diff] [blame] | 747 | * @desc block device descriptor |
| 748 | * @part partition number, 0 identifies a block device |
| 749 | */ |
| 750 | static void *dp_part_fill(void *buf, struct blk_desc *desc, int part) |
| 751 | { |
Simon Glass | ec209a7 | 2022-01-29 14:58:39 -0700 | [diff] [blame] | 752 | struct udevice *dev = desc->bdev; |
Heinrich Schuchardt | 6c6307c | 2018-01-19 20:24:46 +0100 | [diff] [blame] | 753 | |
Simon Glass | 222f3cb | 2021-09-24 18:30:17 -0600 | [diff] [blame] | 754 | buf = dp_fill(buf, dev); |
Heinrich Schuchardt | 6c6307c | 2018-01-19 20:24:46 +0100 | [diff] [blame] | 755 | |
| 756 | if (part == 0) /* the actual disk, not a partition */ |
| 757 | return buf; |
| 758 | |
| 759 | return dp_part_node(buf, desc, part); |
| 760 | } |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 761 | |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 762 | struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part) |
| 763 | { |
| 764 | void *buf, *start; |
| 765 | |
Heinrich Schuchardt | 4564025 | 2023-03-19 09:20:22 +0100 | [diff] [blame] | 766 | start = buf = efi_alloc(dp_part_size(desc, part) + sizeof(END)); |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 767 | if (!buf) |
| 768 | return NULL; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 769 | |
| 770 | buf = dp_part_fill(buf, desc, part); |
| 771 | |
| 772 | *((struct efi_device_path *)buf) = END; |
| 773 | |
| 774 | return start; |
| 775 | } |
| 776 | |
Heinrich Schuchardt | 6c6307c | 2018-01-19 20:24:46 +0100 | [diff] [blame] | 777 | struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part) |
| 778 | { |
| 779 | efi_uintn_t dpsize; |
| 780 | void *buf; |
| 781 | |
| 782 | if (desc->part_type == PART_TYPE_ISO) |
| 783 | dpsize = sizeof(struct efi_device_path_cdrom_path); |
| 784 | else |
| 785 | dpsize = sizeof(struct efi_device_path_hard_drive_path); |
Heinrich Schuchardt | 4564025 | 2023-03-19 09:20:22 +0100 | [diff] [blame] | 786 | buf = efi_alloc(dpsize); |
Heinrich Schuchardt | 6c6307c | 2018-01-19 20:24:46 +0100 | [diff] [blame] | 787 | |
Heinrich Schuchardt | e29fbb3 | 2022-10-06 13:36:02 +0200 | [diff] [blame] | 788 | if (buf) |
| 789 | dp_part_node(buf, desc, part); |
Heinrich Schuchardt | 6c6307c | 2018-01-19 20:24:46 +0100 | [diff] [blame] | 790 | |
| 791 | return buf; |
| 792 | } |
| 793 | |
Heinrich Schuchardt | 8d80af8 | 2019-07-14 19:26:47 +0200 | [diff] [blame] | 794 | /** |
| 795 | * path_to_uefi() - convert UTF-8 path to an UEFI style path |
| 796 | * |
| 797 | * Convert UTF-8 path to a UEFI style path (i.e. with backslashes as path |
| 798 | * separators and UTF-16). |
| 799 | * |
| 800 | * @src: source buffer |
| 801 | * @uefi: target buffer, possibly unaligned |
| 802 | */ |
| 803 | static void path_to_uefi(void *uefi, const char *src) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 804 | { |
Heinrich Schuchardt | 8d80af8 | 2019-07-14 19:26:47 +0200 | [diff] [blame] | 805 | u16 *pos = uefi; |
| 806 | |
| 807 | /* |
| 808 | * efi_set_bootdev() calls this routine indirectly before the UEFI |
| 809 | * subsystem is initialized. So we cannot assume unaligned access to be |
| 810 | * enabled. |
| 811 | */ |
| 812 | allow_unaligned(); |
| 813 | |
| 814 | while (*src) { |
| 815 | s32 code = utf8_get(&src); |
| 816 | |
| 817 | if (code < 0) |
| 818 | code = '?'; |
| 819 | else if (code == '/') |
| 820 | code = '\\'; |
| 821 | utf16_put(code, &pos); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 822 | } |
Heinrich Schuchardt | 8d80af8 | 2019-07-14 19:26:47 +0200 | [diff] [blame] | 823 | *pos = 0; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 824 | } |
| 825 | |
Heinrich Schuchardt | ff08eac | 2023-05-13 10:36:21 +0200 | [diff] [blame] | 826 | struct efi_device_path *efi_dp_from_file(const struct efi_device_path *dp, |
| 827 | const char *path) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 828 | { |
| 829 | struct efi_device_path_file_path *fp; |
Heinrich Schuchardt | 16eff69 | 2023-05-13 10:18:24 +0200 | [diff] [blame] | 830 | void *buf, *pos; |
Heinrich Schuchardt | ff08eac | 2023-05-13 10:36:21 +0200 | [diff] [blame] | 831 | size_t dpsize, fpsize; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 832 | |
Heinrich Schuchardt | ff08eac | 2023-05-13 10:36:21 +0200 | [diff] [blame] | 833 | dpsize = efi_dp_size(dp); |
Heinrich Schuchardt | 8d80af8 | 2019-07-14 19:26:47 +0200 | [diff] [blame] | 834 | fpsize = sizeof(struct efi_device_path) + |
| 835 | 2 * (utf8_utf16_strlen(path) + 1); |
AKASHI Takahiro | f1dbbae | 2019-10-09 16:19:52 +0900 | [diff] [blame] | 836 | if (fpsize > U16_MAX) |
| 837 | return NULL; |
| 838 | |
Heinrich Schuchardt | ff08eac | 2023-05-13 10:36:21 +0200 | [diff] [blame] | 839 | buf = efi_alloc(dpsize + fpsize + sizeof(END)); |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 840 | if (!buf) |
| 841 | return NULL; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 842 | |
Heinrich Schuchardt | ff08eac | 2023-05-13 10:36:21 +0200 | [diff] [blame] | 843 | memcpy(buf, dp, dpsize); |
| 844 | pos = buf + dpsize; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 845 | |
| 846 | /* add file-path: */ |
Heinrich Schuchardt | f57eacb | 2022-06-11 05:22:08 +0000 | [diff] [blame] | 847 | if (*path) { |
Heinrich Schuchardt | 16eff69 | 2023-05-13 10:18:24 +0200 | [diff] [blame] | 848 | fp = pos; |
Heinrich Schuchardt | f57eacb | 2022-06-11 05:22:08 +0000 | [diff] [blame] | 849 | fp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE; |
| 850 | fp->dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH; |
| 851 | fp->dp.length = (u16)fpsize; |
| 852 | path_to_uefi(fp->str, path); |
Heinrich Schuchardt | 16eff69 | 2023-05-13 10:18:24 +0200 | [diff] [blame] | 853 | pos += fpsize; |
Heinrich Schuchardt | f57eacb | 2022-06-11 05:22:08 +0000 | [diff] [blame] | 854 | } |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 855 | |
Heinrich Schuchardt | 16eff69 | 2023-05-13 10:18:24 +0200 | [diff] [blame] | 856 | memcpy(pos, &END, sizeof(END)); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 857 | |
Heinrich Schuchardt | 16eff69 | 2023-05-13 10:18:24 +0200 | [diff] [blame] | 858 | return buf; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 859 | } |
| 860 | |
Heinrich Schuchardt | 77c0da8 | 2021-03-19 02:49:54 +0100 | [diff] [blame] | 861 | struct efi_device_path *efi_dp_from_uart(void) |
| 862 | { |
| 863 | void *buf, *pos; |
| 864 | struct efi_device_path_uart *uart; |
Heinrich Schuchardt | 39568fd | 2023-07-19 06:43:08 +0200 | [diff] [blame] | 865 | size_t dpsize = dp_size(dm_root()) + sizeof(*uart) + sizeof(END); |
Heinrich Schuchardt | 77c0da8 | 2021-03-19 02:49:54 +0100 | [diff] [blame] | 866 | |
Heinrich Schuchardt | 4564025 | 2023-03-19 09:20:22 +0100 | [diff] [blame] | 867 | buf = efi_alloc(dpsize); |
Heinrich Schuchardt | 77c0da8 | 2021-03-19 02:49:54 +0100 | [diff] [blame] | 868 | if (!buf) |
| 869 | return NULL; |
Heinrich Schuchardt | 39568fd | 2023-07-19 06:43:08 +0200 | [diff] [blame] | 870 | pos = dp_fill(buf, dm_root()); |
Heinrich Schuchardt | 77c0da8 | 2021-03-19 02:49:54 +0100 | [diff] [blame] | 871 | uart = pos; |
| 872 | uart->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; |
| 873 | uart->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_UART; |
| 874 | uart->dp.length = sizeof(*uart); |
| 875 | pos += sizeof(*uart); |
| 876 | memcpy(pos, &END, sizeof(END)); |
| 877 | |
| 878 | return buf; |
| 879 | } |
| 880 | |
Adriano Cordova | 1d37031 | 2025-03-03 11:13:14 -0300 | [diff] [blame] | 881 | struct efi_device_path __maybe_unused *efi_dp_from_eth(struct udevice *dev) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 882 | { |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 883 | void *buf, *start; |
| 884 | unsigned dpsize = 0; |
| 885 | |
Adriano Cordova | 1d37031 | 2025-03-03 11:13:14 -0300 | [diff] [blame] | 886 | assert(dev); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 887 | |
Adriano Cordova | 1d37031 | 2025-03-03 11:13:14 -0300 | [diff] [blame] | 888 | dpsize += dp_size(dev); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 889 | |
Heinrich Schuchardt | 4564025 | 2023-03-19 09:20:22 +0100 | [diff] [blame] | 890 | start = buf = efi_alloc(dpsize + sizeof(END)); |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 891 | if (!buf) |
| 892 | return NULL; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 893 | |
Adriano Cordova | 1d37031 | 2025-03-03 11:13:14 -0300 | [diff] [blame] | 894 | buf = dp_fill(buf, dev); |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 895 | |
| 896 | *((struct efi_device_path *)buf) = END; |
| 897 | |
| 898 | return start; |
| 899 | } |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 900 | |
Adriano Cordova | e9be2da | 2024-12-04 00:05:18 -0300 | [diff] [blame] | 901 | /** |
| 902 | * efi_dp_from_ipv4() - set device path from IPv4 address |
| 903 | * |
| 904 | * Set the device path to an ethernet device path as provided by |
| 905 | * efi_dp_from_eth() concatenated with a device path of subtype |
| 906 | * DEVICE_PATH_SUB_TYPE_MSG_IPV4, and an END node. |
| 907 | * |
| 908 | * @ip: IPv4 local address |
| 909 | * @mask: network mask |
| 910 | * @srv: IPv4 remote/server address |
Adriano Cordova | 1d37031 | 2025-03-03 11:13:14 -0300 | [diff] [blame] | 911 | * @dev: net udevice |
Adriano Cordova | e9be2da | 2024-12-04 00:05:18 -0300 | [diff] [blame] | 912 | * Return: pointer to device path, NULL on error |
| 913 | */ |
| 914 | static struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, |
| 915 | struct efi_ipv4_address *mask, |
Adriano Cordova | 1d37031 | 2025-03-03 11:13:14 -0300 | [diff] [blame] | 916 | struct efi_ipv4_address *srv, |
| 917 | struct udevice *dev) |
Adriano Cordova | e9be2da | 2024-12-04 00:05:18 -0300 | [diff] [blame] | 918 | { |
| 919 | struct efi_device_path *dp1, *dp2, *pos; |
| 920 | struct { |
| 921 | struct efi_device_path_ipv4 ipv4dp; |
| 922 | struct efi_device_path end; |
| 923 | } dp; |
| 924 | |
| 925 | memset(&dp.ipv4dp, 0, sizeof(dp.ipv4dp)); |
| 926 | dp.ipv4dp.dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; |
| 927 | dp.ipv4dp.dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_IPV4; |
| 928 | dp.ipv4dp.dp.length = sizeof(dp.ipv4dp); |
| 929 | dp.ipv4dp.protocol = 6; |
| 930 | if (ip) |
| 931 | memcpy(&dp.ipv4dp.local_ip_address, ip, sizeof(*ip)); |
| 932 | if (mask) |
| 933 | memcpy(&dp.ipv4dp.subnet_mask, mask, sizeof(*mask)); |
| 934 | if (srv) |
| 935 | memcpy(&dp.ipv4dp.remote_ip_address, srv, sizeof(*srv)); |
| 936 | pos = &dp.end; |
| 937 | memcpy(pos, &END, sizeof(END)); |
| 938 | |
Adriano Cordova | 1d37031 | 2025-03-03 11:13:14 -0300 | [diff] [blame] | 939 | dp1 = efi_dp_from_eth(dev); |
Adriano Cordova | e9be2da | 2024-12-04 00:05:18 -0300 | [diff] [blame] | 940 | if (!dp1) |
| 941 | return NULL; |
| 942 | |
| 943 | dp2 = efi_dp_concat(dp1, (const struct efi_device_path *)&dp, 0); |
| 944 | |
| 945 | efi_free_pool(dp1); |
| 946 | |
| 947 | return dp2; |
| 948 | } |
| 949 | |
Adriano Cordova | 1d37031 | 2025-03-03 11:13:14 -0300 | [diff] [blame] | 950 | struct efi_device_path *efi_dp_from_http(const char *server, struct udevice *dev) |
Adriano Cordova | 4bd5eca | 2024-12-04 00:05:22 -0300 | [diff] [blame] | 951 | { |
| 952 | struct efi_device_path *dp1, *dp2; |
| 953 | struct efi_device_path_uri *uridp; |
| 954 | efi_uintn_t uridp_len; |
| 955 | char *pos; |
| 956 | char tmp[128]; |
| 957 | struct efi_ipv4_address ip; |
| 958 | struct efi_ipv4_address mask; |
| 959 | |
| 960 | if ((server && strlen("http://") + strlen(server) + 1 > sizeof(tmp)) || |
| 961 | (!server && IS_ENABLED(CONFIG_NET_LWIP))) |
| 962 | return NULL; |
| 963 | |
Adriano Cordova | 5467469 | 2025-03-03 11:13:15 -0300 | [diff] [blame] | 964 | efi_net_get_addr(&ip, &mask, NULL, dev); |
Adriano Cordova | 4bd5eca | 2024-12-04 00:05:22 -0300 | [diff] [blame] | 965 | |
Adriano Cordova | 1d37031 | 2025-03-03 11:13:14 -0300 | [diff] [blame] | 966 | dp1 = efi_dp_from_ipv4(&ip, &mask, NULL, dev); |
Adriano Cordova | 4bd5eca | 2024-12-04 00:05:22 -0300 | [diff] [blame] | 967 | if (!dp1) |
| 968 | return NULL; |
| 969 | |
Adriano Cordova | 1d37031 | 2025-03-03 11:13:14 -0300 | [diff] [blame] | 970 | |
Adriano Cordova | 4bd5eca | 2024-12-04 00:05:22 -0300 | [diff] [blame] | 971 | strcpy(tmp, "http://"); |
| 972 | |
| 973 | if (server) { |
| 974 | strlcat(tmp, server, sizeof(tmp)); |
| 975 | #if !IS_ENABLED(CONFIG_NET_LWIP) |
Tom Rini | 1968754 | 2024-12-04 09:32:28 -0600 | [diff] [blame] | 976 | } else { |
Adriano Cordova | 4bd5eca | 2024-12-04 00:05:22 -0300 | [diff] [blame] | 977 | ip_to_string(net_server_ip, tmp + strlen("http://")); |
| 978 | #endif |
| 979 | } |
| 980 | |
| 981 | uridp_len = sizeof(struct efi_device_path) + strlen(tmp) + 1; |
| 982 | uridp = efi_alloc(uridp_len + sizeof(END)); |
| 983 | if (!uridp) { |
| 984 | log_err("Out of memory\n"); |
| 985 | return NULL; |
| 986 | } |
| 987 | uridp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; |
| 988 | uridp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_URI; |
| 989 | uridp->dp.length = uridp_len; |
| 990 | debug("device path: setting uri device path to %s\n", tmp); |
| 991 | memcpy(uridp->uri, tmp, strlen(tmp) + 1); |
| 992 | |
| 993 | pos = (char *)uridp + uridp_len; |
| 994 | memcpy(pos, &END, sizeof(END)); |
| 995 | |
| 996 | dp2 = efi_dp_concat(dp1, (const struct efi_device_path *)uridp, 0); |
| 997 | |
| 998 | efi_free_pool(uridp); |
| 999 | efi_free_pool(dp1); |
| 1000 | |
| 1001 | return dp2; |
| 1002 | } |
| 1003 | |
Rob Clark | 18ceba7 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 1004 | /* Construct a device-path for memory-mapped image */ |
| 1005 | struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, |
| 1006 | uint64_t start_address, |
Moritz Fischer | fe61a8b | 2024-11-04 01:49:34 +0000 | [diff] [blame] | 1007 | size_t size) |
Rob Clark | 18ceba7 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 1008 | { |
| 1009 | struct efi_device_path_memory *mdp; |
| 1010 | void *buf, *start; |
| 1011 | |
Heinrich Schuchardt | 4564025 | 2023-03-19 09:20:22 +0100 | [diff] [blame] | 1012 | start = buf = efi_alloc(sizeof(*mdp) + sizeof(END)); |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 1013 | if (!buf) |
| 1014 | return NULL; |
Rob Clark | 18ceba7 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 1015 | |
| 1016 | mdp = buf; |
| 1017 | mdp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE; |
| 1018 | mdp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MEMORY; |
| 1019 | mdp->dp.length = sizeof(*mdp); |
| 1020 | mdp->memory_type = memory_type; |
| 1021 | mdp->start_address = start_address; |
Moritz Fischer | fe61a8b | 2024-11-04 01:49:34 +0000 | [diff] [blame] | 1022 | mdp->end_address = start_address + size; |
Rob Clark | 18ceba7 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 1023 | buf = &mdp[1]; |
| 1024 | |
| 1025 | *((struct efi_device_path *)buf) = END; |
| 1026 | |
| 1027 | return start; |
| 1028 | } |
| 1029 | |
Heinrich Schuchardt | 0d36adc | 2019-02-04 12:49:43 +0100 | [diff] [blame] | 1030 | /** |
| 1031 | * efi_dp_split_file_path() - split of relative file path from device path |
| 1032 | * |
| 1033 | * Given a device path indicating a file on a device, separate the device |
| 1034 | * path in two: the device path of the actual device and the file path |
| 1035 | * relative to this device. |
| 1036 | * |
| 1037 | * @full_path: device path including device and file path |
| 1038 | * @device_path: path of the device |
AKASHI Takahiro | 9c6531f | 2019-04-16 17:39:26 +0200 | [diff] [blame] | 1039 | * @file_path: relative path of the file or NULL if there is none |
Heinrich Schuchardt | 0d36adc | 2019-02-04 12:49:43 +0100 | [diff] [blame] | 1040 | * Return: status code |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 1041 | */ |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 1042 | efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path, |
| 1043 | struct efi_device_path **device_path, |
| 1044 | struct efi_device_path **file_path) |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 1045 | { |
AKASHI Takahiro | 9c6531f | 2019-04-16 17:39:26 +0200 | [diff] [blame] | 1046 | struct efi_device_path *p, *dp, *fp = NULL; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 1047 | |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 1048 | *device_path = NULL; |
| 1049 | *file_path = NULL; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 1050 | dp = efi_dp_dup(full_path); |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 1051 | if (!dp) |
| 1052 | return EFI_OUT_OF_RESOURCES; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 1053 | p = dp; |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 1054 | while (!EFI_DP_TYPE(p, MEDIA_DEVICE, FILE_PATH)) { |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 1055 | p = efi_dp_next(p); |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 1056 | if (!p) |
AKASHI Takahiro | 9c6531f | 2019-04-16 17:39:26 +0200 | [diff] [blame] | 1057 | goto out; |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 1058 | } |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 1059 | fp = efi_dp_dup(p); |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 1060 | if (!fp) |
| 1061 | return EFI_OUT_OF_RESOURCES; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 1062 | p->type = DEVICE_PATH_TYPE_END; |
| 1063 | p->sub_type = DEVICE_PATH_SUB_TYPE_END; |
| 1064 | p->length = sizeof(*p); |
| 1065 | |
AKASHI Takahiro | 9c6531f | 2019-04-16 17:39:26 +0200 | [diff] [blame] | 1066 | out: |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 1067 | *device_path = dp; |
| 1068 | *file_path = fp; |
Heinrich Schuchardt | 468bf97 | 2018-01-19 20:24:37 +0100 | [diff] [blame] | 1069 | return EFI_SUCCESS; |
Rob Clark | f90cb9f | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 1070 | } |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 1071 | |
Heinrich Schuchardt | 6e0a1b4 | 2019-10-30 20:13:24 +0100 | [diff] [blame] | 1072 | /** |
| 1073 | * efi_dp_from_name() - convert U-Boot device and file path to device path |
| 1074 | * |
| 1075 | * @dev: U-Boot device, e.g. 'mmc' |
| 1076 | * @devnr: U-Boot device number, e.g. 1 for 'mmc:1' |
| 1077 | * @path: file path relative to U-Boot device, may be NULL |
| 1078 | * @device: pointer to receive device path of the device |
| 1079 | * @file: pointer to receive device path for the file |
| 1080 | * Return: status code |
| 1081 | */ |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 1082 | efi_status_t efi_dp_from_name(const char *dev, const char *devnr, |
| 1083 | const char *path, |
| 1084 | struct efi_device_path **device, |
| 1085 | struct efi_device_path **file) |
| 1086 | { |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 1087 | struct blk_desc *desc = NULL; |
Heinrich Schuchardt | 7e269a3 | 2023-05-13 10:30:43 +0200 | [diff] [blame] | 1088 | struct efi_device_path *dp; |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 1089 | struct disk_partition fs_partition; |
Rui Miguel Silva | 433f15a | 2022-05-11 10:55:40 +0100 | [diff] [blame] | 1090 | size_t image_size; |
| 1091 | void *image_addr; |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 1092 | int part = 0; |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 1093 | |
AKASHI Takahiro | 3984441 | 2018-11-05 18:06:40 +0900 | [diff] [blame] | 1094 | if (path && !file) |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 1095 | return EFI_INVALID_PARAMETER; |
| 1096 | |
AKASHI Takahiro | 9b08b9a | 2024-01-17 13:39:41 +0900 | [diff] [blame] | 1097 | if (IS_ENABLED(CONFIG_EFI_BINARY_EXEC) && |
| 1098 | (!strcmp(dev, "Mem") || !strcmp(dev, "hostfs"))) { |
Heinrich Schuchardt | aecb9e2 | 2023-05-12 20:18:10 +0200 | [diff] [blame] | 1099 | /* loadm command and semihosting */ |
Rui Miguel Silva | 433f15a | 2022-05-11 10:55:40 +0100 | [diff] [blame] | 1100 | efi_get_image_parameters(&image_addr, &image_size); |
| 1101 | |
Heinrich Schuchardt | 7e269a3 | 2023-05-13 10:30:43 +0200 | [diff] [blame] | 1102 | dp = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, |
Moritz Fischer | fe61a8b | 2024-11-04 01:49:34 +0000 | [diff] [blame] | 1103 | (uintptr_t)image_addr, image_size); |
Adriano Cordova | 93cba0f | 2024-12-04 00:05:23 -0300 | [diff] [blame] | 1104 | } else if (IS_ENABLED(CONFIG_NETDEVICES) && |
Adriano Cordova | 5467469 | 2025-03-03 11:13:15 -0300 | [diff] [blame] | 1105 | (!strcmp(dev, "Net") || !strcmp(dev, "Http"))) { |
| 1106 | efi_net_dp_from_dev(&dp, eth_get_dev(), false); |
Heinrich Schuchardt | 87b8a71 | 2023-05-13 09:55:26 +0200 | [diff] [blame] | 1107 | } else if (!strcmp(dev, "Uart")) { |
Heinrich Schuchardt | 7e269a3 | 2023-05-13 10:30:43 +0200 | [diff] [blame] | 1108 | dp = efi_dp_from_uart(); |
Heinrich Schuchardt | 77c0da8 | 2021-03-19 02:49:54 +0100 | [diff] [blame] | 1109 | } else { |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 1110 | part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition, |
| 1111 | 1); |
Patrick Delaunay | ba7a950 | 2019-04-10 11:02:58 +0200 | [diff] [blame] | 1112 | if (part < 0 || !desc) |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 1113 | return EFI_INVALID_PARAMETER; |
| 1114 | |
Heinrich Schuchardt | 7e269a3 | 2023-05-13 10:30:43 +0200 | [diff] [blame] | 1115 | dp = efi_dp_from_part(desc, part); |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 1116 | } |
Heinrich Schuchardt | 7e269a3 | 2023-05-13 10:30:43 +0200 | [diff] [blame] | 1117 | if (device) |
| 1118 | *device = dp; |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 1119 | |
| 1120 | if (!path) |
| 1121 | return EFI_SUCCESS; |
| 1122 | |
Heinrich Schuchardt | ff08eac | 2023-05-13 10:36:21 +0200 | [diff] [blame] | 1123 | *file = efi_dp_from_file(dp, path); |
Heinrich Schuchardt | 6e0a1b4 | 2019-10-30 20:13:24 +0100 | [diff] [blame] | 1124 | if (!*file) |
Heinrich Schuchardt | bf0b3a1 | 2023-05-13 10:22:21 +0200 | [diff] [blame] | 1125 | return EFI_OUT_OF_RESOURCES; |
AKASHI Takahiro | f1dbbae | 2019-10-09 16:19:52 +0900 | [diff] [blame] | 1126 | |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 1127 | return EFI_SUCCESS; |
| 1128 | } |
Heinrich Schuchardt | 22c8e08 | 2020-08-23 10:49:46 +0200 | [diff] [blame] | 1129 | |
| 1130 | /** |
| 1131 | * efi_dp_check_length() - check length of a device path |
| 1132 | * |
| 1133 | * @dp: pointer to device path |
| 1134 | * @maxlen: maximum length of the device path |
| 1135 | * Return: |
| 1136 | * * length of the device path if it is less or equal @maxlen |
| 1137 | * * -1 if the device path is longer then @maxlen |
| 1138 | * * -1 if a device path node has a length of less than 4 |
| 1139 | * * -EINVAL if maxlen exceeds SSIZE_MAX |
| 1140 | */ |
| 1141 | ssize_t efi_dp_check_length(const struct efi_device_path *dp, |
| 1142 | const size_t maxlen) |
| 1143 | { |
| 1144 | ssize_t ret = 0; |
| 1145 | u16 len; |
| 1146 | |
| 1147 | if (maxlen > SSIZE_MAX) |
| 1148 | return -EINVAL; |
| 1149 | for (;;) { |
| 1150 | len = dp->length; |
| 1151 | if (len < 4) |
| 1152 | return -1; |
| 1153 | ret += len; |
| 1154 | if (ret > maxlen) |
| 1155 | return -1; |
| 1156 | if (dp->type == DEVICE_PATH_TYPE_END && |
| 1157 | dp->sub_type == DEVICE_PATH_SUB_TYPE_END) |
| 1158 | return ret; |
| 1159 | dp = (const struct efi_device_path *)((const u8 *)dp + len); |
| 1160 | } |
Ilias Apalodimas | 483d28e | 2021-03-17 21:54:58 +0200 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | /** |
Heinrich Schuchardt | 2ca2680 | 2024-04-26 16:13:19 +0200 | [diff] [blame] | 1164 | * efi_dp_from_lo() - get device-path from load option |
Ilias Apalodimas | 483d28e | 2021-03-17 21:54:58 +0200 | [diff] [blame] | 1165 | * |
Heinrich Schuchardt | 2ca2680 | 2024-04-26 16:13:19 +0200 | [diff] [blame] | 1166 | * The load options in U-Boot may contain multiple concatenated device-paths. |
| 1167 | * The first device-path indicates the EFI binary to execute. Subsequent |
| 1168 | * device-paths start with a VenMedia node where the GUID identifies the |
| 1169 | * function (initrd or fdt). |
| 1170 | * |
| 1171 | * @lo: EFI load option containing a valid device path |
| 1172 | * @guid: GUID identifying device-path or NULL for the EFI binary |
Ilias Apalodimas | 483d28e | 2021-03-17 21:54:58 +0200 | [diff] [blame] | 1173 | * |
| 1174 | * Return: |
Heinrich Schuchardt | 2ca2680 | 2024-04-26 16:13:19 +0200 | [diff] [blame] | 1175 | * device path excluding the matched VenMedia node or NULL. |
Ilias Apalodimas | 483d28e | 2021-03-17 21:54:58 +0200 | [diff] [blame] | 1176 | * Caller must free the returned value. |
| 1177 | */ |
| 1178 | struct |
| 1179 | efi_device_path *efi_dp_from_lo(struct efi_load_option *lo, |
Heinrich Schuchardt | 9979cff | 2021-10-15 01:31:02 +0200 | [diff] [blame] | 1180 | const efi_guid_t *guid) |
Ilias Apalodimas | 483d28e | 2021-03-17 21:54:58 +0200 | [diff] [blame] | 1181 | { |
| 1182 | struct efi_device_path *fp = lo->file_path; |
| 1183 | struct efi_device_path_vendor *vendor; |
| 1184 | int lo_len = lo->file_path_length; |
| 1185 | |
Heinrich Schuchardt | 2ca2680 | 2024-04-26 16:13:19 +0200 | [diff] [blame] | 1186 | if (!guid) |
| 1187 | return efi_dp_dup(fp); |
| 1188 | |
Ilias Apalodimas | 483d28e | 2021-03-17 21:54:58 +0200 | [diff] [blame] | 1189 | for (; lo_len >= sizeof(struct efi_device_path); |
| 1190 | lo_len -= fp->length, fp = (void *)fp + fp->length) { |
| 1191 | if (lo_len < 0 || efi_dp_check_length(fp, lo_len) < 0) |
| 1192 | break; |
| 1193 | if (fp->type != DEVICE_PATH_TYPE_MEDIA_DEVICE || |
| 1194 | fp->sub_type != DEVICE_PATH_SUB_TYPE_VENDOR_PATH) |
| 1195 | continue; |
| 1196 | |
| 1197 | vendor = (struct efi_device_path_vendor *)fp; |
Heinrich Schuchardt | 9979cff | 2021-10-15 01:31:02 +0200 | [diff] [blame] | 1198 | if (!guidcmp(&vendor->guid, guid)) |
Heinrich Schuchardt | 35dd322 | 2021-10-15 02:59:15 +0200 | [diff] [blame] | 1199 | return efi_dp_dup(efi_dp_next(fp)); |
Ilias Apalodimas | 483d28e | 2021-03-17 21:54:58 +0200 | [diff] [blame] | 1200 | } |
| 1201 | log_debug("VenMedia(%pUl) not found in %ls\n", &guid, lo->label); |
| 1202 | |
| 1203 | return NULL; |
Heinrich Schuchardt | 22c8e08 | 2020-08-23 10:49:46 +0200 | [diff] [blame] | 1204 | } |
Masahisa Kojima | 6460c3e | 2021-10-26 17:27:25 +0900 | [diff] [blame] | 1205 | |
| 1206 | /** |
| 1207 | * search_gpt_dp_node() - search gpt device path node |
| 1208 | * |
| 1209 | * @device_path: device path |
| 1210 | * |
| 1211 | * Return: pointer to the gpt device path node |
| 1212 | */ |
| 1213 | struct efi_device_path *search_gpt_dp_node(struct efi_device_path *device_path) |
| 1214 | { |
| 1215 | struct efi_device_path *dp = device_path; |
| 1216 | |
| 1217 | while (dp) { |
| 1218 | if (dp->type == DEVICE_PATH_TYPE_MEDIA_DEVICE && |
| 1219 | dp->sub_type == DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH) { |
| 1220 | struct efi_device_path_hard_drive_path *hd_dp = |
| 1221 | (struct efi_device_path_hard_drive_path *)dp; |
| 1222 | |
| 1223 | if (hd_dp->partmap_type == PART_FORMAT_GPT && |
| 1224 | hd_dp->signature_type == SIG_TYPE_GUID) |
| 1225 | return dp; |
| 1226 | } |
| 1227 | dp = efi_dp_next(dp); |
| 1228 | } |
| 1229 | |
| 1230 | return NULL; |
| 1231 | } |