Simon Glass | 126947b | 2022-04-24 23:31:20 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Bootmethod for sandbox testing |
| 4 | * |
| 5 | * Copyright 2021 Google LLC |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | */ |
| 8 | |
| 9 | #define LOG_CATEGORY UCLASS_BOOTSTD |
| 10 | |
Simon Glass | 126947b | 2022-04-24 23:31:20 -0600 | [diff] [blame] | 11 | #include <bootdev.h> |
| 12 | #include <bootflow.h> |
| 13 | #include <bootmeth.h> |
| 14 | #include <dm.h> |
| 15 | |
| 16 | static int sandbox_check(struct udevice *dev, struct bootflow_iter *iter) |
| 17 | { |
| 18 | return 0; |
| 19 | } |
| 20 | |
| 21 | static int sandbox_read_bootflow(struct udevice *dev, struct bootflow *bflow) |
| 22 | { |
| 23 | /* pretend we are ready */ |
| 24 | bflow->state = BOOTFLOWST_READY; |
| 25 | |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | static int sandbox_read_file(struct udevice *dev, struct bootflow *bflow, |
| 30 | const char *file_path, ulong addr, ulong *sizep) |
| 31 | { |
| 32 | return -ENOSYS; |
| 33 | } |
| 34 | |
| 35 | static int sandbox_boot(struct udevice *dev, struct bootflow *bflow) |
| 36 | { |
| 37 | /* always fail: see bootflow_iter_disable() */ |
| 38 | return -ENOTSUPP; |
| 39 | } |
| 40 | |
| 41 | static int sandbox_bootmeth_bind(struct udevice *dev) |
| 42 | { |
| 43 | struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev); |
| 44 | |
| 45 | plat->desc = "Sandbox boot for testing"; |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static struct bootmeth_ops sandbox_bootmeth_ops = { |
| 51 | .check = sandbox_check, |
| 52 | .read_bootflow = sandbox_read_bootflow, |
| 53 | .read_file = sandbox_read_file, |
| 54 | .boot = sandbox_boot, |
| 55 | }; |
| 56 | |
| 57 | static const struct udevice_id sandbox_bootmeth_ids[] = { |
Simon Glass | 9540302 | 2024-07-17 09:30:58 +0100 | [diff] [blame] | 58 | { .compatible = "u-boot,sandbox-bootmeth" }, |
Simon Glass | 126947b | 2022-04-24 23:31:20 -0600 | [diff] [blame] | 59 | { } |
| 60 | }; |
| 61 | |
| 62 | U_BOOT_DRIVER(bootmeth_sandbox) = { |
| 63 | .name = "bootmeth_sandbox", |
| 64 | .id = UCLASS_BOOTMETH, |
| 65 | .of_match = sandbox_bootmeth_ids, |
| 66 | .ops = &sandbox_bootmeth_ops, |
| 67 | .bind = sandbox_bootmeth_bind, |
| 68 | }; |