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 <bmp_layout.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 #ifdef CONFIG_CMD_NAND
18 static int splash_nand_read(u32 bmp_load_addr, int offset, size_t read_size)
20 return nand_read_skip_bad(&nand_info[nand_curr_device], offset,
22 nand_info[nand_curr_device].size,
23 (u_char *)bmp_load_addr);
26 static int splash_nand_read(u32 bmp_load_addr, int offset, size_t read_size)
28 debug("%s: nand support not available\n", __func__);
33 static int splash_storage_read(struct splash_location *location,
34 u32 bmp_load_addr, size_t read_size)
41 offset = location->offset;
42 switch (location->storage) {
43 case SPLASH_STORAGE_NAND:
44 return splash_nand_read(bmp_load_addr, offset, read_size);
46 printf("Unknown splash location\n");
52 static int splash_load_raw(struct splash_location *location, u32 bmp_load_addr)
54 struct bmp_header *bmp_hdr;
56 size_t bmp_size, bmp_header_size = sizeof(struct bmp_header);
58 if (bmp_load_addr + bmp_header_size >= gd->start_addr_sp)
59 goto splash_address_too_high;
61 res = splash_storage_read(location, bmp_load_addr, bmp_header_size);
65 bmp_hdr = (struct bmp_header *)bmp_load_addr;
66 bmp_size = le32_to_cpu(bmp_hdr->file_size);
68 if (bmp_load_addr + bmp_size >= gd->start_addr_sp)
69 goto splash_address_too_high;
71 return splash_storage_read(location, bmp_load_addr, bmp_size);
73 splash_address_too_high:
74 printf("Error: splashimage address too high. Data overwrites U-Boot "
75 "and/or placed beyond DRAM boundaries.\n");
81 * select_splash_location - return the splash location based on board support
82 * and env variable "splashsource".
84 * @locations: An array of supported splash locations.
85 * @size: Size of splash_locations array.
87 * @return: If a null set of splash locations is given, or
88 * splashsource env variable is set to unsupported value
90 * If splashsource env variable is not defined
91 * return the first entry in splash_locations as default.
92 * If splashsource env variable contains a supported value
93 * return the location selected by splashsource.
95 static struct splash_location *select_splash_location(
96 struct splash_location *locations, uint size)
99 char *env_splashsource;
101 if (!locations || size == 0)
104 env_splashsource = getenv("splashsource");
105 if (env_splashsource == NULL)
106 return &locations[0];
108 for (i = 0; i < size; i++) {
109 if (!strcmp(locations[i].name, env_splashsource))
110 return &locations[i];
113 printf("splashsource env variable set to unsupported value\n");
117 int cl_splash_screen_prepare(struct splash_location *locations, uint size)
119 struct splash_location *splash_location;
120 char *env_splashimage_value;
123 env_splashimage_value = getenv("splashimage");
124 if (env_splashimage_value == NULL)
127 bmp_load_addr = simple_strtoul(env_splashimage_value, 0, 16);
128 if (bmp_load_addr == 0) {
129 printf("Error: bad splashimage address specified\n");
133 splash_location = select_splash_location(locations, size);
134 if (!splash_location)
137 return splash_load_raw(splash_location, bmp_load_addr);