blob: 3ef53627608af1f2429e86ee03eb16264d20d397 [file] [log] [blame]
Simon Glass1b4bc152022-04-24 23:31:21 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
Simon Glass41571582023-07-12 09:04:32 -06003 * Bootdev for sandbox host
Simon Glass1b4bc152022-04-24 23:31:21 -06004 *
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 <bootflow.h>
12#include <bootmeth.h>
13#include <dm.h>
14#include <fs.h>
15
16static int host_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
17 struct bootflow *bflow)
18{
19 int ret;
20
21 if (iter->part)
22 return log_msg_ret("max", -ESHUTDOWN);
23
24 bflow->name = strdup(dev->name);
25 if (!bflow->name)
26 return log_msg_ret("name", -ENOMEM);
27
28 ret = bootmeth_check(bflow->method, iter);
29 if (ret)
30 return log_msg_ret("check", ret);
31
32 bflow->state = BOOTFLOWST_MEDIA;
33 bflow->fs_type = FS_TYPE_SANDBOX;
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
42struct bootdev_ops host_bootdev_ops = {
43 .get_bootflow = host_get_bootflow,
44};
45
46static const struct udevice_id host_bootdev_ids[] = {
47 { .compatible = "sandbox,bootdev-host" },
48 { }
49};
50
51U_BOOT_DRIVER(host_bootdev) = {
52 .name = "host_bootdev",
53 .id = UCLASS_BOOTDEV,
54 .ops = &host_bootdev_ops,
55 .of_match = host_bootdev_ids,
56};