Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image-android-sparse: make the CRC optional #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ Options:
:block-size: The granularity that the sparse image uses to
find "don't care" or "fill" blocks. The supported
block sizes depend on the user. The default is 4k.
:add-crc: Generate sparse comptible images containing the CRC. Ensure
that your sparse tool can handle CRC sparse images.
Defaults to false.

cpio
****
Expand Down
31 changes: 21 additions & 10 deletions image-android-sparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

struct sparse {
uint32_t block_size;
cfg_bool_t add_crc;
};

struct sparse_header {
Expand Down Expand Up @@ -333,16 +334,23 @@ static int android_sparse_generate(struct image *image)
crc32 = crc32_next(zeros, sparse->block_size, crc32);
}

header.input_chunks++;
chunk_header.chunk_type = SPARSE_CRC32;
chunk_header.blocks = 0;
chunk_header.size = sizeof(chunk_header) + sizeof(crc32);
ret = flush_header(image, out_fd, &chunk_header, -1);
if (ret < 0)
return ret;
ret = write_data(image, out_fd, &crc32, sizeof(crc32));
if (ret < 0)
goto out;
if (sparse->add_crc) {
/*
* Albeit CRC is supported by the sparse format, the Android
* tools don't honor the support and now starting to fail if an
* CRC is found.
*/
header.input_chunks++;
chunk_header.chunk_type = SPARSE_CRC32;
chunk_header.blocks = 0;
chunk_header.size = sizeof(chunk_header) + sizeof(crc32);
ret = flush_header(image, out_fd, &chunk_header, -1);
if (ret < 0)
return ret;
ret = write_data(image, out_fd, &crc32, sizeof(crc32));
if (ret < 0)
goto out;
}

offset = lseek(out_fd, 0, SEEK_SET);
if (offset < 0) {
Expand Down Expand Up @@ -396,13 +404,16 @@ static int android_sparse_setup(struct image *image, cfg_t *cfg)
return -EINVAL;
}

sparse->add_crc = cfg_getbool(cfg, "add-crc");

image->handler_priv = sparse;
return 0;
}

static cfg_opt_t android_sparse_opts[] = {
CFG_STR("image", NULL, CFGF_NONE),
CFG_STR("block-size", "4k", CFGF_NONE),
CFG_BOOL("add-crc", cfg_false, CFGF_NONE),
CFG_END()
};

Expand Down
Loading