Commit f82eb2fa5df86b7180ea355a3cb98482f7c27269
Committed by
Stefano Babic
1 parent
3a236a3563
Exists in
v2017.01-smarct4x
and in
37 other branches
common: convert compulab splash load code to common code
Move board/compulab/common/splash.c code to common/splash_source.c to make it available for everybody. This move renames cl_splash_screen_prepare() to splash_source_load(), and the compilation of this code is conditional on CONFIG_SPLASH_SOURCE. splash_source features: * Provide a standardized way for declaring board specific splash screen locations * Provide existing routines for auto loading the splash image from the locations as declared by the board * Introduce the "splashsource" environment variable, which makes it possible to select the splash image source. cm-t35 and cm-fx6 are updated to use the modified version. Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il> Cc: Stefano Babic <sbabic@denx.de> Cc: Tom Rini <trini@ti.com> Cc: Igor Grinberg <grinberg@compulab.co.il> Cc: Anatolij Gustschin <agust@denx.de> Reviewed-by: Tom Rini <trini@ti.com> Acked-by: Igor Grinberg <grinberg@compulab.co.il>
Showing 11 changed files with 209 additions and 191 deletions Side-by-side Diff
board/compulab/cm_fx6/cm_fx6.c
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | #include <netdev.h> |
16 | 16 | #include <fdt_support.h> |
17 | 17 | #include <sata.h> |
18 | +#include <splash.h> | |
18 | 19 | #include <asm/arch/crm_regs.h> |
19 | 20 | #include <asm/arch/sys_proto.h> |
20 | 21 | #include <asm/arch/iomux.h> |
... | ... | @@ -42,8 +43,8 @@ |
42 | 43 | |
43 | 44 | int splash_screen_prepare(void) |
44 | 45 | { |
45 | - return cl_splash_screen_prepare(cm_fx6_splash_locations, | |
46 | - ARRAY_SIZE(cm_fx6_splash_locations)); | |
46 | + return splash_source_load(cm_fx6_splash_locations, | |
47 | + ARRAY_SIZE(cm_fx6_splash_locations)); | |
47 | 48 | } |
48 | 49 | #endif |
49 | 50 |
board/compulab/cm_t35/cm_t35.c
... | ... | @@ -19,6 +19,7 @@ |
19 | 19 | #include <i2c.h> |
20 | 20 | #include <usb.h> |
21 | 21 | #include <mmc.h> |
22 | +#include <splash.h> | |
22 | 23 | #include <twl4030.h> |
23 | 24 | #include <linux/compiler.h> |
24 | 25 | |
... | ... | @@ -69,8 +70,8 @@ |
69 | 70 | |
70 | 71 | int splash_screen_prepare(void) |
71 | 72 | { |
72 | - return cl_splash_screen_prepare(splash_locations, | |
73 | - ARRAY_SIZE(splash_locations)); | |
73 | + return splash_source_load(splash_locations, | |
74 | + ARRAY_SIZE(splash_locations)); | |
74 | 75 | } |
75 | 76 | |
76 | 77 | /* |
board/compulab/common/Makefile
board/compulab/common/common.h
... | ... | @@ -24,27 +24,6 @@ |
24 | 24 | static inline void cl_usb_hub_deinit(int gpio) {} |
25 | 25 | #endif /* CONFIG_CMD_USB */ |
26 | 26 | |
27 | -enum splash_storage { | |
28 | - SPLASH_STORAGE_NAND, | |
29 | - SPLASH_STORAGE_SF, | |
30 | -}; | |
31 | - | |
32 | -struct splash_location { | |
33 | - char *name; | |
34 | - enum splash_storage storage; | |
35 | - u32 offset; /* offset from start of storage */ | |
36 | -}; | |
37 | - | |
38 | -#ifdef CONFIG_SPLASH_SCREEN | |
39 | -int cl_splash_screen_prepare(struct splash_location *locations, uint size); | |
40 | -#else /* !CONFIG_SPLASH_SCREEN */ | |
41 | -static inline int cl_splash_screen_prepare(struct splash_location *locations, | |
42 | - uint size) | |
43 | -{ | |
44 | - return -ENOSYS; | |
45 | -} | |
46 | -#endif /* CONFIG_SPLASH_SCREEN */ | |
47 | - | |
48 | 27 | #ifdef CONFIG_SMC911X |
49 | 28 | int cl_omap3_smc911x_init(int id, int cs, u32 base_addr, |
50 | 29 | int (*reset)(int), int rst_gpio); |
board/compulab/common/splash.c
1 | -/* | |
2 | - * (C) Copyright 2014 CompuLab, Ltd. <www.compulab.co.il> | |
3 | - * | |
4 | - * Authors: Igor Grinberg <grinberg@compulab.co.il> | |
5 | - * | |
6 | - * SPDX-License-Identifier: GPL-2.0+ | |
7 | - */ | |
8 | - | |
9 | -#include <common.h> | |
10 | -#include <nand.h> | |
11 | -#include <errno.h> | |
12 | -#include <spi_flash.h> | |
13 | -#include <spi.h> | |
14 | -#include <bmp_layout.h> | |
15 | -#include "common.h" | |
16 | - | |
17 | -DECLARE_GLOBAL_DATA_PTR; | |
18 | - | |
19 | -#ifdef CONFIG_SPI_FLASH | |
20 | -static struct spi_flash *sf; | |
21 | -static int splash_sf_read(u32 bmp_load_addr, int offset, size_t read_size) | |
22 | -{ | |
23 | - if (!sf) { | |
24 | - sf = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, | |
25 | - CONFIG_SF_DEFAULT_CS, | |
26 | - CONFIG_SF_DEFAULT_SPEED, | |
27 | - CONFIG_SF_DEFAULT_MODE); | |
28 | - if (!sf) | |
29 | - return -ENODEV; | |
30 | - } | |
31 | - | |
32 | - return spi_flash_read(sf, offset, read_size, (void *)bmp_load_addr); | |
33 | -} | |
34 | -#else | |
35 | -static int splash_sf_read(u32 bmp_load_addr, int offset, size_t read_size) | |
36 | -{ | |
37 | - debug("%s: sf support not available\n", __func__); | |
38 | - return -ENOSYS; | |
39 | -} | |
40 | -#endif | |
41 | - | |
42 | -#ifdef CONFIG_CMD_NAND | |
43 | -static int splash_nand_read(u32 bmp_load_addr, int offset, size_t read_size) | |
44 | -{ | |
45 | - return nand_read_skip_bad(&nand_info[nand_curr_device], offset, | |
46 | - &read_size, NULL, | |
47 | - nand_info[nand_curr_device].size, | |
48 | - (u_char *)bmp_load_addr); | |
49 | -} | |
50 | -#else | |
51 | -static int splash_nand_read(u32 bmp_load_addr, int offset, size_t read_size) | |
52 | -{ | |
53 | - debug("%s: nand support not available\n", __func__); | |
54 | - return -ENOSYS; | |
55 | -} | |
56 | -#endif | |
57 | - | |
58 | -static int splash_storage_read(struct splash_location *location, | |
59 | - u32 bmp_load_addr, size_t read_size) | |
60 | -{ | |
61 | - u32 offset; | |
62 | - | |
63 | - if (!location) | |
64 | - return -EINVAL; | |
65 | - | |
66 | - offset = location->offset; | |
67 | - switch (location->storage) { | |
68 | - case SPLASH_STORAGE_NAND: | |
69 | - return splash_nand_read(bmp_load_addr, offset, read_size); | |
70 | - case SPLASH_STORAGE_SF: | |
71 | - return splash_sf_read(bmp_load_addr, offset, read_size); | |
72 | - default: | |
73 | - printf("Unknown splash location\n"); | |
74 | - } | |
75 | - | |
76 | - return -EINVAL; | |
77 | -} | |
78 | - | |
79 | -static int splash_load_raw(struct splash_location *location, u32 bmp_load_addr) | |
80 | -{ | |
81 | - struct bmp_header *bmp_hdr; | |
82 | - int res; | |
83 | - size_t bmp_size, bmp_header_size = sizeof(struct bmp_header); | |
84 | - | |
85 | - if (bmp_load_addr + bmp_header_size >= gd->start_addr_sp) | |
86 | - goto splash_address_too_high; | |
87 | - | |
88 | - res = splash_storage_read(location, bmp_load_addr, bmp_header_size); | |
89 | - if (res < 0) | |
90 | - return res; | |
91 | - | |
92 | - bmp_hdr = (struct bmp_header *)bmp_load_addr; | |
93 | - bmp_size = le32_to_cpu(bmp_hdr->file_size); | |
94 | - | |
95 | - if (bmp_load_addr + bmp_size >= gd->start_addr_sp) | |
96 | - goto splash_address_too_high; | |
97 | - | |
98 | - return splash_storage_read(location, bmp_load_addr, bmp_size); | |
99 | - | |
100 | -splash_address_too_high: | |
101 | - printf("Error: splashimage address too high. Data overwrites U-Boot " | |
102 | - "and/or placed beyond DRAM boundaries.\n"); | |
103 | - | |
104 | - return -EFAULT; | |
105 | -} | |
106 | - | |
107 | -/** | |
108 | - * select_splash_location - return the splash location based on board support | |
109 | - * and env variable "splashsource". | |
110 | - * | |
111 | - * @locations: An array of supported splash locations. | |
112 | - * @size: Size of splash_locations array. | |
113 | - * | |
114 | - * @return: If a null set of splash locations is given, or | |
115 | - * splashsource env variable is set to unsupported value | |
116 | - * return NULL. | |
117 | - * If splashsource env variable is not defined | |
118 | - * return the first entry in splash_locations as default. | |
119 | - * If splashsource env variable contains a supported value | |
120 | - * return the location selected by splashsource. | |
121 | - */ | |
122 | -static struct splash_location *select_splash_location( | |
123 | - struct splash_location *locations, uint size) | |
124 | -{ | |
125 | - int i; | |
126 | - char *env_splashsource; | |
127 | - | |
128 | - if (!locations || size == 0) | |
129 | - return NULL; | |
130 | - | |
131 | - env_splashsource = getenv("splashsource"); | |
132 | - if (env_splashsource == NULL) | |
133 | - return &locations[0]; | |
134 | - | |
135 | - for (i = 0; i < size; i++) { | |
136 | - if (!strcmp(locations[i].name, env_splashsource)) | |
137 | - return &locations[i]; | |
138 | - } | |
139 | - | |
140 | - printf("splashsource env variable set to unsupported value\n"); | |
141 | - return NULL; | |
142 | -} | |
143 | - | |
144 | -int cl_splash_screen_prepare(struct splash_location *locations, uint size) | |
145 | -{ | |
146 | - struct splash_location *splash_location; | |
147 | - char *env_splashimage_value; | |
148 | - u32 bmp_load_addr; | |
149 | - | |
150 | - env_splashimage_value = getenv("splashimage"); | |
151 | - if (env_splashimage_value == NULL) | |
152 | - return -ENOENT; | |
153 | - | |
154 | - bmp_load_addr = simple_strtoul(env_splashimage_value, 0, 16); | |
155 | - if (bmp_load_addr == 0) { | |
156 | - printf("Error: bad splashimage address specified\n"); | |
157 | - return -EFAULT; | |
158 | - } | |
159 | - | |
160 | - splash_location = select_splash_location(locations, size); | |
161 | - if (!splash_location) | |
162 | - return -EINVAL; | |
163 | - | |
164 | - return splash_load_raw(splash_location, bmp_load_addr); | |
165 | -} |
common/Makefile
... | ... | @@ -196,6 +196,7 @@ |
196 | 196 | obj-$(CONFIG_I2C_EDID) += edid.o |
197 | 197 | obj-$(CONFIG_KALLSYMS) += kallsyms.o |
198 | 198 | obj-y += splash.o |
199 | +obj-$(CONFIG_SPLASH_SOURCE) += splash_source.o | |
199 | 200 | obj-$(CONFIG_LCD) += lcd.o lcd_console.o |
200 | 201 | obj-$(CONFIG_LYNXKDI) += lynxkdi.o |
201 | 202 | obj-$(CONFIG_MENU) += menu.o |
common/splash_source.c
1 | +/* | |
2 | + * (C) Copyright 2014 CompuLab, Ltd. <www.compulab.co.il> | |
3 | + * | |
4 | + * Authors: Igor Grinberg <grinberg@compulab.co.il> | |
5 | + * | |
6 | + * SPDX-License-Identifier: GPL-2.0+ | |
7 | + */ | |
8 | + | |
9 | +#include <common.h> | |
10 | +#include <nand.h> | |
11 | +#include <errno.h> | |
12 | +#include <splash.h> | |
13 | +#include <spi_flash.h> | |
14 | +#include <spi.h> | |
15 | +#include <bmp_layout.h> | |
16 | + | |
17 | +DECLARE_GLOBAL_DATA_PTR; | |
18 | + | |
19 | +#ifdef CONFIG_SPI_FLASH | |
20 | +static struct spi_flash *sf; | |
21 | +static int splash_sf_read(u32 bmp_load_addr, int offset, size_t read_size) | |
22 | +{ | |
23 | + if (!sf) { | |
24 | + sf = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, | |
25 | + CONFIG_SF_DEFAULT_CS, | |
26 | + CONFIG_SF_DEFAULT_SPEED, | |
27 | + CONFIG_SF_DEFAULT_MODE); | |
28 | + if (!sf) | |
29 | + return -ENODEV; | |
30 | + } | |
31 | + | |
32 | + return spi_flash_read(sf, offset, read_size, (void *)bmp_load_addr); | |
33 | +} | |
34 | +#else | |
35 | +static int splash_sf_read(u32 bmp_load_addr, int offset, size_t read_size) | |
36 | +{ | |
37 | + debug("%s: sf support not available\n", __func__); | |
38 | + return -ENOSYS; | |
39 | +} | |
40 | +#endif | |
41 | + | |
42 | +#ifdef CONFIG_CMD_NAND | |
43 | +static int splash_nand_read(u32 bmp_load_addr, int offset, size_t read_size) | |
44 | +{ | |
45 | + return nand_read_skip_bad(&nand_info[nand_curr_device], offset, | |
46 | + &read_size, NULL, | |
47 | + nand_info[nand_curr_device].size, | |
48 | + (u_char *)bmp_load_addr); | |
49 | +} | |
50 | +#else | |
51 | +static int splash_nand_read(u32 bmp_load_addr, int offset, size_t read_size) | |
52 | +{ | |
53 | + debug("%s: nand support not available\n", __func__); | |
54 | + return -ENOSYS; | |
55 | +} | |
56 | +#endif | |
57 | + | |
58 | +static int splash_storage_read(struct splash_location *location, | |
59 | + u32 bmp_load_addr, size_t read_size) | |
60 | +{ | |
61 | + u32 offset; | |
62 | + | |
63 | + if (!location) | |
64 | + return -EINVAL; | |
65 | + | |
66 | + offset = location->offset; | |
67 | + switch (location->storage) { | |
68 | + case SPLASH_STORAGE_NAND: | |
69 | + return splash_nand_read(bmp_load_addr, offset, read_size); | |
70 | + case SPLASH_STORAGE_SF: | |
71 | + return splash_sf_read(bmp_load_addr, offset, read_size); | |
72 | + default: | |
73 | + printf("Unknown splash location\n"); | |
74 | + } | |
75 | + | |
76 | + return -EINVAL; | |
77 | +} | |
78 | + | |
79 | +static int splash_load_raw(struct splash_location *location, u32 bmp_load_addr) | |
80 | +{ | |
81 | + struct bmp_header *bmp_hdr; | |
82 | + int res; | |
83 | + size_t bmp_size, bmp_header_size = sizeof(struct bmp_header); | |
84 | + | |
85 | + if (bmp_load_addr + bmp_header_size >= gd->start_addr_sp) | |
86 | + goto splash_address_too_high; | |
87 | + | |
88 | + res = splash_storage_read(location, bmp_load_addr, bmp_header_size); | |
89 | + if (res < 0) | |
90 | + return res; | |
91 | + | |
92 | + bmp_hdr = (struct bmp_header *)bmp_load_addr; | |
93 | + bmp_size = le32_to_cpu(bmp_hdr->file_size); | |
94 | + | |
95 | + if (bmp_load_addr + bmp_size >= gd->start_addr_sp) | |
96 | + goto splash_address_too_high; | |
97 | + | |
98 | + return splash_storage_read(location, bmp_load_addr, bmp_size); | |
99 | + | |
100 | +splash_address_too_high: | |
101 | + printf("Error: splashimage address too high. Data overwrites U-Boot and/or placed beyond DRAM boundaries.\n"); | |
102 | + | |
103 | + return -EFAULT; | |
104 | +} | |
105 | + | |
106 | +/** | |
107 | + * select_splash_location - return the splash location based on board support | |
108 | + * and env variable "splashsource". | |
109 | + * | |
110 | + * @locations: An array of supported splash locations. | |
111 | + * @size: Size of splash_locations array. | |
112 | + * | |
113 | + * @return: If a null set of splash locations is given, or | |
114 | + * splashsource env variable is set to unsupported value | |
115 | + * return NULL. | |
116 | + * If splashsource env variable is not defined | |
117 | + * return the first entry in splash_locations as default. | |
118 | + * If splashsource env variable contains a supported value | |
119 | + * return the location selected by splashsource. | |
120 | + */ | |
121 | +static struct splash_location *select_splash_location( | |
122 | + struct splash_location *locations, uint size) | |
123 | +{ | |
124 | + int i; | |
125 | + char *env_splashsource; | |
126 | + | |
127 | + if (!locations || size == 0) | |
128 | + return NULL; | |
129 | + | |
130 | + env_splashsource = getenv("splashsource"); | |
131 | + if (env_splashsource == NULL) | |
132 | + return &locations[0]; | |
133 | + | |
134 | + for (i = 0; i < size; i++) { | |
135 | + if (!strcmp(locations[i].name, env_splashsource)) | |
136 | + return &locations[i]; | |
137 | + } | |
138 | + | |
139 | + printf("splashsource env variable set to unsupported value\n"); | |
140 | + return NULL; | |
141 | +} | |
142 | + | |
143 | +/** | |
144 | + * splash_source_load - load splash image from a supported location. | |
145 | + * | |
146 | + * Select a splash image location based on the value of splashsource environment | |
147 | + * variable and the board supported splash source locations, and load a | |
148 | + * splashimage to the address pointed to by splashimage environment variable. | |
149 | + * | |
150 | + * @locations: An array of supported splash locations. | |
151 | + * @size: Size of splash_locations array. | |
152 | + * | |
153 | + * @return: 0 on success, negative value on failure. | |
154 | + */ | |
155 | +int splash_source_load(struct splash_location *locations, uint size) | |
156 | +{ | |
157 | + struct splash_location *splash_location; | |
158 | + char *env_splashimage_value; | |
159 | + u32 bmp_load_addr; | |
160 | + | |
161 | + env_splashimage_value = getenv("splashimage"); | |
162 | + if (env_splashimage_value == NULL) | |
163 | + return -ENOENT; | |
164 | + | |
165 | + bmp_load_addr = simple_strtoul(env_splashimage_value, 0, 16); | |
166 | + if (bmp_load_addr == 0) { | |
167 | + printf("Error: bad splashimage address specified\n"); | |
168 | + return -EFAULT; | |
169 | + } | |
170 | + | |
171 | + splash_location = select_splash_location(locations, size); | |
172 | + if (!splash_location) | |
173 | + return -EINVAL; | |
174 | + | |
175 | + return splash_load_raw(splash_location, bmp_load_addr); | |
176 | +} |
doc/README.splashprepare
... | ... | @@ -6,4 +6,17 @@ |
6 | 6 | sequence. It gives the board an opportunity to prepare the splash |
7 | 7 | image data before it is processed and sent to the frame buffer by |
8 | 8 | U-Boot. Define your own version to use this feature. |
9 | + | |
10 | +CONFIG_SPLASH_SOURCE | |
11 | + | |
12 | +Use the splash_source.c library. This library provides facilities to declare | |
13 | +board specific splash image locations, routines for loading splash image from | |
14 | +supported locations, and a way of controlling the selected splash location | |
15 | +using the "splashsource" environment variable. | |
16 | + | |
17 | +splashsource works as follows: | |
18 | +- If splashsource is set to a supported location name as defined by board code, | |
19 | + use that splash location. | |
20 | +- If splashsource is undefined, use the first splash location as default. | |
21 | +- If splashsource is set to an unsupported value, do not load a splash screen. |
include/configs/cm_fx6.h
include/configs/cm_t35.h
include/splash.h
... | ... | @@ -22,7 +22,18 @@ |
22 | 22 | #ifndef _SPLASH_H_ |
23 | 23 | #define _SPLASH_H_ |
24 | 24 | |
25 | +enum splash_storage { | |
26 | + SPLASH_STORAGE_NAND, | |
27 | + SPLASH_STORAGE_SF, | |
28 | +}; | |
25 | 29 | |
30 | +struct splash_location { | |
31 | + char *name; | |
32 | + enum splash_storage storage; | |
33 | + u32 offset; /* offset from start of storage */ | |
34 | +}; | |
35 | + | |
36 | +int splash_source_load(struct splash_location *locations, uint size); | |
26 | 37 | int splash_screen_prepare(void); |
27 | 38 | |
28 | 39 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN |