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