Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 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> |
tomas.melin@vaisala.com | 0a7c732 | 2017-01-13 13:20:13 +0200 | [diff] [blame] | 10 | #include <bmp_layout.h> |
Nikita Kiryanov | f58c509 | 2015-01-14 10:42:49 +0200 | [diff] [blame] | 11 | #include <errno.h> |
tomas.melin@vaisala.com | 0a7c732 | 2017-01-13 13:20:13 +0200 | [diff] [blame] | 12 | #include <fs.h> |
tomas.melin@vaisala.com | 45ee790 | 2017-01-13 13:20:14 +0200 | [diff] [blame] | 13 | #include <fdt_support.h> |
tomas.melin@vaisala.com | 0a7c732 | 2017-01-13 13:20:13 +0200 | [diff] [blame] | 14 | #include <image.h> |
| 15 | #include <nand.h> |
| 16 | #include <sata.h> |
Nikita Kiryanov | 1ab4c76 | 2015-01-14 10:42:52 +0200 | [diff] [blame] | 17 | #include <spi.h> |
tomas.melin@vaisala.com | 0a7c732 | 2017-01-13 13:20:13 +0200 | [diff] [blame] | 18 | #include <spi_flash.h> |
| 19 | #include <splash.h> |
Nikita Kiryanov | bf5c3cc | 2015-10-29 11:54:42 +0200 | [diff] [blame] | 20 | #include <usb.h> |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Nikita Kiryanov | 1ab4c76 | 2015-01-14 10:42:52 +0200 | [diff] [blame] | 24 | #ifdef CONFIG_SPI_FLASH |
| 25 | static struct spi_flash *sf; |
Nikita Kiryanov | b8183de | 2015-10-29 11:54:40 +0200 | [diff] [blame] | 26 | static int splash_sf_read_raw(u32 bmp_load_addr, int offset, size_t read_size) |
Nikita Kiryanov | 1ab4c76 | 2015-01-14 10:42:52 +0200 | [diff] [blame] | 27 | { |
| 28 | if (!sf) { |
| 29 | sf = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, |
| 30 | CONFIG_SF_DEFAULT_CS, |
| 31 | CONFIG_SF_DEFAULT_SPEED, |
| 32 | CONFIG_SF_DEFAULT_MODE); |
| 33 | if (!sf) |
| 34 | return -ENODEV; |
| 35 | } |
| 36 | |
| 37 | return spi_flash_read(sf, offset, read_size, (void *)bmp_load_addr); |
| 38 | } |
| 39 | #else |
Nikita Kiryanov | b8183de | 2015-10-29 11:54:40 +0200 | [diff] [blame] | 40 | static int splash_sf_read_raw(u32 bmp_load_addr, int offset, size_t read_size) |
Nikita Kiryanov | 1ab4c76 | 2015-01-14 10:42:52 +0200 | [diff] [blame] | 41 | { |
| 42 | debug("%s: sf support not available\n", __func__); |
| 43 | return -ENOSYS; |
| 44 | } |
| 45 | #endif |
| 46 | |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 47 | #ifdef CONFIG_CMD_NAND |
Nikita Kiryanov | b8183de | 2015-10-29 11:54:40 +0200 | [diff] [blame] | 48 | static int splash_nand_read_raw(u32 bmp_load_addr, int offset, size_t read_size) |
Nikita Kiryanov | 4b4bfd6 | 2015-01-14 10:42:50 +0200 | [diff] [blame] | 49 | { |
Grygorii Strashko | 5f33b82 | 2017-06-26 19:12:56 -0500 | [diff] [blame] | 50 | struct mtd_info *mtd = get_nand_dev_by_index(nand_curr_device); |
| 51 | return nand_read_skip_bad(mtd, offset, |
Nikita Kiryanov | 4b4bfd6 | 2015-01-14 10:42:50 +0200 | [diff] [blame] | 52 | &read_size, NULL, |
Grygorii Strashko | 5f33b82 | 2017-06-26 19:12:56 -0500 | [diff] [blame] | 53 | mtd->size, |
Nikita Kiryanov | 4b4bfd6 | 2015-01-14 10:42:50 +0200 | [diff] [blame] | 54 | (u_char *)bmp_load_addr); |
| 55 | } |
| 56 | #else |
Nikita Kiryanov | b8183de | 2015-10-29 11:54:40 +0200 | [diff] [blame] | 57 | static int splash_nand_read_raw(u32 bmp_load_addr, int offset, size_t read_size) |
Nikita Kiryanov | 4b4bfd6 | 2015-01-14 10:42:50 +0200 | [diff] [blame] | 58 | { |
| 59 | debug("%s: nand support not available\n", __func__); |
| 60 | return -ENOSYS; |
| 61 | } |
| 62 | #endif |
| 63 | |
Nikita Kiryanov | b8183de | 2015-10-29 11:54:40 +0200 | [diff] [blame] | 64 | static int splash_storage_read_raw(struct splash_location *location, |
Nikita Kiryanov | c2a07e3 | 2015-01-14 10:42:51 +0200 | [diff] [blame] | 65 | u32 bmp_load_addr, size_t read_size) |
Nikita Kiryanov | 4b4bfd6 | 2015-01-14 10:42:50 +0200 | [diff] [blame] | 66 | { |
Nikita Kiryanov | c2a07e3 | 2015-01-14 10:42:51 +0200 | [diff] [blame] | 67 | u32 offset; |
| 68 | |
| 69 | if (!location) |
| 70 | return -EINVAL; |
| 71 | |
| 72 | offset = location->offset; |
| 73 | switch (location->storage) { |
| 74 | case SPLASH_STORAGE_NAND: |
Nikita Kiryanov | b8183de | 2015-10-29 11:54:40 +0200 | [diff] [blame] | 75 | return splash_nand_read_raw(bmp_load_addr, offset, read_size); |
Nikita Kiryanov | 1ab4c76 | 2015-01-14 10:42:52 +0200 | [diff] [blame] | 76 | case SPLASH_STORAGE_SF: |
Nikita Kiryanov | b8183de | 2015-10-29 11:54:40 +0200 | [diff] [blame] | 77 | return splash_sf_read_raw(bmp_load_addr, offset, read_size); |
Nikita Kiryanov | c2a07e3 | 2015-01-14 10:42:51 +0200 | [diff] [blame] | 78 | default: |
| 79 | printf("Unknown splash location\n"); |
| 80 | } |
| 81 | |
| 82 | return -EINVAL; |
Nikita Kiryanov | 4b4bfd6 | 2015-01-14 10:42:50 +0200 | [diff] [blame] | 83 | } |
| 84 | |
Nikita Kiryanov | c2a07e3 | 2015-01-14 10:42:51 +0200 | [diff] [blame] | 85 | static int splash_load_raw(struct splash_location *location, u32 bmp_load_addr) |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 86 | { |
| 87 | struct bmp_header *bmp_hdr; |
| 88 | int res; |
| 89 | size_t bmp_size, bmp_header_size = sizeof(struct bmp_header); |
| 90 | |
| 91 | if (bmp_load_addr + bmp_header_size >= gd->start_addr_sp) |
| 92 | goto splash_address_too_high; |
| 93 | |
Nikita Kiryanov | b8183de | 2015-10-29 11:54:40 +0200 | [diff] [blame] | 94 | res = splash_storage_read_raw(location, bmp_load_addr, bmp_header_size); |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 95 | if (res < 0) |
| 96 | return res; |
| 97 | |
| 98 | bmp_hdr = (struct bmp_header *)bmp_load_addr; |
| 99 | bmp_size = le32_to_cpu(bmp_hdr->file_size); |
| 100 | |
| 101 | if (bmp_load_addr + bmp_size >= gd->start_addr_sp) |
| 102 | goto splash_address_too_high; |
| 103 | |
Nikita Kiryanov | b8183de | 2015-10-29 11:54:40 +0200 | [diff] [blame] | 104 | return splash_storage_read_raw(location, bmp_load_addr, bmp_size); |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 105 | |
| 106 | splash_address_too_high: |
Nikita Kiryanov | 7f9ceea | 2015-01-14 10:42:54 +0200 | [diff] [blame] | 107 | printf("Error: splashimage address too high. Data overwrites U-Boot and/or placed beyond DRAM boundaries.\n"); |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 108 | |
Nikita Kiryanov | f58c509 | 2015-01-14 10:42:49 +0200 | [diff] [blame] | 109 | return -EFAULT; |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 110 | } |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 111 | |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 112 | static int splash_select_fs_dev(struct splash_location *location) |
| 113 | { |
| 114 | int res; |
| 115 | |
| 116 | switch (location->storage) { |
| 117 | case SPLASH_STORAGE_MMC: |
| 118 | res = fs_set_blk_dev("mmc", location->devpart, FS_TYPE_ANY); |
| 119 | break; |
Nikita Kiryanov | bf5c3cc | 2015-10-29 11:54:42 +0200 | [diff] [blame] | 120 | case SPLASH_STORAGE_USB: |
| 121 | res = fs_set_blk_dev("usb", location->devpart, FS_TYPE_ANY); |
| 122 | break; |
Nikita Kiryanov | 80ca30d | 2015-10-29 11:54:43 +0200 | [diff] [blame] | 123 | case SPLASH_STORAGE_SATA: |
| 124 | res = fs_set_blk_dev("sata", location->devpart, FS_TYPE_ANY); |
| 125 | break; |
Eran Matityahu | 07a04a1 | 2016-06-07 10:38:37 +0300 | [diff] [blame] | 126 | case SPLASH_STORAGE_NAND: |
| 127 | if (location->ubivol != NULL) |
| 128 | res = fs_set_blk_dev("ubi", NULL, FS_TYPE_UBIFS); |
| 129 | else |
| 130 | res = -ENODEV; |
| 131 | break; |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 132 | default: |
| 133 | printf("Error: unsupported location storage.\n"); |
| 134 | return -ENODEV; |
| 135 | } |
| 136 | |
| 137 | if (res) |
| 138 | printf("Error: could not access storage.\n"); |
| 139 | |
| 140 | return res; |
| 141 | } |
Nikita Kiryanov | bf5c3cc | 2015-10-29 11:54:42 +0200 | [diff] [blame] | 142 | |
| 143 | #ifdef CONFIG_USB_STORAGE |
| 144 | static int splash_init_usb(void) |
| 145 | { |
| 146 | int err; |
| 147 | |
| 148 | err = usb_init(); |
| 149 | if (err) |
| 150 | return err; |
| 151 | |
Alexey Brodkin | bfcdf3f | 2016-07-01 22:47:36 +0300 | [diff] [blame] | 152 | #ifndef CONFIG_DM_USB |
| 153 | err = usb_stor_scan(1) < 0 ? -ENODEV : 0; |
| 154 | #endif |
| 155 | |
| 156 | return err; |
Nikita Kiryanov | bf5c3cc | 2015-10-29 11:54:42 +0200 | [diff] [blame] | 157 | } |
| 158 | #else |
| 159 | static inline int splash_init_usb(void) |
| 160 | { |
| 161 | printf("Cannot load splash image: no USB support\n"); |
| 162 | return -ENOSYS; |
| 163 | } |
| 164 | #endif |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 165 | |
Simon Glass | ab3055a | 2017-06-14 21:28:25 -0600 | [diff] [blame] | 166 | #ifdef CONFIG_SATA |
Nikita Kiryanov | 80ca30d | 2015-10-29 11:54:43 +0200 | [diff] [blame] | 167 | static int splash_init_sata(void) |
| 168 | { |
Simon Glass | 6c857ad | 2017-07-29 11:35:13 -0600 | [diff] [blame] | 169 | return sata_probe(0); |
Nikita Kiryanov | 80ca30d | 2015-10-29 11:54:43 +0200 | [diff] [blame] | 170 | } |
| 171 | #else |
| 172 | static inline int splash_init_sata(void) |
| 173 | { |
| 174 | printf("Cannot load splash image: no SATA support\n"); |
| 175 | return -ENOSYS; |
| 176 | } |
| 177 | #endif |
| 178 | |
Eran Matityahu | 07a04a1 | 2016-06-07 10:38:37 +0300 | [diff] [blame] | 179 | #ifdef CONFIG_CMD_UBIFS |
| 180 | static int splash_mount_ubifs(struct splash_location *location) |
| 181 | { |
| 182 | int res; |
| 183 | char cmd[32]; |
| 184 | |
| 185 | sprintf(cmd, "ubi part %s", location->mtdpart); |
| 186 | res = run_command(cmd, 0); |
| 187 | if (res) |
| 188 | return res; |
| 189 | |
| 190 | sprintf(cmd, "ubifsmount %s", location->ubivol); |
| 191 | res = run_command(cmd, 0); |
| 192 | |
| 193 | return res; |
| 194 | } |
| 195 | |
| 196 | static inline int splash_umount_ubifs(void) |
| 197 | { |
| 198 | return run_command("ubifsumount", 0); |
| 199 | } |
| 200 | #else |
| 201 | static inline int splash_mount_ubifs(struct splash_location *location) |
| 202 | { |
| 203 | printf("Cannot load splash image: no UBIFS support\n"); |
| 204 | return -ENOSYS; |
| 205 | } |
| 206 | |
| 207 | static inline int splash_umount_ubifs(void) |
| 208 | { |
| 209 | printf("Cannot unmount UBIFS: no UBIFS support\n"); |
| 210 | return -ENOSYS; |
| 211 | } |
| 212 | #endif |
| 213 | |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 214 | #define SPLASH_SOURCE_DEFAULT_FILE_NAME "splash.bmp" |
| 215 | |
| 216 | static int splash_load_fs(struct splash_location *location, u32 bmp_load_addr) |
| 217 | { |
Nikita Kiryanov | bf5c3cc | 2015-10-29 11:54:42 +0200 | [diff] [blame] | 218 | int res = 0; |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 219 | loff_t bmp_size; |
Jonathan Golder | 26b6131 | 2017-02-24 17:46:10 +0100 | [diff] [blame] | 220 | loff_t actread; |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 221 | char *splash_file; |
| 222 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 223 | splash_file = env_get("splashfile"); |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 224 | if (!splash_file) |
| 225 | splash_file = SPLASH_SOURCE_DEFAULT_FILE_NAME; |
| 226 | |
Nikita Kiryanov | bf5c3cc | 2015-10-29 11:54:42 +0200 | [diff] [blame] | 227 | if (location->storage == SPLASH_STORAGE_USB) |
| 228 | res = splash_init_usb(); |
| 229 | |
Nikita Kiryanov | 80ca30d | 2015-10-29 11:54:43 +0200 | [diff] [blame] | 230 | if (location->storage == SPLASH_STORAGE_SATA) |
| 231 | res = splash_init_sata(); |
| 232 | |
Eran Matityahu | 07a04a1 | 2016-06-07 10:38:37 +0300 | [diff] [blame] | 233 | if (location->ubivol != NULL) |
| 234 | res = splash_mount_ubifs(location); |
| 235 | |
Nikita Kiryanov | bf5c3cc | 2015-10-29 11:54:42 +0200 | [diff] [blame] | 236 | if (res) |
| 237 | return res; |
| 238 | |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 239 | res = splash_select_fs_dev(location); |
| 240 | if (res) |
Eran Matityahu | 07a04a1 | 2016-06-07 10:38:37 +0300 | [diff] [blame] | 241 | goto out; |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 242 | |
| 243 | res = fs_size(splash_file, &bmp_size); |
| 244 | if (res) { |
| 245 | printf("Error (%d): cannot determine file size\n", res); |
Eran Matityahu | 07a04a1 | 2016-06-07 10:38:37 +0300 | [diff] [blame] | 246 | goto out; |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | if (bmp_load_addr + bmp_size >= gd->start_addr_sp) { |
| 250 | printf("Error: splashimage address too high. Data overwrites U-Boot and/or placed beyond DRAM boundaries.\n"); |
Eran Matityahu | 07a04a1 | 2016-06-07 10:38:37 +0300 | [diff] [blame] | 251 | res = -EFAULT; |
| 252 | goto out; |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | splash_select_fs_dev(location); |
Jonathan Golder | 26b6131 | 2017-02-24 17:46:10 +0100 | [diff] [blame] | 256 | res = fs_read(splash_file, bmp_load_addr, 0, 0, &actread); |
Eran Matityahu | 07a04a1 | 2016-06-07 10:38:37 +0300 | [diff] [blame] | 257 | |
| 258 | out: |
| 259 | if (location->ubivol != NULL) |
| 260 | splash_umount_ubifs(); |
| 261 | |
| 262 | return res; |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 263 | } |
| 264 | |
Nikita Kiryanov | c2a07e3 | 2015-01-14 10:42:51 +0200 | [diff] [blame] | 265 | /** |
| 266 | * select_splash_location - return the splash location based on board support |
| 267 | * and env variable "splashsource". |
| 268 | * |
| 269 | * @locations: An array of supported splash locations. |
| 270 | * @size: Size of splash_locations array. |
| 271 | * |
| 272 | * @return: If a null set of splash locations is given, or |
| 273 | * splashsource env variable is set to unsupported value |
| 274 | * return NULL. |
| 275 | * If splashsource env variable is not defined |
| 276 | * return the first entry in splash_locations as default. |
| 277 | * If splashsource env variable contains a supported value |
| 278 | * return the location selected by splashsource. |
| 279 | */ |
| 280 | static struct splash_location *select_splash_location( |
| 281 | struct splash_location *locations, uint size) |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 282 | { |
Nikita Kiryanov | c2a07e3 | 2015-01-14 10:42:51 +0200 | [diff] [blame] | 283 | int i; |
| 284 | char *env_splashsource; |
| 285 | |
| 286 | if (!locations || size == 0) |
| 287 | return NULL; |
| 288 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 289 | env_splashsource = env_get("splashsource"); |
Nikita Kiryanov | c2a07e3 | 2015-01-14 10:42:51 +0200 | [diff] [blame] | 290 | if (env_splashsource == NULL) |
| 291 | return &locations[0]; |
| 292 | |
| 293 | for (i = 0; i < size; i++) { |
| 294 | if (!strcmp(locations[i].name, env_splashsource)) |
| 295 | return &locations[i]; |
| 296 | } |
| 297 | |
| 298 | printf("splashsource env variable set to unsupported value\n"); |
| 299 | return NULL; |
| 300 | } |
| 301 | |
tomas.melin@vaisala.com | 45ee790 | 2017-01-13 13:20:14 +0200 | [diff] [blame] | 302 | #ifdef CONFIG_FIT |
| 303 | static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr) |
| 304 | { |
| 305 | int res; |
| 306 | int node_offset; |
| 307 | int splash_offset; |
| 308 | int splash_size; |
| 309 | struct image_header *img_header; |
| 310 | const u32 *fit_header; |
| 311 | u32 fit_size; |
| 312 | const size_t header_size = sizeof(struct image_header); |
| 313 | |
| 314 | /* Read in image header */ |
| 315 | res = splash_storage_read_raw(location, bmp_load_addr, header_size); |
| 316 | if (res < 0) |
| 317 | return res; |
| 318 | |
| 319 | img_header = (struct image_header *)bmp_load_addr; |
Niko Mauno | 7e9e0b5 | 2017-08-03 09:53:24 +0300 | [diff] [blame] | 320 | if (image_get_magic(img_header) != FDT_MAGIC) { |
| 321 | printf("Could not find FDT magic\n"); |
| 322 | return -EINVAL; |
| 323 | } |
| 324 | |
tomas.melin@vaisala.com | 45ee790 | 2017-01-13 13:20:14 +0200 | [diff] [blame] | 325 | fit_size = fdt_totalsize(img_header); |
| 326 | |
| 327 | /* Read in entire FIT */ |
| 328 | fit_header = (const u32 *)(bmp_load_addr + header_size); |
| 329 | res = splash_storage_read_raw(location, (u32)fit_header, fit_size); |
| 330 | if (res < 0) |
| 331 | return res; |
| 332 | |
| 333 | res = fit_check_format(fit_header); |
| 334 | if (!res) { |
| 335 | debug("Could not find valid FIT image\n"); |
| 336 | return -EINVAL; |
| 337 | } |
| 338 | |
| 339 | node_offset = fit_image_get_node(fit_header, location->name); |
| 340 | if (node_offset < 0) { |
| 341 | debug("Could not find splash image '%s' in FIT\n", |
| 342 | location->name); |
| 343 | return -ENOENT; |
| 344 | } |
| 345 | |
| 346 | res = fit_image_get_data_offset(fit_header, node_offset, |
| 347 | &splash_offset); |
| 348 | if (res < 0) { |
| 349 | printf("Failed to load splash image (err=%d)\n", res); |
| 350 | return res; |
| 351 | } |
| 352 | |
| 353 | res = fit_image_get_data_size(fit_header, node_offset, &splash_size); |
| 354 | if (res < 0) { |
| 355 | printf("Failed to load splash image (err=%d)\n", res); |
| 356 | return res; |
| 357 | } |
| 358 | |
| 359 | /* Align data offset to 4-byte boundrary */ |
| 360 | fit_size = fdt_totalsize(fit_header); |
| 361 | fit_size = (fit_size + 3) & ~3; |
| 362 | |
| 363 | /* Read in the splash data */ |
| 364 | location->offset = (location->offset + fit_size + splash_offset); |
| 365 | res = splash_storage_read_raw(location, bmp_load_addr , splash_size); |
| 366 | if (res < 0) |
| 367 | return res; |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | #endif /* CONFIG_FIT */ |
| 372 | |
Nikita Kiryanov | 7f9ceea | 2015-01-14 10:42:54 +0200 | [diff] [blame] | 373 | /** |
| 374 | * splash_source_load - load splash image from a supported location. |
| 375 | * |
| 376 | * Select a splash image location based on the value of splashsource environment |
| 377 | * variable and the board supported splash source locations, and load a |
| 378 | * splashimage to the address pointed to by splashimage environment variable. |
| 379 | * |
| 380 | * @locations: An array of supported splash locations. |
| 381 | * @size: Size of splash_locations array. |
| 382 | * |
| 383 | * @return: 0 on success, negative value on failure. |
| 384 | */ |
| 385 | int splash_source_load(struct splash_location *locations, uint size) |
Nikita Kiryanov | c2a07e3 | 2015-01-14 10:42:51 +0200 | [diff] [blame] | 386 | { |
| 387 | struct splash_location *splash_location; |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 388 | char *env_splashimage_value; |
| 389 | u32 bmp_load_addr; |
| 390 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 391 | env_splashimage_value = env_get("splashimage"); |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 392 | if (env_splashimage_value == NULL) |
Nikita Kiryanov | f58c509 | 2015-01-14 10:42:49 +0200 | [diff] [blame] | 393 | return -ENOENT; |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 394 | |
| 395 | bmp_load_addr = simple_strtoul(env_splashimage_value, 0, 16); |
| 396 | if (bmp_load_addr == 0) { |
| 397 | printf("Error: bad splashimage address specified\n"); |
Nikita Kiryanov | f58c509 | 2015-01-14 10:42:49 +0200 | [diff] [blame] | 398 | return -EFAULT; |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 399 | } |
| 400 | |
Nikita Kiryanov | c2a07e3 | 2015-01-14 10:42:51 +0200 | [diff] [blame] | 401 | splash_location = select_splash_location(locations, size); |
| 402 | if (!splash_location) |
| 403 | return -EINVAL; |
| 404 | |
tomas.melin@vaisala.com | f4650ea | 2016-11-16 13:02:32 +0200 | [diff] [blame] | 405 | if (splash_location->flags == SPLASH_STORAGE_RAW) |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 406 | return splash_load_raw(splash_location, bmp_load_addr); |
tomas.melin@vaisala.com | f4650ea | 2016-11-16 13:02:32 +0200 | [diff] [blame] | 407 | else if (splash_location->flags == SPLASH_STORAGE_FS) |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 408 | return splash_load_fs(splash_location, bmp_load_addr); |
tomas.melin@vaisala.com | 45ee790 | 2017-01-13 13:20:14 +0200 | [diff] [blame] | 409 | #ifdef CONFIG_FIT |
| 410 | else if (splash_location->flags == SPLASH_STORAGE_FIT) |
| 411 | return splash_load_fit(splash_location, bmp_load_addr); |
| 412 | #endif |
Nikita Kiryanov | 7428271 | 2015-10-29 11:54:41 +0200 | [diff] [blame] | 413 | return -EINVAL; |
Igor Grinberg | 86ec16b | 2014-11-03 11:32:20 +0200 | [diff] [blame] | 414 | } |