programmer: Make use of new register_spi_master() API
Pass pointers to dynamically allocated data to register_spi_master().
This way we can avoid some mutable globals.
flashrom-stable: Updated `dirtyjtag_spi` and `dediprog`
that were added/refactored earlier.
Change-Id: Id7821f1db3284b7b5b3d0abfd878b979c53870a1
Signed-off-by: Nico Huber <nico.h@gmx.de>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/54067
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72200
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/dediprog.c b/dediprog.c
index 69c4782..af1f23f 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -1308,8 +1308,7 @@
if (dediprog_set_leds(LED_NONE, dp_data))
goto init_err_cleanup_exit;
- spi_master_dediprog.data = dp_data;
- return register_spi_master(&spi_master_dediprog, NULL);
+ return register_spi_master(&spi_master_dediprog, dp_data);
init_err_cleanup_exit:
dediprog_shutdown(dp_data);
diff --git a/dirtyjtag_spi.c b/dirtyjtag_spi.c
index c9e921f..e7d8664 100644
--- a/dirtyjtag_spi.c
+++ b/dirtyjtag_spi.c
@@ -189,7 +189,7 @@
return dirtyjtag_djtag1_spi_send_command(djtag_data, writecnt, readcnt, writearr, readarr);
}
-static struct spi_master spi_master_dirtyjtag_spi = {
+static const struct spi_master spi_master_dirtyjtag_spi = {
.features = SPI_MASTER_4BA,
.max_data_read = MAX_DATA_READ_UNLIMITED,
.max_data_write = MAX_DATA_WRITE_UNLIMITED,
@@ -300,8 +300,7 @@
if (register_shutdown(dirtyjtag_spi_shutdown, djtag_data))
goto cleanup_libusb_handle;
- spi_master_dirtyjtag_spi.data = djtag_data;
- return register_spi_master(&spi_master_dirtyjtag_spi, NULL);
+ return register_spi_master(&spi_master_dirtyjtag_spi, djtag_data);
cleanup_libusb_handle:
libusb_attach_kernel_driver(handle, 0);
diff --git a/dummyflasher.c b/dummyflasher.c
index 01597f9..bddc2a7 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -113,7 +113,7 @@
static uint32_t dummy_chip_readl(const struct flashctx *flash, const chipaddr addr);
static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
-static struct spi_master spi_master_dummyflasher = {
+static const struct spi_master spi_master_dummyflasher = {
.features = SPI_MASTER_4BA,
.max_data_read = MAX_DATA_READ_UNLIMITED,
.max_data_write = MAX_DATA_UNSPECIFIED,
@@ -441,7 +441,6 @@
return 1;
}
data->emu_chip = EMULATE_NONE;
- spi_master_dummyflasher.data = data;
par_master_dummy.data = data;
msg_pspew("%s\n", __func__);
@@ -499,7 +498,7 @@
register_par_master(&par_master_dummy,
dummy_buses_supported & BUS_NONSPI);
if (dummy_buses_supported & BUS_SPI)
- register_spi_master(&spi_master_dummyflasher, NULL);
+ register_spi_master(&spi_master_dummyflasher, data);
return 0;
}
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 2737dae..b37a60e 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -289,7 +289,7 @@
return ret ? -1 : 0;
}
-static struct spi_master spi_master_ft2232 = {
+static const struct spi_master spi_master_ft2232 = {
.features = SPI_MASTER_4BA,
.max_data_read = 64 * 1024,
.max_data_write = 256,
@@ -695,13 +695,12 @@
spi_data->cs_bits = cs_bits;
spi_data->aux_bits = aux_bits;
spi_data->pindir = pindir;
- spi_master_ft2232.data = spi_data;
if (register_shutdown(ft2232_shutdown, spi_data)) {
ret = -9;
goto ftdi_err;
}
- register_spi_master(&spi_master_ft2232, NULL);
+ register_spi_master(&spi_master_ft2232, spi_data);
return 0;
diff --git a/jlink_spi.c b/jlink_spi.c
index ffa547d..589447a 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -156,7 +156,7 @@
return 0;
}
-static struct spi_master spi_master_jlink_spi = {
+static const struct spi_master spi_master_jlink_spi = {
/* Maximum data read size in one go (excluding opcode+address). */
.max_data_read = JTAG_MAX_TRANSFER_SIZE - 5,
/* Maximum data write size in one go (excluding opcode+address). */
@@ -510,7 +510,6 @@
jlink_data->devh = jaylink_devh;
jlink_data->reset_cs = reset_cs;
jlink_data->enable_target_power = enable_target_power;
- spi_master_jlink_spi.data = jlink_data;
/* Ensure that the CS signal is not active initially. */
if (!deassert_cs(jlink_data))
@@ -518,7 +517,7 @@
if (register_shutdown(jlink_spi_shutdown, jlink_data))
goto init_err;
- register_spi_master(&spi_master_jlink_spi, NULL);
+ register_spi_master(&spi_master_jlink_spi, jlink_data);
return 0;
diff --git a/linux_spi.c b/linux_spi.c
index 697a8a2..ea43f9d 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -61,7 +61,7 @@
static int linux_spi_write_256(struct flashctx *flash, const uint8_t *buf,
unsigned int start, unsigned int len);
-static struct spi_master spi_master_linux = {
+static const struct spi_master spi_master_linux = {
.features = SPI_MASTER_4BA,
.max_data_read = MAX_DATA_UNSPECIFIED, /* TODO? */
.max_data_write = MAX_DATA_UNSPECIFIED, /* TODO? */
@@ -186,13 +186,12 @@
}
spi_data->fd = fd;
spi_data->max_kernel_buf_size = max_kernel_buf_size;
- spi_master_linux.data = spi_data;
if (register_shutdown(linux_spi_shutdown, spi_data)) {
free(spi_data);
goto init_err;
}
- register_spi_master(&spi_master_linux, NULL);
+ register_spi_master(&spi_master_linux, spi_data);
return 0;
init_err:
diff --git a/pickit2_spi.c b/pickit2_spi.c
index 5d0b573..62641f2 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -342,7 +342,7 @@
return millivolt;
}
-static struct spi_master spi_master_pickit2 = {
+static const struct spi_master spi_master_pickit2 = {
.max_data_read = 40,
.max_data_write = 40,
.command = pickit2_spi_send_command,
@@ -477,7 +477,6 @@
return 1;
}
pickit2_data->pickit2_handle = pickit2_handle;
- spi_master_pickit2.data = pickit2_data;
if (pickit2_get_firmware_version(pickit2_handle))
goto init_err_cleanup_exit;
@@ -500,7 +499,7 @@
if (register_shutdown(pickit2_shutdown, pickit2_data))
goto init_err_cleanup_exit;
- register_spi_master(&spi_master_pickit2, NULL);
+ register_spi_master(&spi_master_pickit2, pickit2_data);
return 0;