Simon Glass | 0ccb0ac | 2022-04-24 23:31:23 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Bootdevice for USB |
| 4 | * |
| 5 | * Copyright 2021 Google LLC |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <bootdev.h> |
| 11 | #include <dm.h> |
| 12 | #include <usb.h> |
| 13 | |
| 14 | static int usb_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, |
| 15 | struct bootflow *bflow) |
| 16 | { |
| 17 | struct udevice *blk; |
| 18 | int ret; |
| 19 | |
| 20 | ret = bootdev_get_sibling_blk(dev, &blk); |
| 21 | /* |
| 22 | * If there is no media, indicate that no more partitions should be |
| 23 | * checked |
| 24 | */ |
| 25 | if (ret == -EOPNOTSUPP) |
| 26 | ret = -ESHUTDOWN; |
| 27 | if (ret) |
| 28 | return log_msg_ret("blk", ret); |
| 29 | assert(blk); |
| 30 | ret = bootdev_find_in_blk(dev, blk, iter, bflow); |
| 31 | if (ret) |
| 32 | return log_msg_ret("find", ret); |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | static int usb_bootdev_bind(struct udevice *dev) |
| 38 | { |
| 39 | struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); |
| 40 | |
| 41 | ucp->prio = BOOTDEVP_3_SCAN_SLOW; |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | struct bootdev_ops usb_bootdev_ops = { |
| 47 | .get_bootflow = usb_get_bootflow, |
| 48 | }; |
| 49 | |
| 50 | static const struct udevice_id usb_bootdev_ids[] = { |
| 51 | { .compatible = "u-boot,bootdev-usb" }, |
| 52 | { } |
| 53 | }; |
| 54 | |
| 55 | U_BOOT_DRIVER(usb_bootdev) = { |
| 56 | .name = "usb_bootdev", |
| 57 | .id = UCLASS_BOOTDEV, |
| 58 | .ops = &usb_bootdev_ops, |
| 59 | .bind = usb_bootdev_bind, |
| 60 | .of_match = usb_bootdev_ids, |
| 61 | }; |