blob: 0e520cc1030df205baf7af50d19c1e2e6fcef43c [file] [log] [blame]
Robert Winklerdd4425e2013-06-17 11:31:29 -07001/*
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
Anatolij Gustschinff8fb562013-07-02 00:04:05 +020023#include <common.h>
Simon Glass4e4bf942022-07-31 12:28:48 -060024#include <display_options.h>
Simon Glass7b51b572019-08-01 09:46:52 -060025#include <env.h>
Robert Winklerdd4425e2013-06-17 11:31:29 -070026#include <splash.h>
Nikita Kiryanov7bf71d12015-02-03 13:32:32 +020027#include <lcd.h>
Robert Winklerdd4425e2013-06-17 11:31:29 -070028
Alexey Brodkinb6de2cd2016-07-01 22:48:16 +030029static struct splash_location default_splash_locations[] = {
30 {
31 .name = "sf",
32 .storage = SPLASH_STORAGE_SF,
33 .flags = SPLASH_STORAGE_RAW,
34 .offset = 0x0,
35 },
36 {
37 .name = "mmc_fs",
38 .storage = SPLASH_STORAGE_MMC,
39 .flags = SPLASH_STORAGE_FS,
40 .devpart = "0:1",
41 },
42 {
43 .name = "usb_fs",
44 .storage = SPLASH_STORAGE_USB,
45 .flags = SPLASH_STORAGE_FS,
46 .devpart = "0:1",
47 },
48 {
49 .name = "sata_fs",
50 .storage = SPLASH_STORAGE_SATA,
51 .flags = SPLASH_STORAGE_FS,
52 .devpart = "0:1",
53 },
54};
55
Simon Glass64cfeda2021-11-19 13:24:01 -070056#ifdef CONFIG_VIDEO_LOGO
Anatolij Gustschin7600d622019-09-18 16:47:33 +020057
58#include <bmp_logo_data.h>
59
60static int splash_video_logo_load(void)
61{
62 char *splashimage;
Ye Li70b06d92020-06-10 02:52:22 -070063 ulong bmp_load_addr;
Anatolij Gustschin7600d622019-09-18 16:47:33 +020064
65 splashimage = env_get("splashimage");
66 if (!splashimage)
67 return -ENOENT;
68
Simon Glass7e5f4602021-07-24 09:03:29 -060069 bmp_load_addr = hextoul(splashimage, 0);
Anatolij Gustschin7600d622019-09-18 16:47:33 +020070 if (!bmp_load_addr) {
71 printf("Error: bad 'splashimage' address\n");
72 return -EFAULT;
73 }
74
75 memcpy((void *)bmp_load_addr, bmp_logo_bitmap,
76 ARRAY_SIZE(bmp_logo_bitmap));
77
78 return 0;
79}
80#else
81static inline int splash_video_logo_load(void) { return -ENOSYS; }
82#endif
83
Jeroen Hofsteecc64b922014-06-26 19:53:16 +020084__weak int splash_screen_prepare(void)
Robert Winklerdd4425e2013-06-17 11:31:29 -070085{
Anatolij Gustschin7600d622019-09-18 16:47:33 +020086 if (CONFIG_IS_ENABLED(SPLASH_SOURCE))
87 return splash_source_load(default_splash_locations,
88 ARRAY_SIZE(default_splash_locations));
89
90 return splash_video_logo_load();
Robert Winklerdd4425e2013-06-17 11:31:29 -070091}
Robert Winkler59b15922013-06-17 11:31:30 -070092
Anatolij Gustschinff8fb562013-07-02 00:04:05 +020093#ifdef CONFIG_SPLASH_SCREEN_ALIGN
94void splash_get_pos(int *x, int *y)
95{
Simon Glass00caae62017-08-03 12:22:12 -060096 char *s = env_get("splashpos");
Anatolij Gustschinff8fb562013-07-02 00:04:05 +020097
98 if (!s)
99 return;
100
101 if (s[0] == 'm')
102 *x = BMP_ALIGN_CENTER;
103 else
104 *x = simple_strtol(s, NULL, 0);
105
106 s = strchr(s + 1, ',');
107 if (s != NULL) {
108 if (s[1] == 'm')
109 *y = BMP_ALIGN_CENTER;
110 else
111 *y = simple_strtol(s + 1, NULL, 0);
112 }
113}
114#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
Nikita Kiryanov7bf71d12015-02-03 13:32:32 +0200115
Anatolij Gustschind2a82712019-09-20 17:23:41 +0200116#if defined(CONFIG_DM_VIDEO) && !defined(CONFIG_HIDE_LOGO_VERSION)
117
118#ifdef CONFIG_VIDEO_LOGO
119#include <bmp_logo.h>
120#endif
121#include <dm.h>
122#include <video_console.h>
123#include <video_font.h>
124
125void splash_display_banner(void)
126{
127 struct udevice *dev;
128 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
129 int col, row, ret;
130
131 ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &dev);
132 if (ret)
133 return;
134
135#ifdef CONFIG_VIDEO_LOGO
136 col = BMP_LOGO_WIDTH / VIDEO_FONT_WIDTH + 1;
137 row = BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT + 1;
138#else
139 col = 0;
140 row = 0;
141#endif
142
143 display_options_get_banner(false, buf, sizeof(buf));
144 vidconsole_position_cursor(dev, col, 1);
145 vidconsole_put_string(dev, buf);
146 vidconsole_position_cursor(dev, 0, row);
147}
Anatolij Gustschind2a82712019-09-20 17:23:41 +0200148#endif /* CONFIG_DM_VIDEO && !CONFIG_HIDE_LOGO_VERSION */
149
Igor Opaniuk5eb83c02019-05-29 09:01:43 +0000150/*
151 * Common function to show a splash image if env("splashimage") is set.
152 * Is used for both dm_video and lcd video stacks. For additional
153 * details please refer to doc/README.splashprepare.
154 */
155#if defined(CONFIG_SPLASH_SCREEN) && defined(CONFIG_CMD_BMP)
156int splash_display(void)
Nikita Kiryanov7bf71d12015-02-03 13:32:32 +0200157{
Igor Opaniuk5eb83c02019-05-29 09:01:43 +0000158 ulong addr;
159 char *s;
Nikita Kiryanov7bf71d12015-02-03 13:32:32 +0200160 int x = 0, y = 0, ret;
161
Igor Opaniuk5eb83c02019-05-29 09:01:43 +0000162 s = env_get("splashimage");
163 if (!s)
164 return -EINVAL;
165
Simon Glass7e5f4602021-07-24 09:03:29 -0600166 addr = hextoul(s, NULL);
Nikita Kiryanov7bf71d12015-02-03 13:32:32 +0200167 ret = splash_screen_prepare();
168 if (ret)
169 return ret;
170
171 splash_get_pos(&x, &y);
172
Anatolij Gustschind2a82712019-09-20 17:23:41 +0200173 ret = bmp_display(addr, x, y);
174
175 /* Skip banner output on video console if the logo is not at 0,0 */
176 if (x || y)
177 goto end;
178
Anatolij Gustschin2ad84942019-10-30 15:04:10 +0100179#if defined(CONFIG_DM_VIDEO) && !defined(CONFIG_HIDE_LOGO_VERSION)
Anatolij Gustschind2a82712019-09-20 17:23:41 +0200180 splash_display_banner();
Anatolij Gustschin2ad84942019-10-30 15:04:10 +0100181#endif
Anatolij Gustschind2a82712019-09-20 17:23:41 +0200182end:
183 return ret;
Nikita Kiryanov7bf71d12015-02-03 13:32:32 +0200184}
185#endif