summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnastasia Klimchuk <aklm@chromium.org>2021-07-06 16:03:11 +1000
committerNico Huber <nico.h@gmx.de>2021-08-17 09:39:18 +0000
commit0a7f036610673f6664c9d1492912abfdfbdf9f20 (patch)
treeca67f6d90b777debae831039267adfcab01c18d9
parent5a97be363a269b364569be8223369d9a5bf92292 (diff)
downloadflashrom-0a7f036610673f6664c9d1492912abfdfbdf9f20.tar.gz
flashrom-0a7f036610673f6664c9d1492912abfdfbdf9f20.tar.bz2
flashrom-0a7f036610673f6664c9d1492912abfdfbdf9f20.zip
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>
-rw-r--r--bitbang_spi.c14
-rw-r--r--buspirate_spi.c64
-rw-r--r--ch341a_spi.c28
-rw-r--r--dediprog.c36
-rw-r--r--digilent_spi.c23
-rw-r--r--dummyflasher.c36
-rw-r--r--it87spi.c13
-rw-r--r--jlink_spi.c26
-rw-r--r--lspcon_i2c_spi.c20
-rw-r--r--pickit2_spi.c20
-rw-r--r--realtek_mst_i2c_spi.c20
-rw-r--r--sb600spi.c22
-rw-r--r--serprog.c38
-rw-r--r--wbsio_spi.c12
14 files changed, 184 insertions, 188 deletions
diff --git a/bitbang_spi.c b/bitbang_spi.c
index 3d973c587..83c3501be 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -131,6 +131,13 @@ static int bitbang_spi_send_command(const struct flashctx *flash,
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 @@ static const struct spi_master spi_master_bitbang = {
.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 b56d422bd..3c0a6ff92 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -130,38 +130,6 @@ static int buspirate_wait_for_string(unsigned char *buf, const char *key)
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 @@ out_shutdown:
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 185e5827d..22c97813c 100644
--- a/ch341a_spi.c
+++ b/ch341a_spi.c
@@ -385,20 +385,6 @@ static int ch341a_spi_spi_send_command(const struct flashctx *flash, unsigned in
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 @@ static int ch341a_spi_shutdown(void *data)
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 b47e8e94f..d98af4934 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -992,6 +992,24 @@ static int parse_voltage(char *voltage)
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 @@ static int dediprog_open(int index)
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 8a3699d93..0ec402e96 100644
--- a/digilent_spi.c
+++ b/digilent_spi.c
@@ -315,18 +315,6 @@ static int digilent_spi_send_command(const struct flashctx *flash, unsigned int
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 @@ static int digilent_spi_shutdown(void *data)
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 049f9d5aa..231157645 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -580,7 +580,23 @@ static int dummy_spi_send_command(const struct flashctx *flash, unsigned int wri
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 @@ static const struct par_master par_master_dummyflasher = {
.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 cbf830bd4..e55232858 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -290,6 +290,12 @@ static int it8716f_spi_chip_write_256(struct flashctx *flash, const uint8_t *buf
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 @@ static const struct spi_master spi_master_it87xx = {
.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 8b8533cab..daa8eb67e 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -155,19 +155,6 @@ static int jlink_spi_send_command(const struct flashctx *flash, unsigned int wri
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 @@ static int jlink_spi_shutdown(void *data)
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 b590f1db9..e9ff2ddc7 100644
--- a/lspcon_i2c_spi.c
+++ b/lspcon_i2c_spi.c
@@ -410,16 +410,6 @@ static int lspcon_i2c_spi_write_aai(struct flashctx *flash, const uint8_t *buf,
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 @@ static int lspcon_i2c_spi_shutdown(void *data)
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 bec945746..73ace4be9 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -340,16 +340,6 @@ static int parse_voltage(char *voltage)
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 @@ static int pickit2_shutdown(void *data)
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 a45838cb6..41458645e 100644
--- a/realtek_mst_i2c_spi.c
+++ b/realtek_mst_i2c_spi.c
@@ -410,16 +410,6 @@ static int realtek_mst_i2c_spi_write_aai(struct flashctx *flash, const uint8_t *
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 @@ static int realtek_mst_i2c_spi_shutdown(void *data)
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 c4b25e527..5c6547548 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -570,6 +570,17 @@ static int promontory_read_memmapped(struct flashctx *flash, uint8_t *buf,
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 @@ static const struct spi_master spi_master_promontory = {
.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 e8d1f52f9..b207fd2d2 100644
--- a/serprog.c
+++ b/serprog.c
@@ -394,6 +394,25 @@ static int serprog_spi_send_command(const struct flashctx *flash,
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 @@ static const struct par_master par_master_serprog = {
.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 c3814aab6..233684560 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -177,6 +177,12 @@ static int wbsio_spi_read(struct flashctx *flash, uint8_t *buf,
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 @@ static const struct spi_master spi_master_wbsio = {
.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;