blob: 2f327c1f8ce29df00ddafcf577ecb895d3738a54 [file] [log] [blame]
Simon Glass309e6ec2022-04-24 23:31:19 -06001// 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
Simon Glass161e1e32022-07-30 15:52:22 -060018/**
19 * struct efi_mgr_priv - private info for the efi-mgr driver
20 *
21 * @fake_bootflow: Fake a valid bootflow for testing
22 */
23struct efi_mgr_priv {
24 bool fake_dev;
25};
26
27void sandbox_set_fake_efi_mgr_dev(struct udevice *dev, bool fake_dev)
28{
29 struct efi_mgr_priv *priv = dev_get_priv(dev);
30
31 priv->fake_dev = fake_dev;
32}
33
Simon Glass309e6ec2022-04-24 23:31:19 -060034static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
35{
36 int ret;
37
38 /* Must be an bootstd device */
39 ret = bootflow_iter_uses_system(iter);
40 if (ret)
41 return log_msg_ret("net", ret);
42
43 return 0;
44}
45
46static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
47{
Simon Glass161e1e32022-07-30 15:52:22 -060048 struct efi_mgr_priv *priv = dev_get_priv(dev);
Simon Glass309e6ec2022-04-24 23:31:19 -060049
Simon Glass161e1e32022-07-30 15:52:22 -060050 if (priv->fake_dev) {
51 bflow->state = BOOTFLOWST_READY;
52 return 0;
53 }
54
55 /* To be implemented */
56
57 return -EINVAL;
Simon Glass309e6ec2022-04-24 23:31:19 -060058}
59
60static int efi_mgr_read_file(struct udevice *dev, struct bootflow *bflow,
61 const char *file_path, ulong addr, ulong *sizep)
62{
63 /* Files are loaded by the 'bootefi bootmgr' command */
64
65 return -ENOSYS;
66}
67
68static int efi_mgr_boot(struct udevice *dev, struct bootflow *bflow)
69{
70 int ret;
71
72 /* Booting is handled by the 'bootefi bootmgr' command */
73 ret = run_command("bootefi bootmgr", 0);
74
75 return 0;
76}
77
78static int bootmeth_efi_mgr_bind(struct udevice *dev)
79{
80 struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev);
81
82 plat->desc = "EFI bootmgr flow";
Simon Glass4f8633d2022-07-30 15:52:21 -060083 plat->flags = BOOTMETHF_GLOBAL;
Simon Glass309e6ec2022-04-24 23:31:19 -060084
85 return 0;
86}
87
88static struct bootmeth_ops efi_mgr_bootmeth_ops = {
89 .check = efi_mgr_check,
90 .read_bootflow = efi_mgr_read_bootflow,
91 .read_file = efi_mgr_read_file,
92 .boot = efi_mgr_boot,
93};
94
95static const struct udevice_id efi_mgr_bootmeth_ids[] = {
96 { .compatible = "u-boot,efi-bootmgr" },
97 { }
98};
99
Simon Glass4f8633d2022-07-30 15:52:21 -0600100U_BOOT_DRIVER(bootmeth_efi_mgr) = {
Simon Glass309e6ec2022-04-24 23:31:19 -0600101 .name = "bootmeth_efi_mgr",
102 .id = UCLASS_BOOTMETH,
103 .of_match = efi_mgr_bootmeth_ids,
104 .ops = &efi_mgr_bootmeth_ops,
105 .bind = bootmeth_efi_mgr_bind,
Simon Glass161e1e32022-07-30 15:52:22 -0600106 .priv_auto = sizeof(struct efi_mgr_priv),
Simon Glass309e6ec2022-04-24 23:31:19 -0600107};