Nico Huber submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Nico Huber: Looks good to me, approved Edward O'Callaghan: Looks good to me, approved
spi_master: Move shutdown function above spi_master struct

This patch prepares spi masters to use new API which allows to
register shutdown function in spi_master struct. See also later
patch in this chain, where spi masters are converted to new API.

BUG=b:185191942
TEST=builds and ninja test
Comparing flashrom binary before and after the patch,
make clean && make CONFIG_EVERYTHING=yes VERSION=none
binary is the same

Change-Id: I50716686552b4ddcc6089d5afadb19ef59d9f9b4
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56101
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
---
M bitbang_spi.c
M buspirate_spi.c
M ch341a_spi.c
M dediprog.c
M digilent_spi.c
M dummyflasher.c
M it87spi.c
M jlink_spi.c
M lspcon_i2c_spi.c
M pickit2_spi.c
M realtek_mst_i2c_spi.c
M sb600spi.c
M serprog.c
M wbsio_spi.c
14 files changed, 184 insertions(+), 188 deletions(-)

diff --git a/bitbang_spi.c b/bitbang_spi.c
index 3d973c5..83c3501 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -131,6 +131,13 @@
return 0;
}

+static int bitbang_spi_shutdown(void *data)
+{
+ /* FIXME: Run bitbang_spi_release_bus here or per command? */
+ free(data);
+ return 0;
+}
+
static const struct spi_master spi_master_bitbang = {
.features = SPI_MASTER_4BA,
.max_data_read = MAX_DATA_READ_UNLIMITED,
@@ -142,13 +149,6 @@
.write_aai = default_spi_write_aai,
};

-static int bitbang_spi_shutdown(void *data)
-{
- /* FIXME: Run bitbang_spi_release_bus here or per command? */
- free(data);
- return 0;
-}
-
int register_spi_bitbang_master(const struct bitbang_spi_master *master, void *spi_data)
{
struct spi_master mst = spi_master_bitbang;
diff --git a/buspirate_spi.c b/buspirate_spi.c
index b56d422..3c0a6ff 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -130,38 +130,6 @@
return ret;
}

-static struct spi_master spi_master_buspirate = {
- .features = SPI_MASTER_4BA,
- .max_data_read = MAX_DATA_UNSPECIFIED,
- .max_data_write = MAX_DATA_UNSPECIFIED,
- .command = NULL,
- .multicommand = default_spi_send_multicommand,
- .read = default_spi_read,
- .write_256 = default_spi_write_256,
- .write_aai = default_spi_write_aai,
-};
-
-static const struct buspirate_speeds spispeeds[] = {
- {"30k", 0x0},
- {"125k", 0x1},
- {"250k", 0x2},
- {"1M", 0x3},
- {"2M", 0x4},
- {"2.6M", 0x5},
- {"4M", 0x6},
- {"8M", 0x7},
- {NULL, 0x0}
-};
-
-static const struct buspirate_speeds serialspeeds[] = {
- {"115200", 115200},
- {"230400", 230400},
- {"250000", 250000},
- {"2000000", 2000000},
- {"2M", 2000000},
- {NULL, 0}
-};
-
static int buspirate_spi_shutdown(void *data)
{
struct bp_spi_data *bp_data = data;
@@ -204,6 +172,38 @@
return ret;
}

+static struct spi_master spi_master_buspirate = {
+ .features = SPI_MASTER_4BA,
+ .max_data_read = MAX_DATA_UNSPECIFIED,
+ .max_data_write = MAX_DATA_UNSPECIFIED,
+ .command = NULL,
+ .multicommand = default_spi_send_multicommand,
+ .read = default_spi_read,
+ .write_256 = default_spi_write_256,
+ .write_aai = default_spi_write_aai,
+};
+
+static const struct buspirate_speeds spispeeds[] = {
+ {"30k", 0x0},
+ {"125k", 0x1},
+ {"250k", 0x2},
+ {"1M", 0x3},
+ {"2M", 0x4},
+ {"2.6M", 0x5},
+ {"4M", 0x6},
+ {"8M", 0x7},
+ {NULL, 0x0}
+};
+
+static const struct buspirate_speeds serialspeeds[] = {
+ {"115200", 115200},
+ {"230400", 230400},
+ {"250000", 250000},
+ {"2000000", 2000000},
+ {"2M", 2000000},
+ {NULL, 0}
+};
+
static int buspirate_spi_send_command_v1(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr)
{
diff --git a/ch341a_spi.c b/ch341a_spi.c
index 185e582..22c9781 100644
--- a/ch341a_spi.c
+++ b/ch341a_spi.c
@@ -385,20 +385,6 @@
return 0;
}

-static const struct spi_master spi_master_ch341a_spi = {
- .features = SPI_MASTER_4BA,
- /* flashrom's current maximum is 256 B. CH341A was tested on Linux and Windows to accept atleast
- * 128 kB. Basically there should be no hard limit because transfers are broken up into USB packets
- * sent to the device and most of their payload streamed via SPI. */
- .max_data_read = 4 * 1024,
- .max_data_write = 4 * 1024,
- .command = ch341a_spi_spi_send_command,
- .multicommand = default_spi_send_multicommand,
- .read = default_spi_read,
- .write_256 = default_spi_write_256,
- .write_aai = default_spi_write_aai,
-};
-
static int ch341a_spi_shutdown(void *data)
{
if (handle == NULL)
@@ -419,6 +405,20 @@
return 0;
}

+static const struct spi_master spi_master_ch341a_spi = {
+ .features = SPI_MASTER_4BA,
+ /* flashrom's current maximum is 256 B. CH341A was tested on Linux and Windows to accept atleast
+ * 128 kB. Basically there should be no hard limit because transfers are broken up into USB packets
+ * sent to the device and most of their payload streamed via SPI. */
+ .max_data_read = 4 * 1024,
+ .max_data_write = 4 * 1024,
+ .command = ch341a_spi_spi_send_command,
+ .multicommand = default_spi_send_multicommand,
+ .read = default_spi_read,
+ .write_256 = default_spi_write_256,
+ .write_aai = default_spi_write_aai,
+};
+
static int ch341a_spi_init(void)
{
if (handle != NULL) {
diff --git a/dediprog.c b/dediprog.c
index b47e8e9..d98af49 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -992,6 +992,24 @@
return millivolt;
}

+static int dediprog_shutdown(void *data)
+{
+ dediprog_devicetype = DEV_UNKNOWN;
+
+ /* URB 28. Command Set SPI Voltage to 0. */
+ if (dediprog_set_spi_voltage(0x0))
+ return 1;
+
+ if (libusb_release_interface(dediprog_handle, 0)) {
+ msg_perr("Could not release USB interface!\n");
+ return 1;
+ }
+ libusb_close(dediprog_handle);
+ libusb_exit(usb_ctx);
+
+ return 0;
+}
+
static struct spi_master spi_master_dediprog = {
.features = SPI_MASTER_NO_4BA_MODES,
.max_data_read = 16, /* 18 seems to work fine as well, but 19 times out sometimes with FW 5.15. */
@@ -1037,24 +1055,6 @@
return 0;
}

-static int dediprog_shutdown(void *data)
-{
- dediprog_devicetype = DEV_UNKNOWN;
-
- /* URB 28. Command Set SPI Voltage to 0. */
- if (dediprog_set_spi_voltage(0x0))
- return 1;
-
- if (libusb_release_interface(dediprog_handle, 0)) {
- msg_perr("Could not release USB interface!\n");
- return 1;
- }
- libusb_close(dediprog_handle);
- libusb_exit(usb_ctx);
-
- return 0;
-}
-
static int dediprog_init(void)
{
char *voltage, *id_str, *device, *spispeed, *target_str;
diff --git a/digilent_spi.c b/digilent_spi.c
index 8a3699d..0ec402e 100644
--- a/digilent_spi.c
+++ b/digilent_spi.c
@@ -315,18 +315,6 @@
return 0;
}

-static const struct spi_master spi_master_digilent_spi = {
- .features = SPI_MASTER_4BA,
- .max_data_read = 252,
- .max_data_write = 252,
- .command = digilent_spi_send_command,
- .multicommand = default_spi_send_multicommand,
- .read = default_spi_read,
- .write_256 = default_spi_write_256,
- .write_aai = default_spi_write_aai,
-};
-
-
static int digilent_spi_shutdown(void *data)
{
struct digilent_spi_data *digilent_data = data;
@@ -340,6 +328,17 @@
return 0;
}

+static const struct spi_master spi_master_digilent_spi = {
+ .features = SPI_MASTER_4BA,
+ .max_data_read = 252,
+ .max_data_write = 252,
+ .command = digilent_spi_send_command,
+ .multicommand = default_spi_send_multicommand,
+ .read = default_spi_read,
+ .write_256 = default_spi_write_256,
+ .write_aai = default_spi_write_aai,
+};
+
static bool default_reset(struct libusb_device_handle *handle)
{
char board[17];
diff --git a/dummyflasher.c b/dummyflasher.c
index 049f9d5..2311576 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -580,7 +580,23 @@
return 0;
}

-
+static int dummy_shutdown(void *data)
+{
+ msg_pspew("%s\n", __func__);
+ struct emu_data *emu_data = (struct emu_data *)data;
+ if (emu_data->emu_chip != EMULATE_NONE) {
+ if (emu_data->emu_persistent_image && emu_data->emu_modified) {
+ msg_pdbg("Writing %s\n", emu_data->emu_persistent_image);
+ write_buf_to_file(emu_data->flashchip_contents,
+ emu_data->emu_chip_size,
+ emu_data->emu_persistent_image);
+ }
+ free(emu_data->emu_persistent_image);
+ free(emu_data->flashchip_contents);
+ }
+ free(data);
+ return 0;
+}

static const struct spi_master spi_master_dummyflasher = {
.features = SPI_MASTER_4BA,
@@ -604,24 +620,6 @@
.chip_writen = dummy_chip_writen,
};

-static int dummy_shutdown(void *data)
-{
- msg_pspew("%s\n", __func__);
- struct emu_data *emu_data = (struct emu_data *)data;
- if (emu_data->emu_chip != EMULATE_NONE) {
- if (emu_data->emu_persistent_image && emu_data->emu_modified) {
- msg_pdbg("Writing %s\n", emu_data->emu_persistent_image);
- write_buf_to_file(emu_data->flashchip_contents,
- emu_data->emu_chip_size,
- emu_data->emu_persistent_image);
- }
- free(emu_data->emu_persistent_image);
- free(emu_data->flashchip_contents);
- }
- free(data);
- return 0;
-}
-
static int init_data(struct emu_data *data, enum chipbustype *dummy_buses_supported)
{

diff --git a/it87spi.c b/it87spi.c
index cbf830b..e552328 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -290,6 +290,12 @@
return 0;
}

+static int it8716f_shutdown(void *data)
+{
+ free(data);
+ return 0;
+}
+
static const struct spi_master spi_master_it87xx = {
.max_data_read = 3,
.max_data_write = MAX_DATA_UNSPECIFIED,
@@ -300,13 +306,6 @@
.write_aai = spi_chip_write_1,
};

-
-static int it8716f_shutdown(void *data)
-{
- free(data);
- return 0;
-}
-
static uint16_t it87spi_probe(uint16_t port)
{
uint8_t tmp = 0;
diff --git a/jlink_spi.c b/jlink_spi.c
index 8b8533c..daa8eb6 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -155,19 +155,6 @@
return 0;
}

-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). */
- .max_data_write = JTAG_MAX_TRANSFER_SIZE - 5,
- .command = jlink_spi_send_command,
- .multicommand = default_spi_send_multicommand,
- .read = default_spi_read,
- .write_256 = default_spi_write_256,
- .write_aai = default_spi_write_aai,
- .features = SPI_MASTER_4BA,
-};
-
static int jlink_spi_shutdown(void *data)
{
struct jlink_spi_data *jlink_data = data;
@@ -181,6 +168,19 @@
return 0;
}

+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). */
+ .max_data_write = JTAG_MAX_TRANSFER_SIZE - 5,
+ .command = jlink_spi_send_command,
+ .multicommand = default_spi_send_multicommand,
+ .read = default_spi_read,
+ .write_256 = default_spi_write_256,
+ .write_aai = default_spi_write_aai,
+ .features = SPI_MASTER_4BA,
+};
+
static int jlink_spi_init(void)
{
char *arg;
diff --git a/lspcon_i2c_spi.c b/lspcon_i2c_spi.c
index b590f1d..e9ff2dd 100644
--- a/lspcon_i2c_spi.c
+++ b/lspcon_i2c_spi.c
@@ -410,16 +410,6 @@
return SPI_GENERIC_ERROR;
}

-static const struct spi_master spi_master_i2c_lspcon = {
- .max_data_read = 16,
- .max_data_write = 12,
- .command = lspcon_i2c_spi_send_command,
- .multicommand = default_spi_send_multicommand,
- .read = lspcon_i2c_spi_read,
- .write_256 = lspcon_i2c_spi_write_256,
- .write_aai = lspcon_i2c_spi_write_aai,
-};
-
static int lspcon_i2c_spi_shutdown(void *data)
{
int ret = 0;
@@ -436,6 +426,16 @@
return ret;
}

+static const struct spi_master spi_master_i2c_lspcon = {
+ .max_data_read = 16,
+ .max_data_write = 12,
+ .command = lspcon_i2c_spi_send_command,
+ .multicommand = default_spi_send_multicommand,
+ .read = lspcon_i2c_spi_read,
+ .write_256 = lspcon_i2c_spi_write_256,
+ .write_aai = lspcon_i2c_spi_write_aai,
+};
+
static int lspcon_i2c_spi_init(void)
{
int fd = i2c_open_from_programmer_params(REGISTER_ADDRESS, 0);
diff --git a/pickit2_spi.c b/pickit2_spi.c
index bec9457..73ace4b 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -340,16 +340,6 @@
return millivolt;
}

-static const struct spi_master spi_master_pickit2 = {
- .max_data_read = 40,
- .max_data_write = 40,
- .command = pickit2_spi_send_command,
- .multicommand = default_spi_send_multicommand,
- .read = default_spi_read,
- .write_256 = default_spi_write_256,
- .write_aai = default_spi_write_aai,
-};
-
static int pickit2_shutdown(void *data)
{
struct pickit2_spi_data *pickit2_data = data;
@@ -388,6 +378,16 @@
return ret;
}

+static const struct spi_master spi_master_pickit2 = {
+ .max_data_read = 40,
+ .max_data_write = 40,
+ .command = pickit2_spi_send_command,
+ .multicommand = default_spi_send_multicommand,
+ .read = default_spi_read,
+ .write_256 = default_spi_write_256,
+ .write_aai = default_spi_write_aai,
+};
+
static int pickit2_spi_init(void)
{
uint8_t buf[CMD_LENGTH] = {
diff --git a/realtek_mst_i2c_spi.c b/realtek_mst_i2c_spi.c
index a45838c..4145864 100644
--- a/realtek_mst_i2c_spi.c
+++ b/realtek_mst_i2c_spi.c
@@ -410,16 +410,6 @@
return SPI_GENERIC_ERROR;
}

-static const struct spi_master spi_master_i2c_realtek_mst = {
- .max_data_read = 16,
- .max_data_write = 8,
- .command = realtek_mst_i2c_spi_send_command,
- .multicommand = default_spi_send_multicommand,
- .read = realtek_mst_i2c_spi_read,
- .write_256 = realtek_mst_i2c_spi_write_256,
- .write_aai = realtek_mst_i2c_spi_write_aai,
-};
-
static int realtek_mst_i2c_spi_shutdown(void *data)
{
int ret = 0;
@@ -442,6 +432,16 @@
return ret;
}

+static const struct spi_master spi_master_i2c_realtek_mst = {
+ .max_data_read = 16,
+ .max_data_write = 8,
+ .command = realtek_mst_i2c_spi_send_command,
+ .multicommand = default_spi_send_multicommand,
+ .read = realtek_mst_i2c_spi_read,
+ .write_256 = realtek_mst_i2c_spi_write_256,
+ .write_aai = realtek_mst_i2c_spi_write_aai,
+};
+
static int get_params(int *reset, int *enter_isp)
{
char *reset_str = NULL, *isp_str = NULL;
diff --git a/sb600spi.c b/sb600spi.c
index c4b25e5..5c65475 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -570,6 +570,17 @@
return 0;
}

+static int sb600spi_shutdown(void *data)
+{
+ struct sb600spi_data *sb600_data = data;
+ struct flashctx *flash = sb600_data->flash;
+ if (flash)
+ finalize_flash_access(flash);
+
+ free(data);
+ return 0;
+}
+
static const struct spi_master spi_master_sb600 = {
.max_data_read = FIFO_SIZE_OLD,
.max_data_write = FIFO_SIZE_OLD - 3,
@@ -600,17 +611,6 @@
.write_aai = default_spi_write_aai,
};

-static int sb600spi_shutdown(void *data)
-{
- struct sb600spi_data *sb600_data = data;
- struct flashctx *flash = sb600_data->flash;
- if (flash)
- finalize_flash_access(flash);
-
- free(data);
- return 0;
-}
-
int sb600_probe_spi(struct pci_dev *dev)
{
struct pci_dev *smbus_dev;
diff --git a/serprog.c b/serprog.c
index e8d1f52..b207fd2 100644
--- a/serprog.c
+++ b/serprog.c
@@ -394,6 +394,25 @@
return ret;
}

+static int serprog_shutdown(void *data)
+{
+ if ((sp_opbuf_usage) || (sp_max_write_n && sp_write_n_bytes))
+ if (sp_execute_opbuf() != 0)
+ msg_pwarn("Could not flush command buffer.\n");
+ if (sp_check_commandavail(S_CMD_S_PIN_STATE)) {
+ uint8_t dis = 0;
+ if (sp_docommand(S_CMD_S_PIN_STATE, 1, &dis, 0, NULL) == 0)
+ msg_pdbg(MSGHEADER "Output drivers disabled\n");
+ else
+ msg_pwarn(MSGHEADER "%s: Warning: could not disable output buffers\n", __func__);
+ }
+ /* FIXME: fix sockets on windows(?), especially closing */
+ serialport_shutdown(&sp_fd);
+ if (sp_max_write_n)
+ free(sp_write_n_buf);
+ return 0;
+}
+
static struct spi_master spi_master_serprog = {
.features = SPI_MASTER_4BA,
.max_data_read = MAX_DATA_READ_UNLIMITED,
@@ -518,25 +537,6 @@
.chip_writen = fallback_chip_writen,
};

-static int serprog_shutdown(void *data)
-{
- if ((sp_opbuf_usage) || (sp_max_write_n && sp_write_n_bytes))
- if (sp_execute_opbuf() != 0)
- msg_pwarn("Could not flush command buffer.\n");
- if (sp_check_commandavail(S_CMD_S_PIN_STATE)) {
- uint8_t dis = 0;
- if (sp_docommand(S_CMD_S_PIN_STATE, 1, &dis, 0, NULL) == 0)
- msg_pdbg(MSGHEADER "Output drivers disabled\n");
- else
- msg_pwarn(MSGHEADER "%s: Warning: could not disable output buffers\n", __func__);
- }
- /* FIXME: fix sockets on windows(?), especially closing */
- serialport_shutdown(&sp_fd);
- if (sp_max_write_n)
- free(sp_write_n_buf);
- return 0;
-}
-
static enum chipbustype serprog_buses_supported = BUS_NONE;

static int serprog_init(void)
diff --git a/wbsio_spi.c b/wbsio_spi.c
index c3814aa..2336845 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -177,6 +177,12 @@
return 0;
}

+static int wbsio_spi_shutdown(void *data)
+{
+ free(data);
+ return 0;
+}
+
static const struct spi_master spi_master_wbsio = {
.max_data_read = MAX_DATA_UNSPECIFIED,
.max_data_write = MAX_DATA_UNSPECIFIED,
@@ -187,12 +193,6 @@
.write_aai = spi_chip_write_1,
};

-static int wbsio_spi_shutdown(void *data)
-{
- free(data);
- return 0;
-}
-
int wbsio_check_for_spi(void)
{
uint16_t wbsio_spibase = 0;

To view, visit change 56101. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I50716686552b4ddcc6089d5afadb19ef59d9f9b4
Gerrit-Change-Number: 56101
Gerrit-PatchSet: 6
Gerrit-Owner: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Thomas Heijligen <src@posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter@mailbox.org>
Gerrit-MessageType: merged