MCPcopy Create free account
hub / github.com/coreboot/coreboot / ifwi_write

Function ifwi_write

util/cbfstool/ifwitool.c:1186–1268  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

1184 * with FF.
1185 */
1186static 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 }

Callers 1

ifwi_repackFunction · 0.85

Calls 11

find_entry_by_typeFunction · 0.85
buffer_sizeFunction · 0.85
alloc_bufferFunction · 0.85
buffer_getFunction · 0.85
buffer_spliceFunction · 0.85
bpdt_writeFunction · 0.85
buffer_write_fileFunction · 0.85
exitFunction · 0.85
buffer_deleteFunction · 0.85
printfFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected