From 5d25f04fd53584e71f12f682430b6c85d3e49ea8 Mon Sep 17 00:00:00 2001 From: Thomas Heijligen Date: Tue, 1 Jun 2021 14:37:12 +0200 Subject: programmer_init: use struct programmer_entry* Change-Id: Iacf0f25abc94a84c5d52c8d69a3e8640817b060a Signed-off-by: Thomas Heijligen Reviewed-on: https://review.coreboot.org/c/flashrom/+/55121 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber --- cli_classic.c | 2 +- flashrom.c | 6 +++--- libflashrom.c | 2 +- programmer.h | 2 +- tests/init_shutdown.c | 18 +++++++++--------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cli_classic.c b/cli_classic.c index f3ae123b..ba6885c9 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -562,7 +562,7 @@ int main(int argc, char *argv[]) /* FIXME: Delay calibration should happen in programmer code. */ myusec_calibrate_delay(); - if (programmer_init(prog, pparam)) { + if (programmer_init(programmer_table[prog], pparam)) { msg_perr("Error: Programmer initialization failed.\n"); ret = 1; goto out_shutdown; diff --git a/flashrom.c b/flashrom.c index 9a7fb181..c3bab170 100644 --- a/flashrom.c +++ b/flashrom.c @@ -130,15 +130,15 @@ static int deregister_chip_restore(struct flashctx *flash) return rc; } -int programmer_init(enum programmer prog, const char *param) +int programmer_init(const struct programmer_entry *prog, const char *param) { int ret; - if (prog >= programmer_table_size) { + if (prog == NULL) { msg_perr("Invalid programmer specified!\n"); return -1; } - programmer = programmer_table[prog]; + programmer = prog; /* Initialize all programmer specific data. */ /* Default to unlimited decode sizes. */ max_rom_decode = (const struct decode_sizes) { diff --git a/libflashrom.c b/libflashrom.c index 1a8b0517..67d3ef30 100644 --- a/libflashrom.c +++ b/libflashrom.c @@ -287,7 +287,7 @@ int flashrom_programmer_init(struct flashrom_programmer **const flashprog, list_programmers_linebreak(0, 80, 0); return 1; } - return programmer_init(prog, prog_param); + return programmer_init(programmer_table[prog], prog_param); } /** diff --git a/programmer.h b/programmer.h index 0dda67e3..809674fc 100644 --- a/programmer.h +++ b/programmer.h @@ -178,7 +178,7 @@ struct programmer_entry { extern const struct programmer_entry *const programmer_table[]; extern const size_t programmer_table_size; -int programmer_init(enum programmer prog, const char *param); +int programmer_init(const struct programmer_entry *prog, const char *param); int programmer_shutdown(void); struct bitbang_spi_master { diff --git a/tests/init_shutdown.c b/tests/init_shutdown.c index 4d9c5490..80440bdb 100644 --- a/tests/init_shutdown.c +++ b/tests/init_shutdown.c @@ -19,22 +19,22 @@ #include "io_mock.h" #include "programmer.h" -static void run_lifecycle(void **state, enum programmer prog, const char *param) +static void run_lifecycle(void **state, const struct programmer_entry *prog, const char *param) { (void) state; /* unused */ - printf("Testing programmer_init for programmer=%u ...\n", prog); + printf("Testing programmer_init for programmer=%s ...\n", prog->name); assert_int_equal(0, programmer_init(prog, strdup(param))); - printf("... programmer_init for programmer=%u successful\n", prog); + printf("... programmer_init for programmer=%s successful\n", prog->name); - printf("Testing programmer_shutdown for programmer=%u ...\n", prog); + printf("Testing programmer_shutdown for programmer=%s ...\n", prog->name); assert_int_equal(0, programmer_shutdown()); - printf("... programmer_shutdown for programmer=%u successful\n", prog); + printf("... programmer_shutdown for programmer=%s successful\n", prog->name); } void dummy_init_and_shutdown_test_success(void **state) { - run_lifecycle(state, PROGRAMMER_DUMMY, "bus=parallel+lpc+fwh+spi"); + run_lifecycle(state, &programmer_dummy, "bus=parallel+lpc+fwh+spi"); } struct mec1308_io_state { @@ -72,7 +72,7 @@ void mec1308_init_and_shutdown_test_success(void **state) io_mock_register(&mec1308_io); will_return_always(__wrap_sio_read, 0x4d); /* MEC1308_DEVICE_ID_VAL */ - run_lifecycle(state, PROGRAMMER_MEC1308, ""); + run_lifecycle(state, &programmer_mec1308, ""); io_mock_register(NULL); } @@ -131,7 +131,7 @@ void ene_lpc_init_and_shutdown_test_success(void **state) io_mock_register(&ene_lpc_io); - run_lifecycle(state, PROGRAMMER_ENE_LPC, ""); + run_lifecycle(state, &programmer_ene_lpc, ""); io_mock_register(NULL); } @@ -144,5 +144,5 @@ void linux_spi_init_and_shutdown_test_success(void **state) * and the fallback to getpagesize(). This test does the latter (fallback to * getpagesize). */ - run_lifecycle(state, PROGRAMMER_LINUX_SPI, "dev=/dev/null"); + run_lifecycle(state, &programmer_linux_spi, "dev=/dev/null"); } -- cgit v1.2.3