diff options
author | Edward O'Callaghan <quasisec@google.com> | 2021-11-29 11:02:46 +1100 |
---|---|---|
committer | Edward O'Callaghan <quasisec@chromium.org> | 2022-01-14 23:10:55 +0000 |
commit | d74b8d9c990780ba64515b36aaff79d719d71ead (patch) | |
tree | d6adb48a2f271cb333f9182e8b839015b612950b /util/cbfstool/elogtool.c | |
parent | e565f752217d8f67504f65b980fe7511724e8dd9 (diff) |
util/cbfstool: Port elogtool to libflashrom
This also uncouples cbfstool from being overly Chromium
specific. However the main objective is to not subprocess
flashrom any more and instead use the programmatic API.
BUG=b:207808292
TEST=built and ran `elogtool (list|clear|add 0x16 C0FFEE)`.
Change-Id: I79df2934b9b0492a554a4fecdd533a0abe1df231
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/59714
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Sam McNally <sammc@google.com>
Diffstat (limited to 'util/cbfstool/elogtool.c')
-rw-r--r-- | util/cbfstool/elogtool.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/util/cbfstool/elogtool.c b/util/cbfstool/elogtool.c index 253e2ee95a..44823dd89a 100644 --- a/util/cbfstool/elogtool.c +++ b/util/cbfstool/elogtool.c @@ -11,9 +11,9 @@ #include <common.h> #include <commonlib/bsd/elog.h> -#include <flashrom.h> #include "eventlog.h" +#include "uflashrom.h" /* Only refers to the data max size. The "-1" is the checksum byte */ #define ELOG_MAX_EVENT_DATA_SIZE (ELOG_MAX_EVENT_SIZE - sizeof(struct event_header) - 1) @@ -78,16 +78,18 @@ static void usage(char *invoked_as) */ static int elog_read(struct buffer *buffer, const char *filename) { - if (filename == NULL) { - uint8_t *buf; - uint32_t buf_size; + struct firmware_programmer image = { + .programmer = FLASHROM_PROGRAMMER_INTERNAL_AP, + .data = NULL, + .size = 0, + }; - if (flashrom_read(FLASHROM_PROGRAMMER_INTERNAL_AP, ELOG_RW_REGION_NAME, - &buf, &buf_size) != VB2_SUCCESS) { + if (filename == NULL) { + if (flashrom_read(&image, ELOG_RW_REGION_NAME) != 0) { fprintf(stderr, "Could not read RW_ELOG region using flashrom\n"); return ELOGTOOL_EXIT_READ_ERROR; } - buffer_init(buffer, NULL, buf, buf_size); + buffer_init(buffer, NULL, image.data, image.size); } else if (buffer_from_file(buffer, filename) != 0) { fprintf(stderr, "Could not read input file: %s\n", filename); return ELOGTOOL_EXIT_READ_ERROR; @@ -108,9 +110,14 @@ static int elog_read(struct buffer *buffer, const char *filename) */ static int elog_write(struct buffer *buf, const char *filename) { + struct firmware_programmer image = { + .programmer = FLASHROM_PROGRAMMER_INTERNAL_AP, + .data = buffer_get(buf), + .size = buffer_size(buf), + }; + if (filename == NULL) { - if (flashrom_write(FLASHROM_PROGRAMMER_INTERNAL_AP, ELOG_RW_REGION_NAME, - buffer_get(buf), buffer_size(buf)) != VB2_SUCCESS) { + if (flashrom_write(&image, ELOG_RW_REGION_NAME) != 0) { fprintf(stderr, "Failed to write to RW_ELOG region using flashrom\n"); return ELOGTOOL_EXIT_WRITE_ERROR; |