Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Copyright (c) 2009-2014, The Linux Foundation. All rights reserved. |
Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 6 | * Portions Copyright 2014 Broadcom Corporation. |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * * Neither the name of The Linux Foundation nor |
| 16 | * the names of its contributors may be used to endorse or promote |
| 17 | * products derived from this software without specific prior written |
| 18 | * permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 23 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 27 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 28 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 30 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
Steve Rae | 1c39d85 | 2014-09-03 10:05:53 -0700 | [diff] [blame] | 32 | * NOTE: |
| 33 | * Although it is very similar, this license text is not identical |
| 34 | * to the "BSD-3-Clause", therefore, DO NOT MODIFY THIS LICENSE TEXT! |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 35 | */ |
| 36 | |
Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 37 | #include <config.h> |
| 38 | #include <common.h> |
Maxime Ripard | 40aeeda | 2015-10-15 14:34:12 +0200 | [diff] [blame] | 39 | #include <div64.h> |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 40 | #include <errno.h> |
Maxime Ripard | 3d4ef38 | 2015-10-15 14:34:19 +0200 | [diff] [blame] | 41 | #include <image-sparse.h> |
Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 42 | #include <malloc.h> |
| 43 | #include <part.h> |
| 44 | #include <sparse_format.h> |
| 45 | |
Maxime Ripard | 40aeeda | 2015-10-15 14:34:12 +0200 | [diff] [blame] | 46 | #include <linux/math64.h> |
| 47 | |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 48 | typedef struct sparse_buffer { |
| 49 | void *data; |
| 50 | u32 length; |
| 51 | u32 repeat; |
| 52 | u16 type; |
| 53 | } sparse_buffer_t; |
| 54 | |
Maxime Ripard | 1f8690a | 2015-10-15 14:34:16 +0200 | [diff] [blame] | 55 | static uint32_t last_offset; |
| 56 | |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 57 | static unsigned int sparse_get_chunk_data_size(sparse_header_t *sparse, |
| 58 | chunk_header_t *chunk) |
| 59 | { |
| 60 | return chunk->total_sz - sparse->chunk_hdr_sz; |
| 61 | } |
| 62 | |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 63 | static unsigned int sparse_block_size_to_storage(unsigned int size, |
| 64 | sparse_storage_t *storage, |
| 65 | sparse_header_t *sparse) |
| 66 | { |
Jeffy Chen | d3bafe3 | 2016-02-03 18:13:55 +0800 | [diff] [blame] | 67 | return (unsigned int)lldiv((uint64_t)size * sparse->blk_sz, |
| 68 | storage->block_sz); |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 69 | } |
| 70 | |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 71 | static bool sparse_chunk_has_buffer(chunk_header_t *chunk) |
| 72 | { |
| 73 | switch (chunk->chunk_type) { |
| 74 | case CHUNK_TYPE_RAW: |
| 75 | case CHUNK_TYPE_FILL: |
| 76 | return true; |
| 77 | |
| 78 | default: |
| 79 | return false; |
| 80 | } |
| 81 | } |
| 82 | |
Maxime Ripard | bb83c0f | 2015-10-15 14:34:10 +0200 | [diff] [blame] | 83 | static sparse_header_t *sparse_parse_header(void **data) |
| 84 | { |
| 85 | /* Read and skip over sparse image header */ |
| 86 | sparse_header_t *sparse_header = (sparse_header_t *) *data; |
| 87 | |
| 88 | *data += sparse_header->file_hdr_sz; |
| 89 | |
| 90 | debug("=== Sparse Image Header ===\n"); |
| 91 | debug("magic: 0x%x\n", sparse_header->magic); |
| 92 | debug("major_version: 0x%x\n", sparse_header->major_version); |
| 93 | debug("minor_version: 0x%x\n", sparse_header->minor_version); |
| 94 | debug("file_hdr_sz: %d\n", sparse_header->file_hdr_sz); |
| 95 | debug("chunk_hdr_sz: %d\n", sparse_header->chunk_hdr_sz); |
| 96 | debug("blk_sz: %d\n", sparse_header->blk_sz); |
| 97 | debug("total_blks: %d\n", sparse_header->total_blks); |
| 98 | debug("total_chunks: %d\n", sparse_header->total_chunks); |
| 99 | |
| 100 | return sparse_header; |
| 101 | } |
| 102 | |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 103 | static int sparse_parse_fill_chunk(sparse_header_t *sparse, |
| 104 | chunk_header_t *chunk) |
| 105 | { |
| 106 | unsigned int chunk_data_sz = sparse_get_chunk_data_size(sparse, chunk); |
| 107 | |
| 108 | if (chunk_data_sz != sizeof(uint32_t)) |
| 109 | return -EINVAL; |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static int sparse_parse_raw_chunk(sparse_header_t *sparse, |
| 115 | chunk_header_t *chunk) |
| 116 | { |
| 117 | unsigned int chunk_data_sz = sparse_get_chunk_data_size(sparse, chunk); |
| 118 | |
| 119 | /* Check if the data size is a multiple of the main block size */ |
| 120 | if (chunk_data_sz % sparse->blk_sz) |
| 121 | return -EINVAL; |
| 122 | |
| 123 | /* Check that the chunk size is consistent */ |
| 124 | if ((chunk_data_sz / sparse->blk_sz) != chunk->chunk_sz) |
| 125 | return -EINVAL; |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static chunk_header_t *sparse_parse_chunk(sparse_header_t *sparse, |
| 131 | void **image) |
| 132 | { |
| 133 | chunk_header_t *chunk = (chunk_header_t *) *image; |
| 134 | int ret; |
| 135 | |
| 136 | debug("=== Chunk Header ===\n"); |
| 137 | debug("chunk_type: 0x%x\n", chunk->chunk_type); |
| 138 | debug("chunk_data_sz: 0x%x\n", chunk->chunk_sz); |
| 139 | debug("total_size: 0x%x\n", chunk->total_sz); |
| 140 | |
| 141 | switch (chunk->chunk_type) { |
| 142 | case CHUNK_TYPE_RAW: |
| 143 | ret = sparse_parse_raw_chunk(sparse, chunk); |
| 144 | if (ret) |
| 145 | return NULL; |
| 146 | break; |
| 147 | |
| 148 | case CHUNK_TYPE_FILL: |
| 149 | ret = sparse_parse_fill_chunk(sparse, chunk); |
| 150 | if (ret) |
| 151 | return NULL; |
| 152 | break; |
| 153 | |
| 154 | case CHUNK_TYPE_DONT_CARE: |
| 155 | case CHUNK_TYPE_CRC32: |
| 156 | debug("Ignoring chunk\n"); |
| 157 | break; |
| 158 | |
| 159 | default: |
| 160 | printf("%s: Unknown chunk type: %x\n", __func__, |
| 161 | chunk->chunk_type); |
| 162 | return NULL; |
| 163 | } |
| 164 | |
| 165 | *image += sparse->chunk_hdr_sz; |
| 166 | |
| 167 | return chunk; |
| 168 | } |
| 169 | |
| 170 | static int sparse_get_fill_buffer(sparse_header_t *sparse, |
| 171 | chunk_header_t *chunk, |
| 172 | sparse_buffer_t *buffer, |
| 173 | unsigned int blk_sz, |
| 174 | void *data) |
| 175 | { |
| 176 | int i; |
| 177 | |
| 178 | buffer->type = CHUNK_TYPE_FILL; |
| 179 | |
| 180 | /* |
| 181 | * We create a buffer of one block, and ask it to be |
| 182 | * repeated as many times as needed. |
| 183 | */ |
| 184 | buffer->length = blk_sz; |
| 185 | buffer->repeat = (chunk->chunk_sz * sparse->blk_sz) / blk_sz; |
| 186 | |
| 187 | buffer->data = memalign(ARCH_DMA_MINALIGN, |
| 188 | ROUNDUP(blk_sz, |
| 189 | ARCH_DMA_MINALIGN)); |
| 190 | if (!buffer->data) |
| 191 | return -ENOMEM; |
| 192 | |
| 193 | for (i = 0; i < (buffer->length / sizeof(uint32_t)); i++) |
| 194 | ((uint32_t *)buffer->data)[i] = *(uint32_t *)(data); |
| 195 | |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | static int sparse_get_raw_buffer(sparse_header_t *sparse, |
| 200 | chunk_header_t *chunk, |
| 201 | sparse_buffer_t *buffer, |
| 202 | unsigned int blk_sz, |
| 203 | void *data) |
| 204 | { |
| 205 | unsigned int chunk_data_sz = sparse_get_chunk_data_size(sparse, chunk); |
| 206 | |
| 207 | buffer->type = CHUNK_TYPE_RAW; |
| 208 | buffer->length = chunk_data_sz; |
| 209 | buffer->data = data; |
| 210 | buffer->repeat = 1; |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static sparse_buffer_t *sparse_get_data_buffer(sparse_header_t *sparse, |
| 216 | chunk_header_t *chunk, |
| 217 | unsigned int blk_sz, |
| 218 | void **image) |
| 219 | { |
| 220 | unsigned int chunk_data_sz = sparse_get_chunk_data_size(sparse, chunk); |
| 221 | sparse_buffer_t *buffer; |
| 222 | void *data = *image; |
| 223 | int ret; |
| 224 | |
| 225 | *image += chunk_data_sz; |
| 226 | |
| 227 | if (!sparse_chunk_has_buffer(chunk)) |
| 228 | return NULL; |
| 229 | |
| 230 | buffer = calloc(sizeof(sparse_buffer_t), 1); |
| 231 | if (!buffer) |
| 232 | return NULL; |
| 233 | |
| 234 | switch (chunk->chunk_type) { |
| 235 | case CHUNK_TYPE_RAW: |
| 236 | ret = sparse_get_raw_buffer(sparse, chunk, buffer, blk_sz, |
| 237 | data); |
| 238 | if (ret) |
| 239 | return NULL; |
| 240 | break; |
| 241 | |
| 242 | case CHUNK_TYPE_FILL: |
| 243 | ret = sparse_get_fill_buffer(sparse, chunk, buffer, blk_sz, |
| 244 | data); |
| 245 | if (ret) |
| 246 | return NULL; |
| 247 | break; |
| 248 | |
| 249 | default: |
| 250 | return NULL; |
| 251 | } |
| 252 | |
| 253 | debug("=== Buffer ===\n"); |
| 254 | debug("length: 0x%x\n", buffer->length); |
| 255 | debug("repeat: 0x%x\n", buffer->repeat); |
| 256 | debug("type: 0x%x\n", buffer->type); |
| 257 | debug("data: 0x%p\n", buffer->data); |
| 258 | |
| 259 | return buffer; |
| 260 | } |
| 261 | |
| 262 | static void sparse_put_data_buffer(sparse_buffer_t *buffer) |
| 263 | { |
| 264 | if (buffer->type == CHUNK_TYPE_FILL) |
| 265 | free(buffer->data); |
| 266 | |
| 267 | free(buffer); |
| 268 | } |
| 269 | |
Maxime Ripard | 6c9e00e | 2015-10-15 14:34:15 +0200 | [diff] [blame] | 270 | int store_sparse_image(sparse_storage_t *storage, void *storage_priv, |
| 271 | unsigned int session_id, void *data) |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 272 | { |
Maxime Ripard | 40aeeda | 2015-10-15 14:34:12 +0200 | [diff] [blame] | 273 | unsigned int chunk, offset; |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 274 | sparse_header_t *sparse_header; |
| 275 | chunk_header_t *chunk_header; |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 276 | sparse_buffer_t *buffer; |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 277 | uint32_t start; |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 278 | uint32_t total_blocks = 0; |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 279 | uint32_t skipped = 0; |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 280 | int i; |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 281 | |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 282 | debug("=== Storage ===\n"); |
| 283 | debug("name: %s\n", storage->name); |
| 284 | debug("block_size: 0x%x\n", storage->block_sz); |
| 285 | debug("start: 0x%x\n", storage->start); |
| 286 | debug("size: 0x%x\n", storage->size); |
| 287 | debug("write: 0x%p\n", storage->write); |
| 288 | debug("priv: 0x%p\n", storage_priv); |
| 289 | |
Maxime Ripard | bb83c0f | 2015-10-15 14:34:10 +0200 | [diff] [blame] | 290 | sparse_header = sparse_parse_header(&data); |
| 291 | if (!sparse_header) { |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 292 | printf("sparse header issue\n"); |
| 293 | return -EINVAL; |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Maxime Ripard | 40aeeda | 2015-10-15 14:34:12 +0200 | [diff] [blame] | 296 | /* |
| 297 | * Verify that the sparse block size is a multiple of our |
| 298 | * storage backend block size |
| 299 | */ |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 300 | div_u64_rem(sparse_header->blk_sz, storage->block_sz, &offset); |
Maxime Ripard | 40aeeda | 2015-10-15 14:34:12 +0200 | [diff] [blame] | 301 | if (offset) { |
Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 302 | printf("%s: Sparse image block size issue [%u]\n", |
| 303 | __func__, sparse_header->blk_sz); |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 304 | return -EINVAL; |
Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Maxime Ripard | 1f8690a | 2015-10-15 14:34:16 +0200 | [diff] [blame] | 307 | /* |
| 308 | * If it's a new flashing session, start at the beginning of |
| 309 | * the partition. If not, then simply resume where we were. |
| 310 | */ |
| 311 | if (session_id > 0) |
| 312 | start = last_offset; |
| 313 | else |
| 314 | start = storage->start; |
| 315 | |
| 316 | printf("Flashing sparse image on partition %s at offset 0x%x (ID: %d)\n", |
| 317 | storage->name, start * storage->block_sz, session_id); |
Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 318 | |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 319 | /* Start processing chunks */ |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 320 | for (chunk = 0; chunk < sparse_header->total_chunks; chunk++) { |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 321 | uint32_t blkcnt; |
| 322 | |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 323 | chunk_header = sparse_parse_chunk(sparse_header, &data); |
| 324 | if (!chunk_header) { |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 325 | printf("Unknown chunk type"); |
| 326 | return -EINVAL; |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 327 | } |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 328 | |
| 329 | /* |
| 330 | * If we have a DONT_CARE type, just skip the blocks |
| 331 | * and go on parsing the rest of the chunks |
| 332 | */ |
| 333 | if (chunk_header->chunk_type == CHUNK_TYPE_DONT_CARE) { |
Steve Rae | c7529db | 2016-02-09 11:19:10 -0800 | [diff] [blame^] | 334 | blkcnt = sparse_block_size_to_storage(chunk_header->chunk_sz, |
| 335 | storage, |
| 336 | sparse_header); |
| 337 | #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV |
| 338 | total_blocks += blkcnt; |
| 339 | #endif |
| 340 | skipped += blkcnt; |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 341 | continue; |
| 342 | } |
| 343 | |
| 344 | /* Retrieve the buffer we're going to write */ |
| 345 | buffer = sparse_get_data_buffer(sparse_header, chunk_header, |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 346 | storage->block_sz, &data); |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 347 | if (!buffer) |
| 348 | continue; |
| 349 | |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 350 | blkcnt = (buffer->length / storage->block_sz) * buffer->repeat; |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 351 | |
| 352 | if ((start + total_blocks + blkcnt) > |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 353 | (storage->start + storage->size)) { |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 354 | printf("%s: Request would exceed partition size!\n", |
| 355 | __func__); |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 356 | return -EINVAL; |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | for (i = 0; i < buffer->repeat; i++) { |
| 360 | unsigned long buffer_blk_cnt; |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 361 | int ret; |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 362 | |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 363 | buffer_blk_cnt = buffer->length / storage->block_sz; |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 364 | |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 365 | ret = storage->write(storage, storage_priv, |
| 366 | start + total_blocks, |
| 367 | buffer_blk_cnt, |
| 368 | buffer->data); |
| 369 | if (ret < 0) { |
| 370 | printf("%s: Write %d failed %d\n", |
| 371 | __func__, i, ret); |
| 372 | return ret; |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 373 | } |
| 374 | |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 375 | total_blocks += ret; |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | sparse_put_data_buffer(buffer); |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Maxime Ripard | 7bfc3b1 | 2015-10-15 14:34:11 +0200 | [diff] [blame] | 381 | debug("Wrote %d blocks, skipped %d, expected to write %d blocks\n", |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 382 | total_blocks, skipped, |
| 383 | sparse_block_size_to_storage(sparse_header->total_blks, |
| 384 | storage, sparse_header)); |
| 385 | printf("........ wrote %d blocks to '%s'\n", total_blocks, |
| 386 | storage->name); |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 387 | |
Steve Rae | c7529db | 2016-02-09 11:19:10 -0800 | [diff] [blame^] | 388 | if (total_blocks != |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 389 | sparse_block_size_to_storage(sparse_header->total_blks, |
| 390 | storage, sparse_header)) { |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 391 | printf("sparse image write failure\n"); |
| 392 | return -EIO; |
| 393 | } |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 394 | |
Maxime Ripard | 1f8690a | 2015-10-15 14:34:16 +0200 | [diff] [blame] | 395 | last_offset = start + total_blocks; |
| 396 | |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 397 | return 0; |
Steve Rae | b4e4bbe | 2014-09-03 10:05:51 -0700 | [diff] [blame] | 398 | } |