blob: 9f03e2648a31bb1d51077b48d395cc8c77734952 [file] [log] [blame]
Simon Glassa6131a22016-02-22 22:55:56 -07001/*
2 * Copyright (C) 2016 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
Philipp Tomsiche61eff92017-09-13 21:29:34 +02005 * SPDX-License-Identifier: GPL-2.0+
Simon Glassa6131a22016-02-22 22:55:56 -07006 */
7
8#include <common.h>
9#include <errno.h>
10#include <image.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090011#include <linux/libfdt.h>
Simon Glassa6131a22016-02-22 22:55:56 -070012#include <spl.h>
13
York Suna6945fe2017-08-15 11:14:43 -070014#ifndef CONFIG_SYS_BOOTM_LEN
15#define CONFIG_SYS_BOOTM_LEN (64 << 20)
16#endif
17
Andre Przywara525e9c92017-04-26 01:32:34 +010018/**
Philipp Tomsiche61eff92017-09-13 21:29:34 +020019 * spl_fit_get_image_name(): By using the matching configuration subnode,
Andre Przywara525e9c92017-04-26 01:32:34 +010020 * retrieve the name of an image, specified by a property name and an index
21 * into that.
22 * @fit: Pointer to the FDT blob.
23 * @images: Offset of the /images subnode.
24 * @type: Name of the property within the configuration subnode.
25 * @index: Index into the list of strings in this property.
Philipp Tomsiche61eff92017-09-13 21:29:34 +020026 * @outname: Name of the image
Andre Przywara525e9c92017-04-26 01:32:34 +010027 *
Philipp Tomsiche61eff92017-09-13 21:29:34 +020028 * Return: 0 on success, or a negative error number
Andre Przywara525e9c92017-04-26 01:32:34 +010029 */
Philipp Tomsiche61eff92017-09-13 21:29:34 +020030static int spl_fit_get_image_name(const void *fit, int images,
31 const char *type, int index,
32 char **outname)
Andre Przywara1e329b62017-04-26 01:32:33 +010033{
34 const char *name, *str;
Philipp Tomsiche61eff92017-09-13 21:29:34 +020035 __maybe_unused int node;
36 int conf_node;
Andre Przywara1e329b62017-04-26 01:32:33 +010037 int len, i;
38
Cooper Jr., Frankline6792402017-06-16 17:25:05 -050039 conf_node = fit_find_config_node(fit);
Andre Przywara1e329b62017-04-26 01:32:33 +010040 if (conf_node < 0) {
41#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
42 printf("No matching DT out of these options:\n");
43 for (node = fdt_first_subnode(fit, conf_node);
44 node >= 0;
45 node = fdt_next_subnode(fit, node)) {
46 name = fdt_getprop(fit, node, "description", &len);
47 printf(" %s\n", name);
Simon Glassa6131a22016-02-22 22:55:56 -070048 }
Andre Przywara1e329b62017-04-26 01:32:33 +010049#endif
50 return conf_node;
51 }
Simon Glassa6131a22016-02-22 22:55:56 -070052
Andre Przywara1e329b62017-04-26 01:32:33 +010053 name = fdt_getprop(fit, conf_node, type, &len);
54 if (!name) {
55 debug("cannot find property '%s': %d\n", type, len);
56 return -EINVAL;
57 }
Simon Glassa6131a22016-02-22 22:55:56 -070058
Andre Przywara1e329b62017-04-26 01:32:33 +010059 str = name;
60 for (i = 0; i < index; i++) {
61 str = strchr(str, '\0') + 1;
62 if (!str || (str - name >= len)) {
63 debug("no string for index %d\n", index);
64 return -E2BIG;
65 }
Simon Glassa6131a22016-02-22 22:55:56 -070066 }
67
Philipp Tomsiche61eff92017-09-13 21:29:34 +020068 *outname = (char *)str;
69 return 0;
70}
71
72/**
73 * spl_fit_get_image_node(): By using the matching configuration subnode,
74 * retrieve the name of an image, specified by a property name and an index
75 * into that.
76 * @fit: Pointer to the FDT blob.
77 * @images: Offset of the /images subnode.
78 * @type: Name of the property within the configuration subnode.
79 * @index: Index into the list of strings in this property.
80 *
81 * Return: the node offset of the respective image node or a negative
82 * error number.
83 */
84static int spl_fit_get_image_node(const void *fit, int images,
85 const char *type, int index)
86{
87 char *str;
88 int err;
89 int node;
90
91 err = spl_fit_get_image_name(fit, images, type, index, &str);
92 if (err)
93 return err;
94
Andre Przywara1e329b62017-04-26 01:32:33 +010095 debug("%s: '%s'\n", type, str);
Philipp Tomsiche61eff92017-09-13 21:29:34 +020096
Andre Przywara1e329b62017-04-26 01:32:33 +010097 node = fdt_subnode_offset(fit, images, str);
98 if (node < 0) {
99 debug("cannot find image node '%s': %d\n", str, node);
100 return -EINVAL;
Simon Glassa6131a22016-02-22 22:55:56 -0700101 }
Simon Glassa6131a22016-02-22 22:55:56 -0700102
Andre Przywara525e9c92017-04-26 01:32:34 +0100103 return node;
Simon Glassa6131a22016-02-22 22:55:56 -0700104}
105
Lokesh Vutlaf62cef12016-05-24 10:34:38 +0530106static int get_aligned_image_offset(struct spl_load_info *info, int offset)
107{
108 /*
109 * If it is a FS read, get the first address before offset which is
110 * aligned to ARCH_DMA_MINALIGN. If it is raw read return the
111 * block number to which offset belongs.
112 */
113 if (info->filename)
114 return offset & ~(ARCH_DMA_MINALIGN - 1);
115
116 return offset / info->bl_len;
117}
118
119static int get_aligned_image_overhead(struct spl_load_info *info, int offset)
120{
121 /*
122 * If it is a FS read, get the difference between the offset and
123 * the first address before offset which is aligned to
124 * ARCH_DMA_MINALIGN. If it is raw read return the offset within the
125 * block.
126 */
127 if (info->filename)
128 return offset & (ARCH_DMA_MINALIGN - 1);
129
130 return offset % info->bl_len;
131}
132
133static int get_aligned_image_size(struct spl_load_info *info, int data_size,
134 int offset)
135{
Lokesh Vutlaf0531a62016-07-19 14:56:14 +0530136 data_size = data_size + get_aligned_image_overhead(info, offset);
137
Lokesh Vutlaf62cef12016-05-24 10:34:38 +0530138 if (info->filename)
Lokesh Vutlaf0531a62016-07-19 14:56:14 +0530139 return data_size;
Lokesh Vutlaf62cef12016-05-24 10:34:38 +0530140
141 return (data_size + info->bl_len - 1) / info->bl_len;
142}
143
Andre Przywara29053e92017-04-26 01:32:36 +0100144/**
145 * spl_load_fit_image(): load the image described in a certain FIT node
146 * @info: points to information about the device to load data from
147 * @sector: the start sector of the FIT image on the device
148 * @fit: points to the flattened device tree blob describing the FIT
Philipp Tomsiche61eff92017-09-13 21:29:34 +0200149 * image
Andre Przywara29053e92017-04-26 01:32:36 +0100150 * @base_offset: the beginning of the data area containing the actual
151 * image data, relative to the beginning of the FIT
152 * @node: offset of the DT node describing the image to load (relative
Philipp Tomsiche61eff92017-09-13 21:29:34 +0200153 * to @fit)
Andre Przywara29053e92017-04-26 01:32:36 +0100154 * @image_info: will be filled with information about the loaded image
Philipp Tomsiche61eff92017-09-13 21:29:34 +0200155 * If the FIT node does not contain a "load" (address) property,
156 * the image gets loaded to the address pointed to by the
157 * load_addr member in this struct.
Andre Przywara29053e92017-04-26 01:32:36 +0100158 *
159 * Return: 0 on success or a negative error number.
160 */
161static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
162 void *fit, ulong base_offset, int node,
163 struct spl_image_info *image_info)
164{
York Sunadf99fa2017-08-15 11:14:44 -0700165 int offset;
Andre Przywara29053e92017-04-26 01:32:36 +0100166 size_t length;
York Sunadf99fa2017-08-15 11:14:44 -0700167 int len;
York Sun25d65f12017-09-15 08:21:13 -0700168 ulong size;
Andre Przywara29053e92017-04-26 01:32:36 +0100169 ulong load_addr, load_ptr;
170 void *src;
171 ulong overhead;
172 int nr_sectors;
173 int align_len = ARCH_DMA_MINALIGN - 1;
York Suna6945fe2017-08-15 11:14:43 -0700174 uint8_t image_comp = -1, type = -1;
York Sunadf99fa2017-08-15 11:14:44 -0700175 const void *data;
Peng Fan8876c7e2017-12-05 13:20:59 +0800176 bool external_data = false;
Jun Nieadf5d1c2018-02-27 16:55:58 +0800177#ifdef CONFIG_SPL_FIT_SIGNATURE
178 int ret;
179#endif
York Suna6945fe2017-08-15 11:14:43 -0700180
181 if (IS_ENABLED(CONFIG_SPL_OS_BOOT) && IS_ENABLED(CONFIG_SPL_GZIP)) {
182 if (fit_image_get_comp(fit, node, &image_comp))
183 puts("Cannot get image compression format.\n");
184 else
185 debug("%s ", genimg_get_comp_name(image_comp));
186
187 if (fit_image_get_type(fit, node, &type))
188 puts("Cannot get image type.\n");
189 else
190 debug("%s ", genimg_get_type_name(type));
191 }
Andre Przywara29053e92017-04-26 01:32:36 +0100192
York Sunadf99fa2017-08-15 11:14:44 -0700193 if (fit_image_get_load(fit, node, &load_addr))
Andre Przywara29053e92017-04-26 01:32:36 +0100194 load_addr = image_info->load_addr;
Andre Przywara29053e92017-04-26 01:32:36 +0100195
Peng Fan8876c7e2017-12-05 13:20:59 +0800196 if (!fit_image_get_data_position(fit, node, &offset)) {
197 external_data = true;
198 } else if (!fit_image_get_data_offset(fit, node, &offset)) {
York Sunadf99fa2017-08-15 11:14:44 -0700199 offset += base_offset;
Peng Fan8876c7e2017-12-05 13:20:59 +0800200 external_data = true;
201 }
202
203 if (external_data) {
204 /* External data */
York Sunadf99fa2017-08-15 11:14:44 -0700205 if (fit_image_get_data_size(fit, node, &len))
206 return -ENOENT;
Andre Przywara29053e92017-04-26 01:32:36 +0100207
York Sunadf99fa2017-08-15 11:14:44 -0700208 load_ptr = (load_addr + align_len) & ~align_len;
209 length = len;
210
211 overhead = get_aligned_image_overhead(info, offset);
212 nr_sectors = get_aligned_image_size(info, length, offset);
213
214 if (info->read(info,
215 sector + get_aligned_image_offset(info, offset),
216 nr_sectors, (void *)load_ptr) != nr_sectors)
217 return -EIO;
218
219 debug("External data: dst=%lx, offset=%x, size=%lx\n",
220 load_ptr, offset, (unsigned long)length);
221 src = (void *)load_ptr + overhead;
222 } else {
223 /* Embedded data */
224 if (fit_image_get_data(fit, node, &data, &length)) {
225 puts("Cannot get image data/size\n");
226 return -ENOENT;
227 }
228 debug("Embedded data: dst=%lx, size=%lx\n", load_addr,
229 (unsigned long)length);
230 src = (void *)data;
231 }
Andre Przywara29053e92017-04-26 01:32:36 +0100232
Andre Przywara29053e92017-04-26 01:32:36 +0100233#ifdef CONFIG_SPL_FIT_IMAGE_POST_PROCESS
234 board_fit_image_post_process(&src, &length);
235#endif
236
York Suna6945fe2017-08-15 11:14:43 -0700237 if (IS_ENABLED(CONFIG_SPL_OS_BOOT) &&
238 IS_ENABLED(CONFIG_SPL_GZIP) &&
239 image_comp == IH_COMP_GZIP &&
240 type == IH_TYPE_KERNEL) {
York Sun25d65f12017-09-15 08:21:13 -0700241 size = length;
York Suna6945fe2017-08-15 11:14:43 -0700242 if (gunzip((void *)load_addr, CONFIG_SYS_BOOTM_LEN,
York Sun25d65f12017-09-15 08:21:13 -0700243 src, &size)) {
York Suna6945fe2017-08-15 11:14:43 -0700244 puts("Uncompressing error\n");
245 return -EIO;
246 }
York Sun25d65f12017-09-15 08:21:13 -0700247 length = size;
York Suna6945fe2017-08-15 11:14:43 -0700248 } else {
249 memcpy((void *)load_addr, src, length);
250 }
Andre Przywara29053e92017-04-26 01:32:36 +0100251
252 if (image_info) {
253 image_info->load_addr = load_addr;
254 image_info->size = length;
255 image_info->entry_point = fdt_getprop_u32(fit, node, "entry");
256 }
257
Jun Nieadf5d1c2018-02-27 16:55:58 +0800258#ifdef CONFIG_SPL_FIT_SIGNATURE
259 printf("## Checking hash(es) for Image %s ...\n",
260 fit_get_name(fit, node, NULL));
261 ret = fit_image_verify_with_data(fit, node,
262 (const void *)load_addr, length);
263 printf("\n");
264 return !ret;
265#else
Andre Przywara29053e92017-04-26 01:32:36 +0100266 return 0;
Jun Nieadf5d1c2018-02-27 16:55:58 +0800267#endif
Andre Przywara29053e92017-04-26 01:32:36 +0100268}
269
Philipp Tomsich1345ffa2017-09-13 21:29:32 +0200270static int spl_fit_append_fdt(struct spl_image_info *spl_image,
271 struct spl_load_info *info, ulong sector,
272 void *fit, int images, ulong base_offset)
273{
274 struct spl_image_info image_info;
275 int node, ret;
276
277 /* Figure out which device tree the board wants to use */
278 node = spl_fit_get_image_node(fit, images, FIT_FDT_PROP, 0);
279 if (node < 0) {
280 debug("%s: cannot find FDT node\n", __func__);
281 return node;
282 }
283
284 /*
285 * Read the device tree and place it after the image.
286 * Align the destination address to ARCH_DMA_MINALIGN.
287 */
288 image_info.load_addr = spl_image->load_addr + spl_image->size;
289 ret = spl_load_fit_image(info, sector, fit, base_offset, node,
290 &image_info);
Philipp Tomsiche61eff92017-09-13 21:29:34 +0200291
292 if (ret < 0)
293 return ret;
294
295 /* Make the load-address of the FDT available for the SPL framework */
296 spl_image->fdt_addr = (void *)image_info.load_addr;
Philipp Tomsich4faa0112017-11-24 13:26:03 +0100297#if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY)
Philipp Tomsiche61eff92017-09-13 21:29:34 +0200298 /* Try to make space, so we can inject details on the loadables */
299 ret = fdt_shrink_to_minimum(spl_image->fdt_addr, 8192);
Philipp Tomsich4faa0112017-11-24 13:26:03 +0100300#endif
Philipp Tomsiche61eff92017-09-13 21:29:34 +0200301
Philipp Tomsich1345ffa2017-09-13 21:29:32 +0200302 return ret;
303}
304
Philipp Tomsiche61eff92017-09-13 21:29:34 +0200305static int spl_fit_record_loadable(const void *fit, int images, int index,
306 void *blob, struct spl_image_info *image)
307{
Philipp Tomsich4faa0112017-11-24 13:26:03 +0100308 int ret = 0;
309#if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY)
Philipp Tomsiche61eff92017-09-13 21:29:34 +0200310 char *name;
Philipp Tomsich4faa0112017-11-24 13:26:03 +0100311 int node;
Philipp Tomsiche61eff92017-09-13 21:29:34 +0200312
313 ret = spl_fit_get_image_name(fit, images, "loadables",
314 index, &name);
315 if (ret < 0)
316 return ret;
317
318 node = spl_fit_get_image_node(fit, images, "loadables", index);
319
320 ret = fdt_record_loadable(blob, index, name, image->load_addr,
321 image->size, image->entry_point,
322 fdt_getprop(fit, node, "type", NULL),
323 fdt_getprop(fit, node, "os", NULL));
Philipp Tomsich4faa0112017-11-24 13:26:03 +0100324#endif
Philipp Tomsiche61eff92017-09-13 21:29:34 +0200325 return ret;
326}
327
Philipp Tomsich4faa0112017-11-24 13:26:03 +0100328static int spl_fit_image_get_os(const void *fit, int noffset, uint8_t *os)
329{
330#if CONFIG_IS_ENABLED(FIT_IMAGE_TINY)
331 return -ENOTSUPP;
332#else
333 return fit_image_get_os(fit, noffset, os);
334#endif
335}
336
Simon Glass43a734f2016-09-24 18:20:16 -0600337int spl_load_simple_fit(struct spl_image_info *spl_image,
338 struct spl_load_info *info, ulong sector, void *fit)
Simon Glassa6131a22016-02-22 22:55:56 -0700339{
340 int sectors;
Andre Przywara29053e92017-04-26 01:32:36 +0100341 ulong size;
Simon Glassa6131a22016-02-22 22:55:56 -0700342 unsigned long count;
Andre Przywara29053e92017-04-26 01:32:36 +0100343 struct spl_image_info image_info;
York Suna058b8a2017-08-15 11:14:45 -0700344 int node = -1;
345 int images, ret;
Lokesh Vutlaf62cef12016-05-24 10:34:38 +0530346 int base_offset, align_len = ARCH_DMA_MINALIGN - 1;
Andre Przywarae7c58562017-04-26 01:32:37 +0100347 int index = 0;
Simon Glassa6131a22016-02-22 22:55:56 -0700348
349 /*
York Suna058b8a2017-08-15 11:14:45 -0700350 * For FIT with external data, figure out where the external images
351 * start. This is the base for the data-offset properties in each
352 * image.
Simon Glassa6131a22016-02-22 22:55:56 -0700353 */
354 size = fdt_totalsize(fit);
355 size = (size + 3) & ~3;
356 base_offset = (size + 3) & ~3;
357
358 /*
359 * So far we only have one block of data from the FIT. Read the entire
360 * thing, including that first block, placing it so it finishes before
361 * where we will load the image.
362 *
363 * Note that we will load the image such that its first byte will be
364 * at the load address. Since that byte may be part-way through a
365 * block, we may load the image up to one block before the load
366 * address. So take account of that here by subtracting an addition
367 * block length from the FIT start position.
368 *
369 * In fact the FIT has its own load address, but we assume it cannot
370 * be before CONFIG_SYS_TEXT_BASE.
York Suna058b8a2017-08-15 11:14:45 -0700371 *
372 * For FIT with data embedded, data is loaded as part of FIT image.
373 * For FIT with external data, data is not loaded in this step.
Simon Glassa6131a22016-02-22 22:55:56 -0700374 */
Lokesh Vutlac8405852016-06-01 10:28:31 +0530375 fit = (void *)((CONFIG_SYS_TEXT_BASE - size - info->bl_len -
376 align_len) & ~align_len);
Lokesh Vutlaf62cef12016-05-24 10:34:38 +0530377 sectors = get_aligned_image_size(info, size, 0);
Simon Glassa6131a22016-02-22 22:55:56 -0700378 count = info->read(info, sector, sectors, fit);
379 debug("fit read sector %lx, sectors=%d, dst=%p, count=%lu\n",
380 sector, sectors, fit, count);
381 if (count == 0)
382 return -EIO;
383
Andre Przywara525e9c92017-04-26 01:32:34 +0100384 /* find the node holding the images information */
Simon Glassa6131a22016-02-22 22:55:56 -0700385 images = fdt_path_offset(fit, FIT_IMAGES_PATH);
386 if (images < 0) {
387 debug("%s: Cannot find /images node: %d\n", __func__, images);
388 return -1;
389 }
Andre Przywara525e9c92017-04-26 01:32:34 +0100390
Philipp Tomsich1345ffa2017-09-13 21:29:32 +0200391 /*
392 * Find the U-Boot image using the following search order:
393 * - start at 'firmware' (e.g. an ARM Trusted Firmware)
394 * - fall back 'kernel' (e.g. a Falcon-mode OS boot
395 * - fall back to using the first 'loadables' entry
396 */
397 if (node < 0)
Michal Simekb766e8f2018-03-26 16:31:26 +0200398 node = spl_fit_get_image_node(fit, images, FIT_FIRMWARE_PROP,
399 0);
York Suna058b8a2017-08-15 11:14:45 -0700400#ifdef CONFIG_SPL_OS_BOOT
York Suna058b8a2017-08-15 11:14:45 -0700401 if (node < 0)
Philipp Tomsich1345ffa2017-09-13 21:29:32 +0200402 node = spl_fit_get_image_node(fit, images, FIT_KERNEL_PROP, 0);
York Suna058b8a2017-08-15 11:14:45 -0700403#endif
Andre Przywara525e9c92017-04-26 01:32:34 +0100404 if (node < 0) {
405 debug("could not find firmware image, trying loadables...\n");
406 node = spl_fit_get_image_node(fit, images, "loadables", 0);
Andre Przywarae7c58562017-04-26 01:32:37 +0100407 /*
408 * If we pick the U-Boot image from "loadables", start at
409 * the second image when later loading additional images.
410 */
411 index = 1;
Andre Przywara525e9c92017-04-26 01:32:34 +0100412 }
Simon Glassa6131a22016-02-22 22:55:56 -0700413 if (node < 0) {
Andre Przywara525e9c92017-04-26 01:32:34 +0100414 debug("%s: Cannot find u-boot image node: %d\n",
415 __func__, node);
Simon Glassa6131a22016-02-22 22:55:56 -0700416 return -1;
417 }
418
Andre Przywara29053e92017-04-26 01:32:36 +0100419 /* Load the image and set up the spl_image structure */
420 ret = spl_load_fit_image(info, sector, fit, base_offset, node,
421 spl_image);
422 if (ret)
423 return ret;
Daniel Allredcf839bd2016-06-27 09:19:21 -0500424
Philipp Tomsich1345ffa2017-09-13 21:29:32 +0200425 /*
426 * For backward compatibility, we treat the first node that is
427 * as a U-Boot image, if no OS-type has been declared.
428 */
Philipp Tomsich4faa0112017-11-24 13:26:03 +0100429 if (!spl_fit_image_get_os(fit, node, &spl_image->os))
York Suna058b8a2017-08-15 11:14:45 -0700430 debug("Image OS is %s\n", genimg_get_os_name(spl_image->os));
Philipp Tomsich1345ffa2017-09-13 21:29:32 +0200431#if !defined(CONFIG_SPL_OS_BOOT)
432 else
433 spl_image->os = IH_OS_U_BOOT;
York Suna058b8a2017-08-15 11:14:45 -0700434#endif
Simon Glassa6131a22016-02-22 22:55:56 -0700435
Philipp Tomsich1345ffa2017-09-13 21:29:32 +0200436 /*
437 * Booting a next-stage U-Boot may require us to append the FDT.
438 * We allow this to fail, as the U-Boot image might embed its FDT.
439 */
440 if (spl_image->os == IH_OS_U_BOOT)
441 spl_fit_append_fdt(spl_image, info, sector, fit,
442 images, base_offset);
Andre Przywarae7c58562017-04-26 01:32:37 +0100443
444 /* Now check if there are more images for us to load */
445 for (; ; index++) {
Philipp Tomsich1345ffa2017-09-13 21:29:32 +0200446 uint8_t os_type = IH_OS_INVALID;
447
Andre Przywarae7c58562017-04-26 01:32:37 +0100448 node = spl_fit_get_image_node(fit, images, "loadables", index);
449 if (node < 0)
450 break;
451
452 ret = spl_load_fit_image(info, sector, fit, base_offset, node,
453 &image_info);
454 if (ret < 0)
455 continue;
456
Philipp Tomsich4faa0112017-11-24 13:26:03 +0100457 if (!spl_fit_image_get_os(fit, node, &os_type))
Philipp Tomsich1345ffa2017-09-13 21:29:32 +0200458 debug("Loadable is %s\n", genimg_get_os_name(os_type));
459
Philipp Tomsiche61eff92017-09-13 21:29:34 +0200460 if (os_type == IH_OS_U_BOOT) {
461 spl_fit_append_fdt(&image_info, info, sector,
Philipp Tomsich1345ffa2017-09-13 21:29:32 +0200462 fit, images, base_offset);
Philipp Tomsiche61eff92017-09-13 21:29:34 +0200463 spl_image->fdt_addr = image_info.fdt_addr;
464 }
Philipp Tomsich1345ffa2017-09-13 21:29:32 +0200465
Andre Przywarae7c58562017-04-26 01:32:37 +0100466 /*
467 * If the "firmware" image did not provide an entry point,
468 * use the first valid entry point from the loadables.
469 */
470 if (spl_image->entry_point == FDT_ERROR &&
471 image_info.entry_point != FDT_ERROR)
472 spl_image->entry_point = image_info.entry_point;
Philipp Tomsiche61eff92017-09-13 21:29:34 +0200473
474 /* Record our loadables into the FDT */
475 if (spl_image->fdt_addr)
476 spl_fit_record_loadable(fit, images, index,
477 spl_image->fdt_addr,
478 &image_info);
Andre Przywarae7c58562017-04-26 01:32:37 +0100479 }
480
481 /*
482 * If a platform does not provide CONFIG_SYS_UBOOT_START, U-Boot's
483 * Makefile will set it to 0 and it will end up as the entry point
484 * here. What it actually means is: use the load address.
485 */
486 if (spl_image->entry_point == FDT_ERROR || spl_image->entry_point == 0)
487 spl_image->entry_point = spl_image->load_addr;
488
489 return 0;
Simon Glassa6131a22016-02-22 22:55:56 -0700490}