bootmeth_efi_mgr.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #define LOG_CATEGORY UCLASS_BOOTSTD
  9. #include <common.h>
  10. #include <bootdev.h>
  11. #include <bootflow.h>
  12. #include <bootmeth.h>
  13. #include <command.h>
  14. #include <dm.h>
  15. /**
  16. * struct efi_mgr_priv - private info for the efi-mgr driver
  17. *
  18. * @fake_bootflow: Fake a valid bootflow for testing
  19. */
  20. struct efi_mgr_priv {
  21. bool fake_dev;
  22. };
  23. void sandbox_set_fake_efi_mgr_dev(struct udevice *dev, bool fake_dev)
  24. {
  25. struct efi_mgr_priv *priv = dev_get_priv(dev);
  26. priv->fake_dev = fake_dev;
  27. }
  28. static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
  29. {
  30. int ret;
  31. /* Must be an bootstd device */
  32. ret = bootflow_iter_check_system(iter);
  33. if (ret)
  34. return log_msg_ret("net", ret);
  35. return 0;
  36. }
  37. static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
  38. {
  39. struct efi_mgr_priv *priv = dev_get_priv(dev);
  40. if (priv->fake_dev) {
  41. bflow->state = BOOTFLOWST_READY;
  42. return 0;
  43. }
  44. /* To be implemented */
  45. return -EINVAL;
  46. }
  47. static int efi_mgr_read_file(struct udevice *dev, struct bootflow *bflow,
  48. const char *file_path, ulong addr, ulong *sizep)
  49. {
  50. /* Files are loaded by the 'bootefi bootmgr' command */
  51. return -ENOSYS;
  52. }
  53. static int efi_mgr_boot(struct udevice *dev, struct bootflow *bflow)
  54. {
  55. int ret;
  56. /* Booting is handled by the 'bootefi bootmgr' command */
  57. ret = run_command("bootefi bootmgr", 0);
  58. return 0;
  59. }
  60. static int bootmeth_efi_mgr_bind(struct udevice *dev)
  61. {
  62. struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev);
  63. plat->desc = "EFI bootmgr flow";
  64. plat->flags = BOOTMETHF_GLOBAL;
  65. return 0;
  66. }
  67. static struct bootmeth_ops efi_mgr_bootmeth_ops = {
  68. .check = efi_mgr_check,
  69. .read_bootflow = efi_mgr_read_bootflow,
  70. .read_file = efi_mgr_read_file,
  71. .boot = efi_mgr_boot,
  72. };
  73. static const struct udevice_id efi_mgr_bootmeth_ids[] = {
  74. { .compatible = "u-boot,efi-bootmgr" },
  75. { }
  76. };
  77. U_BOOT_DRIVER(bootmeth_efi_mgr) = {
  78. .name = "bootmeth_efi_mgr",
  79. .id = UCLASS_BOOTMETH,
  80. .of_match = efi_mgr_bootmeth_ids,
  81. .ops = &efi_mgr_bootmeth_ops,
  82. .bind = bootmeth_efi_mgr_bind,
  83. .priv_auto = sizeof(struct efi_mgr_priv),
  84. };