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