vbe.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Verified Boot for Embedded (VBE) command
  4. *
  5. * Copyright 2022 Google LLC
  6. * Written by Simon Glass <sjg@chromium.org>
  7. */
  8. #include <common.h>
  9. #include <bloblist.h>
  10. #include <bootmeth.h>
  11. #include <bootstd.h>
  12. #include <command.h>
  13. #include <spl.h>
  14. #include <vbe.h>
  15. static int do_vbe_list(struct cmd_tbl *cmdtp, int flag, int argc,
  16. char *const argv[])
  17. {
  18. vbe_list();
  19. return 0;
  20. }
  21. static int do_vbe_select(struct cmd_tbl *cmdtp, int flag, int argc,
  22. char *const argv[])
  23. {
  24. struct bootstd_priv *std;
  25. struct udevice *dev;
  26. int ret;
  27. ret = bootstd_get_priv(&std);
  28. if (ret)
  29. return CMD_RET_FAILURE;
  30. if (argc < 2) {
  31. std->vbe_bootmeth = NULL;
  32. return 0;
  33. }
  34. if (vbe_find_by_any(argv[1], &dev))
  35. return CMD_RET_FAILURE;
  36. std->vbe_bootmeth = dev;
  37. return 0;
  38. }
  39. static int do_vbe_info(struct cmd_tbl *cmdtp, int flag, int argc,
  40. char *const argv[])
  41. {
  42. struct bootstd_priv *std;
  43. char buf[256];
  44. int ret, len;
  45. ret = bootstd_get_priv(&std);
  46. if (ret)
  47. return CMD_RET_FAILURE;
  48. if (!std->vbe_bootmeth) {
  49. printf("No VBE bootmeth selected\n");
  50. return CMD_RET_FAILURE;
  51. }
  52. ret = bootmeth_get_state_desc(std->vbe_bootmeth, buf, sizeof(buf));
  53. if (ret) {
  54. printf("Failed (err=%d)\n", ret);
  55. return CMD_RET_FAILURE;
  56. }
  57. len = strnlen(buf, sizeof(buf));
  58. if (len >= sizeof(buf)) {
  59. printf("Buffer overflow\n");
  60. return CMD_RET_FAILURE;
  61. }
  62. puts(buf);
  63. if (buf[len] != '\n')
  64. putc('\n');
  65. return 0;
  66. }
  67. static int do_vbe_state(struct cmd_tbl *cmdtp, int flag, int argc,
  68. char *const argv[])
  69. {
  70. struct vbe_handoff *handoff = NULL;
  71. int i;
  72. if (IS_ENABLED(CONFIG_BLOBLIST)) {
  73. handoff = bloblist_find(BLOBLISTT_VBE,
  74. sizeof(struct vbe_handoff));
  75. }
  76. if (!handoff) {
  77. printf("No VBE state\n");
  78. return CMD_RET_FAILURE;
  79. }
  80. printf("Phases:");
  81. for (i = PHASE_NONE; i < PHASE_COUNT; i++) {
  82. if (handoff->phases & (1 << i))
  83. printf(" %s", spl_phase_name(i));
  84. }
  85. if (!handoff->phases)
  86. printf(" (none)");
  87. printf("\n");
  88. return 0;
  89. }
  90. #ifdef CONFIG_SYS_LONGHELP
  91. static char vbe_help_text[] =
  92. "list - list VBE bootmeths\n"
  93. "vbe select - select a VBE bootmeth by sequence or name\n"
  94. "vbe info - show information about a VBE bootmeth\n"
  95. "vbe state - show VBE state";
  96. #endif
  97. U_BOOT_CMD_WITH_SUBCMDS(vbe, "Verified Boot for Embedded", vbe_help_text,
  98. U_BOOT_SUBCMD_MKENT(list, 1, 1, do_vbe_list),
  99. U_BOOT_SUBCMD_MKENT(select, 2, 1, do_vbe_select),
  100. U_BOOT_SUBCMD_MKENT(state, 2, 1, do_vbe_state),
  101. U_BOOT_SUBCMD_MKENT(info, 2, 1, do_vbe_info));