spl: Allow to load a FIT containing U-Boot from FS
This provides a way to load a FIT containing U-Boot and a selection of device tree files from a File system. Making sure that all the reads and writes are aligned to their respective needs. Tested-by: Michal Simek <michal.simek@xilinx.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com> Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com> [trini: Make this still apply with Michal's alignment change for 'fit'] Signed-off-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
parent
4d9d34a7f2
commit
eafd5410af
|
@ -87,6 +87,42 @@ static int spl_fit_select_fdt(const void *fdt, int images, int *fdt_offsetp)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int get_aligned_image_offset(struct spl_load_info *info, int offset)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* If it is a FS read, get the first address before offset which is
|
||||||
|
* aligned to ARCH_DMA_MINALIGN. If it is raw read return the
|
||||||
|
* block number to which offset belongs.
|
||||||
|
*/
|
||||||
|
if (info->filename)
|
||||||
|
return offset & ~(ARCH_DMA_MINALIGN - 1);
|
||||||
|
|
||||||
|
return offset / info->bl_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int get_aligned_image_overhead(struct spl_load_info *info, int offset)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* If it is a FS read, get the difference between the offset and
|
||||||
|
* the first address before offset which is aligned to
|
||||||
|
* ARCH_DMA_MINALIGN. If it is raw read return the offset within the
|
||||||
|
* block.
|
||||||
|
*/
|
||||||
|
if (info->filename)
|
||||||
|
return offset & (ARCH_DMA_MINALIGN - 1);
|
||||||
|
|
||||||
|
return offset % info->bl_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int get_aligned_image_size(struct spl_load_info *info, int data_size,
|
||||||
|
int offset)
|
||||||
|
{
|
||||||
|
if (info->filename)
|
||||||
|
return data_size + get_aligned_image_overhead(info, offset);
|
||||||
|
|
||||||
|
return (data_size + info->bl_len - 1) / info->bl_len;
|
||||||
|
}
|
||||||
|
|
||||||
int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
|
int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
|
||||||
{
|
{
|
||||||
int sectors;
|
int sectors;
|
||||||
|
@ -96,7 +132,7 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
|
||||||
void *load_ptr;
|
void *load_ptr;
|
||||||
int fdt_offset, fdt_len;
|
int fdt_offset, fdt_len;
|
||||||
int data_offset, data_size;
|
int data_offset, data_size;
|
||||||
int base_offset;
|
int base_offset, align_len = ARCH_DMA_MINALIGN - 1;
|
||||||
int src_sector;
|
int src_sector;
|
||||||
void *dst;
|
void *dst;
|
||||||
|
|
||||||
|
@ -124,7 +160,7 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
|
||||||
*/
|
*/
|
||||||
fit = (void *)(CONFIG_SYS_TEXT_BASE - size - info->bl_len);
|
fit = (void *)(CONFIG_SYS_TEXT_BASE - size - info->bl_len);
|
||||||
fit = (void *)ALIGN((ulong)fit, 8);
|
fit = (void *)ALIGN((ulong)fit, 8);
|
||||||
sectors = (size + info->bl_len - 1) / info->bl_len;
|
sectors = get_aligned_image_size(info, size, 0);
|
||||||
count = info->read(info, sector, sectors, fit);
|
count = info->read(info, sector, sectors, fit);
|
||||||
debug("fit read sector %lx, sectors=%d, dst=%p, count=%lu\n",
|
debug("fit read sector %lx, sectors=%d, dst=%p, count=%lu\n",
|
||||||
sector, sectors, fit, count);
|
sector, sectors, fit, count);
|
||||||
|
@ -157,19 +193,23 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
|
||||||
* byte will be at 'load'. This may mean we need to load it starting
|
* byte will be at 'load'. This may mean we need to load it starting
|
||||||
* before then, since we can only read whole blocks.
|
* before then, since we can only read whole blocks.
|
||||||
*/
|
*/
|
||||||
sectors = (data_size + info->bl_len - 1) / info->bl_len;
|
|
||||||
data_offset += base_offset;
|
data_offset += base_offset;
|
||||||
|
sectors = get_aligned_image_size(info, data_size, data_offset);
|
||||||
load_ptr = (void *)load;
|
load_ptr = (void *)load;
|
||||||
debug("U-Boot size %x, data %p\n", data_size, load_ptr);
|
debug("U-Boot size %x, data %p\n", data_size, load_ptr);
|
||||||
dst = load_ptr - (data_offset % info->bl_len);
|
dst = load_ptr;
|
||||||
|
|
||||||
/* Read the image */
|
/* Read the image */
|
||||||
src_sector = sector + data_offset / info->bl_len;
|
src_sector = sector + get_aligned_image_offset(info, data_offset);
|
||||||
debug("image: data_offset=%x, dst=%p, src_sector=%x, sectors=%x\n",
|
debug("Aligned image read: dst=%p, src_sector=%x, sectors=%x\n",
|
||||||
data_offset, dst, src_sector, sectors);
|
dst, src_sector, sectors);
|
||||||
count = info->read(info, src_sector, sectors, dst);
|
count = info->read(info, src_sector, sectors, dst);
|
||||||
if (count != sectors)
|
if (count != sectors)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
debug("image: dst=%p, data_offset=%x, size=%x\n", dst, data_offset,
|
||||||
|
data_size);
|
||||||
|
memcpy(dst, dst + get_aligned_image_overhead(info, data_offset),
|
||||||
|
data_size);
|
||||||
|
|
||||||
/* Figure out which device tree the board wants to use */
|
/* Figure out which device tree the board wants to use */
|
||||||
fdt_len = spl_fit_select_fdt(fit, images, &fdt_offset);
|
fdt_len = spl_fit_select_fdt(fit, images, &fdt_offset);
|
||||||
|
@ -179,14 +219,15 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
|
||||||
/*
|
/*
|
||||||
* Read the device tree and place it after the image. There may be
|
* Read the device tree and place it after the image. There may be
|
||||||
* some extra data before it since we can only read entire blocks.
|
* some extra data before it since we can only read entire blocks.
|
||||||
|
* And also align the destination address to ARCH_DMA_MINALIGN.
|
||||||
*/
|
*/
|
||||||
dst = load_ptr + data_size;
|
dst = (void *)((load + data_size + align_len) & ~align_len);
|
||||||
fdt_offset += base_offset;
|
fdt_offset += base_offset;
|
||||||
sectors = (fdt_len + info->bl_len - 1) / info->bl_len;
|
sectors = get_aligned_image_size(info, fdt_len, fdt_offset);
|
||||||
count = info->read(info, sector + fdt_offset / info->bl_len, sectors,
|
src_sector = sector + get_aligned_image_offset(info, fdt_offset);
|
||||||
dst);
|
count = info->read(info, src_sector, sectors, dst);
|
||||||
debug("fit read %x sectors to %x, dst %p, data_offset %x\n",
|
debug("Aligned fdt read: dst %p, src_sector = %x, sectors %x\n",
|
||||||
sectors, spl_image.load_addr, dst, fdt_offset);
|
dst, src_sector, sectors);
|
||||||
if (count != sectors)
|
if (count != sectors)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
|
@ -195,7 +236,10 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
|
||||||
* After this we will have the U-Boot image and its device tree ready
|
* After this we will have the U-Boot image and its device tree ready
|
||||||
* for us to start.
|
* for us to start.
|
||||||
*/
|
*/
|
||||||
memcpy(dst, dst + fdt_offset % info->bl_len, fdt_len);
|
debug("fdt: dst=%p, data_offset=%x, size=%x\n", dst, fdt_offset,
|
||||||
|
fdt_len);
|
||||||
|
memcpy(load_ptr + data_size,
|
||||||
|
dst + get_aligned_image_overhead(info, fdt_offset), fdt_len);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector)
|
||||||
debug("Found FIT\n");
|
debug("Found FIT\n");
|
||||||
load.dev = mmc;
|
load.dev = mmc;
|
||||||
load.priv = NULL;
|
load.priv = NULL;
|
||||||
|
load.filename = NULL;
|
||||||
load.bl_len = mmc->read_bl_len;
|
load.bl_len = mmc->read_bl_len;
|
||||||
load.read = h_spl_load_read;
|
load.read = h_spl_load_read;
|
||||||
ret = spl_load_simple_fit(&load, sector, header);
|
ret = spl_load_simple_fit(&load, sector, header);
|
||||||
|
|
|
@ -35,16 +35,28 @@ struct spl_image_info {
|
||||||
* @dev: Pointer to the device, e.g. struct mmc *
|
* @dev: Pointer to the device, e.g. struct mmc *
|
||||||
* @priv: Private data for the device
|
* @priv: Private data for the device
|
||||||
* @bl_len: Block length for reading in bytes
|
* @bl_len: Block length for reading in bytes
|
||||||
|
* @filename: Name of the fit image file.
|
||||||
* @read: Function to call to read from the device
|
* @read: Function to call to read from the device
|
||||||
*/
|
*/
|
||||||
struct spl_load_info {
|
struct spl_load_info {
|
||||||
void *dev;
|
void *dev;
|
||||||
void *priv;
|
void *priv;
|
||||||
int bl_len;
|
int bl_len;
|
||||||
|
const char *filename;
|
||||||
ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
|
ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
|
||||||
void *buf);
|
void *buf);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* spl_load_simple_fit() - Loads a fit image from a device.
|
||||||
|
* @info: Structure containing the information required to load data.
|
||||||
|
* @sector: Sector number where FIT image is located in the device
|
||||||
|
* @fdt: Pointer to the copied FIT header.
|
||||||
|
*
|
||||||
|
* Reads the FIT image @sector in the device. Loads u-boot image to
|
||||||
|
* specified load address and copies the dtb to end of u-boot image.
|
||||||
|
* Returns 0 on success.
|
||||||
|
*/
|
||||||
int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fdt);
|
int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fdt);
|
||||||
|
|
||||||
#define SPL_COPY_PAYLOAD_ONLY 1
|
#define SPL_COPY_PAYLOAD_ONLY 1
|
||||||
|
|
Loading…
Reference in New Issue