console.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* console.c - console interface layer for U-Boot platforms */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2013 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/term.h>
  20. #include <grub/misc.h>
  21. #include <grub/types.h>
  22. #include <grub/err.h>
  23. #include <grub/terminfo.h>
  24. #include <grub/uboot/uboot.h>
  25. #include <grub/uboot/console.h>
  26. static void
  27. put (struct grub_term_output *term __attribute__ ((unused)), const int c)
  28. {
  29. grub_uboot_putc (c);
  30. }
  31. static int
  32. readkey (struct grub_term_input *term __attribute__ ((unused)))
  33. {
  34. if (grub_uboot_tstc () > 0)
  35. return grub_uboot_getc ();
  36. return -1;
  37. }
  38. static void
  39. uboot_console_setcursor (struct grub_term_output *term
  40. __attribute__ ((unused)), int on
  41. __attribute__ ((unused)))
  42. {
  43. grub_terminfo_setcursor (term, on);
  44. }
  45. static grub_err_t
  46. uboot_console_init_input (struct grub_term_input *term)
  47. {
  48. return grub_terminfo_input_init (term);
  49. }
  50. extern struct grub_terminfo_output_state uboot_console_terminfo_output;
  51. static grub_err_t
  52. uboot_console_init_output (struct grub_term_output *term)
  53. {
  54. grub_terminfo_output_init (term);
  55. return 0;
  56. }
  57. struct grub_terminfo_input_state uboot_console_terminfo_input = {
  58. .readkey = readkey
  59. };
  60. struct grub_terminfo_output_state uboot_console_terminfo_output = {
  61. .put = put,
  62. /* FIXME: In rare cases when console isn't serial,
  63. determine real width. */
  64. .size = { 80, 24 }
  65. };
  66. static struct grub_term_input uboot_console_term_input = {
  67. .name = "console",
  68. .init = uboot_console_init_input,
  69. .getkey = grub_terminfo_getkey,
  70. .data = &uboot_console_terminfo_input
  71. };
  72. static struct grub_term_output uboot_console_term_output = {
  73. .name = "console",
  74. .init = uboot_console_init_output,
  75. .putchar = grub_terminfo_putchar,
  76. .getwh = grub_terminfo_getwh,
  77. .getxy = grub_terminfo_getxy,
  78. .gotoxy = grub_terminfo_gotoxy,
  79. .cls = grub_terminfo_cls,
  80. .setcolorstate = grub_terminfo_setcolorstate,
  81. .setcursor = uboot_console_setcursor,
  82. .flags = GRUB_TERM_CODE_TYPE_ASCII,
  83. .data = &uboot_console_terminfo_output,
  84. .progress_update_divisor = GRUB_PROGRESS_FAST
  85. };
  86. void
  87. grub_console_init_early (void)
  88. {
  89. grub_term_register_input ("console", &uboot_console_term_input);
  90. grub_term_register_output ("console", &uboot_console_term_output);
  91. }
  92. /*
  93. * grub_console_init_lately():
  94. * Initializes terminfo formatting by registering terminal type.
  95. * Called after heap has been configured.
  96. *
  97. */
  98. void
  99. grub_console_init_lately (void)
  100. {
  101. const char *type;
  102. /* See if explicitly set by U-Boot environment */
  103. type = grub_uboot_env_get ("grub_term");
  104. if (!type)
  105. type = "vt100";
  106. grub_terminfo_init ();
  107. grub_terminfo_output_register (&uboot_console_term_output, type);
  108. }
  109. void
  110. grub_console_fini (void)
  111. {
  112. }