blob: aabc57e635a88bc9e41a572330392af80acf4326 [file] [log] [blame]
Simon Glass126947b2022-04-24 23:31:20 -06001// 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
Tom Rinid678a592024-05-18 20:20:43 -060011#include <common.h>
Simon Glass126947b2022-04-24 23:31:20 -060012#include <bootdev.h>
13#include <bootflow.h>
14#include <bootmeth.h>
15#include <dm.h>
16
17static int sandbox_check(struct udevice *dev, struct bootflow_iter *iter)
18{
19 return 0;
20}
21
22static int sandbox_read_bootflow(struct udevice *dev, struct bootflow *bflow)
23{
24 /* pretend we are ready */
25 bflow->state = BOOTFLOWST_READY;
26
27 return 0;
28}
29
30static int sandbox_read_file(struct udevice *dev, struct bootflow *bflow,
31 const char *file_path, ulong addr, ulong *sizep)
32{
33 return -ENOSYS;
34}
35
36static int sandbox_boot(struct udevice *dev, struct bootflow *bflow)
37{
38 /* always fail: see bootflow_iter_disable() */
39 return -ENOTSUPP;
40}
41
42static int sandbox_bootmeth_bind(struct udevice *dev)
43{
44 struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev);
45
46 plat->desc = "Sandbox boot for testing";
47
48 return 0;
49}
50
51static struct bootmeth_ops sandbox_bootmeth_ops = {
52 .check = sandbox_check,
53 .read_bootflow = sandbox_read_bootflow,
54 .read_file = sandbox_read_file,
55 .boot = sandbox_boot,
56};
57
58static const struct udevice_id sandbox_bootmeth_ids[] = {
Simon Glass79f66352023-05-10 16:34:46 -060059 { .compatible = "u-boot,sandbox-extlinux" },
Simon Glass126947b2022-04-24 23:31:20 -060060 { }
61};
62
63U_BOOT_DRIVER(bootmeth_sandbox) = {
64 .name = "bootmeth_sandbox",
65 .id = UCLASS_BOOTMETH,
66 .of_match = sandbox_bootmeth_ids,
67 .ops = &sandbox_bootmeth_ops,
68 .bind = sandbox_bootmeth_bind,
69};