From patchwork Tue Feb 2 08:43:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffy Chen X-Patchwork-Id: 577000 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3DACC140AD9 for ; Tue, 2 Feb 2016 19:43:49 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C1A77A7524; Tue, 2 Feb 2016 09:43:45 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0kdE-fL9Qs56; Tue, 2 Feb 2016 09:43:45 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9E518A74FF; Tue, 2 Feb 2016 09:43:37 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F210CA74E9 for ; Tue, 2 Feb 2016 09:41:27 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id S_hcGpjW-EUe for ; Tue, 2 Feb 2016 09:41:25 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from va-smtp01.263.net (va-smtp01.263.net [54.88.144.211]) by theia.denx.de (Postfix) with ESMTP id BBE9C4BF63 for ; Tue, 2 Feb 2016 09:41:16 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by va-smtp01.263.net (Postfix) with ESMTP id 7F8FD9F603; Tue, 2 Feb 2016 16:41:07 +0800 (CST) X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: u-boot@lists.denx.de X-SENDER-IP: 104.37.5.188 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: <6d3823c7f27d6d3cac502d71d9f5722d> X-ATTACHMENT-NUM: 0 X-SENDER: cjf@rock-chips.com X-DNS-TYPE: 0 Received: from localhost (unknown [104.37.5.188]) by va-smtp01.263.net (Postfix) whith ESMTP id 20244C6VZ1S; Tue, 02 Feb 2016 16:41:10 +0800 (CST) From: Jeffy Chen To: u-boot@lists.denx.de Date: Tue, 2 Feb 2016 16:43:31 +0800 Message-Id: <1454402611-17864-1-git-send-email-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.1.4 Cc: trini@konsulko.com, Jeffy Chen , ccross@android.com Subject: [U-Boot] [PATCH] fastboot: sparse: fix chunk write offset calculation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" We should count skipped blocks in when calculating write offset. Signed-off-by: Jeffy Chen --- common/image-sparse.c | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/common/image-sparse.c b/common/image-sparse.c index dffe844..542a8c4 100644 --- a/common/image-sparse.c +++ b/common/image-sparse.c @@ -52,8 +52,6 @@ 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) { @@ -273,8 +271,7 @@ int store_sparse_image(sparse_storage_t *storage, void *storage_priv, sparse_header_t *sparse_header; chunk_header_t *chunk_header; sparse_buffer_t *buffer; - uint32_t start; - uint32_t total_blocks = 0; + uint32_t wrote_blocks = 0; uint32_t skipped = 0; int i; @@ -303,17 +300,8 @@ int store_sparse_image(sparse_storage_t *storage, void *storage_priv, return -EINVAL; } - /* - * 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); + storage->name, storage->start * storage->block_sz, session_id); /* Start processing chunks */ for (chunk = 0; chunk < sparse_header->total_chunks; chunk++) { @@ -344,8 +332,7 @@ int store_sparse_image(sparse_storage_t *storage, void *storage_priv, blkcnt = (buffer->length / storage->block_sz) * buffer->repeat; - if ((start + total_blocks + blkcnt) > - (storage->start + storage->size)) { + if ((wrote_blocks + skipped + blkcnt) > storage->size) { printf("%s: Request would exceed partition size!\n", __func__); return -EINVAL; @@ -358,7 +345,7 @@ int store_sparse_image(sparse_storage_t *storage, void *storage_priv, buffer_blk_cnt = buffer->length / storage->block_sz; ret = storage->write(storage, storage_priv, - start + total_blocks, + storage->start + wrote_blocks + skipped, buffer_blk_cnt, buffer->data); if (ret < 0) { @@ -367,27 +354,25 @@ int store_sparse_image(sparse_storage_t *storage, void *storage_priv, return ret; } - total_blocks += ret; + wrote_blocks += ret; } sparse_put_data_buffer(buffer); } debug("Wrote %d blocks, skipped %d, expected to write %d blocks\n", - total_blocks, skipped, + wrote_blocks, skipped, sparse_block_size_to_storage(sparse_header->total_blks, storage, sparse_header)); - printf("........ wrote %d blocks to '%s'\n", total_blocks, + printf("........ wrote %d blocks to '%s'\n", wrote_blocks, storage->name); - if ((total_blocks + skipped) != + if ((wrote_blocks + skipped) != sparse_block_size_to_storage(sparse_header->total_blks, storage, sparse_header)) { printf("sparse image write failure\n"); return -EIO; } - last_offset = start + total_blocks; - return 0; }