cbfstool: add code to serialize the header using the new xdr functions
This change adds a header serialization function. Programmers can thus just set up a header as needed, without worrying about forgetting if and how to use the [hn]to[hn]* functions. BUG=None TEST=Build a peppy image and verify that it's bit for bit the same. BRANCH=None Change-Id: I0f9b8e7cac5f52d0ea330ba948650fa0803aa0d5 Signed-off-by: Ronald G. Minnich <rminnich@google.com> Reviewed-on: https://chromium-review.googlesource.com/181552 Reviewed-by: Ronald Minnich <rminnich@chromium.org> Commit-Queue: Ronald Minnich <rminnich@chromium.org> Tested-by: Ronald Minnich <rminnich@chromium.org>
This commit is contained in:
parent
0154239467
commit
919e89c303
2 changed files with 32 additions and 13 deletions
|
|
@ -119,6 +119,21 @@ static int cbfs_fix_legacy_size(struct cbfs_image *image)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void cbfs_put_header(void *dest, struct cbfs_header *header)
|
||||
{
|
||||
struct buffer outheader;
|
||||
|
||||
outheader.data = dest;
|
||||
outheader.size = 0;
|
||||
|
||||
xdr_be.put32(&outheader, header->magic);
|
||||
xdr_be.put32(&outheader, header->version);
|
||||
xdr_be.put32(&outheader, header->romsize);
|
||||
xdr_be.put32(&outheader, header->bootblocksize);
|
||||
xdr_be.put32(&outheader, header->align);
|
||||
xdr_be.put32(&outheader, header->offset);
|
||||
xdr_be.put32(&outheader, header->architecture);
|
||||
}
|
||||
int cbfs_image_create(struct cbfs_image *image,
|
||||
uint32_t architecture,
|
||||
size_t size,
|
||||
|
|
@ -128,7 +143,7 @@ int cbfs_image_create(struct cbfs_image *image,
|
|||
int32_t header_offset,
|
||||
int32_t entries_offset)
|
||||
{
|
||||
struct cbfs_header *header;
|
||||
struct cbfs_header header;
|
||||
struct cbfs_file *entry;
|
||||
uint32_t cbfs_len;
|
||||
size_t entry_header_len;
|
||||
|
|
@ -136,7 +151,7 @@ int cbfs_image_create(struct cbfs_image *image,
|
|||
DEBUG("cbfs_image_create: bootblock=0x%x+0x%zx, "
|
||||
"header=0x%x+0x%zx, entries_offset=0x%x\n",
|
||||
bootblock_offset, bootblock->size,
|
||||
header_offset, sizeof(*header), entries_offset);
|
||||
header_offset, sizeof(header), entries_offset);
|
||||
|
||||
if (buffer_create(&image->buffer, size, "(new)") != 0)
|
||||
return -1;
|
||||
|
|
@ -174,20 +189,20 @@ int cbfs_image_create(struct cbfs_image *image,
|
|||
bootblock->size);
|
||||
|
||||
// Prepare header
|
||||
if (header_offset + sizeof(*header) > size) {
|
||||
if (header_offset + sizeof(header) > size) {
|
||||
ERROR("Header (0x%x+0x%zx) exceed ROM size (0x%zx)\n",
|
||||
header_offset, sizeof(*header), size);
|
||||
header_offset, sizeof(header), size);
|
||||
return -1;
|
||||
}
|
||||
header = (struct cbfs_header *)(image->buffer.data + header_offset);
|
||||
image->header = header;
|
||||
header->magic = htonl(CBFS_HEADER_MAGIC);
|
||||
header->version = htonl(CBFS_HEADER_VERSION);
|
||||
header->romsize = htonl(size);
|
||||
header->bootblocksize = htonl(bootblock->size);
|
||||
header->align = htonl(align);
|
||||
header->offset = htonl(entries_offset);
|
||||
header->architecture = htonl(architecture);
|
||||
image->header = (struct cbfs_header *)(image->buffer.data + header_offset);
|
||||
header.magic = CBFS_HEADER_MAGIC;
|
||||
header.version = CBFS_HEADER_VERSION;
|
||||
header.romsize = size;
|
||||
header.bootblocksize = bootblock->size;
|
||||
header.align = align;
|
||||
header.offset = entries_offset;
|
||||
header.architecture = architecture;
|
||||
cbfs_put_header(image->header, &header);
|
||||
|
||||
// Prepare entries
|
||||
if (align_up(entries_offset, align) != entries_offset) {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ struct cbfs_image {
|
|||
struct cbfs_header *header;
|
||||
};
|
||||
|
||||
/* Given a pointer, serialize the header from host-native byte format
|
||||
* to cbfs format, i.e. big-endian. */
|
||||
void cbfs_put_header(void *dest, struct cbfs_header *header);
|
||||
|
||||
/* Creates an empty CBFS image by given size, and description to its content
|
||||
* (bootblock, align, header location, starting offset of CBFS entries.
|
||||
* The output image will contain a valid cbfs_header, with one cbfs_file
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue