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

Function cbfs_image_create

util/cbfstool/cbfs_image.c:193–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191}
192
193int cbfs_image_create(struct cbfs_image *image, size_t entries_size)
194{
195 assert(image);
196 assert(image->buffer.data);
197
198 size_t empty_header_len = cbfs_calculate_file_header_size("");
199 uint32_t entries_offset = 0;
200 uint32_t align = CBFS_ALIGNMENT;
201 if (image->has_header) {
202 entries_offset = image->header.offset;
203
204 if (entries_offset > image->buffer.size) {
205 ERROR("CBFS file entries are located outside CBFS itself\n");
206 return -1;
207 }
208
209 align = image->header.align;
210 }
211
212 // This attribute must be given in order to prove that this module
213 // correctly preserves certain CBFS properties. See the block comment
214 // near the top of this file (and the associated commit message).
215 if (align < empty_header_len) {
216 ERROR("CBFS must be aligned to at least %zu bytes\n",
217 empty_header_len);
218 return -1;
219 }
220
221 if (entries_size > image->buffer.size - entries_offset) {
222 ERROR("CBFS doesn't have enough space to fit its file entries\n");
223 return -1;
224 }
225
226 if (empty_header_len > entries_size) {
227 ERROR("CBFS is too small to fit any header\n");
228 return -1;
229 }
230 struct cbfs_file *entry_header =
231 (struct cbfs_file *)(image->buffer.data + entries_offset);
232 // This alignment is necessary in order to prove that this module
233 // correctly preserves certain CBFS properties. See the block comment
234 // near the top of this file (and the associated commit message).
235 entries_size -= entries_size % align;
236
237 size_t capacity = entries_size - empty_header_len;
238 LOG("Created CBFS (capacity = %zu bytes)\n", capacity);
239 return cbfs_create_empty_entry(entry_header, CBFS_TYPE_NULL,
240 capacity, "");
241}
242
243int cbfs_legacy_image_create(struct cbfs_image *image,
244 uint32_t architecture,

Callers 2

cbfs_createFunction · 0.85
cbfs_legacy_image_createFunction · 0.85

Calls 2

cbfs_create_empty_entryFunction · 0.85

Tested by

no test coverage detected