diff options
author | Simon Glass <sjg@chromium.org> | 2016-02-22 22:55:58 -0700 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2016-03-14 19:18:31 -0400 |
commit | 96debd1f0b90547bf53ce224113dbcdff24818e2 (patch) | |
tree | 316b4666b416375f59a768ef4244d3bd0b0a7630 /common | |
parent | cdf172461caa1a2b29be54438628e4c227956565 (diff) | |
download | u-boot-96debd1f0b90547bf53ce224113dbcdff24818e2.tar.gz |
spl: Support loading a FIT from MMC
Detect a FIT when loading from MMC and handle it using the new FIT SPL
support.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/spl/spl_mmc.c | 75 |
1 files changed, 57 insertions, 18 deletions
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index c27a250251..94821421dc 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -18,41 +18,80 @@ DECLARE_GLOBAL_DATA_PTR; +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; +} + +#ifdef CONFIG_SPL_LOAD_FIT +static ulong h_spl_load_read(struct spl_load_info *load, ulong sector, + ulong count, void *buf) +{ + struct mmc *mmc = load->dev; + + return mmc->block_dev.block_read(&mmc->block_dev, sector, count, buf); +} +#endif + static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector) { unsigned long count; - u32 image_size_sectors; struct image_header *header; + int ret = 0; header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - sizeof(struct image_header)); /* 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) + debug("hdr read sector %lx, count=%lu\n", sector, count); + if (count == 0) { + ret = -EIO; goto end; + } - if (image_get_magic(header) != IH_MAGIC) { + switch (image_get_magic(header)) { + case IH_MAGIC: + ret = mmc_load_legacy(mmc, sector, header); + break; +#ifdef CONFIG_SPL_LOAD_FIT + case FDT_MAGIC: { + struct spl_load_info load; + + debug("Found FIT\n"); + load.dev = mmc; + load.priv = NULL; + load.bl_len = mmc->read_bl_len; + load.read = h_spl_load_read; + ret = spl_load_simple_fit(&load, sector, header); + break; + } +#endif + default: puts("bad magic\n"); 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 |