*
* Return: 0 on success, or a negative error number
*/
-static int spl_fit_get_image_name(const void *fit, int images,
+static int spl_fit_get_image_name(const struct spl_fit_info *ctx,
const char *type, int index,
const char **outname)
{
int len, i;
bool found = true;
- conf_node = fit_find_config_node(fit);
+ conf_node = fit_find_config_node(ctx->fit);
if (conf_node < 0) {
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
printf("No matching DT out of these options:\n");
- for (node = fdt_first_subnode(fit, conf_node);
+ for (node = fdt_first_subnode(ctx->fit, conf_node);
node >= 0;
- node = fdt_next_subnode(fit, node)) {
- name = fdt_getprop(fit, node, "description", &len);
+ node = fdt_next_subnode(ctx->fit, node)) {
+ name = fdt_getprop(ctx->fit, node, "description", &len);
printf(" %s\n", name);
}
#endif
return conf_node;
}
- name = fdt_getprop(fit, conf_node, type, &len);
+ name = fdt_getprop(ctx->fit, conf_node, type, &len);
if (!name) {
debug("cannot find property '%s': %d\n", type, len);
return -EINVAL;
* node name.
*/
int node;
- int images = fdt_path_offset(fit, FIT_IMAGES_PATH);
+ int images = fdt_path_offset(ctx->fit, FIT_IMAGES_PATH);
- node = find_node_from_desc(fit, images, str);
+ node = find_node_from_desc(ctx->fit, images, str);
if (node > 0)
- str = fdt_get_name(fit, node, NULL);
+ str = fdt_get_name(ctx->fit, node, NULL);
found = true;
}
* Return: the node offset of the respective image node or a negative
* error number.
*/
-static int spl_fit_get_image_node(const void *fit, int images,
+static int spl_fit_get_image_node(const struct spl_fit_info *ctx,
const char *type, int index)
{
const char *str;
int err;
int node;
- err = spl_fit_get_image_name(fit, images, type, index, &str);
+ err = spl_fit_get_image_name(ctx, type, index, &str);
if (err)
return err;
debug("%s: '%s'\n", type, str);
- node = fdt_subnode_offset(fit, images, str);
+ node = fdt_subnode_offset(ctx->fit, ctx->images_node, str);
if (node < 0) {
pr_err("cannot find image node '%s': %d\n", str, node);
return -EINVAL;
* spl_load_fit_image(): load the image described in a certain FIT node
* @info: points to information about the device to load data from
* @sector: the start sector of the FIT image on the device
- * @fit: points to the flattened device tree blob describing the FIT
- * image
- * @base_offset: the beginning of the data area containing the actual
- * image data, relative to the beginning of the FIT
+ * @ctx: points to the FIT context structure
* @node: offset of the DT node describing the image to load (relative
* to @fit)
* @image_info: will be filled with information about the loaded image
* Return: 0 on success or a negative error number.
*/
static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
- void *fit, ulong base_offset, int node,
+ const struct spl_fit_info *ctx, int node,
struct spl_image_info *image_info)
{
int offset;
int align_len = ARCH_DMA_MINALIGN - 1;
uint8_t image_comp = -1, type = -1;
const void *data;
+ const void *fit = ctx->fit;
bool external_data = false;
if (IS_ENABLED(CONFIG_SPL_FPGA) ||
if (!fit_image_get_data_position(fit, node, &offset)) {
external_data = true;
} else if (!fit_image_get_data_offset(fit, node, &offset)) {
- offset += base_offset;
+ offset += ctx->ext_data_offset;
external_data = true;
}
static int spl_fit_append_fdt(struct spl_image_info *spl_image,
struct spl_load_info *info, ulong sector,
- void *fit, int images, ulong base_offset)
+ const struct spl_fit_info *ctx)
{
struct spl_image_info image_info;
int node, ret = 0, index = 0;
image_info.load_addr = spl_image->load_addr + spl_image->size;
/* Figure out which device tree the board wants to use */
- node = spl_fit_get_image_node(fit, images, FIT_FDT_PROP, index++);
+ node = spl_fit_get_image_node(ctx, FIT_FDT_PROP, index++);
if (node < 0) {
debug("%s: cannot find FDT node\n", __func__);
else
return node;
} else {
- ret = spl_load_fit_image(info, sector, fit, base_offset, node,
+ ret = spl_load_fit_image(info, sector, ctx, node,
&image_info);
if (ret < 0)
return ret;
void *tmpbuffer = NULL;
for (; ; index++) {
- node = spl_fit_get_image_node(fit, images, FIT_FDT_PROP,
- index);
+ node = spl_fit_get_image_node(ctx, FIT_FDT_PROP, index);
if (node == -E2BIG) {
debug("%s: No additional FDT node\n", __func__);
break;
__func__);
}
image_info.load_addr = (ulong)tmpbuffer;
- ret = spl_load_fit_image(info, sector, fit, base_offset,
+ ret = spl_load_fit_image(info, sector, ctx,
node, &image_info);
if (ret < 0)
break;
(void *)image_info.load_addr);
if (ret) {
pr_err("failed to apply DT overlay %s\n",
- fit_get_name(fit, node, NULL));
+ fit_get_name(ctx->fit, node, NULL));
break;
}
debug("%s: DT overlay %s applied\n", __func__,
- fit_get_name(fit, node, NULL));
+ fit_get_name(ctx->fit, node, NULL));
}
free(tmpbuffer);
if (ret)
return ret;
}
-static int spl_fit_record_loadable(const void *fit, int images, int index,
+static int spl_fit_record_loadable(const struct spl_fit_info *ctx, int index,
void *blob, struct spl_image_info *image)
{
int ret = 0;
const char *name;
int node;
- ret = spl_fit_get_image_name(fit, images, "loadables",
- index, &name);
+ ret = spl_fit_get_image_name(ctx, "loadables", index, &name);
if (ret < 0)
return ret;
- node = spl_fit_get_image_node(fit, images, "loadables", index);
+ node = spl_fit_get_image_node(ctx, "loadables", index);
ret = fdt_record_loadable(blob, index, name, image->load_addr,
image->size, image->entry_point,
- fdt_getprop(fit, node, "type", NULL),
- fdt_getprop(fit, node, "os", NULL));
+ fdt_getprop(ctx->fit, node, "type", NULL),
+ fdt_getprop(ctx->fit, node, "os", NULL));
#endif
return ret;
}
struct spl_image_info image_info;
struct spl_fit_info ctx;
int node = -1;
- int images, ret;
- int base_offset;
+ int ret;
int index = 0;
int firmware_node;
if (ret < 0)
return ret;
- images = ctx.images_node;
- fit = (void *)ctx.fit;
- base_offset = ctx.ext_data_offset;
-
#ifdef CONFIG_SPL_FPGA
- node = spl_fit_get_image_node(fit, images, "fpga", 0);
+ node = spl_fit_get_image_node(&ctx, "fpga", 0);
if (node >= 0) {
/* Load the image and set up the spl_image structure */
- ret = spl_load_fit_image(info, sector, fit, base_offset, node,
- spl_image);
+ ret = spl_load_fit_image(info, sector, &ctx, node, spl_image);
if (ret) {
printf("%s: Cannot load the FPGA: %i\n", __func__, ret);
return ret;
* - fall back to using the first 'loadables' entry
*/
if (node < 0)
- node = spl_fit_get_image_node(fit, images, FIT_FIRMWARE_PROP,
- 0);
+ node = spl_fit_get_image_node(&ctx, FIT_FIRMWARE_PROP, 0);
#ifdef CONFIG_SPL_OS_BOOT
if (node < 0)
- node = spl_fit_get_image_node(fit, images, FIT_KERNEL_PROP, 0);
+ node = spl_fit_get_image_node(&ctx, FIT_KERNEL_PROP, 0);
#endif
if (node < 0) {
debug("could not find firmware image, trying loadables...\n");
- node = spl_fit_get_image_node(fit, images, "loadables", 0);
+ node = spl_fit_get_image_node(&ctx, "loadables", 0);
/*
* If we pick the U-Boot image from "loadables", start at
* the second image when later loading additional images.
}
/* Load the image and set up the spl_image structure */
- ret = spl_load_fit_image(info, sector, fit, base_offset, node,
- spl_image);
+ ret = spl_load_fit_image(info, sector, &ctx, node, spl_image);
if (ret)
return ret;
* For backward compatibility, we treat the first node that is
* as a U-Boot image, if no OS-type has been declared.
*/
- if (!spl_fit_image_get_os(fit, node, &spl_image->os))
+ if (!spl_fit_image_get_os(ctx.fit, node, &spl_image->os))
debug("Image OS is %s\n", genimg_get_os_name(spl_image->os));
#if !defined(CONFIG_SPL_OS_BOOT)
else
* We allow this to fail, as the U-Boot image might embed its FDT.
*/
if (spl_image->os == IH_OS_U_BOOT) {
- ret = spl_fit_append_fdt(spl_image, info, sector, fit,
- images, base_offset);
+ ret = spl_fit_append_fdt(spl_image, info, sector, &ctx);
if (!IS_ENABLED(CONFIG_OF_EMBED) && ret < 0)
return ret;
}
for (; ; index++) {
uint8_t os_type = IH_OS_INVALID;
- node = spl_fit_get_image_node(fit, images, "loadables", index);
+ node = spl_fit_get_image_node(&ctx, "loadables", index);
if (node < 0)
break;
if (firmware_node == node)
continue;
- ret = spl_load_fit_image(info, sector, fit, base_offset, node,
- &image_info);
+ ret = spl_load_fit_image(info, sector, &ctx, node, &image_info);
if (ret < 0) {
printf("%s: can't load image loadables index %d (ret = %d)\n",
__func__, index, ret);
return ret;
}
- if (!spl_fit_image_get_os(fit, node, &os_type))
+ if (!spl_fit_image_get_os(ctx.fit, node, &os_type))
debug("Loadable is %s\n", genimg_get_os_name(os_type));
if (os_type == IH_OS_U_BOOT) {
- spl_fit_append_fdt(&image_info, info, sector,
- fit, images, base_offset);
+ spl_fit_append_fdt(&image_info, info, sector, &ctx);
spl_image->fdt_addr = image_info.fdt_addr;
}
/* Record our loadables into the FDT */
if (spl_image->fdt_addr)
- spl_fit_record_loadable(fit, images, index,
+ spl_fit_record_loadable(&ctx, index,
spl_image->fdt_addr,
&image_info);
}
spl_image->flags |= SPL_FIT_FOUND;
#ifdef CONFIG_IMX_HAB
- board_spl_fit_post_load(fit);
+ board_spl_fit_post_load(ctx.fit);
#endif
return 0;