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

Function cmd_add

util/cbfstool/elogtool.c:332–368  ·  view source on GitHub ↗

Appends an elog entry to EventLog buffer. */

Source from the content-addressed store, hash-verified

330
331/* Appends an elog entry to EventLog buffer. */
332static int cmd_add(const struct buffer *buf,
333 enum elogtool_flag flags __maybe_unused)
334{
335 uint8_t data[ELOG_MAX_EVENT_DATA_SIZE];
336 size_t data_size = 0;
337 struct buffer copy;
338 uint8_t type = 0;
339 size_t next_event;
340 size_t threshold;
341 int ret;
342
343 if (cmd_add_parse_args(&type, data, &data_size) != ELOGTOOL_EXIT_SUCCESS) {
344 cmd_add_usage();
345 return ELOGTOOL_EXIT_BAD_ARGS;
346 }
347
348 buffer_clone(&copy, buf);
349 buffer_seek(&copy, sizeof(struct elog_header));
350
351 threshold = buffer_size(&copy) * 3 / 4;
352 next_event = next_available_event_offset(&copy);
353
354 if (next_event > threshold) {
355 /* Shrink ~ 1/4 of the size */
356 ret = shrink_buffer(&copy, buffer_size(buf) - threshold);
357 if (ret != ELOGTOOL_EXIT_SUCCESS)
358 return ret;
359 next_event = next_available_event_offset(&copy);
360 }
361
362 buffer_seek(&copy, next_event);
363
364 if (!eventlog_init_event(&copy, type, data, data_size))
365 return ELOGTOOL_EXIT_NOT_ENOUGH_BUFFER_SPACE;
366
367 return ELOGTOOL_EXIT_SUCCESS;
368}
369
370int main(int argc, char **argv)
371{

Callers

nothing calls this directly

Calls 8

cmd_add_parse_argsFunction · 0.85
cmd_add_usageFunction · 0.85
buffer_cloneFunction · 0.85
buffer_seekFunction · 0.85
buffer_sizeFunction · 0.85
shrink_bufferFunction · 0.85
eventlog_init_eventFunction · 0.85

Tested by

no test coverage detected