Merge https://gitlab.denx.de/u-boot/custodians/u-boot-mpc85xx
[platform/kernel/u-boot.git] / fs / sandbox / host_bootdev.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Bootdevice for MMC
4  *
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
16 static 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
42 struct bootdev_ops host_bootdev_ops = {
43         .get_bootflow   = host_get_bootflow,
44 };
45
46 static const struct udevice_id host_bootdev_ids[] = {
47         { .compatible = "sandbox,bootdev-host" },
48         { }
49 };
50
51 U_BOOT_DRIVER(host_bootdev) = {
52         .name           = "host_bootdev",
53         .id             = UCLASS_BOOTDEV,
54         .ops            = &host_bootdev_ops,
55         .of_match       = host_bootdev_ids,
56 };