if (is_sparse_image(download_buffer)) {
struct fb_mmc_sparse sparse_priv;
struct sparse_storage sparse;
+ int err;
sparse_priv.dev_desc = dev_desc;
sparse.size = info.size;
sparse.write = fb_mmc_sparse_write;
sparse.reserve = fb_mmc_sparse_reserve;
+ sparse.mssg = fastboot_fail;
printf("Flashing sparse image at offset " LBAFU "\n",
sparse.start);
sparse.priv = &sparse_priv;
- write_sparse_image(&sparse, cmd, download_buffer);
+ err = write_sparse_image(&sparse, cmd, download_buffer);
+ if (!err)
+ fastboot_okay("");
} else {
write_raw_image(dev_desc, &info, cmd, download_buffer,
download_bytes);
#include <malloc.h>
#include <part.h>
#include <sparse_format.h>
-#include <fastboot.h>
#include <linux/math64.h>
#define CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE (1024 * 512)
#endif
-void write_sparse_image(
- struct sparse_storage *info, const char *part_name,
- void *data)
+static void default_log(const char *ignored) {}
+
+int write_sparse_image(struct sparse_storage *info,
+ const char *part_name, void *data)
{
lbaint_t blk;
lbaint_t blkcnt;
data += (sparse_header->file_hdr_sz - sizeof(sparse_header_t));
}
+ if (!info->mssg)
+ info->mssg = default_log;
+
debug("=== Sparse Image Header ===\n");
debug("magic: 0x%x\n", sparse_header->magic);
debug("major_version: 0x%x\n", sparse_header->major_version);
if (offset) {
printf("%s: Sparse image block size issue [%u]\n",
__func__, sparse_header->blk_sz);
- fastboot_fail("sparse image block size issue");
- return;
+ info->mssg("sparse image block size issue");
+ return -1;
}
puts("Flashing Sparse Image\n");
case CHUNK_TYPE_RAW:
if (chunk_header->total_sz !=
(sparse_header->chunk_hdr_sz + chunk_data_sz)) {
- fastboot_fail(
- "Bogus chunk size for chunk type Raw");
- return;
+ info->mssg("Bogus chunk size for chunk type Raw");
+ return -1;
}
if (blk + blkcnt > info->start + info->size) {
printf(
"%s: Request would exceed partition size!\n",
__func__);
- fastboot_fail(
- "Request would exceed partition size!");
- return;
+ info->mssg("Request would exceed partition size!");
+ return -1;
}
blks = info->write(info, blk, blkcnt, data);
printf("%s: %s" LBAFU " [" LBAFU "]\n",
__func__, "Write failed, block #",
blk, blks);
- fastboot_fail(
- "flash write failure");
- return;
+ info->mssg("flash write failure");
+ return -1;
}
blk += blks;
bytes_written += blkcnt * info->blksz;
case CHUNK_TYPE_FILL:
if (chunk_header->total_sz !=
(sparse_header->chunk_hdr_sz + sizeof(uint32_t))) {
- fastboot_fail(
- "Bogus chunk size for chunk type FILL");
- return;
+ info->mssg("Bogus chunk size for chunk type FILL");
+ return -1;
}
fill_buf = (uint32_t *)
info->blksz * fill_buf_num_blks,
ARCH_DMA_MINALIGN));
if (!fill_buf) {
- fastboot_fail(
- "Malloc failed for: CHUNK_TYPE_FILL");
- return;
+ info->mssg("Malloc failed for: CHUNK_TYPE_FILL");
+ return -1;
}
fill_val = *(uint32_t *)data;
printf(
"%s: Request would exceed partition size!\n",
__func__);
- fastboot_fail(
- "Request would exceed partition size!");
- return;
+ info->mssg("Request would exceed partition size!");
+ return -1;
}
for (i = 0; i < blkcnt;) {
__func__,
"Write failed, block #",
blk, j);
- fastboot_fail(
- "flash write failure");
+ info->mssg("flash write failure");
free(fill_buf);
- return;
+ return -1;
}
blk += blks;
i += j;
case CHUNK_TYPE_CRC32:
if (chunk_header->total_sz !=
sparse_header->chunk_hdr_sz) {
- fastboot_fail(
- "Bogus chunk size for chunk type Dont Care");
- return;
+ info->mssg("Bogus chunk size for chunk type Dont Care");
+ return -1;
}
total_blocks += chunk_header->chunk_sz;
data += chunk_data_sz;
default:
printf("%s: Unknown chunk type: %x\n", __func__,
chunk_header->chunk_type);
- fastboot_fail("Unknown chunk type");
- return;
+ info->mssg("Unknown chunk type");
+ return -1;
}
}
total_blocks, sparse_header->total_blks);
printf("........ wrote %u bytes to '%s'\n", bytes_written, part_name);
- if (total_blocks != sparse_header->total_blks)
- fastboot_fail("sparse image write failure");
- else
- fastboot_okay("");
+ if (total_blocks != sparse_header->total_blks) {
+ info->mssg("sparse image write failure");
+ return -1;
+ }
- return;
+ return 0;
}