blob: 08d9328af4e83e13a48b23d21f7d45d137d2d262 [file] [log] [blame]
Simon Glass0b415252022-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
18static 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
30static 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
41static 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
49static 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
59static 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";
Simon Glassbc06aa02022-07-30 15:52:21 -060064 plat->flags = BOOTMETHF_GLOBAL;
Simon Glass0b415252022-04-24 23:31:19 -060065
66 return 0;
67}
68
69static struct bootmeth_ops efi_mgr_bootmeth_ops = {
70 .check = efi_mgr_check,
71 .read_bootflow = efi_mgr_read_bootflow,
72 .read_file = efi_mgr_read_file,
73 .boot = efi_mgr_boot,
74};
75
76static const struct udevice_id efi_mgr_bootmeth_ids[] = {
77 { .compatible = "u-boot,efi-bootmgr" },
78 { }
79};
80
Simon Glassbc06aa02022-07-30 15:52:21 -060081U_BOOT_DRIVER(bootmeth_efi_mgr) = {
Simon Glass0b415252022-04-24 23:31:19 -060082 .name = "bootmeth_efi_mgr",
83 .id = UCLASS_BOOTMETH,
84 .of_match = efi_mgr_bootmeth_ids,
85 .ops = &efi_mgr_bootmeth_ops,
86 .bind = bootmeth_efi_mgr_bind,
87};