* Follows these steps to re-create image: * 1. Write any non-IFWI prefix. * 2. Write out BPDT header and entries. * 3. Write sub-partition buffers to respective offsets. * 4. Write any non-IFWI suffix. * * While performing the above steps, make sure that any empty holes are filled * with FF. */
| 1184 | * with FF. |
| 1185 | */ |
| 1186 | static void ifwi_write(const char *image_name) |
| 1187 | { |
| 1188 | struct bpdt_entry *s = find_entry_by_type(S_BPDT_TYPE); |
| 1189 | assert(s); |
| 1190 | |
| 1191 | size_t ifwi_start, ifwi_end, file_end; |
| 1192 | |
| 1193 | ifwi_start = ifwi_image.input_ifwi_start_offset; |
| 1194 | ifwi_end = ifwi_start + ALIGN_UP(s->offset + s->size, 4 * KiB); |
| 1195 | file_end = ifwi_end + (buffer_size(&ifwi_image.input_buff) - |
| 1196 | ifwi_image.input_ifwi_end_offset); |
| 1197 | |
| 1198 | struct buffer b; |
| 1199 | |
| 1200 | alloc_buffer(&b, file_end, "Final-IFWI"); |
| 1201 | |
| 1202 | uint8_t *input_data = buffer_get(&ifwi_image.input_buff); |
| 1203 | uint8_t *output_data = buffer_get(&b); |
| 1204 | |
| 1205 | DEBUG("ifwi_start:0x%zx, ifwi_end:0x%zx, file_end:0x%zx\n", ifwi_start, |
| 1206 | ifwi_end, file_end); |
| 1207 | |
| 1208 | /* Copy non-IFWI prefix, if any. */ |
| 1209 | memcpy(output_data, input_data, ifwi_start); |
| 1210 | |
| 1211 | DEBUG("Copied non-IFWI prefix (offset=0x0, size=0x%zx).\n", ifwi_start); |
| 1212 | |
| 1213 | struct buffer ifwi; |
| 1214 | buffer_splice(&ifwi, &b, ifwi_start, ifwi_end - ifwi_start); |
| 1215 | uint8_t *ifwi_data = buffer_get(&ifwi); |
| 1216 | |
| 1217 | /* Copy sub-partitions using pack_order. */ |
| 1218 | struct bpdt_entry *curr; |
| 1219 | struct buffer *subpart_buf; |
| 1220 | int i, type; |
| 1221 | for (i = 0; i < MAX_SUBPARTS; i++) { |
| 1222 | type = bpdt_pack_order[i]; |
| 1223 | |
| 1224 | if (type == S_BPDT_TYPE) |
| 1225 | continue; |
| 1226 | |
| 1227 | curr = find_entry_by_type(type); |
| 1228 | |
| 1229 | if ((curr == NULL) || (curr->size == 0)) |
| 1230 | continue; |
| 1231 | |
| 1232 | subpart_buf = &ifwi_image.subpart_buf[type]; |
| 1233 | |
| 1234 | DEBUG("curr->offset=0x%x, curr->size=0x%x, type=%d, " |
| 1235 | "write_size=0x%zx\n", curr->offset, curr->size, type, |
| 1236 | buffer_size(subpart_buf)); |
| 1237 | |
| 1238 | assert((curr->offset + buffer_size(subpart_buf)) <= |
| 1239 | buffer_size(&ifwi)); |
| 1240 | |
| 1241 | memcpy(ifwi_data + curr->offset, buffer_get(subpart_buf), |
| 1242 | buffer_size(subpart_buf)); |
| 1243 | } |
no test coverage detected