* 6. BCM4908 tail
*/
struct bcm4908img_info {
- size_t file_size;
size_t cferom_offset;
size_t bootfs_offset;
size_t padding_offset;
size_t rootfs_offset;
+ size_t tail_offset;
uint32_t crc32; /* Calculated checksum */
struct bcm4908img_tail tail;
};
fseek(fp, info->cferom_offset, SEEK_SET);
info->crc32 = 0xffffffff;
- length = info->file_size - info->cferom_offset - sizeof(struct bcm4908img_tail);
+ length = info->tail_offset - info->cferom_offset;
while (length && (bytes = fread(buf, 1, bcm4908img_min(sizeof(buf), length), fp)) > 0) {
info->crc32 = bcm4908img_crc32(info->crc32, buf, bytes);
length -= bytes;
struct chk_header *chk;
struct stat st;
uint8_t buf[1024];
+ size_t file_size;
uint16_t tmp16;
size_t length;
size_t bytes;
fprintf(stderr, "Failed to fstat: %d\n", err);
return err;
}
- info->file_size = st.st_size;
+ file_size = st.st_size;
+
+ info->tail_offset = file_size - sizeof(*tail);
/* Vendor formats */
/* Offsets */
for (info->bootfs_offset = info->cferom_offset;
- info->bootfs_offset < info->file_size;
+ info->bootfs_offset < info->tail_offset;
info->bootfs_offset += 0x20000) {
if (fseek(fp, info->bootfs_offset, SEEK_SET)) {
err = -errno;
if (be16_to_cpu(tmp16) == 0x8519)
break;
}
- if (info->bootfs_offset >= info->file_size) {
+ if (info->bootfs_offset >= info->tail_offset) {
fprintf(stderr, "Failed to find bootfs offset\n");
return -EPROTO;
}
for (info->rootfs_offset = info->bootfs_offset;
- info->rootfs_offset < info->file_size;
+ info->rootfs_offset < info->tail_offset;
info->rootfs_offset += 0x20000) {
uint32_t *magic = (uint32_t *)&buf[0];
if (be32_to_cpu(*magic) == UBI_EC_HDR_MAGIC)
break;
}
- if (info->rootfs_offset >= info->file_size) {
+ if (info->rootfs_offset >= info->tail_offset) {
fprintf(stderr, "Failed to find rootfs offset\n");
return -EPROTO;
}
fseek(fp, info->cferom_offset, SEEK_SET);
info->crc32 = 0xffffffff;
- length = info->file_size - info->cferom_offset - sizeof(*tail);
+ length = info->tail_offset - info->cferom_offset;
while (length && (bytes = fread(buf, 1, bcm4908img_min(sizeof(buf), length), fp)) > 0) {
info->crc32 = bcm4908img_crc32(info->crc32, buf, bytes);
length -= bytes;
length = (info.padding_offset ? info.padding_offset : info.rootfs_offset) - offset;
} else if (!strcmp(type, "rootfs")) {
offset = info.rootfs_offset;
- length = info.file_size - offset - sizeof(struct bcm4908img_tail);
+ length = info.tail_offset - offset;
} else if (!strcmp(type, "firmware")) {
offset = info.bootfs_offset;
- length = info.file_size - offset - sizeof(struct bcm4908img_tail);
+ length = info.tail_offset - offset;
} else {
err = -EINVAL;
fprintf(stderr, "Unsupported extract type: %s\n", type);