* Read the content of a sub-partition from input file and store it in * ifwi_image.subpart_buf[SUB-PARTITION_TYPE]. * * Returns the maximum offset occupied by the sub-partitions. */
| 636 | * Returns the maximum offset occupied by the sub-partitions. |
| 637 | */ |
| 638 | static size_t read_subpart_buf(void *data, size_t size, struct bpdt_entry *e, |
| 639 | size_t count) |
| 640 | { |
| 641 | size_t i, type; |
| 642 | struct buffer *buf; |
| 643 | size_t max_offset = 0; |
| 644 | |
| 645 | for (i = 0; i < count; i++) { |
| 646 | type = e[i].type; |
| 647 | |
| 648 | if (type >= MAX_SUBPARTS) { |
| 649 | ERROR("Invalid sub-partition type %zd.\n", type); |
| 650 | exit(-1); |
| 651 | } |
| 652 | |
| 653 | if (buffer_size(&ifwi_image.subpart_buf[type])) { |
| 654 | ERROR("Multiple sub-partitions of type %zd(%s).\n", |
| 655 | type, subparts[type].name); |
| 656 | exit(-1); |
| 657 | } |
| 658 | |
| 659 | if (e[i].size == 0) { |
| 660 | INFO("Dummy sub-partition %zd(%s). Skipping.\n", type, |
| 661 | subparts[type].name); |
| 662 | continue; |
| 663 | } |
| 664 | |
| 665 | assert((e[i].offset + e[i].size) <= size); |
| 666 | |
| 667 | /* |
| 668 | * Sub-partitions in IFWI image are not in the same order as |
| 669 | * in BPDT entries. BPDT entries are in header_order whereas |
| 670 | * sub-partition offsets in the image are in pack_order. |
| 671 | */ |
| 672 | if ((e[i].offset + e[i].size) > max_offset) |
| 673 | max_offset = e[i].offset + e[i].size; |
| 674 | |
| 675 | /* |
| 676 | * S-BPDT sub-partition contains information about all the |
| 677 | * non-critical sub-partitions. Thus, size of S-BPDT |
| 678 | * sub-partition equals size of S-BPDT plus size of all the |
| 679 | * non-critical sub-partitions. Thus, reading whole of S-BPDT |
| 680 | * here would be redundant as the non-critical partitions are |
| 681 | * read and allocated buffers separately. Also, S-BPDT requires |
| 682 | * special handling for reading header and entries. |
| 683 | */ |
| 684 | if (type == S_BPDT_TYPE) |
| 685 | continue; |
| 686 | |
| 687 | buf = &ifwi_image.subpart_buf[type]; |
| 688 | |
| 689 | alloc_buffer(buf, e[i].size, subparts[type].name); |
| 690 | memcpy(buffer_get(buf), (uint8_t *)data + e[i].offset, |
| 691 | e[i].size); |
| 692 | } |
| 693 | |
| 694 | assert(max_offset); |
| 695 | return max_offset; |
no test coverage detected