image_t **p = &image_head;
while (*p) {
- if (!memcmp(&(*p)->uuid, &image->uuid, sizeof(image->uuid)))
+ if (!memcmp(&(*p)->toc_e.uuid, &image->toc_e.uuid,
+ sizeof(image->toc_e.uuid)))
break;
p = &(*p)->next;
}
image_t *image;
for (image = image_head; image != NULL; image = image->next)
- if (memcmp(&image->uuid, uuid, sizeof(uuid_t)) == 0)
+ if (!memcmp(&image->toc_e.uuid, uuid, sizeof(*uuid)))
return image;
return NULL;
}
*/
image = xzalloc(sizeof(*image),
"failed to allocate memory for image");
- memcpy(&image->uuid, &toc_entry->uuid, sizeof(uuid_t));
+ image->toc_e = *toc_entry;
image->buffer = xmalloc(toc_entry->size,
"failed to allocate image buffer, is FIP file corrupted?");
/* Overflow checks before memory copy. */
memcpy(image->buffer, buf + toc_entry->offset_address,
toc_entry->size);
- image->size = toc_entry->size;
/* If this is an unknown image, create a descriptor for it. */
- desc = lookup_image_desc_from_uuid(&image->uuid);
+ desc = lookup_image_desc_from_uuid(&toc_entry->uuid);
if (desc == NULL) {
char name[_UUID_STR_LEN + 1], filename[PATH_MAX];
- uuid_to_str(name, sizeof(name), &image->uuid);
+ uuid_to_str(name, sizeof(name), &toc_entry->uuid);
snprintf(filename, sizeof(filename), "%s%s",
name, ".bin");
- desc = new_image_desc(&image->uuid, name, "blob");
+ desc = new_image_desc(&toc_entry->uuid, name, "blob");
desc->action = DO_UNPACK;
desc->action_arg = xstrdup(filename,
"failed to allocate memory for blob filename");
log_errx("fstat %s", filename);
image = xzalloc(sizeof(*image), "failed to allocate memory for image");
- memcpy(&image->uuid, uuid, sizeof(uuid_t));
+ image->toc_e.uuid = *uuid;
image->buffer = xmalloc(st.st_size, "failed to allocate image buffer");
if (fread(image->buffer, 1, st.st_size, fp) != st.st_size)
log_errx("Failed to read %s", filename);
- image->size = st.st_size;
+ image->toc_e.size = st.st_size;
fclose(fp);
return image;
fp = fopen(filename, "w");
if (fp == NULL)
log_err("fopen");
- xfwrite(image->buffer, image->size, fp, filename);
+ xfwrite(image->buffer, image->toc_e.size, fp, filename);
fclose(fp);
return 0;
}
static int info_cmd(int argc, char *argv[])
{
image_t *image;
- uint64_t image_offset;
- uint64_t image_size;
fip_toc_header_t toc_header;
if (argc != 2)
(unsigned long long)toc_header.flags);
}
- image_offset = sizeof(fip_toc_header_t) +
- (sizeof(fip_toc_entry_t) * (nr_images + 1));
-
for (image = image_head; image != NULL; image = image->next) {
image_desc_t *desc;
- desc = lookup_image_desc_from_uuid(&image->uuid);
+ desc = lookup_image_desc_from_uuid(&image->toc_e.uuid);
assert(desc != NULL);
- printf("%s: ", desc->name);
- image_size = image->size;
- printf("offset=0x%llX, size=0x%llX, cmdline=\"--%s\"",
- (unsigned long long)image_offset,
- (unsigned long long)image_size,
+ printf("%s: offset=0x%llX, size=0x%llX, cmdline=\"--%s\"",
+ desc->name,
+ (unsigned long long)image->toc_e.offset_address,
+ (unsigned long long)image->toc_e.size,
desc->cmdline_name);
if (verbose) {
unsigned char md[SHA256_DIGEST_LENGTH];
- SHA256(image->buffer, image_size, md);
+ SHA256(image->buffer, image->toc_e.size, md);
printf(", sha256=");
md_print(md, sizeof(md));
}
putchar('\n');
- image_offset += image_size;
}
free_images();
fip_toc_header_t *toc_header;
fip_toc_entry_t *toc_entry;
char *buf;
- uint64_t entry_offset, buf_size, payload_size;
-
- /* Calculate total payload size and allocate scratch buffer. */
- payload_size = 0;
- for (image = image_head; image != NULL; image = image->next)
- payload_size += image->size;
+ uint64_t entry_offset, buf_size, payload_size = 0;
buf_size = sizeof(fip_toc_header_t) +
sizeof(fip_toc_entry_t) * (nr_images + 1);
entry_offset = buf_size;
for (image = image_head; image != NULL; image = image->next) {
- memcpy(&toc_entry->uuid, &image->uuid, sizeof(uuid_t));
- toc_entry->offset_address = entry_offset;
- toc_entry->size = image->size;
- toc_entry->flags = 0;
- entry_offset += toc_entry->size;
- toc_entry++;
+ payload_size += image->toc_e.size;
+ image->toc_e.offset_address = entry_offset;
+ *toc_entry++ = image->toc_e;
+ entry_offset += image->toc_e.size;
}
/* Append a null uuid entry to mark the end of ToC entries. */
- memcpy(&toc_entry->uuid, &uuid_null, sizeof(uuid_t));
+ memset(toc_entry, 0, sizeof(*toc_entry));
toc_entry->offset_address = entry_offset;
- toc_entry->size = 0;
- toc_entry->flags = 0;
/* Generate the FIP file. */
fp = fopen(filename, "w");
log_dbgx("Payload size: %zu bytes", payload_size);
for (image = image_head; image != NULL; image = image->next)
- xfwrite(image->buffer, image->size, fp, filename);
+ xfwrite(image->buffer, image->toc_e.size, fp, filename);
fclose(fp);
return 0;