Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2021 Google LLC |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | */ |
| 6 | |
| 7 | #define LOG_CATEGORY UCLASS_BOOTSTD |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <dm.h> |
| 11 | #include <bootdev.h> |
| 12 | #include <bootflow.h> |
Simon Glass | 03fcbf9 | 2022-04-24 23:31:09 -0600 | [diff] [blame] | 13 | #include <bootmeth.h> |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 14 | #include <bootstd.h> |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 15 | #include <fs.h> |
| 16 | #include <log.h> |
| 17 | #include <malloc.h> |
| 18 | #include <part.h> |
| 19 | #include <sort.h> |
| 20 | #include <dm/device-internal.h> |
| 21 | #include <dm/lists.h> |
| 22 | #include <dm/uclass-internal.h> |
| 23 | |
| 24 | enum { |
| 25 | /* |
| 26 | * Set some sort of limit on the number of partitions a bootdev can |
| 27 | * have. Note that for disks this limits the partitions numbers that |
| 28 | * are scanned to 1..MAX_BOOTFLOWS_PER_BOOTDEV |
| 29 | */ |
| 30 | MAX_PART_PER_BOOTDEV = 30, |
| 31 | |
| 32 | /* Maximum supported length of the "boot_targets" env string */ |
| 33 | BOOT_TARGETS_MAX_LEN = 100, |
| 34 | }; |
| 35 | |
| 36 | int bootdev_add_bootflow(struct bootflow *bflow) |
| 37 | { |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 38 | struct bootstd_priv *std; |
| 39 | struct bootflow *new; |
| 40 | int ret; |
| 41 | |
| 42 | assert(bflow->dev); |
| 43 | ret = bootstd_get_priv(&std); |
| 44 | if (ret) |
| 45 | return ret; |
| 46 | |
| 47 | new = malloc(sizeof(*bflow)); |
| 48 | if (!new) |
| 49 | return log_msg_ret("bflow", -ENOMEM); |
| 50 | memcpy(new, bflow, sizeof(*bflow)); |
| 51 | |
| 52 | list_add_tail(&new->glob_node, &std->glob_head); |
Simon Glass | dee4d64 | 2022-07-30 15:52:23 -0600 | [diff] [blame] | 53 | if (bflow->dev) { |
| 54 | struct bootdev_uc_plat *ucp = dev_get_uclass_plat(bflow->dev); |
| 55 | |
| 56 | list_add_tail(&new->bm_node, &ucp->bootflow_head); |
| 57 | } |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | int bootdev_first_bootflow(struct udevice *dev, struct bootflow **bflowp) |
| 63 | { |
| 64 | struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); |
| 65 | |
| 66 | if (list_empty(&ucp->bootflow_head)) |
| 67 | return -ENOENT; |
| 68 | |
| 69 | *bflowp = list_first_entry(&ucp->bootflow_head, struct bootflow, |
| 70 | bm_node); |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | int bootdev_next_bootflow(struct bootflow **bflowp) |
| 76 | { |
| 77 | struct bootflow *bflow = *bflowp; |
| 78 | struct bootdev_uc_plat *ucp = dev_get_uclass_plat(bflow->dev); |
| 79 | |
| 80 | *bflowp = NULL; |
| 81 | |
| 82 | if (list_is_last(&bflow->bm_node, &ucp->bootflow_head)) |
| 83 | return -ENOENT; |
| 84 | |
| 85 | *bflowp = list_entry(bflow->bm_node.next, struct bootflow, bm_node); |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | int bootdev_bind(struct udevice *parent, const char *drv_name, const char *name, |
| 91 | struct udevice **devp) |
| 92 | { |
| 93 | struct udevice *dev; |
| 94 | char dev_name[30]; |
| 95 | char *str; |
| 96 | int ret; |
| 97 | |
| 98 | snprintf(dev_name, sizeof(dev_name), "%s.%s", parent->name, name); |
| 99 | str = strdup(dev_name); |
| 100 | if (!str) |
| 101 | return -ENOMEM; |
| 102 | ret = device_bind_driver(parent, drv_name, str, &dev); |
| 103 | if (ret) |
| 104 | return ret; |
| 105 | device_set_name_alloced(dev); |
| 106 | *devp = dev; |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | int bootdev_find_in_blk(struct udevice *dev, struct udevice *blk, |
| 112 | struct bootflow_iter *iter, struct bootflow *bflow) |
| 113 | { |
| 114 | struct blk_desc *desc = dev_get_uclass_plat(blk); |
| 115 | struct disk_partition info; |
| 116 | char partstr[20]; |
| 117 | char name[60]; |
| 118 | int ret; |
| 119 | |
| 120 | /* Sanity check */ |
| 121 | if (iter->part >= MAX_PART_PER_BOOTDEV) |
| 122 | return log_msg_ret("max", -ESHUTDOWN); |
| 123 | |
| 124 | bflow->blk = blk; |
| 125 | if (iter->part) |
| 126 | snprintf(partstr, sizeof(partstr), "part_%x", iter->part); |
| 127 | else |
| 128 | strcpy(partstr, "whole"); |
| 129 | snprintf(name, sizeof(name), "%s.%s", dev->name, partstr); |
| 130 | bflow->name = strdup(name); |
| 131 | if (!bflow->name) |
| 132 | return log_msg_ret("name", -ENOMEM); |
| 133 | |
| 134 | bflow->part = iter->part; |
| 135 | |
Simon Glass | 03fcbf9 | 2022-04-24 23:31:09 -0600 | [diff] [blame] | 136 | ret = bootmeth_check(bflow->method, iter); |
| 137 | if (ret) |
| 138 | return log_msg_ret("check", ret); |
| 139 | |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 140 | /* |
| 141 | * partition numbers start at 0 so this cannot succeed, but it can tell |
| 142 | * us whether there is valid media there |
| 143 | */ |
| 144 | ret = part_get_info(desc, iter->part, &info); |
| 145 | if (!iter->part && ret == -ENOENT) |
| 146 | ret = 0; |
| 147 | |
| 148 | /* |
| 149 | * This error indicates the media is not present. Otherwise we just |
| 150 | * blindly scan the next partition. We could be more intelligent here |
| 151 | * and check which partition numbers actually exist. |
| 152 | */ |
| 153 | if (ret == -EOPNOTSUPP) |
| 154 | ret = -ESHUTDOWN; |
| 155 | else |
| 156 | bflow->state = BOOTFLOWST_MEDIA; |
| 157 | if (ret) |
| 158 | return log_msg_ret("part", ret); |
| 159 | |
| 160 | /* |
| 161 | * Currently we don't get the number of partitions, so just |
| 162 | * assume a large number |
| 163 | */ |
| 164 | iter->max_part = MAX_PART_PER_BOOTDEV; |
| 165 | |
Simon Glass | 64cbc5c | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 166 | /* If this is the whole disk, check if we have bootable partitions */ |
| 167 | if (!iter->part) { |
| 168 | iter->first_bootable = part_get_bootable(desc); |
| 169 | log_debug("checking bootable=%d\n", iter->first_bootable); |
| 170 | |
| 171 | /* if there are bootable partitions, scan only those */ |
| 172 | } else if (iter->first_bootable ? !info.bootable : iter->part != 1) { |
| 173 | return log_msg_ret("boot", -EINVAL); |
| 174 | } else { |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 175 | ret = fs_set_blk_dev_with_part(desc, bflow->part); |
| 176 | bflow->state = BOOTFLOWST_PART; |
Simon Glass | a40f782 | 2023-04-24 13:49:49 +1200 | [diff] [blame] | 177 | if (ret) |
| 178 | return log_msg_ret("fs", ret); |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 179 | |
| 180 | /* Use an #ifdef due to info.sys_ind */ |
| 181 | #ifdef CONFIG_DOS_PARTITION |
| 182 | log_debug("%s: Found partition %x type %x fstype %d\n", |
| 183 | blk->name, bflow->part, info.sys_ind, |
| 184 | ret ? -1 : fs_get_type()); |
| 185 | #endif |
Simon Glass | a40f782 | 2023-04-24 13:49:49 +1200 | [diff] [blame] | 186 | bflow->blk = blk; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 187 | bflow->state = BOOTFLOWST_FS; |
| 188 | } |
| 189 | |
Simon Glass | 03fcbf9 | 2022-04-24 23:31:09 -0600 | [diff] [blame] | 190 | ret = bootmeth_read_bootflow(bflow->method, bflow); |
| 191 | if (ret) |
| 192 | return log_msg_ret("method", ret); |
| 193 | |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | void bootdev_list(bool probe) |
| 198 | { |
| 199 | struct udevice *dev; |
| 200 | int ret; |
| 201 | int i; |
| 202 | |
| 203 | printf("Seq Probed Status Uclass Name\n"); |
| 204 | printf("--- ------ ------ -------- ------------------\n"); |
| 205 | if (probe) |
Michal Suchanek | 675e908 | 2022-10-12 21:57:53 +0200 | [diff] [blame] | 206 | ret = uclass_first_device_check(UCLASS_BOOTDEV, &dev); |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 207 | else |
| 208 | ret = uclass_find_first_device(UCLASS_BOOTDEV, &dev); |
| 209 | for (i = 0; dev; i++) { |
| 210 | printf("%3x [ %c ] %6s %-9.9s %s\n", dev_seq(dev), |
| 211 | device_active(dev) ? '+' : ' ', |
| 212 | ret ? simple_itoa(ret) : "OK", |
| 213 | dev_get_uclass_name(dev_get_parent(dev)), dev->name); |
| 214 | if (probe) |
Michal Suchanek | 675e908 | 2022-10-12 21:57:53 +0200 | [diff] [blame] | 215 | ret = uclass_next_device_check(&dev); |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 216 | else |
| 217 | ret = uclass_find_next_device(&dev); |
| 218 | } |
| 219 | printf("--- ------ ------ -------- ------------------\n"); |
| 220 | printf("(%d bootdev%s)\n", i, i != 1 ? "s" : ""); |
| 221 | } |
| 222 | |
| 223 | int bootdev_setup_for_dev(struct udevice *parent, const char *drv_name) |
| 224 | { |
| 225 | struct udevice *bdev; |
| 226 | int ret; |
| 227 | |
| 228 | ret = device_find_first_child_by_uclass(parent, UCLASS_BOOTDEV, |
| 229 | &bdev); |
| 230 | if (ret) { |
| 231 | if (ret != -ENODEV) { |
| 232 | log_debug("Cannot access bootdev device\n"); |
| 233 | return ret; |
| 234 | } |
| 235 | |
| 236 | ret = bootdev_bind(parent, drv_name, "bootdev", &bdev); |
| 237 | if (ret) { |
| 238 | log_debug("Cannot create bootdev device\n"); |
| 239 | return ret; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
Simon Glass | b1dc36a | 2023-01-17 10:47:25 -0700 | [diff] [blame] | 246 | static int bootdev_get_suffix_start(struct udevice *dev, const char *suffix) |
| 247 | { |
| 248 | int len, slen; |
| 249 | |
| 250 | len = strlen(dev->name); |
| 251 | slen = strlen(suffix); |
| 252 | if (len > slen && !strcmp(suffix, dev->name + len - slen)) |
| 253 | return len - slen; |
| 254 | |
| 255 | return len; |
| 256 | } |
| 257 | |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 258 | int bootdev_setup_sibling_blk(struct udevice *blk, const char *drv_name) |
| 259 | { |
| 260 | struct udevice *parent, *dev; |
| 261 | char dev_name[50]; |
Simon Glass | b1dc36a | 2023-01-17 10:47:25 -0700 | [diff] [blame] | 262 | int ret, len; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 263 | |
Simon Glass | b1dc36a | 2023-01-17 10:47:25 -0700 | [diff] [blame] | 264 | len = bootdev_get_suffix_start(blk, ".blk"); |
| 265 | snprintf(dev_name, sizeof(dev_name), "%.*s.%s", len, blk->name, |
| 266 | "bootdev"); |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 267 | |
| 268 | parent = dev_get_parent(blk); |
| 269 | ret = device_find_child_by_name(parent, dev_name, &dev); |
| 270 | if (ret) { |
| 271 | char *str; |
| 272 | |
| 273 | if (ret != -ENODEV) { |
| 274 | log_debug("Cannot access bootdev device\n"); |
| 275 | return ret; |
| 276 | } |
| 277 | str = strdup(dev_name); |
| 278 | if (!str) |
| 279 | return -ENOMEM; |
| 280 | |
| 281 | ret = device_bind_driver(parent, drv_name, str, &dev); |
| 282 | if (ret) { |
| 283 | log_debug("Cannot create bootdev device\n"); |
| 284 | return ret; |
| 285 | } |
| 286 | device_set_name_alloced(dev); |
| 287 | } |
| 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | int bootdev_get_sibling_blk(struct udevice *dev, struct udevice **blkp) |
| 293 | { |
| 294 | struct udevice *parent = dev_get_parent(dev); |
| 295 | struct udevice *blk; |
| 296 | int ret, len; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 297 | |
| 298 | if (device_get_uclass_id(dev) != UCLASS_BOOTDEV) |
| 299 | return -EINVAL; |
| 300 | |
| 301 | /* This should always work if bootdev_setup_sibling_blk() was used */ |
Simon Glass | b1dc36a | 2023-01-17 10:47:25 -0700 | [diff] [blame] | 302 | len = bootdev_get_suffix_start(dev, ".bootdev"); |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 303 | ret = device_find_child_by_namelen(parent, dev->name, len, &blk); |
Simon Glass | b1dc36a | 2023-01-17 10:47:25 -0700 | [diff] [blame] | 304 | if (ret) { |
| 305 | char dev_name[50]; |
| 306 | |
| 307 | snprintf(dev_name, sizeof(dev_name), "%.*s.blk", len, |
| 308 | dev->name); |
| 309 | ret = device_find_child_by_name(parent, dev_name, &blk); |
| 310 | if (ret) |
| 311 | return log_msg_ret("find", ret); |
| 312 | } |
Simon Glass | b73a829 | 2023-01-28 15:00:19 -0700 | [diff] [blame] | 313 | ret = device_probe(blk); |
| 314 | if (ret) |
| 315 | return log_msg_ret("act", ret); |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 316 | *blkp = blk; |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | static int bootdev_get_from_blk(struct udevice *blk, struct udevice **bootdevp) |
| 322 | { |
| 323 | struct udevice *parent = dev_get_parent(blk); |
| 324 | struct udevice *bootdev; |
| 325 | char dev_name[50]; |
Simon Glass | b1dc36a | 2023-01-17 10:47:25 -0700 | [diff] [blame] | 326 | int ret, len; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 327 | |
| 328 | if (device_get_uclass_id(blk) != UCLASS_BLK) |
| 329 | return -EINVAL; |
| 330 | |
| 331 | /* This should always work if bootdev_setup_sibling_blk() was used */ |
Simon Glass | b1dc36a | 2023-01-17 10:47:25 -0700 | [diff] [blame] | 332 | len = bootdev_get_suffix_start(blk, ".blk"); |
| 333 | snprintf(dev_name, sizeof(dev_name), "%.*s.%s", len, blk->name, |
| 334 | "bootdev"); |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 335 | ret = device_find_child_by_name(parent, dev_name, &bootdev); |
| 336 | if (ret) |
| 337 | return log_msg_ret("find", ret); |
| 338 | *bootdevp = bootdev; |
| 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | int bootdev_unbind_dev(struct udevice *parent) |
| 344 | { |
| 345 | struct udevice *dev; |
| 346 | int ret; |
| 347 | |
| 348 | ret = device_find_first_child_by_uclass(parent, UCLASS_BOOTDEV, &dev); |
| 349 | if (!ret) { |
| 350 | ret = device_remove(dev, DM_REMOVE_NORMAL); |
| 351 | if (ret) |
| 352 | return log_msg_ret("rem", ret); |
| 353 | ret = device_unbind(dev); |
| 354 | if (ret) |
| 355 | return log_msg_ret("unb", ret); |
| 356 | } |
| 357 | |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | /** |
Simon Glass | 7370825 | 2023-01-17 10:48:00 -0700 | [diff] [blame] | 362 | * label_to_uclass() - Convert a label to a uclass and sequence number |
| 363 | * |
| 364 | * @label: Label to look up (e.g. "mmc1" or "mmc0") |
| 365 | * @seqp: Returns the sequence number, or -1 if none |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 366 | * @method_flagsp: If non-NULL, returns any flags implied by the label |
| 367 | * (enum bootflow_meth_flags_t), 0 if none |
Simon Glass | 4108c6b | 2023-04-24 13:49:47 +1200 | [diff] [blame] | 368 | * Returns: sequence number on success, -EPFNOSUPPORT is the uclass is not |
| 369 | * known, other -ve error code on other error |
Simon Glass | 7370825 | 2023-01-17 10:48:00 -0700 | [diff] [blame] | 370 | */ |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 371 | static int label_to_uclass(const char *label, int *seqp, int *method_flagsp) |
Simon Glass | 7370825 | 2023-01-17 10:48:00 -0700 | [diff] [blame] | 372 | { |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 373 | int seq, len, method_flags; |
Simon Glass | 7370825 | 2023-01-17 10:48:00 -0700 | [diff] [blame] | 374 | enum uclass_id id; |
| 375 | const char *end; |
Simon Glass | 7370825 | 2023-01-17 10:48:00 -0700 | [diff] [blame] | 376 | |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 377 | method_flags = 0; |
Simon Glass | 7370825 | 2023-01-17 10:48:00 -0700 | [diff] [blame] | 378 | seq = trailing_strtoln_end(label, NULL, &end); |
| 379 | len = end - label; |
| 380 | if (!len) |
| 381 | return -EINVAL; |
| 382 | id = uclass_get_by_namelen(label, len); |
| 383 | log_debug("find %s: seq=%d, id=%d/%s\n", label, seq, id, |
| 384 | uclass_get_name(id)); |
| 385 | if (id == UCLASS_INVALID) { |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 386 | /* try some special cases */ |
| 387 | if (IS_ENABLED(CONFIG_BOOTDEV_SPI_FLASH) && |
| 388 | !strncmp("spi", label, len)) { |
| 389 | id = UCLASS_SPI_FLASH; |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 390 | } else if (IS_ENABLED(CONFIG_BOOTDEV_ETH) && |
| 391 | !strncmp("pxe", label, len)) { |
| 392 | id = UCLASS_ETH; |
| 393 | method_flags |= BOOTFLOW_METHF_PXE_ONLY; |
| 394 | } else if (IS_ENABLED(CONFIG_BOOTDEV_ETH) && |
| 395 | !strncmp("dhcp", label, len)) { |
| 396 | id = UCLASS_ETH; |
| 397 | method_flags |= BOOTFLOW_METHF_DHCP_ONLY; |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 398 | } else { |
Simon Glass | 4108c6b | 2023-04-24 13:49:47 +1200 | [diff] [blame] | 399 | return -EPFNOSUPPORT; |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 400 | } |
Simon Glass | 7370825 | 2023-01-17 10:48:00 -0700 | [diff] [blame] | 401 | } |
| 402 | if (id == UCLASS_USB) |
| 403 | id = UCLASS_MASS_STORAGE; |
| 404 | *seqp = seq; |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 405 | if (method_flagsp) |
| 406 | *method_flagsp = method_flags; |
Simon Glass | 7370825 | 2023-01-17 10:48:00 -0700 | [diff] [blame] | 407 | |
| 408 | return id; |
| 409 | } |
| 410 | |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 411 | int bootdev_find_by_label(const char *label, struct udevice **devp, |
| 412 | int *method_flagsp) |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 413 | { |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 414 | int seq, ret, method_flags = 0; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 415 | struct udevice *media; |
| 416 | struct uclass *uc; |
| 417 | enum uclass_id id; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 418 | |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 419 | ret = label_to_uclass(label, &seq, &method_flags); |
Simon Glass | 7370825 | 2023-01-17 10:48:00 -0700 | [diff] [blame] | 420 | if (ret < 0) |
| 421 | return log_msg_ret("uc", ret); |
| 422 | id = ret; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 423 | |
| 424 | /* Iterate through devices in the media uclass (e.g. UCLASS_MMC) */ |
| 425 | uclass_id_foreach_dev(id, media, uc) { |
| 426 | struct udevice *bdev, *blk; |
| 427 | int ret; |
| 428 | |
| 429 | /* if there is no seq, match anything */ |
| 430 | if (seq != -1 && dev_seq(media) != seq) { |
| 431 | log_debug("- skip, media seq=%d\n", dev_seq(media)); |
| 432 | continue; |
| 433 | } |
| 434 | |
| 435 | ret = device_find_first_child_by_uclass(media, UCLASS_BOOTDEV, |
| 436 | &bdev); |
| 437 | if (ret) { |
| 438 | log_debug("- looking via blk, seq=%d, id=%d\n", seq, |
| 439 | id); |
| 440 | ret = blk_find_device(id, seq, &blk); |
| 441 | if (!ret) { |
| 442 | log_debug("- get from blk %s\n", blk->name); |
| 443 | ret = bootdev_get_from_blk(blk, &bdev); |
| 444 | } |
| 445 | } |
| 446 | if (!ret) { |
| 447 | log_debug("- found %s\n", bdev->name); |
| 448 | *devp = bdev; |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 449 | |
| 450 | /* |
| 451 | * if no sequence number was provided, we must scan all |
| 452 | * bootdevs for this media uclass |
| 453 | */ |
| 454 | if (IS_ENABLED(CONFIG_BOOTSTD_FULL) && seq == -1) |
| 455 | method_flags |= BOOTFLOW_METHF_SINGLE_UCLASS; |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 456 | if (method_flagsp) |
| 457 | *method_flagsp = method_flags; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 458 | return 0; |
| 459 | } |
| 460 | log_debug("- no device in %s\n", media->name); |
| 461 | } |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 462 | |
| 463 | return -ENOENT; |
| 464 | } |
| 465 | |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 466 | int bootdev_find_by_any(const char *name, struct udevice **devp, |
| 467 | int *method_flagsp) |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 468 | { |
| 469 | struct udevice *dev; |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 470 | int method_flags = 0; |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 471 | int ret = -ENODEV, seq; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 472 | char *endp; |
| 473 | |
| 474 | seq = simple_strtol(name, &endp, 16); |
| 475 | |
| 476 | /* Select by name, label or number */ |
| 477 | if (*endp) { |
| 478 | ret = uclass_get_device_by_name(UCLASS_BOOTDEV, name, &dev); |
| 479 | if (ret == -ENODEV) { |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 480 | ret = bootdev_find_by_label(name, &dev, &method_flags); |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 481 | if (ret) { |
| 482 | printf("Cannot find bootdev '%s' (err=%d)\n", |
| 483 | name, ret); |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 484 | return log_msg_ret("lab", ret); |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 485 | } |
| 486 | ret = device_probe(dev); |
| 487 | } |
| 488 | if (ret) { |
| 489 | printf("Cannot probe bootdev '%s' (err=%d)\n", name, |
| 490 | ret); |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 491 | return log_msg_ret("pro", ret); |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 492 | } |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 493 | } else if (IS_ENABLED(CONFIG_BOOTSTD_FULL)) { |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 494 | ret = uclass_get_device_by_seq(UCLASS_BOOTDEV, seq, &dev); |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 495 | method_flags |= BOOTFLOW_METHF_SINGLE_DEV; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 496 | } |
| 497 | if (ret) { |
| 498 | printf("Cannot find '%s' (err=%d)\n", name, ret); |
| 499 | return ret; |
| 500 | } |
| 501 | |
| 502 | *devp = dev; |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 503 | if (method_flagsp) |
| 504 | *method_flagsp = method_flags; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 509 | int bootdev_hunt_and_find_by_label(const char *label, struct udevice **devp, |
| 510 | int *method_flagsp) |
| 511 | { |
| 512 | int ret; |
| 513 | |
| 514 | ret = bootdev_hunt(label, false); |
| 515 | if (ret) |
| 516 | return log_msg_ret("scn", ret); |
| 517 | ret = bootdev_find_by_label(label, devp, method_flagsp); |
| 518 | if (ret) |
| 519 | return log_msg_ret("fnd", ret); |
| 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | |
Simon Glass | d6e39d1 | 2023-01-17 10:47:26 -0700 | [diff] [blame] | 524 | static int default_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, |
| 525 | struct bootflow *bflow) |
| 526 | { |
| 527 | struct udevice *blk; |
| 528 | int ret; |
| 529 | |
| 530 | ret = bootdev_get_sibling_blk(dev, &blk); |
| 531 | /* |
| 532 | * If there is no media, indicate that no more partitions should be |
| 533 | * checked |
| 534 | */ |
| 535 | if (ret == -EOPNOTSUPP) |
| 536 | ret = -ESHUTDOWN; |
| 537 | if (ret) |
| 538 | return log_msg_ret("blk", ret); |
| 539 | assert(blk); |
| 540 | ret = bootdev_find_in_blk(dev, blk, iter, bflow); |
| 541 | if (ret) |
| 542 | return log_msg_ret("find", ret); |
| 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 547 | int bootdev_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, |
| 548 | struct bootflow *bflow) |
| 549 | { |
| 550 | const struct bootdev_ops *ops = bootdev_get_ops(dev); |
| 551 | |
Simon Glass | 3306346 | 2023-01-17 10:48:18 -0700 | [diff] [blame] | 552 | log_debug("->get_bootflow %s=%p\n", dev->name, ops->get_bootflow); |
Simon Glass | 00501fc | 2022-10-20 18:22:51 -0600 | [diff] [blame] | 553 | bootflow_init(bflow, dev, iter->method); |
Simon Glass | d6e39d1 | 2023-01-17 10:47:26 -0700 | [diff] [blame] | 554 | if (!ops->get_bootflow) |
| 555 | return default_get_bootflow(dev, iter, bflow); |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 556 | |
| 557 | return ops->get_bootflow(dev, iter, bflow); |
| 558 | } |
| 559 | |
| 560 | void bootdev_clear_bootflows(struct udevice *dev) |
| 561 | { |
| 562 | struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); |
| 563 | |
| 564 | while (!list_empty(&ucp->bootflow_head)) { |
| 565 | struct bootflow *bflow; |
| 566 | |
| 567 | bflow = list_first_entry(&ucp->bootflow_head, struct bootflow, |
| 568 | bm_node); |
Simon Glass | 03fcbf9 | 2022-04-24 23:31:09 -0600 | [diff] [blame] | 569 | bootflow_remove(bflow); |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 573 | int bootdev_next_label(struct bootflow_iter *iter, struct udevice **devp, |
| 574 | int *method_flagsp) |
| 575 | { |
| 576 | struct udevice *dev; |
| 577 | |
| 578 | log_debug("next\n"); |
| 579 | for (dev = NULL; !dev && iter->labels[++iter->cur_label];) { |
Simon Glass | 4108c6b | 2023-04-24 13:49:47 +1200 | [diff] [blame] | 580 | const char *label = iter->labels[iter->cur_label]; |
| 581 | int ret; |
| 582 | |
| 583 | log_debug("Scanning: %s\n", label); |
| 584 | ret = bootdev_hunt_and_find_by_label(label, &dev, |
| 585 | method_flagsp); |
| 586 | if (iter->flags & BOOTFLOWIF_SHOW) { |
| 587 | if (ret == -EPFNOSUPPORT) { |
| 588 | log_warning("Unknown uclass '%s' in label\n", |
| 589 | label); |
| 590 | } else if (ret == -ENOENT) { |
| 591 | /* |
| 592 | * looking for, e.g. 'scsi0' should find |
| 593 | * something if SCSI is present |
| 594 | */ |
| 595 | if (!trailing_strtol(label)) { |
| 596 | log_warning("No bootdevs for '%s'\n", |
| 597 | label); |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | if (!dev) |
| 605 | return log_msg_ret("fin", -ENODEV); |
| 606 | *devp = dev; |
| 607 | |
| 608 | return 0; |
| 609 | } |
| 610 | |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 611 | int bootdev_next_prio(struct bootflow_iter *iter, struct udevice **devp) |
| 612 | { |
| 613 | struct udevice *dev = *devp; |
| 614 | bool found; |
| 615 | int ret; |
| 616 | |
| 617 | /* find the next device with this priority */ |
| 618 | *devp = NULL; |
| 619 | log_debug("next prio %d: dev=%p/%s\n", iter->cur_prio, dev, |
| 620 | dev ? dev->name : "none"); |
| 621 | do { |
| 622 | /* |
| 623 | * Don't probe devices here since they may not be of the |
| 624 | * required priority |
| 625 | */ |
| 626 | if (!dev) |
| 627 | uclass_find_first_device(UCLASS_BOOTDEV, &dev); |
| 628 | else |
| 629 | uclass_find_next_device(&dev); |
| 630 | found = false; |
| 631 | |
| 632 | /* scan for the next device with the correct priority */ |
| 633 | while (dev) { |
| 634 | struct bootdev_uc_plat *plat; |
| 635 | |
| 636 | plat = dev_get_uclass_plat(dev); |
| 637 | log_debug("- %s: %d, want %d\n", dev->name, plat->prio, |
| 638 | iter->cur_prio); |
| 639 | if (plat->prio == iter->cur_prio) |
| 640 | break; |
| 641 | uclass_find_next_device(&dev); |
| 642 | } |
| 643 | |
| 644 | /* none found for this priority, so move to the next */ |
| 645 | if (!dev) { |
| 646 | log_debug("None found at prio %d, moving to %d\n", |
| 647 | iter->cur_prio, iter->cur_prio + 1); |
| 648 | if (++iter->cur_prio == BOOTDEVP_COUNT) |
| 649 | return log_msg_ret("fin", -ENODEV); |
| 650 | |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 651 | if (iter->flags & BOOTFLOWIF_HUNT) { |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 652 | /* hunt to find new bootdevs */ |
| 653 | ret = bootdev_hunt_prio(iter->cur_prio, |
| 654 | iter->flags & |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 655 | BOOTFLOWIF_SHOW); |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 656 | log_debug("- hunt ret %d\n", ret); |
| 657 | if (ret) |
| 658 | return log_msg_ret("hun", ret); |
| 659 | } |
| 660 | } else { |
| 661 | ret = device_probe(dev); |
| 662 | if (ret) { |
| 663 | log_debug("Device '%s' failed to probe\n", |
| 664 | dev->name); |
| 665 | dev = NULL; |
| 666 | } |
| 667 | } |
| 668 | } while (!dev); |
| 669 | |
| 670 | *devp = dev; |
| 671 | |
| 672 | return 0; |
| 673 | } |
| 674 | |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 675 | int bootdev_setup_iter(struct bootflow_iter *iter, const char *label, |
| 676 | struct udevice **devp, int *method_flagsp) |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 677 | { |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 678 | struct udevice *bootstd, *dev = NULL; |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 679 | bool show = iter->flags & BOOTFLOWIF_SHOW; |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 680 | int method_flags; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 681 | int ret; |
| 682 | |
| 683 | ret = uclass_first_device_err(UCLASS_BOOTSTD, &bootstd); |
| 684 | if (ret) { |
| 685 | log_err("Missing bootstd device\n"); |
| 686 | return log_msg_ret("std", ret); |
| 687 | } |
| 688 | |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 689 | /* hunt for any pre-scan devices */ |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 690 | if (iter->flags & BOOTFLOWIF_HUNT) { |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 691 | ret = bootdev_hunt_prio(BOOTDEVP_1_PRE_SCAN, show); |
| 692 | if (ret) |
| 693 | return log_msg_ret("pre", ret); |
| 694 | } |
| 695 | |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 696 | /* Handle scanning a single device */ |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 697 | if (IS_ENABLED(CONFIG_BOOTSTD_FULL) && label) { |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 698 | if (iter->flags & BOOTFLOWIF_HUNT) { |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 699 | ret = bootdev_hunt(label, show); |
| 700 | if (ret) |
| 701 | return log_msg_ret("hun", ret); |
| 702 | } |
| 703 | ret = bootdev_find_by_any(label, &dev, &method_flags); |
| 704 | if (ret) |
| 705 | return log_msg_ret("lab", ret); |
| 706 | |
| 707 | log_debug("method_flags: %x\n", method_flags); |
| 708 | if (method_flags & BOOTFLOW_METHF_SINGLE_UCLASS) |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 709 | iter->flags |= BOOTFLOWIF_SINGLE_UCLASS; |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 710 | else if (method_flags & BOOTFLOW_METHF_SINGLE_DEV) |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 711 | iter->flags |= BOOTFLOWIF_SINGLE_DEV; |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 712 | else |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 713 | iter->flags |= BOOTFLOWIF_SINGLE_MEDIA; |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 714 | log_debug("Selected label: %s, flags %x\n", label, iter->flags); |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 715 | } else { |
| 716 | bool ok; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 717 | |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 718 | /* This either returns a non-empty list or NULL */ |
| 719 | iter->labels = bootstd_get_bootdev_order(bootstd, &ok); |
| 720 | if (!ok) |
| 721 | return log_msg_ret("ord", -ENOMEM); |
| 722 | log_debug("setup labels %p\n", iter->labels); |
| 723 | if (iter->labels) { |
| 724 | iter->cur_label = -1; |
| 725 | ret = bootdev_next_label(iter, &dev, &method_flags); |
| 726 | } else { |
| 727 | ret = bootdev_next_prio(iter, &dev); |
| 728 | method_flags = 0; |
| 729 | } |
| 730 | if (!dev) |
| 731 | return log_msg_ret("fin", -ENOENT); |
| 732 | log_debug("Selected bootdev: %s\n", dev->name); |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 733 | } |
| 734 | |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 735 | ret = device_probe(dev); |
| 736 | if (ret) |
| 737 | return log_msg_ret("probe", ret); |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 738 | if (method_flagsp) |
| 739 | *method_flagsp = method_flags; |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 740 | *devp = dev; |
| 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | |
Simon Glass | 1248d2b | 2023-01-17 10:47:34 -0700 | [diff] [blame] | 745 | static int bootdev_hunt_drv(struct bootdev_hunter *info, uint seq, bool show) |
| 746 | { |
| 747 | const char *name = uclass_get_name(info->uclass); |
| 748 | struct bootstd_priv *std; |
| 749 | int ret; |
| 750 | |
| 751 | ret = bootstd_get_priv(&std); |
| 752 | if (ret) |
| 753 | return log_msg_ret("std", ret); |
| 754 | |
| 755 | if (!(std->hunters_used & BIT(seq))) { |
| 756 | if (show) |
| 757 | printf("Hunting with: %s\n", |
| 758 | uclass_get_name(info->uclass)); |
| 759 | log_debug("Hunting with: %s\n", name); |
| 760 | if (info->hunt) { |
| 761 | ret = info->hunt(info, show); |
| 762 | if (ret) |
| 763 | return ret; |
| 764 | } |
| 765 | std->hunters_used |= BIT(seq); |
| 766 | } |
| 767 | |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | int bootdev_hunt(const char *spec, bool show) |
| 772 | { |
| 773 | struct bootdev_hunter *start; |
| 774 | const char *end; |
| 775 | int n_ent, i; |
| 776 | int result; |
| 777 | size_t len; |
| 778 | |
| 779 | start = ll_entry_start(struct bootdev_hunter, bootdev_hunter); |
| 780 | n_ent = ll_entry_count(struct bootdev_hunter, bootdev_hunter); |
| 781 | result = 0; |
| 782 | |
| 783 | len = SIZE_MAX; |
| 784 | if (spec) { |
| 785 | trailing_strtoln_end(spec, NULL, &end); |
| 786 | len = end - spec; |
| 787 | } |
| 788 | |
| 789 | for (i = 0; i < n_ent; i++) { |
| 790 | struct bootdev_hunter *info = start + i; |
| 791 | const char *name = uclass_get_name(info->uclass); |
| 792 | int ret; |
| 793 | |
| 794 | log_debug("looking at %.*s for %s\n", |
| 795 | (int)max(strlen(name), len), spec, name); |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 796 | if (spec && strncmp(spec, name, max(strlen(name), len))) { |
| 797 | if (info->uclass != UCLASS_ETH || |
| 798 | (strcmp("dhcp", spec) && strcmp("pxe", spec))) |
| 799 | continue; |
| 800 | } |
Simon Glass | 1248d2b | 2023-01-17 10:47:34 -0700 | [diff] [blame] | 801 | ret = bootdev_hunt_drv(info, i, show); |
| 802 | if (ret) |
| 803 | result = ret; |
| 804 | } |
| 805 | |
| 806 | return result; |
| 807 | } |
| 808 | |
Simon Glass | 3e9f6be | 2023-01-17 10:48:07 -0700 | [diff] [blame] | 809 | int bootdev_hunt_prio(enum bootdev_prio_t prio, bool show) |
| 810 | { |
| 811 | struct bootdev_hunter *start; |
| 812 | int n_ent, i; |
| 813 | int result; |
| 814 | |
| 815 | start = ll_entry_start(struct bootdev_hunter, bootdev_hunter); |
| 816 | n_ent = ll_entry_count(struct bootdev_hunter, bootdev_hunter); |
| 817 | result = 0; |
| 818 | |
| 819 | log_debug("Hunting for priority %d\n", prio); |
| 820 | for (i = 0; i < n_ent; i++) { |
| 821 | struct bootdev_hunter *info = start + i; |
| 822 | int ret; |
| 823 | |
| 824 | if (prio != info->prio) |
| 825 | continue; |
| 826 | ret = bootdev_hunt_drv(info, i, show); |
| 827 | if (ret && ret != -ENOENT) |
| 828 | result = ret; |
| 829 | } |
| 830 | |
| 831 | return result; |
| 832 | } |
| 833 | |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 834 | void bootdev_list_hunters(struct bootstd_priv *std) |
| 835 | { |
| 836 | struct bootdev_hunter *orig, *start; |
| 837 | int n_ent, i; |
| 838 | |
| 839 | orig = ll_entry_start(struct bootdev_hunter, bootdev_hunter); |
| 840 | n_ent = ll_entry_count(struct bootdev_hunter, bootdev_hunter); |
| 841 | |
| 842 | /* |
| 843 | * workaround for strange bug in clang-12 which sees all the below data |
| 844 | * as zeroes. Any access of start seems to fix it, such as |
| 845 | * |
| 846 | * printf("%p", start); |
| 847 | * |
| 848 | * Use memcpy() to force the correct behaviour. |
| 849 | */ |
| 850 | memcpy(&start, &orig, sizeof(orig)); |
| 851 | printf("%4s %4s %-15s %s\n", "Prio", "Used", "Uclass", "Hunter"); |
| 852 | printf("%4s %4s %-15s %s\n", "----", "----", "---------------", "---------------"); |
| 853 | for (i = 0; i < n_ent; i++) { |
| 854 | struct bootdev_hunter *info = start + i; |
| 855 | |
| 856 | printf("%4d %4s %-15s %s\n", info->prio, |
| 857 | std->hunters_used & BIT(i) ? "*" : "", |
| 858 | uclass_get_name(info->uclass), |
| 859 | info->drv ? info->drv->name : "(none)"); |
| 860 | } |
| 861 | |
| 862 | printf("(total hunters: %d)\n", n_ent); |
| 863 | } |
| 864 | |
Simon Glass | 017656e | 2022-04-24 23:31:07 -0600 | [diff] [blame] | 865 | static int bootdev_post_bind(struct udevice *dev) |
| 866 | { |
| 867 | struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); |
| 868 | |
| 869 | INIT_LIST_HEAD(&ucp->bootflow_head); |
| 870 | |
| 871 | return 0; |
| 872 | } |
| 873 | |
| 874 | static int bootdev_pre_unbind(struct udevice *dev) |
| 875 | { |
| 876 | bootdev_clear_bootflows(dev); |
| 877 | |
| 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | UCLASS_DRIVER(bootdev) = { |
| 882 | .id = UCLASS_BOOTDEV, |
| 883 | .name = "bootdev", |
| 884 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
| 885 | .per_device_plat_auto = sizeof(struct bootdev_uc_plat), |
| 886 | .post_bind = bootdev_post_bind, |
| 887 | .pre_unbind = bootdev_pre_unbind, |
| 888 | }; |