Simon Glass | ab5bbe2 | 2022-04-24 23:31:18 -0600 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Bootdevice for system, used for bootmeths not tied to any partition device |
| 4 | * |
| 5 | * Copyright 2021 Google LLC |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | */ |
| 8 | |
| 9 | #define LOG_CATEGORY UCLASS_BOOTSTD |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <bootdev.h> |
| 13 | #include <bootflow.h> |
| 14 | #include <bootmeth.h> |
| 15 | #include <command.h> |
| 16 | #include <distro.h> |
| 17 | #include <dm.h> |
| 18 | #include <log.h> |
| 19 | #include <net.h> |
| 20 | |
| 21 | static int system_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, |
| 22 | struct bootflow *bflow) |
| 23 | { |
| 24 | int ret; |
| 25 | |
| 26 | /* Must be an bootstd device */ |
| 27 | ret = bootflow_iter_uses_system(iter); |
| 28 | if (ret) |
| 29 | return log_msg_ret("net", ret); |
| 30 | |
| 31 | ret = bootmeth_check(bflow->method, iter); |
| 32 | if (ret) |
| 33 | return log_msg_ret("check", ret); |
| 34 | |
| 35 | ret = bootmeth_read_bootflow(bflow->method, bflow); |
| 36 | if (ret) |
| 37 | return log_msg_ret("method", ret); |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | static int system_bootdev_bind(struct udevice *dev) |
| 43 | { |
| 44 | struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); |
| 45 | |
| 46 | ucp->prio = BOOTDEVP_6_SYSTEM; |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | struct bootdev_ops system_bootdev_ops = { |
| 52 | .get_bootflow = system_get_bootflow, |
| 53 | }; |
| 54 | |
| 55 | static const struct udevice_id system_bootdev_ids[] = { |
| 56 | { .compatible = "u-boot,bootdev-system" }, |
| 57 | { } |
| 58 | }; |
| 59 | |
| 60 | U_BOOT_DRIVER(system_bootdev) = { |
| 61 | .name = "system_bootdev", |
| 62 | .id = UCLASS_BOOTDEV, |
| 63 | .ops = &system_bootdev_ops, |
| 64 | .bind = system_bootdev_bind, |
| 65 | .of_match = system_bootdev_ids, |
| 66 | }; |