2 * (C) Copyright 2014 CompuLab, Ltd. <www.compulab.co.il>
4 * Authors: Igor Grinberg <grinberg@compulab.co.il>
6 * SPDX-License-Identifier: GPL-2.0+
12 #include <spi_flash.h>
14 #include <bmp_layout.h>
17 DECLARE_GLOBAL_DATA_PTR;
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)
24 sf = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
26 CONFIG_SF_DEFAULT_SPEED,
27 CONFIG_SF_DEFAULT_MODE);
32 return spi_flash_read(sf, offset, read_size, (void *)bmp_load_addr);
35 static int splash_sf_read(u32 bmp_load_addr, int offset, size_t read_size)
37 debug("%s: sf support not available\n", __func__);
42 #ifdef CONFIG_CMD_NAND
43 static int splash_nand_read(u32 bmp_load_addr, int offset, size_t read_size)
45 return nand_read_skip_bad(&nand_info[nand_curr_device], offset,
47 nand_info[nand_curr_device].size,
48 (u_char *)bmp_load_addr);
51 static int splash_nand_read(u32 bmp_load_addr, int offset, size_t read_size)
53 debug("%s: nand support not available\n", __func__);
58 static int splash_storage_read(struct splash_location *location,
59 u32 bmp_load_addr, size_t read_size)
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);
73 printf("Unknown splash location\n");
79 static int splash_load_raw(struct splash_location *location, u32 bmp_load_addr)
81 struct bmp_header *bmp_hdr;
83 size_t bmp_size, bmp_header_size = sizeof(struct bmp_header);
85 if (bmp_load_addr + bmp_header_size >= gd->start_addr_sp)
86 goto splash_address_too_high;
88 res = splash_storage_read(location, bmp_load_addr, bmp_header_size);
92 bmp_hdr = (struct bmp_header *)bmp_load_addr;
93 bmp_size = le32_to_cpu(bmp_hdr->file_size);
95 if (bmp_load_addr + bmp_size >= gd->start_addr_sp)
96 goto splash_address_too_high;
98 return splash_storage_read(location, bmp_load_addr, bmp_size);
100 splash_address_too_high:
101 printf("Error: splashimage address too high. Data overwrites U-Boot "
102 "and/or placed beyond DRAM boundaries.\n");
108 * select_splash_location - return the splash location based on board support
109 * and env variable "splashsource".
111 * @locations: An array of supported splash locations.
112 * @size: Size of splash_locations array.
114 * @return: If a null set of splash locations is given, or
115 * splashsource env variable is set to unsupported value
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.
122 static struct splash_location *select_splash_location(
123 struct splash_location *locations, uint size)
126 char *env_splashsource;
128 if (!locations || size == 0)
131 env_splashsource = getenv("splashsource");
132 if (env_splashsource == NULL)
133 return &locations[0];
135 for (i = 0; i < size; i++) {
136 if (!strcmp(locations[i].name, env_splashsource))
137 return &locations[i];
140 printf("splashsource env variable set to unsupported value\n");
144 int cl_splash_screen_prepare(struct splash_location *locations, uint size)
146 struct splash_location *splash_location;
147 char *env_splashimage_value;
150 env_splashimage_value = getenv("splashimage");
151 if (env_splashimage_value == NULL)
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");
160 splash_location = select_splash_location(locations, size);
161 if (!splash_location)
164 return splash_load_raw(splash_location, bmp_load_addr);