diff mbox

[U-Boot,v2,08/14] sparse: Implement several chunks flashing

Message ID 1444912462-3949-9-git-send-email-maxime.ripard@free-electrons.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Maxime Ripard Oct. 15, 2015, 12:34 p.m. UTC
The fastboot client will split the sparse images into several chunks if the
image that it tries to flash is bigger than what the device can handle.

In such a case, the bootloader is supposed to retain the last offset to
which it wrote to, so that it can resume the writes at the right offset
when flashing the next chunk.

Retain the last offset we used, and use the session ID to know if we need
it or not.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 common/aboot.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

Comments

Tom Rini Oct. 20, 2015, 7:47 p.m. UTC | #1
On Thu, Oct 15, 2015 at 02:34:16PM +0200, Maxime Ripard wrote:

> The fastboot client will split the sparse images into several chunks if the
> image that it tries to flash is bigger than what the device can handle.
> 
> In such a case, the bootloader is supposed to retain the last offset to
> which it wrote to, so that it can resume the writes at the right offset
> when flashing the next chunk.
> 
> Retain the last offset we used, and use the session ID to know if we need
> it or not.
> 
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
Tom Rini Nov. 13, 2015, 1:27 a.m. UTC | #2
On Thu, Oct 15, 2015 at 02:34:16PM +0200, Maxime Ripard wrote:

> The fastboot client will split the sparse images into several chunks if the
> image that it tries to flash is bigger than what the device can handle.
> 
> In such a case, the bootloader is supposed to retain the last offset to
> which it wrote to, so that it can resume the writes at the right offset
> when flashing the next chunk.
> 
> Retain the last offset we used, and use the session ID to know if we need
> it or not.
> 
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> Reviewed-by: Tom Rini <trini@konsulko.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/common/aboot.c b/common/aboot.c
index 7f412ac0ad4f..6d76c1e758f9 100644
--- a/common/aboot.c
+++ b/common/aboot.c
@@ -52,6 +52,8 @@  typedef struct sparse_buffer {
 	u16	type;
 } sparse_buffer_t;
 
+static uint32_t last_offset;
+
 static unsigned int sparse_get_chunk_data_size(sparse_header_t *sparse,
 					       chunk_header_t *chunk)
 {
@@ -301,10 +303,19 @@  int store_sparse_image(sparse_storage_t *storage, void *storage_priv,
 		return -EINVAL;
 	}
 
-	puts("Flashing Sparse Image\n");
+	/*
+	 * If it's a new flashing session, start at the beginning of
+	 * the partition. If not, then simply resume where we were.
+	 */
+	if (session_id > 0)
+		start = last_offset;
+	else
+		start = storage->start;
+
+	printf("Flashing sparse image on partition %s at offset 0x%x (ID: %d)\n",
+	       storage->name, start * storage->block_sz, session_id);
 
 	/* Start processing chunks */
-	start = storage->start;
 	for (chunk = 0; chunk < sparse_header->total_chunks; chunk++) {
 		uint32_t blkcnt;
 
@@ -376,5 +387,7 @@  int store_sparse_image(sparse_storage_t *storage, void *storage_priv,
 		return -EIO;
 	}
 
+	last_offset = start + total_blocks;
+
 	return 0;
 }