splash.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Copyright (C) 2013, Boundary Devices <info@boundarydevices.com>
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., http://www.fsf.org/about/contact/
  20. *
  21. */
  22. #include <common.h>
  23. #include <display_options.h>
  24. #include <env.h>
  25. #include <splash.h>
  26. #include <video.h>
  27. static struct splash_location default_splash_locations[] = {
  28. {
  29. .name = "sf",
  30. .storage = SPLASH_STORAGE_SF,
  31. .flags = SPLASH_STORAGE_RAW,
  32. .offset = 0x0,
  33. },
  34. {
  35. .name = "mmc_fs",
  36. .storage = SPLASH_STORAGE_MMC,
  37. .flags = SPLASH_STORAGE_FS,
  38. .devpart = "0:1",
  39. },
  40. {
  41. .name = "mmc_raw",
  42. .storage = SPLASH_STORAGE_MMC,
  43. .flags = SPLASH_STORAGE_RAW,
  44. .devpart = "0:1",
  45. },
  46. {
  47. .name = "usb_fs",
  48. .storage = SPLASH_STORAGE_USB,
  49. .flags = SPLASH_STORAGE_FS,
  50. .devpart = "0:1",
  51. },
  52. {
  53. .name = "sata_fs",
  54. .storage = SPLASH_STORAGE_SATA,
  55. .flags = SPLASH_STORAGE_FS,
  56. .devpart = "0:1",
  57. },
  58. };
  59. #ifdef CONFIG_VIDEO_LOGO
  60. #include <bmp_logo_data.h>
  61. static int splash_video_logo_load(void)
  62. {
  63. char *splashimage;
  64. ulong bmp_load_addr;
  65. splashimage = env_get("splashimage");
  66. if (!splashimage)
  67. return -ENOENT;
  68. bmp_load_addr = hextoul(splashimage, 0);
  69. if (!bmp_load_addr) {
  70. printf("Error: bad 'splashimage' address\n");
  71. return -EFAULT;
  72. }
  73. memcpy((void *)bmp_load_addr, bmp_logo_bitmap,
  74. ARRAY_SIZE(bmp_logo_bitmap));
  75. return 0;
  76. }
  77. #else
  78. static inline int splash_video_logo_load(void) { return -ENOSYS; }
  79. #endif
  80. __weak int splash_screen_prepare(void)
  81. {
  82. if (CONFIG_IS_ENABLED(SPLASH_SOURCE))
  83. return splash_source_load(default_splash_locations,
  84. ARRAY_SIZE(default_splash_locations));
  85. return splash_video_logo_load();
  86. }
  87. void splash_get_pos(int *x, int *y)
  88. {
  89. char *s = env_get("splashpos");
  90. if (!CONFIG_IS_ENABLED(SPLASH_SCREEN_ALIGN) || !s)
  91. return;
  92. if (s[0] == 'm')
  93. *x = BMP_ALIGN_CENTER;
  94. else
  95. *x = simple_strtol(s, NULL, 0);
  96. s = strchr(s + 1, ',');
  97. if (s != NULL) {
  98. if (s[1] == 'm')
  99. *y = BMP_ALIGN_CENTER;
  100. else
  101. *y = simple_strtol(s + 1, NULL, 0);
  102. }
  103. }
  104. #if CONFIG_IS_ENABLED(VIDEO) && !CONFIG_IS_ENABLED(HIDE_LOGO_VERSION)
  105. #ifdef CONFIG_VIDEO_LOGO
  106. #include <bmp_logo.h>
  107. #endif
  108. #include <dm.h>
  109. #include <video_console.h>
  110. #include <video_font.h>
  111. #include <video_font_data.h>
  112. void splash_display_banner(void)
  113. {
  114. struct video_fontdata __maybe_unused *fontdata = fonts;
  115. struct udevice *dev;
  116. char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
  117. int col, row, ret;
  118. ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &dev);
  119. if (ret)
  120. return;
  121. #if IS_ENABLED(CONFIG_VIDEO_LOGO)
  122. col = BMP_LOGO_WIDTH / fontdata->width + 1;
  123. row = BMP_LOGO_HEIGHT / fontdata->height + 1;
  124. #else
  125. col = 0;
  126. row = 0;
  127. #endif
  128. display_options_get_banner(false, buf, sizeof(buf));
  129. vidconsole_position_cursor(dev, col, 1);
  130. vidconsole_put_string(dev, buf);
  131. vidconsole_position_cursor(dev, 0, row);
  132. }
  133. #endif /* CONFIG_VIDEO && !CONFIG_HIDE_LOGO_VERSION */
  134. /*
  135. * Common function to show a splash image if env("splashimage") is set.
  136. * For additional details please refer to doc/README.splashprepare.
  137. */
  138. int splash_display(void)
  139. {
  140. ulong addr;
  141. char *s;
  142. int x = 0, y = 0, ret;
  143. if (!CONFIG_IS_ENABLED(SPLASH_SCREEN))
  144. return -ENOSYS;
  145. s = env_get("splashimage");
  146. if (!s)
  147. return -EINVAL;
  148. addr = hextoul(s, NULL);
  149. ret = splash_screen_prepare();
  150. if (ret)
  151. return ret;
  152. splash_get_pos(&x, &y);
  153. if (CONFIG_IS_ENABLED(BMP))
  154. ret = bmp_display(addr, x, y);
  155. else
  156. return -ENOSYS;
  157. /* Skip banner output on video console if the logo is not at 0,0 */
  158. if (x || y)
  159. goto end;
  160. #if CONFIG_IS_ENABLED(VIDEO) && !CONFIG_IS_ENABLED(HIDE_LOGO_VERSION)
  161. splash_display_banner();
  162. #endif
  163. end:
  164. return ret;
  165. }