summaryrefslogtreecommitdiffstats
path: root/common/fb_mmc.c
diff options
context:
space:
mode:
authorMaxime Ripard <maxime.ripard@free-electrons.com>2015-10-15 14:34:14 +0200
committerTom Rini <trini@konsulko.com>2015-11-12 13:17:31 -0500
commita5d1e04a532b1fccd9c4f0a1d4ed6410664a9424 (patch)
tree561fecb1a34ffb3de34b542236184b254adb6610 /common/fb_mmc.c
parent3c8f98f5fed5c6f03bb185b79191477885748b14 (diff)
downloadblackbird-obmc-uboot-a5d1e04a532b1fccd9c4f0a1d4ed6410664a9424.tar.gz
blackbird-obmc-uboot-a5d1e04a532b1fccd9c4f0a1d4ed6410664a9424.zip
sparse: Implement storage abstraction
The current sparse image parser relies heavily on the MMC layer, and doesn't allow any other kind of storage medium to be used. Rework the parser to support any kind of storage medium, as long as there is an implementation for it. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Reviewed-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'common/fb_mmc.c')
-rw-r--r--common/fb_mmc.c45
1 files changed, 41 insertions, 4 deletions
diff --git a/common/fb_mmc.c b/common/fb_mmc.c
index b31a9fb929..c9f2ed6b58 100644
--- a/common/fb_mmc.c
+++ b/common/fb_mmc.c
@@ -6,6 +6,7 @@
#include <config.h>
#include <common.h>
+#include <errno.h>
#include <fastboot.h>
#include <fb_mmc.h>
#include <part.h>
@@ -19,6 +20,10 @@
static char *response_str;
+struct fb_mmc_sparse {
+ block_dev_desc_t *dev_desc;
+};
+
static int get_partition_info_efi_by_name_or_alias(block_dev_desc_t *dev_desc,
const char *name, disk_partition_t *info)
{
@@ -41,6 +46,24 @@ static int get_partition_info_efi_by_name_or_alias(block_dev_desc_t *dev_desc,
return ret;
}
+
+static int fb_mmc_sparse_write(struct sparse_storage *storage,
+ void *priv,
+ unsigned int offset,
+ unsigned int size,
+ char *data)
+{
+ struct fb_mmc_sparse *sparse = priv;
+ block_dev_desc_t *dev_desc = sparse->dev_desc;
+ int ret;
+
+ ret = dev_desc->block_write(dev_desc->dev, offset, size, data);
+ if (!ret)
+ return -EIO;
+
+ return ret;
+}
+
static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info,
const char *part_name, void *buffer,
unsigned int download_bytes)
@@ -113,12 +136,26 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
return;
}
- if (is_sparse_image(download_buffer))
- write_sparse_image(dev_desc, &info, cmd, download_buffer,
- download_bytes);
- else
+ if (is_sparse_image(download_buffer)) {
+ struct fb_mmc_sparse sparse_priv;
+ sparse_storage_t sparse;
+
+ sparse_priv.dev_desc = dev_desc;
+
+ sparse.block_sz = info.blksz;
+ sparse.start = info.start;
+ sparse.size = info.size;
+ sparse.name = cmd;
+ sparse.write = fb_mmc_sparse_write;
+
+ printf("Flashing sparse image at offset " LBAFU "\n",
+ info.start);
+
+ store_sparse_image(&sparse, &sparse_priv, download_buffer);
+ } else {
write_raw_image(dev_desc, &info, cmd, download_buffer,
download_bytes);
+ }
fastboot_okay(response_str, "");
}
OpenPOWER on IntegriCloud