blob: 3f74972a9f81a88ecc7efcf208ef2134840ce46f [file] [log] [blame]
Simon Glass7d0478d2022-04-24 23:31:21 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
Simon Glass4de979f2023-07-12 09:04:32 -06003 * Bootdev for sandbox host
Simon Glass7d0478d2022-04-24 23:31:21 -06004 *
5 * Copyright 2021 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
Simon Glass7d0478d2022-04-24 23:31:21 -06009#include <bootdev.h>
10#include <bootflow.h>
11#include <bootmeth.h>
12#include <dm.h>
13#include <fs.h>
14
15static int host_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
16 struct bootflow *bflow)
17{
18 int ret;
19
20 if (iter->part)
21 return log_msg_ret("max", -ESHUTDOWN);
22
23 bflow->name = strdup(dev->name);
24 if (!bflow->name)
25 return log_msg_ret("name", -ENOMEM);
26
27 ret = bootmeth_check(bflow->method, iter);
28 if (ret)
29 return log_msg_ret("check", ret);
30
31 bflow->state = BOOTFLOWST_MEDIA;
32 bflow->fs_type = FS_TYPE_SANDBOX;
33
34 ret = bootmeth_read_bootflow(bflow->method, bflow);
35 if (ret)
36 return log_msg_ret("method", ret);
37
38 return 0;
39}
40
41struct bootdev_ops host_bootdev_ops = {
42 .get_bootflow = host_get_bootflow,
43};
44
45static const struct udevice_id host_bootdev_ids[] = {
46 { .compatible = "sandbox,bootdev-host" },
47 { }
48};
49
50U_BOOT_DRIVER(host_bootdev) = {
51 .name = "host_bootdev",
52 .id = UCLASS_BOOTDEV,
53 .ops = &host_bootdev_ops,
54 .of_match = host_bootdev_ids,
55};