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