Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <errno.h> |
Jean-Jacques Hiblot | 9037b7f | 2019-10-22 16:39:22 +0200 | [diff] [blame] | 9 | #include <board.h> |
Michal Simek | f707b5a | 2018-07-18 14:33:15 +0200 | [diff] [blame] | 10 | #include <fpga.h> |
Simon Glass | 1a974af | 2019-08-01 09:46:36 -0600 | [diff] [blame] | 11 | #include <gzip.h> |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 12 | #include <image.h> |
Jean-Jacques Hiblot | 0da5815 | 2019-10-22 16:39:13 +0200 | [diff] [blame] | 13 | #include <malloc.h> |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 14 | #include <spl.h> |
Jean-Jacques Hiblot | 0da5815 | 2019-10-22 16:39:13 +0200 | [diff] [blame] | 15 | #include <linux/libfdt.h> |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 16 | |
Lukas Auer | 80afee7 | 2019-08-21 21:14:42 +0200 | [diff] [blame] | 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Jean-Jacques Hiblot | 0da5815 | 2019-10-22 16:39:13 +0200 | [diff] [blame] | 19 | #ifndef CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY_BUF_SZ |
| 20 | #define CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY_BUF_SZ (64 * 1024) |
| 21 | #endif |
| 22 | |
York Sun | a6945fe | 2017-08-15 11:14:43 -0700 | [diff] [blame] | 23 | #ifndef CONFIG_SYS_BOOTM_LEN |
| 24 | #define CONFIG_SYS_BOOTM_LEN (64 << 20) |
| 25 | #endif |
| 26 | |
Ye Li | 9d5b0f4 | 2018-11-17 09:10:25 +0000 | [diff] [blame] | 27 | __weak void board_spl_fit_post_load(ulong load_addr, size_t length) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | __weak ulong board_spl_fit_size_align(ulong size) |
| 32 | { |
| 33 | return size; |
| 34 | } |
| 35 | |
Jean-Jacques Hiblot | 9037b7f | 2019-10-22 16:39:22 +0200 | [diff] [blame] | 36 | static int find_node_from_desc(const void *fit, int node, const char *str) |
| 37 | { |
| 38 | int child; |
| 39 | |
| 40 | if (node < 0) |
| 41 | return -EINVAL; |
| 42 | |
| 43 | /* iterate the FIT nodes and find a matching description */ |
| 44 | for (child = fdt_first_subnode(fit, node); child >= 0; |
| 45 | child = fdt_next_subnode(fit, child)) { |
| 46 | int len; |
| 47 | const char *desc = fdt_getprop(fit, child, "description", &len); |
| 48 | |
| 49 | if (!desc) |
| 50 | continue; |
| 51 | |
| 52 | if (!strcmp(desc, str)) |
| 53 | return child; |
| 54 | } |
| 55 | |
| 56 | return -ENOENT; |
| 57 | } |
| 58 | |
Andre Przywara | 525e9c9 | 2017-04-26 01:32:34 +0100 | [diff] [blame] | 59 | /** |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 60 | * spl_fit_get_image_name(): By using the matching configuration subnode, |
Andre Przywara | 525e9c9 | 2017-04-26 01:32:34 +0100 | [diff] [blame] | 61 | * retrieve the name of an image, specified by a property name and an index |
| 62 | * into that. |
| 63 | * @fit: Pointer to the FDT blob. |
| 64 | * @images: Offset of the /images subnode. |
| 65 | * @type: Name of the property within the configuration subnode. |
| 66 | * @index: Index into the list of strings in this property. |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 67 | * @outname: Name of the image |
Andre Przywara | 525e9c9 | 2017-04-26 01:32:34 +0100 | [diff] [blame] | 68 | * |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 69 | * Return: 0 on success, or a negative error number |
Andre Przywara | 525e9c9 | 2017-04-26 01:32:34 +0100 | [diff] [blame] | 70 | */ |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 71 | static int spl_fit_get_image_name(const void *fit, int images, |
| 72 | const char *type, int index, |
Jean-Jacques Hiblot | 64e82dc | 2019-10-22 16:39:17 +0200 | [diff] [blame] | 73 | const char **outname) |
Andre Przywara | 1e329b6 | 2017-04-26 01:32:33 +0100 | [diff] [blame] | 74 | { |
Jean-Jacques Hiblot | 9037b7f | 2019-10-22 16:39:22 +0200 | [diff] [blame] | 75 | struct udevice *board; |
Andre Przywara | 1e329b6 | 2017-04-26 01:32:33 +0100 | [diff] [blame] | 76 | const char *name, *str; |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 77 | __maybe_unused int node; |
| 78 | int conf_node; |
Andre Przywara | 1e329b6 | 2017-04-26 01:32:33 +0100 | [diff] [blame] | 79 | int len, i; |
Jean-Jacques Hiblot | 9037b7f | 2019-10-22 16:39:22 +0200 | [diff] [blame] | 80 | bool found = true; |
Andre Przywara | 1e329b6 | 2017-04-26 01:32:33 +0100 | [diff] [blame] | 81 | |
Cooper Jr., Franklin | e679240 | 2017-06-16 17:25:05 -0500 | [diff] [blame] | 82 | conf_node = fit_find_config_node(fit); |
Andre Przywara | 1e329b6 | 2017-04-26 01:32:33 +0100 | [diff] [blame] | 83 | if (conf_node < 0) { |
| 84 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
| 85 | printf("No matching DT out of these options:\n"); |
| 86 | for (node = fdt_first_subnode(fit, conf_node); |
| 87 | node >= 0; |
| 88 | node = fdt_next_subnode(fit, node)) { |
| 89 | name = fdt_getprop(fit, node, "description", &len); |
| 90 | printf(" %s\n", name); |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 91 | } |
Andre Przywara | 1e329b6 | 2017-04-26 01:32:33 +0100 | [diff] [blame] | 92 | #endif |
| 93 | return conf_node; |
| 94 | } |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 95 | |
Andre Przywara | 1e329b6 | 2017-04-26 01:32:33 +0100 | [diff] [blame] | 96 | name = fdt_getprop(fit, conf_node, type, &len); |
| 97 | if (!name) { |
| 98 | debug("cannot find property '%s': %d\n", type, len); |
| 99 | return -EINVAL; |
| 100 | } |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 101 | |
Andre Przywara | 1e329b6 | 2017-04-26 01:32:33 +0100 | [diff] [blame] | 102 | str = name; |
| 103 | for (i = 0; i < index; i++) { |
| 104 | str = strchr(str, '\0') + 1; |
| 105 | if (!str || (str - name >= len)) { |
Jean-Jacques Hiblot | 9037b7f | 2019-10-22 16:39:22 +0200 | [diff] [blame] | 106 | found = false; |
| 107 | break; |
Andre Przywara | 1e329b6 | 2017-04-26 01:32:33 +0100 | [diff] [blame] | 108 | } |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Jean-Jacques Hiblot | 9037b7f | 2019-10-22 16:39:22 +0200 | [diff] [blame] | 111 | if (!found && !board_get(&board)) { |
| 112 | int rc; |
| 113 | /* |
| 114 | * no string in the property for this index. Check if the board |
| 115 | * level code can supply one. |
| 116 | */ |
| 117 | rc = board_get_fit_loadable(board, index - i - 1, type, &str); |
| 118 | if (rc && rc != -ENOENT) |
| 119 | return rc; |
| 120 | |
| 121 | if (!rc) { |
| 122 | /* |
| 123 | * The board provided a name for a loadable. |
| 124 | * Try to match it against the description properties |
| 125 | * first. If no matching node is found, use it as a |
| 126 | * node name. |
| 127 | */ |
| 128 | int node; |
| 129 | int images = fdt_path_offset(fit, FIT_IMAGES_PATH); |
| 130 | |
| 131 | node = find_node_from_desc(fit, images, str); |
| 132 | if (node > 0) |
| 133 | str = fdt_get_name(fit, node, NULL); |
| 134 | |
| 135 | found = true; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if (!found) { |
| 140 | debug("no string for index %d\n", index); |
| 141 | return -E2BIG; |
| 142 | } |
| 143 | |
| 144 | *outname = str; |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * spl_fit_get_image_node(): By using the matching configuration subnode, |
| 150 | * retrieve the name of an image, specified by a property name and an index |
| 151 | * into that. |
| 152 | * @fit: Pointer to the FDT blob. |
| 153 | * @images: Offset of the /images subnode. |
| 154 | * @type: Name of the property within the configuration subnode. |
| 155 | * @index: Index into the list of strings in this property. |
| 156 | * |
| 157 | * Return: the node offset of the respective image node or a negative |
| 158 | * error number. |
| 159 | */ |
| 160 | static int spl_fit_get_image_node(const void *fit, int images, |
| 161 | const char *type, int index) |
| 162 | { |
Jean-Jacques Hiblot | 64e82dc | 2019-10-22 16:39:17 +0200 | [diff] [blame] | 163 | const char *str; |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 164 | int err; |
| 165 | int node; |
| 166 | |
| 167 | err = spl_fit_get_image_name(fit, images, type, index, &str); |
| 168 | if (err) |
| 169 | return err; |
| 170 | |
Andre Przywara | 1e329b6 | 2017-04-26 01:32:33 +0100 | [diff] [blame] | 171 | debug("%s: '%s'\n", type, str); |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 172 | |
Andre Przywara | 1e329b6 | 2017-04-26 01:32:33 +0100 | [diff] [blame] | 173 | node = fdt_subnode_offset(fit, images, str); |
| 174 | if (node < 0) { |
Jean-Jacques Hiblot | 9443a73 | 2019-10-22 16:39:15 +0200 | [diff] [blame] | 175 | pr_err("cannot find image node '%s': %d\n", str, node); |
Andre Przywara | 1e329b6 | 2017-04-26 01:32:33 +0100 | [diff] [blame] | 176 | return -EINVAL; |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 177 | } |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 178 | |
Andre Przywara | 525e9c9 | 2017-04-26 01:32:34 +0100 | [diff] [blame] | 179 | return node; |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Lokesh Vutla | f62cef1 | 2016-05-24 10:34:38 +0530 | [diff] [blame] | 182 | static int get_aligned_image_offset(struct spl_load_info *info, int offset) |
| 183 | { |
| 184 | /* |
| 185 | * If it is a FS read, get the first address before offset which is |
| 186 | * aligned to ARCH_DMA_MINALIGN. If it is raw read return the |
| 187 | * block number to which offset belongs. |
| 188 | */ |
| 189 | if (info->filename) |
| 190 | return offset & ~(ARCH_DMA_MINALIGN - 1); |
| 191 | |
| 192 | return offset / info->bl_len; |
| 193 | } |
| 194 | |
| 195 | static int get_aligned_image_overhead(struct spl_load_info *info, int offset) |
| 196 | { |
| 197 | /* |
| 198 | * If it is a FS read, get the difference between the offset and |
| 199 | * the first address before offset which is aligned to |
| 200 | * ARCH_DMA_MINALIGN. If it is raw read return the offset within the |
| 201 | * block. |
| 202 | */ |
| 203 | if (info->filename) |
| 204 | return offset & (ARCH_DMA_MINALIGN - 1); |
| 205 | |
| 206 | return offset % info->bl_len; |
| 207 | } |
| 208 | |
| 209 | static int get_aligned_image_size(struct spl_load_info *info, int data_size, |
| 210 | int offset) |
| 211 | { |
Lokesh Vutla | f0531a6 | 2016-07-19 14:56:14 +0530 | [diff] [blame] | 212 | data_size = data_size + get_aligned_image_overhead(info, offset); |
| 213 | |
Lokesh Vutla | f62cef1 | 2016-05-24 10:34:38 +0530 | [diff] [blame] | 214 | if (info->filename) |
Lokesh Vutla | f0531a6 | 2016-07-19 14:56:14 +0530 | [diff] [blame] | 215 | return data_size; |
Lokesh Vutla | f62cef1 | 2016-05-24 10:34:38 +0530 | [diff] [blame] | 216 | |
| 217 | return (data_size + info->bl_len - 1) / info->bl_len; |
| 218 | } |
| 219 | |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 220 | /** |
| 221 | * spl_load_fit_image(): load the image described in a certain FIT node |
| 222 | * @info: points to information about the device to load data from |
| 223 | * @sector: the start sector of the FIT image on the device |
| 224 | * @fit: points to the flattened device tree blob describing the FIT |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 225 | * image |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 226 | * @base_offset: the beginning of the data area containing the actual |
| 227 | * image data, relative to the beginning of the FIT |
| 228 | * @node: offset of the DT node describing the image to load (relative |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 229 | * to @fit) |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 230 | * @image_info: will be filled with information about the loaded image |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 231 | * If the FIT node does not contain a "load" (address) property, |
| 232 | * the image gets loaded to the address pointed to by the |
| 233 | * load_addr member in this struct. |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 234 | * |
| 235 | * Return: 0 on success or a negative error number. |
| 236 | */ |
| 237 | static int spl_load_fit_image(struct spl_load_info *info, ulong sector, |
| 238 | void *fit, ulong base_offset, int node, |
| 239 | struct spl_image_info *image_info) |
| 240 | { |
Michal Simek | f707b5a | 2018-07-18 14:33:15 +0200 | [diff] [blame] | 241 | int offset; |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 242 | size_t length; |
York Sun | adf99fa | 2017-08-15 11:14:44 -0700 | [diff] [blame] | 243 | int len; |
York Sun | 25d65f1 | 2017-09-15 08:21:13 -0700 | [diff] [blame] | 244 | ulong size; |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 245 | ulong load_addr, load_ptr; |
| 246 | void *src; |
| 247 | ulong overhead; |
| 248 | int nr_sectors; |
| 249 | int align_len = ARCH_DMA_MINALIGN - 1; |
York Sun | a6945fe | 2017-08-15 11:14:43 -0700 | [diff] [blame] | 250 | uint8_t image_comp = -1, type = -1; |
York Sun | adf99fa | 2017-08-15 11:14:44 -0700 | [diff] [blame] | 251 | const void *data; |
Peng Fan | 8876c7e | 2017-12-05 13:20:59 +0800 | [diff] [blame] | 252 | bool external_data = false; |
York Sun | a6945fe | 2017-08-15 11:14:43 -0700 | [diff] [blame] | 253 | |
Marek Vasut | 72bc5d5 | 2018-06-01 23:19:29 +0200 | [diff] [blame] | 254 | if (IS_ENABLED(CONFIG_SPL_FPGA_SUPPORT) || |
| 255 | (IS_ENABLED(CONFIG_SPL_OS_BOOT) && IS_ENABLED(CONFIG_SPL_GZIP))) { |
| 256 | if (fit_image_get_type(fit, node, &type)) |
| 257 | puts("Cannot get image type.\n"); |
| 258 | else |
| 259 | debug("%s ", genimg_get_type_name(type)); |
| 260 | } |
| 261 | |
Klaus H. Sorensen | 4a9a042 | 2019-12-11 11:03:33 +0000 | [diff] [blame^] | 262 | if (IS_ENABLED(CONFIG_SPL_GZIP)) { |
| 263 | fit_image_get_comp(fit, node, &image_comp); |
| 264 | debug("%s ", genimg_get_comp_name(image_comp)); |
York Sun | a6945fe | 2017-08-15 11:14:43 -0700 | [diff] [blame] | 265 | } |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 266 | |
York Sun | adf99fa | 2017-08-15 11:14:44 -0700 | [diff] [blame] | 267 | if (fit_image_get_load(fit, node, &load_addr)) |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 268 | load_addr = image_info->load_addr; |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 269 | |
Peng Fan | 8876c7e | 2017-12-05 13:20:59 +0800 | [diff] [blame] | 270 | if (!fit_image_get_data_position(fit, node, &offset)) { |
| 271 | external_data = true; |
| 272 | } else if (!fit_image_get_data_offset(fit, node, &offset)) { |
York Sun | adf99fa | 2017-08-15 11:14:44 -0700 | [diff] [blame] | 273 | offset += base_offset; |
Peng Fan | 8876c7e | 2017-12-05 13:20:59 +0800 | [diff] [blame] | 274 | external_data = true; |
| 275 | } |
| 276 | |
| 277 | if (external_data) { |
| 278 | /* External data */ |
York Sun | adf99fa | 2017-08-15 11:14:44 -0700 | [diff] [blame] | 279 | if (fit_image_get_data_size(fit, node, &len)) |
| 280 | return -ENOENT; |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 281 | |
York Sun | adf99fa | 2017-08-15 11:14:44 -0700 | [diff] [blame] | 282 | load_ptr = (load_addr + align_len) & ~align_len; |
| 283 | length = len; |
| 284 | |
| 285 | overhead = get_aligned_image_overhead(info, offset); |
| 286 | nr_sectors = get_aligned_image_size(info, length, offset); |
| 287 | |
Michal Simek | f707b5a | 2018-07-18 14:33:15 +0200 | [diff] [blame] | 288 | if (info->read(info, |
| 289 | sector + get_aligned_image_offset(info, offset), |
York Sun | adf99fa | 2017-08-15 11:14:44 -0700 | [diff] [blame] | 290 | nr_sectors, (void *)load_ptr) != nr_sectors) |
| 291 | return -EIO; |
| 292 | |
| 293 | debug("External data: dst=%lx, offset=%x, size=%lx\n", |
| 294 | load_ptr, offset, (unsigned long)length); |
| 295 | src = (void *)load_ptr + overhead; |
| 296 | } else { |
| 297 | /* Embedded data */ |
| 298 | if (fit_image_get_data(fit, node, &data, &length)) { |
| 299 | puts("Cannot get image data/size\n"); |
| 300 | return -ENOENT; |
| 301 | } |
| 302 | debug("Embedded data: dst=%lx, size=%lx\n", load_addr, |
| 303 | (unsigned long)length); |
| 304 | src = (void *)data; |
| 305 | } |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 306 | |
Ben Whitten | 54a9119 | 2018-06-07 11:37:27 +0100 | [diff] [blame] | 307 | #ifdef CONFIG_SPL_FIT_SIGNATURE |
| 308 | printf("## Checking hash(es) for Image %s ... ", |
| 309 | fit_get_name(fit, node, NULL)); |
| 310 | if (!fit_image_verify_with_data(fit, node, |
| 311 | src, length)) |
| 312 | return -EPERM; |
| 313 | puts("OK\n"); |
| 314 | #endif |
| 315 | |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 316 | #ifdef CONFIG_SPL_FIT_IMAGE_POST_PROCESS |
| 317 | board_fit_image_post_process(&src, &length); |
| 318 | #endif |
| 319 | |
Michal Simek | f354c3f | 2018-07-24 15:05:00 +0200 | [diff] [blame] | 320 | if (IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP) { |
York Sun | 25d65f1 | 2017-09-15 08:21:13 -0700 | [diff] [blame] | 321 | size = length; |
York Sun | a6945fe | 2017-08-15 11:14:43 -0700 | [diff] [blame] | 322 | if (gunzip((void *)load_addr, CONFIG_SYS_BOOTM_LEN, |
York Sun | 25d65f1 | 2017-09-15 08:21:13 -0700 | [diff] [blame] | 323 | src, &size)) { |
York Sun | a6945fe | 2017-08-15 11:14:43 -0700 | [diff] [blame] | 324 | puts("Uncompressing error\n"); |
| 325 | return -EIO; |
| 326 | } |
York Sun | 25d65f1 | 2017-09-15 08:21:13 -0700 | [diff] [blame] | 327 | length = size; |
York Sun | a6945fe | 2017-08-15 11:14:43 -0700 | [diff] [blame] | 328 | } else { |
| 329 | memcpy((void *)load_addr, src, length); |
| 330 | } |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 331 | |
| 332 | if (image_info) { |
| 333 | image_info->load_addr = load_addr; |
| 334 | image_info->size = length; |
| 335 | image_info->entry_point = fdt_getprop_u32(fit, node, "entry"); |
| 336 | } |
| 337 | |
| 338 | return 0; |
| 339 | } |
| 340 | |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 341 | static int spl_fit_append_fdt(struct spl_image_info *spl_image, |
| 342 | struct spl_load_info *info, ulong sector, |
| 343 | void *fit, int images, ulong base_offset) |
| 344 | { |
| 345 | struct spl_image_info image_info; |
Michal Simek | bf703df | 2019-10-22 16:39:11 +0200 | [diff] [blame] | 346 | int node, ret = 0, index = 0; |
Lukas Auer | 80afee7 | 2019-08-21 21:14:42 +0200 | [diff] [blame] | 347 | |
| 348 | /* |
| 349 | * Use the address following the image as target address for the |
| 350 | * device tree. |
| 351 | */ |
| 352 | image_info.load_addr = spl_image->load_addr + spl_image->size; |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 353 | |
| 354 | /* Figure out which device tree the board wants to use */ |
Michal Simek | bf703df | 2019-10-22 16:39:11 +0200 | [diff] [blame] | 355 | node = spl_fit_get_image_node(fit, images, FIT_FDT_PROP, index++); |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 356 | if (node < 0) { |
| 357 | debug("%s: cannot find FDT node\n", __func__); |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 358 | |
Lukas Auer | 80afee7 | 2019-08-21 21:14:42 +0200 | [diff] [blame] | 359 | /* |
| 360 | * U-Boot did not find a device tree inside the FIT image. Use |
| 361 | * the U-Boot device tree instead. |
| 362 | */ |
| 363 | if (gd->fdt_blob) |
| 364 | memcpy((void *)image_info.load_addr, gd->fdt_blob, |
| 365 | fdt_totalsize(gd->fdt_blob)); |
| 366 | else |
| 367 | return node; |
| 368 | } else { |
| 369 | ret = spl_load_fit_image(info, sector, fit, base_offset, node, |
| 370 | &image_info); |
| 371 | if (ret < 0) |
| 372 | return ret; |
| 373 | } |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 374 | |
| 375 | /* Make the load-address of the FDT available for the SPL framework */ |
| 376 | spl_image->fdt_addr = (void *)image_info.load_addr; |
Philipp Tomsich | 4faa011 | 2017-11-24 13:26:03 +0100 | [diff] [blame] | 377 | #if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY) |
Michal Simek | bf703df | 2019-10-22 16:39:11 +0200 | [diff] [blame] | 378 | if (CONFIG_IS_ENABLED(LOAD_FIT_APPLY_OVERLAY)) { |
Jean-Jacques Hiblot | 0da5815 | 2019-10-22 16:39:13 +0200 | [diff] [blame] | 379 | void *tmpbuffer = NULL; |
| 380 | |
Michal Simek | bf703df | 2019-10-22 16:39:11 +0200 | [diff] [blame] | 381 | for (; ; index++) { |
| 382 | node = spl_fit_get_image_node(fit, images, FIT_FDT_PROP, |
| 383 | index); |
Jean-Jacques Hiblot | c6ab6a1 | 2019-10-22 16:39:14 +0200 | [diff] [blame] | 384 | if (node == -E2BIG) { |
Michal Simek | bf703df | 2019-10-22 16:39:11 +0200 | [diff] [blame] | 385 | debug("%s: No additional FDT node\n", __func__); |
Jean-Jacques Hiblot | 0da5815 | 2019-10-22 16:39:13 +0200 | [diff] [blame] | 386 | break; |
Jean-Jacques Hiblot | c6ab6a1 | 2019-10-22 16:39:14 +0200 | [diff] [blame] | 387 | } else if (node < 0) { |
| 388 | debug("%s: unable to find FDT node %d\n", |
| 389 | __func__, index); |
| 390 | continue; |
Michal Simek | bf703df | 2019-10-22 16:39:11 +0200 | [diff] [blame] | 391 | } |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 392 | |
Jean-Jacques Hiblot | 0da5815 | 2019-10-22 16:39:13 +0200 | [diff] [blame] | 393 | if (!tmpbuffer) { |
| 394 | /* |
| 395 | * allocate memory to store the DT overlay |
| 396 | * before it is applied. It may not be used |
| 397 | * depending on how the overlay is stored, so |
| 398 | * don't fail yet if the allocation failed. |
| 399 | */ |
| 400 | tmpbuffer = malloc(CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY_BUF_SZ); |
| 401 | if (!tmpbuffer) |
| 402 | debug("%s: unable to allocate space for overlays\n", |
| 403 | __func__); |
| 404 | } |
| 405 | image_info.load_addr = (ulong)tmpbuffer; |
Michal Simek | bf703df | 2019-10-22 16:39:11 +0200 | [diff] [blame] | 406 | ret = spl_load_fit_image(info, sector, fit, base_offset, |
| 407 | node, &image_info); |
| 408 | if (ret < 0) |
Jean-Jacques Hiblot | 0da5815 | 2019-10-22 16:39:13 +0200 | [diff] [blame] | 409 | break; |
Michal Simek | bf703df | 2019-10-22 16:39:11 +0200 | [diff] [blame] | 410 | |
Jean-Jacques Hiblot | 74addb6 | 2019-10-22 16:39:12 +0200 | [diff] [blame] | 411 | /* Make room in FDT for changes from the overlay */ |
| 412 | ret = fdt_increase_size(spl_image->fdt_addr, |
| 413 | image_info.size); |
| 414 | if (ret < 0) |
Jean-Jacques Hiblot | 0da5815 | 2019-10-22 16:39:13 +0200 | [diff] [blame] | 415 | break; |
Jean-Jacques Hiblot | 74addb6 | 2019-10-22 16:39:12 +0200 | [diff] [blame] | 416 | |
Michal Simek | bf703df | 2019-10-22 16:39:11 +0200 | [diff] [blame] | 417 | ret = fdt_overlay_apply_verbose(spl_image->fdt_addr, |
| 418 | (void *)image_info.load_addr); |
Jean-Jacques Hiblot | 9443a73 | 2019-10-22 16:39:15 +0200 | [diff] [blame] | 419 | if (ret) { |
| 420 | pr_err("failed to apply DT overlay %s\n", |
| 421 | fit_get_name(fit, node, NULL)); |
Jean-Jacques Hiblot | 0da5815 | 2019-10-22 16:39:13 +0200 | [diff] [blame] | 422 | break; |
Jean-Jacques Hiblot | 9443a73 | 2019-10-22 16:39:15 +0200 | [diff] [blame] | 423 | } |
Michal Simek | bf703df | 2019-10-22 16:39:11 +0200 | [diff] [blame] | 424 | |
| 425 | debug("%s: DT overlay %s applied\n", __func__, |
| 426 | fit_get_name(fit, node, NULL)); |
| 427 | } |
Jean-Jacques Hiblot | 0da5815 | 2019-10-22 16:39:13 +0200 | [diff] [blame] | 428 | if (tmpbuffer) |
| 429 | free(tmpbuffer); |
| 430 | if (ret) |
| 431 | return ret; |
Michal Simek | bf703df | 2019-10-22 16:39:11 +0200 | [diff] [blame] | 432 | } |
Jean-Jacques Hiblot | 74addb6 | 2019-10-22 16:39:12 +0200 | [diff] [blame] | 433 | /* Try to make space, so we can inject details on the loadables */ |
| 434 | ret = fdt_shrink_to_minimum(spl_image->fdt_addr, 8192); |
| 435 | if (ret < 0) |
| 436 | return ret; |
| 437 | #endif |
| 438 | |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 439 | return ret; |
| 440 | } |
| 441 | |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 442 | static int spl_fit_record_loadable(const void *fit, int images, int index, |
| 443 | void *blob, struct spl_image_info *image) |
| 444 | { |
Philipp Tomsich | 4faa011 | 2017-11-24 13:26:03 +0100 | [diff] [blame] | 445 | int ret = 0; |
| 446 | #if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY) |
Jean-Jacques Hiblot | 64e82dc | 2019-10-22 16:39:17 +0200 | [diff] [blame] | 447 | const char *name; |
Philipp Tomsich | 4faa011 | 2017-11-24 13:26:03 +0100 | [diff] [blame] | 448 | int node; |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 449 | |
| 450 | ret = spl_fit_get_image_name(fit, images, "loadables", |
| 451 | index, &name); |
| 452 | if (ret < 0) |
| 453 | return ret; |
| 454 | |
| 455 | node = spl_fit_get_image_node(fit, images, "loadables", index); |
| 456 | |
| 457 | ret = fdt_record_loadable(blob, index, name, image->load_addr, |
| 458 | image->size, image->entry_point, |
| 459 | fdt_getprop(fit, node, "type", NULL), |
| 460 | fdt_getprop(fit, node, "os", NULL)); |
Philipp Tomsich | 4faa011 | 2017-11-24 13:26:03 +0100 | [diff] [blame] | 461 | #endif |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 462 | return ret; |
| 463 | } |
| 464 | |
Philipp Tomsich | 4faa011 | 2017-11-24 13:26:03 +0100 | [diff] [blame] | 465 | static int spl_fit_image_get_os(const void *fit, int noffset, uint8_t *os) |
| 466 | { |
Jean-Jacques Hiblot | 943ec25 | 2019-04-26 15:21:25 +0200 | [diff] [blame] | 467 | #if CONFIG_IS_ENABLED(FIT_IMAGE_TINY) && !defined(CONFIG_SPL_OS_BOOT) |
Philipp Tomsich | 4faa011 | 2017-11-24 13:26:03 +0100 | [diff] [blame] | 468 | return -ENOTSUPP; |
| 469 | #else |
| 470 | return fit_image_get_os(fit, noffset, os); |
| 471 | #endif |
| 472 | } |
| 473 | |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 474 | /* |
| 475 | * Weak default function to allow customizing SPL fit loading for load-only |
| 476 | * use cases by allowing to skip the parsing/processing of the FIT contents |
| 477 | * (so that this can be done separately in a more customized fashion) |
| 478 | */ |
| 479 | __weak bool spl_load_simple_fit_skip_processing(void) |
| 480 | { |
| 481 | return false; |
| 482 | } |
| 483 | |
Simon Glass | 43a734f | 2016-09-24 18:20:16 -0600 | [diff] [blame] | 484 | int spl_load_simple_fit(struct spl_image_info *spl_image, |
| 485 | struct spl_load_info *info, ulong sector, void *fit) |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 486 | { |
| 487 | int sectors; |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 488 | ulong size; |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 489 | unsigned long count; |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 490 | struct spl_image_info image_info; |
York Sun | a058b8a | 2017-08-15 11:14:45 -0700 | [diff] [blame] | 491 | int node = -1; |
| 492 | int images, ret; |
Marek Vasut | 1dda46f | 2018-08-14 11:27:02 +0200 | [diff] [blame] | 493 | int base_offset, hsize, align_len = ARCH_DMA_MINALIGN - 1; |
Andre Przywara | e7c5856 | 2017-04-26 01:32:37 +0100 | [diff] [blame] | 494 | int index = 0; |
Jean-Jacques Hiblot | 776ce60 | 2019-10-22 16:39:10 +0200 | [diff] [blame] | 495 | int firmware_node; |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 496 | |
| 497 | /* |
York Sun | a058b8a | 2017-08-15 11:14:45 -0700 | [diff] [blame] | 498 | * For FIT with external data, figure out where the external images |
| 499 | * start. This is the base for the data-offset properties in each |
| 500 | * image. |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 501 | */ |
| 502 | size = fdt_totalsize(fit); |
| 503 | size = (size + 3) & ~3; |
Ye Li | 9d5b0f4 | 2018-11-17 09:10:25 +0000 | [diff] [blame] | 504 | size = board_spl_fit_size_align(size); |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 505 | base_offset = (size + 3) & ~3; |
| 506 | |
| 507 | /* |
| 508 | * So far we only have one block of data from the FIT. Read the entire |
| 509 | * thing, including that first block, placing it so it finishes before |
| 510 | * where we will load the image. |
| 511 | * |
| 512 | * Note that we will load the image such that its first byte will be |
| 513 | * at the load address. Since that byte may be part-way through a |
| 514 | * block, we may load the image up to one block before the load |
| 515 | * address. So take account of that here by subtracting an addition |
| 516 | * block length from the FIT start position. |
| 517 | * |
| 518 | * In fact the FIT has its own load address, but we assume it cannot |
| 519 | * be before CONFIG_SYS_TEXT_BASE. |
York Sun | a058b8a | 2017-08-15 11:14:45 -0700 | [diff] [blame] | 520 | * |
| 521 | * For FIT with data embedded, data is loaded as part of FIT image. |
| 522 | * For FIT with external data, data is not loaded in this step. |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 523 | */ |
Marek Vasut | 1dda46f | 2018-08-14 11:27:02 +0200 | [diff] [blame] | 524 | hsize = (size + info->bl_len + align_len) & ~align_len; |
| 525 | fit = spl_get_load_buffer(-hsize, hsize); |
Lokesh Vutla | f62cef1 | 2016-05-24 10:34:38 +0530 | [diff] [blame] | 526 | sectors = get_aligned_image_size(info, size, 0); |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 527 | count = info->read(info, sector, sectors, fit); |
Ye Li | 9d5b0f4 | 2018-11-17 09:10:25 +0000 | [diff] [blame] | 528 | debug("fit read sector %lx, sectors=%d, dst=%p, count=%lu, size=0x%lx\n", |
| 529 | sector, sectors, fit, count, size); |
| 530 | |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 531 | if (count == 0) |
| 532 | return -EIO; |
| 533 | |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 534 | /* skip further processing if requested to enable load-only use cases */ |
| 535 | if (spl_load_simple_fit_skip_processing()) |
| 536 | return 0; |
| 537 | |
Andre Przywara | 525e9c9 | 2017-04-26 01:32:34 +0100 | [diff] [blame] | 538 | /* find the node holding the images information */ |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 539 | images = fdt_path_offset(fit, FIT_IMAGES_PATH); |
| 540 | if (images < 0) { |
| 541 | debug("%s: Cannot find /images node: %d\n", __func__, images); |
| 542 | return -1; |
| 543 | } |
Marek Vasut | 33dd00e | 2018-05-12 22:25:28 +0200 | [diff] [blame] | 544 | |
| 545 | #ifdef CONFIG_SPL_FPGA_SUPPORT |
| 546 | node = spl_fit_get_image_node(fit, images, "fpga", 0); |
| 547 | if (node >= 0) { |
| 548 | /* Load the image and set up the spl_image structure */ |
| 549 | ret = spl_load_fit_image(info, sector, fit, base_offset, node, |
| 550 | spl_image); |
| 551 | if (ret) { |
| 552 | printf("%s: Cannot load the FPGA: %i\n", __func__, ret); |
| 553 | return ret; |
| 554 | } |
Michal Simek | f707b5a | 2018-07-18 14:33:15 +0200 | [diff] [blame] | 555 | |
| 556 | debug("FPGA bitstream at: %x, size: %x\n", |
| 557 | (u32)spl_image->load_addr, spl_image->size); |
| 558 | |
| 559 | ret = fpga_load(0, (const void *)spl_image->load_addr, |
| 560 | spl_image->size, BIT_FULL); |
| 561 | if (ret) { |
| 562 | printf("%s: Cannot load the image to the FPGA\n", |
| 563 | __func__); |
| 564 | return ret; |
| 565 | } |
| 566 | |
Luis Araneda | eece623 | 2018-07-19 03:10:16 -0400 | [diff] [blame] | 567 | puts("FPGA image loaded from FIT\n"); |
Marek Vasut | 33dd00e | 2018-05-12 22:25:28 +0200 | [diff] [blame] | 568 | node = -1; |
| 569 | } |
| 570 | #endif |
Andre Przywara | 525e9c9 | 2017-04-26 01:32:34 +0100 | [diff] [blame] | 571 | |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 572 | /* |
| 573 | * Find the U-Boot image using the following search order: |
| 574 | * - start at 'firmware' (e.g. an ARM Trusted Firmware) |
| 575 | * - fall back 'kernel' (e.g. a Falcon-mode OS boot |
| 576 | * - fall back to using the first 'loadables' entry |
| 577 | */ |
| 578 | if (node < 0) |
Michal Simek | b766e8f | 2018-03-26 16:31:26 +0200 | [diff] [blame] | 579 | node = spl_fit_get_image_node(fit, images, FIT_FIRMWARE_PROP, |
| 580 | 0); |
York Sun | a058b8a | 2017-08-15 11:14:45 -0700 | [diff] [blame] | 581 | #ifdef CONFIG_SPL_OS_BOOT |
York Sun | a058b8a | 2017-08-15 11:14:45 -0700 | [diff] [blame] | 582 | if (node < 0) |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 583 | node = spl_fit_get_image_node(fit, images, FIT_KERNEL_PROP, 0); |
York Sun | a058b8a | 2017-08-15 11:14:45 -0700 | [diff] [blame] | 584 | #endif |
Andre Przywara | 525e9c9 | 2017-04-26 01:32:34 +0100 | [diff] [blame] | 585 | if (node < 0) { |
| 586 | debug("could not find firmware image, trying loadables...\n"); |
| 587 | node = spl_fit_get_image_node(fit, images, "loadables", 0); |
Andre Przywara | e7c5856 | 2017-04-26 01:32:37 +0100 | [diff] [blame] | 588 | /* |
| 589 | * If we pick the U-Boot image from "loadables", start at |
| 590 | * the second image when later loading additional images. |
| 591 | */ |
| 592 | index = 1; |
Andre Przywara | 525e9c9 | 2017-04-26 01:32:34 +0100 | [diff] [blame] | 593 | } |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 594 | if (node < 0) { |
Andre Przywara | 525e9c9 | 2017-04-26 01:32:34 +0100 | [diff] [blame] | 595 | debug("%s: Cannot find u-boot image node: %d\n", |
| 596 | __func__, node); |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 597 | return -1; |
| 598 | } |
| 599 | |
Andre Przywara | 29053e9 | 2017-04-26 01:32:36 +0100 | [diff] [blame] | 600 | /* Load the image and set up the spl_image structure */ |
| 601 | ret = spl_load_fit_image(info, sector, fit, base_offset, node, |
| 602 | spl_image); |
| 603 | if (ret) |
| 604 | return ret; |
Daniel Allred | cf839bd | 2016-06-27 09:19:21 -0500 | [diff] [blame] | 605 | |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 606 | /* |
| 607 | * For backward compatibility, we treat the first node that is |
| 608 | * as a U-Boot image, if no OS-type has been declared. |
| 609 | */ |
Philipp Tomsich | 4faa011 | 2017-11-24 13:26:03 +0100 | [diff] [blame] | 610 | if (!spl_fit_image_get_os(fit, node, &spl_image->os)) |
York Sun | a058b8a | 2017-08-15 11:14:45 -0700 | [diff] [blame] | 611 | debug("Image OS is %s\n", genimg_get_os_name(spl_image->os)); |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 612 | #if !defined(CONFIG_SPL_OS_BOOT) |
| 613 | else |
| 614 | spl_image->os = IH_OS_U_BOOT; |
York Sun | a058b8a | 2017-08-15 11:14:45 -0700 | [diff] [blame] | 615 | #endif |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 616 | |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 617 | /* |
| 618 | * Booting a next-stage U-Boot may require us to append the FDT. |
| 619 | * We allow this to fail, as the U-Boot image might embed its FDT. |
| 620 | */ |
| 621 | if (spl_image->os == IH_OS_U_BOOT) |
| 622 | spl_fit_append_fdt(spl_image, info, sector, fit, |
| 623 | images, base_offset); |
Andre Przywara | e7c5856 | 2017-04-26 01:32:37 +0100 | [diff] [blame] | 624 | |
Jean-Jacques Hiblot | 776ce60 | 2019-10-22 16:39:10 +0200 | [diff] [blame] | 625 | firmware_node = node; |
Andre Przywara | e7c5856 | 2017-04-26 01:32:37 +0100 | [diff] [blame] | 626 | /* Now check if there are more images for us to load */ |
| 627 | for (; ; index++) { |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 628 | uint8_t os_type = IH_OS_INVALID; |
| 629 | |
Andre Przywara | e7c5856 | 2017-04-26 01:32:37 +0100 | [diff] [blame] | 630 | node = spl_fit_get_image_node(fit, images, "loadables", index); |
| 631 | if (node < 0) |
| 632 | break; |
| 633 | |
Jean-Jacques Hiblot | 776ce60 | 2019-10-22 16:39:10 +0200 | [diff] [blame] | 634 | /* |
| 635 | * if the firmware is also a loadable, skip it because |
| 636 | * it already has been loaded. This is typically the case with |
| 637 | * u-boot.img generated by mkimage. |
| 638 | */ |
| 639 | if (firmware_node == node) |
| 640 | continue; |
| 641 | |
Andre Przywara | e7c5856 | 2017-04-26 01:32:37 +0100 | [diff] [blame] | 642 | ret = spl_load_fit_image(info, sector, fit, base_offset, node, |
| 643 | &image_info); |
| 644 | if (ret < 0) |
| 645 | continue; |
| 646 | |
Philipp Tomsich | 4faa011 | 2017-11-24 13:26:03 +0100 | [diff] [blame] | 647 | if (!spl_fit_image_get_os(fit, node, &os_type)) |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 648 | debug("Loadable is %s\n", genimg_get_os_name(os_type)); |
Abel Vesa | 53420dc | 2019-03-12 08:34:31 +0000 | [diff] [blame] | 649 | #if CONFIG_IS_ENABLED(FIT_IMAGE_TINY) |
| 650 | else |
| 651 | os_type = IH_OS_U_BOOT; |
| 652 | #endif |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 653 | |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 654 | if (os_type == IH_OS_U_BOOT) { |
| 655 | spl_fit_append_fdt(&image_info, info, sector, |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 656 | fit, images, base_offset); |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 657 | spl_image->fdt_addr = image_info.fdt_addr; |
| 658 | } |
Philipp Tomsich | 1345ffa | 2017-09-13 21:29:32 +0200 | [diff] [blame] | 659 | |
Andre Przywara | e7c5856 | 2017-04-26 01:32:37 +0100 | [diff] [blame] | 660 | /* |
| 661 | * If the "firmware" image did not provide an entry point, |
| 662 | * use the first valid entry point from the loadables. |
| 663 | */ |
| 664 | if (spl_image->entry_point == FDT_ERROR && |
| 665 | image_info.entry_point != FDT_ERROR) |
| 666 | spl_image->entry_point = image_info.entry_point; |
Philipp Tomsich | e61eff9 | 2017-09-13 21:29:34 +0200 | [diff] [blame] | 667 | |
| 668 | /* Record our loadables into the FDT */ |
| 669 | if (spl_image->fdt_addr) |
| 670 | spl_fit_record_loadable(fit, images, index, |
| 671 | spl_image->fdt_addr, |
| 672 | &image_info); |
Andre Przywara | e7c5856 | 2017-04-26 01:32:37 +0100 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | /* |
| 676 | * If a platform does not provide CONFIG_SYS_UBOOT_START, U-Boot's |
| 677 | * Makefile will set it to 0 and it will end up as the entry point |
| 678 | * here. What it actually means is: use the load address. |
| 679 | */ |
| 680 | if (spl_image->entry_point == FDT_ERROR || spl_image->entry_point == 0) |
| 681 | spl_image->entry_point = spl_image->load_addr; |
| 682 | |
Ye Li | 9d5b0f4 | 2018-11-17 09:10:25 +0000 | [diff] [blame] | 683 | spl_image->flags |= SPL_FIT_FOUND; |
| 684 | |
Stefano Babic | f8b509b | 2019-09-20 08:47:53 +0200 | [diff] [blame] | 685 | #ifdef CONFIG_IMX_HAB |
Ye Li | 9d5b0f4 | 2018-11-17 09:10:25 +0000 | [diff] [blame] | 686 | board_spl_fit_post_load((ulong)fit, size); |
| 687 | #endif |
| 688 | |
Andre Przywara | e7c5856 | 2017-04-26 01:32:37 +0100 | [diff] [blame] | 689 | return 0; |
Simon Glass | a6131a2 | 2016-02-22 22:55:56 -0700 | [diff] [blame] | 690 | } |