Commit 8205eb43 authored by Simon Glass's avatar Simon Glass
Browse files

wipo

parent aa050d26
......@@ -6,6 +6,7 @@
*
* SPDX-License-Identifier: GPL-2.0+
*/
#define DEBUG
#include <common.h>
#include <dm.h>
#include <spl.h>
......@@ -18,11 +19,72 @@
DECLARE_GLOBAL_DATA_PTR;
static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector)
static int mmc_load_legacy(struct mmc *mmc, ulong sector,
struct image_header *header)
{
u32 image_size_sectors;
unsigned long count;
spl_parse_image_header(header);
/* convert size to sectors - round up */
image_size_sectors = (spl_image.size + mmc->read_bl_len - 1) /
mmc->read_bl_len;
/* Read the header too to avoid extra memcpy */
count = mmc->block_dev.block_read(&mmc->block_dev, sector,
image_size_sectors,
(void *)(ulong)spl_image.load_addr);
debug("read %x sectors to %x\n", image_size_sectors,
spl_image.load_addr);
if (count != image_size_sectors)
return -EIO;
return 0;
}
static int mmc_load_fit(struct mmc *mmc, ulong sector, void *fdt)
{
u32 image_size_sectors;
uint64_t addr64, size64;
ulong load, size, base;
unsigned long count;
int offset;
int ret;
size = fdt_totalsize(fdt);
debug("size=%lu\n", size);
if (!fdt_num_mem_rsv(fdt)) {
/* fit_build_fit() does this correctly. What is wrong? */
printf("FIT: missing image offset\n");
return -EINVAL;
}
ret = fdt_get_mem_rsv(fdt, 0, &addr64, &size64);
if (ret)
return ret;
offset = addr64;
load = size64;
base = load - offset;
/* convert size to sectors - round up */
image_size_sectors = (size + mmc->read_bl_len - 1) / mmc->read_bl_len;
/* Read the header too to avoid extra memcpy */
count = mmc->block_dev.block_read(&mmc->block_dev, sector,
image_size_sectors,
(void *)base);
debug("read %x sectors to %x\n", image_size_sectors,
spl_image.load_addr);
if (count != image_size_sectors)
return -EIO;
return 0;
}
static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector)
{
unsigned long count;
struct image_header *header;
int ret = 0;
header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
sizeof(struct image_header));
......@@ -30,29 +92,28 @@ static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector)
/* read image header to find the image size & load address */
count = mmc->block_dev.block_read(&mmc->block_dev, sector, 1, header);
debug("read sector %lx, count=%lu\n", sector, count);
if (count == 0)
if (count == 0) {
ret = -EIO;
goto end;
}
if (image_get_magic(header) != IH_MAGIC) {
puts("bad magic\n");
switch (image_get_magic(header)) {
case IH_MAGIC:
ret = mmc_load_legacy(mmc, sector, header);
break;
#ifdef CONFIG_SPL_LOAD_FIT
case FDT_MAGIC:
debug("Found FIT\n");
ret = mmc_load_fit(mmc, sector, header);
break;
#endif
default:
printf("bad magic %x\n", image_get_magic(header));
return -1;
}
spl_parse_image_header(header);
/* convert size to sectors - round up */
image_size_sectors = (spl_image.size + mmc->read_bl_len - 1) /
mmc->read_bl_len;
/* Read the header too to avoid extra memcpy */
count = mmc->block_dev.block_read(&mmc->block_dev, sector,
image_size_sectors,
(void *)(ulong)spl_image.load_addr);
debug("read %x sectors to %x\n", image_size_sectors,
spl_image.load_addr);
end:
if (count == 0) {
if (ret) {
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
puts("spl: mmc block read error\n");
#endif
......
......@@ -147,6 +147,12 @@ static int fdt_property_strf(void *fdt, const char *name, const char *fmt, ...)
return fdt_property_string(fdt, name, str);
}
/**
* fit_write_images() - Write out a list of images to the FIT
*
* We always include the main image (params->datafile). If there are device
* tree files, we include an fdt@ node for each of those too.
*/
static int fit_write_images(struct image_tool_params *params, char *fdt)
{
struct content_info *cont;
......@@ -170,7 +176,7 @@ static int fit_write_images(struct image_tool_params *params, char *fdt)
fdt_property_string(fdt, "os", genimg_get_os_name(params->os));
fdt_property_string(fdt, "compression",
genimg_get_comp_name(params->comp));
fdt_property_u32(fdt, "load", params->addr);;
fdt_property_u32(fdt, "load", params->addr);
fdt_property_u32(fdt, "entry", params->ep);
fdt_end_node(fdt);
......@@ -185,7 +191,12 @@ static int fit_write_images(struct image_tool_params *params, char *fdt)
snprintf(str, sizeof(str), "%s@%d", FIT_FDT_PROP, ++upto);
fdt_begin_node(fdt, str);
/* Use the base name as the 'name' field */
/*
* Use the base name as the 'name' field. So for example:
*
* "arch/arm/dts/sun7i-a20-bananapro.dtb"
* becomes "sun7i-a20-bananapro"
*/
p = strrchr(cont->fname, '/');
start = p ? p + 1 : cont->fname;
p = strrchr(cont->fname, '.');
......@@ -212,6 +223,15 @@ static int fit_write_images(struct image_tool_params *params, char *fdt)
return 0;
}
/**
* fit_write_configs() - Write out a list of configurations to the FIT
*
* If there are device tree files, we include a configuration for each, which
* selects the main image (params->datafile) and its corresponding device
* tree file.
*
* Otherwise we just create a configuration with the main image in it.
*/
static void fit_write_configs(struct image_tool_params *params, char *fdt)
{
struct content_info *cont;
......@@ -251,7 +271,8 @@ static void fit_write_configs(struct image_tool_params *params, char *fdt)
static int fit_build_fdt(struct image_tool_params *params, char *fdt, int size)
{
int ret;
int ret, node, len;
const char *ptr;
ret = fdt_create(fdt, size);
if (ret)
......@@ -272,6 +293,39 @@ static int fit_build_fdt(struct image_tool_params *params, char *fdt, int size)
if (ret)
return ret;
ret = fdt_open_into(fdt, fdt, size);
if (ret) {
fprintf(stderr, "%s: Cannot expand FDT space: %s\n",
params->cmdname, fdt_strerror(ret));
return -1;
}
/* store the position of the first byte of the image */
node = fdt_path_offset(fdt, FIT_IMAGES_PATH);
if (node < 0) {
fprintf(stderr, "%s: Cannot find /images node: %s\n",
params->cmdname, fdt_strerror(node));
return -1;
}
node = fdt_first_subnode(fdt, node);
if (node < 0) {
fprintf(stderr, "%s: Cannot find first image node: %s\n",
params->cmdname, fdt_strerror(node));
return -1;
}
ptr = fdt_getprop(fdt, node, "data", &len);
if (!ptr) {
fprintf(stderr, "%s: Cannot find data property: %s\n",
params->cmdname, fdt_strerror(len));
return len;
}
ret = fdt_add_mem_rsv(fdt, ptr - fdt, params->addr);
if (ret) {
fprintf(stderr, "%s: Cannot add image position: %s\n",
params->cmdname, fdt_strerror(ret));
return ret;
}
return fdt_totalsize(fdt);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment