splash.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 <env.h>
  24. #include <splash.h>
  25. #include <lcd.h>
  26. static struct splash_location default_splash_locations[] = {
  27. {
  28. .name = "sf",
  29. .storage = SPLASH_STORAGE_SF,
  30. .flags = SPLASH_STORAGE_RAW,
  31. .offset = 0x0,
  32. },
  33. {
  34. .name = "mmc_fs",
  35. .storage = SPLASH_STORAGE_MMC,
  36. .flags = SPLASH_STORAGE_FS,
  37. .devpart = "0:1",
  38. },
  39. {
  40. .name = "usb_fs",
  41. .storage = SPLASH_STORAGE_USB,
  42. .flags = SPLASH_STORAGE_FS,
  43. .devpart = "0:1",
  44. },
  45. {
  46. .name = "sata_fs",
  47. .storage = SPLASH_STORAGE_SATA,
  48. .flags = SPLASH_STORAGE_FS,
  49. .devpart = "0:1",
  50. },
  51. };
  52. #if defined(CONFIG_DM_VIDEO) && defined(CONFIG_VIDEO_LOGO)
  53. #include <bmp_logo_data.h>
  54. static int splash_video_logo_load(void)
  55. {
  56. char *splashimage;
  57. u32 bmp_load_addr;
  58. splashimage = env_get("splashimage");
  59. if (!splashimage)
  60. return -ENOENT;
  61. bmp_load_addr = simple_strtoul(splashimage, 0, 16);
  62. if (!bmp_load_addr) {
  63. printf("Error: bad 'splashimage' address\n");
  64. return -EFAULT;
  65. }
  66. memcpy((void *)bmp_load_addr, bmp_logo_bitmap,
  67. ARRAY_SIZE(bmp_logo_bitmap));
  68. return 0;
  69. }
  70. #else
  71. static inline int splash_video_logo_load(void) { return -ENOSYS; }
  72. #endif
  73. __weak int splash_screen_prepare(void)
  74. {
  75. if (CONFIG_IS_ENABLED(SPLASH_SOURCE))
  76. return splash_source_load(default_splash_locations,
  77. ARRAY_SIZE(default_splash_locations));
  78. return splash_video_logo_load();
  79. }
  80. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  81. void splash_get_pos(int *x, int *y)
  82. {
  83. char *s = env_get("splashpos");
  84. if (!s)
  85. return;
  86. if (s[0] == 'm')
  87. *x = BMP_ALIGN_CENTER;
  88. else
  89. *x = simple_strtol(s, NULL, 0);
  90. s = strchr(s + 1, ',');
  91. if (s != NULL) {
  92. if (s[1] == 'm')
  93. *y = BMP_ALIGN_CENTER;
  94. else
  95. *y = simple_strtol(s + 1, NULL, 0);
  96. }
  97. }
  98. #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
  99. #if defined(CONFIG_DM_VIDEO) && !defined(CONFIG_HIDE_LOGO_VERSION)
  100. #ifdef CONFIG_VIDEO_LOGO
  101. #include <bmp_logo.h>
  102. #endif
  103. #include <dm.h>
  104. #include <video_console.h>
  105. #include <video_font.h>
  106. void splash_display_banner(void)
  107. {
  108. struct udevice *dev;
  109. char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
  110. int col, row, ret;
  111. ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &dev);
  112. if (ret)
  113. return;
  114. #ifdef CONFIG_VIDEO_LOGO
  115. col = BMP_LOGO_WIDTH / VIDEO_FONT_WIDTH + 1;
  116. row = BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT + 1;
  117. #else
  118. col = 0;
  119. row = 0;
  120. #endif
  121. display_options_get_banner(false, buf, sizeof(buf));
  122. vidconsole_position_cursor(dev, col, 1);
  123. vidconsole_put_string(dev, buf);
  124. vidconsole_position_cursor(dev, 0, row);
  125. }
  126. #endif /* CONFIG_DM_VIDEO && !CONFIG_HIDE_LOGO_VERSION */
  127. /*
  128. * Common function to show a splash image if env("splashimage") is set.
  129. * Is used for both dm_video and lcd video stacks. For additional
  130. * details please refer to doc/README.splashprepare.
  131. */
  132. #if defined(CONFIG_SPLASH_SCREEN) && defined(CONFIG_CMD_BMP)
  133. int splash_display(void)
  134. {
  135. ulong addr;
  136. char *s;
  137. int x = 0, y = 0, ret;
  138. s = env_get("splashimage");
  139. if (!s)
  140. return -EINVAL;
  141. addr = simple_strtoul(s, NULL, 16);
  142. ret = splash_screen_prepare();
  143. if (ret)
  144. return ret;
  145. splash_get_pos(&x, &y);
  146. ret = bmp_display(addr, x, y);
  147. /* Skip banner output on video console if the logo is not at 0,0 */
  148. if (x || y)
  149. goto end;
  150. #if defined(CONFIG_DM_VIDEO) && !defined(CONFIG_HIDE_LOGO_VERSION)
  151. splash_display_banner();
  152. #endif
  153. end:
  154. return ret;
  155. }
  156. #endif