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