Simon Glass | 309e6ec | 2022-04-24 23:31:19 -0600 | [diff] [blame] | 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 | |
Simon Glass | 161e1e3 | 2022-07-30 15:52:22 -0600 | [diff] [blame] | 18 | /** |
| 19 | * struct efi_mgr_priv - private info for the efi-mgr driver |
| 20 | * |
| 21 | * @fake_bootflow: Fake a valid bootflow for testing |
| 22 | */ |
| 23 | struct efi_mgr_priv { |
| 24 | bool fake_dev; |
| 25 | }; |
| 26 | |
| 27 | void 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 Glass | 309e6ec | 2022-04-24 23:31:19 -0600 | [diff] [blame] | 34 | static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter) |
| 35 | { |
| 36 | int ret; |
| 37 | |
| 38 | /* Must be an bootstd device */ |
Simon Glass | 18c5040 | 2023-01-17 10:47:54 -0700 | [diff] [blame] | 39 | ret = bootflow_iter_check_system(iter); |
Simon Glass | 309e6ec | 2022-04-24 23:31:19 -0600 | [diff] [blame] | 40 | if (ret) |
| 41 | return log_msg_ret("net", ret); |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow) |
| 47 | { |
Simon Glass | 161e1e3 | 2022-07-30 15:52:22 -0600 | [diff] [blame] | 48 | struct efi_mgr_priv *priv = dev_get_priv(dev); |
Simon Glass | 309e6ec | 2022-04-24 23:31:19 -0600 | [diff] [blame] | 49 | |
Simon Glass | 161e1e3 | 2022-07-30 15:52:22 -0600 | [diff] [blame] | 50 | if (priv->fake_dev) { |
| 51 | bflow->state = BOOTFLOWST_READY; |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | /* To be implemented */ |
| 56 | |
| 57 | return -EINVAL; |
Simon Glass | 309e6ec | 2022-04-24 23:31:19 -0600 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static 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 | |
| 68 | static 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 | |
| 78 | static 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 Glass | 4f8633d | 2022-07-30 15:52:21 -0600 | [diff] [blame] | 83 | plat->flags = BOOTMETHF_GLOBAL; |
Simon Glass | 309e6ec | 2022-04-24 23:31:19 -0600 | [diff] [blame] | 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static 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 | |
| 95 | static const struct udevice_id efi_mgr_bootmeth_ids[] = { |
| 96 | { .compatible = "u-boot,efi-bootmgr" }, |
| 97 | { } |
| 98 | }; |
| 99 | |
Simon Glass | 4f8633d | 2022-07-30 15:52:21 -0600 | [diff] [blame] | 100 | U_BOOT_DRIVER(bootmeth_efi_mgr) = { |
Simon Glass | 309e6ec | 2022-04-24 23:31:19 -0600 | [diff] [blame] | 101 | .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 Glass | 161e1e3 | 2022-07-30 15:52:22 -0600 | [diff] [blame] | 106 | .priv_auto = sizeof(struct efi_mgr_priv), |
Simon Glass | 309e6ec | 2022-04-24 23:31:19 -0600 | [diff] [blame] | 107 | }; |