summaryrefslogtreecommitdiff
path: root/arch/arm/mach-imx/spl_imx_romapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-imx/spl_imx_romapi.c')
-rw-r--r--arch/arm/mach-imx/spl_imx_romapi.c75
1 files changed, 52 insertions, 23 deletions
diff --git a/arch/arm/mach-imx/spl_imx_romapi.c b/arch/arm/mach-imx/spl_imx_romapi.c
index 4af41699678..c4a4185eed1 100644
--- a/arch/arm/mach-imx/spl_imx_romapi.c
+++ b/arch/arm/mach-imx/spl_imx_romapi.c
@@ -133,6 +133,41 @@ err:
return -1;
}
+struct stream_state {
+ u8 *base;
+ u8 *end;
+ u32 pagesize;
+};
+
+static ulong spl_romapi_read_stream(struct spl_load_info *load, ulong sector,
+ ulong count, void *buf)
+{
+ struct stream_state *ss = load->priv;
+ u8 *end = (u8*)(sector + count);
+ u32 bytes;
+ int ret;
+
+ if (end > ss->end) {
+ bytes = end - ss->end;
+ bytes += ss->pagesize - 1;
+ bytes /= ss->pagesize;
+ bytes *= ss->pagesize;
+
+ debug("downloading another 0x%x bytes\n", bytes);
+ ret = rom_api_download_image(ss->end, 0, bytes);
+
+ if (ret != ROM_API_OKAY) {
+ printf("Failure download %d\n", bytes);
+ return 0;
+ }
+
+ ss->end = end;
+ }
+
+ memcpy(buf, (void *)(sector), count);
+ return count;
+}
+
static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector,
ulong count, void *buf)
{
@@ -149,23 +184,6 @@ static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector,
return count;
}
-static ulong get_fit_image_size(void *fit)
-{
- struct spl_image_info spl_image;
- struct spl_load_info spl_load_info;
- ulong last = (ulong)fit;
-
- memset(&spl_load_info, 0, sizeof(spl_load_info));
- spl_load_info.bl_len = 1;
- spl_load_info.read = spl_ram_load_read;
- spl_load_info.priv = &last;
-
- spl_load_simple_fit(&spl_image, &spl_load_info,
- (uintptr_t)fit, fit);
-
- return last - (ulong)fit;
-}
-
static u8 *search_fit_header(u8 *p, int size)
{
int i;
@@ -226,9 +244,7 @@ static int img_info_size(void *img_hdr)
static int img_total_size(void *img_hdr)
{
- if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) {
- return get_fit_image_size(img_hdr);
- } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+ if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
int total = get_container_size((ulong)img_hdr, NULL);
if (total < 0) {
@@ -316,6 +332,21 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image,
}
}
+ if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) {
+ struct stream_state ss;
+
+ ss.base = phdr;
+ ss.end = p;
+ ss.pagesize = pagesize;
+
+ memset(&load, 0, sizeof(load));
+ load.bl_len = 1;
+ load.read = spl_romapi_read_stream;
+ load.priv = &ss;
+
+ return spl_load_simple_fit(spl_image, &load, (ulong)phdr, phdr);
+ }
+
total = img_total_size(phdr);
total += 3;
total &= ~0x3;
@@ -336,9 +367,7 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image,
load.bl_len = 1;
load.read = spl_ram_load_read;
- if (IS_ENABLED(CONFIG_SPL_LOAD_FIT))
- return spl_load_simple_fit(spl_image, &load, (ulong)phdr, phdr);
- else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER))
+ if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER))
return spl_load_imx_container(spl_image, &load, (ulong)phdr);
return -1;