Merge https://gitlab.denx.de/u-boot/custodians/u-boot-mpc85xx
[platform/kernel/u-boot.git] / boot / bootmeth_efi_mgr.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Bootmethod for EFI boot manager
4  *
5  * Copyright 2021 Google LLC
6  * Written by Simon Glass <sjg@chromium.org>
7  */
8
9 #define LOG_CATEGORY UCLASS_BOOTSTD
10
11 #include <common.h>
12 #include <bootdev.h>
13 #include <bootflow.h>
14 #include <bootmeth.h>
15 #include <command.h>
16 #include <dm.h>
17
18 static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
19 {
20         int ret;
21
22         /* Must be an bootstd device */
23         ret = bootflow_iter_uses_system(iter);
24         if (ret)
25                 return log_msg_ret("net", ret);
26
27         return 0;
28 }
29
30 static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
31 {
32         /*
33          * Just assume there is something to boot since we don't have any way
34          * of knowing in advance
35          */
36         bflow->state = BOOTFLOWST_READY;
37
38         return 0;
39 }
40
41 static int efi_mgr_read_file(struct udevice *dev, struct bootflow *bflow,
42                                 const char *file_path, ulong addr, ulong *sizep)
43 {
44         /* Files are loaded by the 'bootefi bootmgr' command */
45
46         return -ENOSYS;
47 }
48
49 static int efi_mgr_boot(struct udevice *dev, struct bootflow *bflow)
50 {
51         int ret;
52
53         /* Booting is handled by the 'bootefi bootmgr' command */
54         ret = run_command("bootefi bootmgr", 0);
55
56         return 0;
57 }
58
59 static int bootmeth_efi_mgr_bind(struct udevice *dev)
60 {
61         struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev);
62
63         plat->desc = "EFI bootmgr flow";
64
65         return 0;
66 }
67
68 static struct bootmeth_ops efi_mgr_bootmeth_ops = {
69         .check          = efi_mgr_check,
70         .read_bootflow  = efi_mgr_read_bootflow,
71         .read_file      = efi_mgr_read_file,
72         .boot           = efi_mgr_boot,
73 };
74
75 static const struct udevice_id efi_mgr_bootmeth_ids[] = {
76         { .compatible = "u-boot,efi-bootmgr" },
77         { }
78 };
79
80 U_BOOT_DRIVER(bootmeth_zefi_mgr) = {
81         .name           = "bootmeth_efi_mgr",
82         .id             = UCLASS_BOOTMETH,
83         .of_match       = efi_mgr_bootmeth_ids,
84         .ops            = &efi_mgr_bootmeth_ops,
85         .bind           = bootmeth_efi_mgr_bind,
86 };