Thomas Heijligen submitted this change.
6 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
tree/: Drop default_spi_probe_opcode for NULL case
A NULL func pointer is necessary and sufficient for the
condition `NULL func pointer => true' as to not need this
boilerplate as it implies default behaviour of a supported
opcode within the `check_block_eraser()` match supported loop.
Ran;
```
$ find . -name '*.[c,h]' -exec sed -i '/.probe_opcode = default_spi_probe_opcode,/d' '{}' \;
```
Change-Id: Id502c5d2596ad1db52faf05723083620e4c52c12
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/70264
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
---
M asm106x.c
M bitbang_spi.c
M buspirate_spi.c
M ch341a_spi.c
M ch347_spi.c
M dediprog.c
M digilent_spi.c
M dirtyjtag_spi.c
M flashrom.c
M ft2232_spi.c
M include/chipdrivers.h
M include/programmer.h
M it87spi.c
M jlink_spi.c
M linux_spi.c
M mediatek_i2c_spi.c
M mstarddc_spi.c
M ni845x_spi.c
M parade_lspcon.c
M pickit2_spi.c
M raiden_debug_spi.c
M realtek_mst_i2c_spi.c
M sb600spi.c
M serprog.c
M spi.c
M spi25_statusreg.c
M stlinkv3_spi.c
M usbblaster_spi.c
M wbsio_spi.c
29 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/asm106x.c b/asm106x.c
index 78c0b74..0c9cf11 100644
--- a/asm106x.c
+++ b/asm106x.c
@@ -125,7 +125,6 @@
.shutdown = asm106x_shutdown,
.read = default_spi_read,
.write_256 = default_spi_write_256,
- .probe_opcode = default_spi_probe_opcode,
};
static int asm106x_init(const struct programmer_cfg *cfg)
diff --git a/bitbang_spi.c b/bitbang_spi.c
index 6488650..dde5dbc 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -146,7 +146,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = bitbang_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
int register_spi_bitbang_master(const struct bitbang_spi_master *master, void *spi_data)
diff --git a/buspirate_spi.c b/buspirate_spi.c
index 192d274..d3114c4 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -181,7 +181,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = buspirate_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static const struct buspirate_speeds spispeeds[] = {
diff --git a/ch341a_spi.c b/ch341a_spi.c
index b9be18e..a66503d 100644
--- a/ch341a_spi.c
+++ b/ch341a_spi.c
@@ -416,7 +416,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = ch341a_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
.delay = ch341a_spi_delay,
};
diff --git a/ch347_spi.c b/ch347_spi.c
index e828f00..570e25b 100644
--- a/ch347_spi.c
+++ b/ch347_spi.c
@@ -257,7 +257,6 @@
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = ch347_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
/* Largely copied from ch341a_spi.c */
diff --git a/dediprog.c b/dediprog.c
index 60ce6e6..734fcfa 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -1038,7 +1038,6 @@
.write_256 = dediprog_spi_write_256,
.write_aai = dediprog_spi_write_aai,
.shutdown = dediprog_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
/*
diff --git a/digilent_spi.c b/digilent_spi.c
index 5fa60b9..ef0d23c 100644
--- a/digilent_spi.c
+++ b/digilent_spi.c
@@ -336,7 +336,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = digilent_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static bool default_reset(struct libusb_device_handle *handle)
diff --git a/dirtyjtag_spi.c b/dirtyjtag_spi.c
index 9f0e43b..19764f6 100644
--- a/dirtyjtag_spi.c
+++ b/dirtyjtag_spi.c
@@ -197,7 +197,6 @@
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = dirtyjtag_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static int dirtyjtag_spi_init(const struct programmer_cfg *cfg)
diff --git a/flashrom.c b/flashrom.c
index 62e5757..3cf67f1 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -470,7 +470,7 @@
if (flash->mst->buses_supported & BUS_SPI) {
const uint8_t *opcode = spi_get_opcode_from_erasefn(eraser.block_erase);
for (int i = 0; opcode[i]; i++) {
- if (!flash->mst->spi.probe_opcode(flash, opcode[i])) {
+ if (!spi_probe_opcode(flash, opcode[i])) {
if (log)
msg_cdbg("block erase function and layout found "
"but SPI master doesn't support the function. ");
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 16bcfe3..7d7283b 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -299,7 +299,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = ft2232_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
/* Returns 0 upon success, a negative number upon errors. */
diff --git a/include/chipdrivers.h b/include/chipdrivers.h
index 71b8795..c485aaf 100644
--- a/include/chipdrivers.h
+++ b/include/chipdrivers.h
@@ -26,6 +26,7 @@
int spi_aai_write(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
int spi_chip_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, int unsigned len);
+bool spi_probe_opcode(const struct flashctx *flash, uint8_t opcode);
/* spi25.c */
int probe_spi_rdid(struct flashctx *flash);
diff --git a/include/programmer.h b/include/programmer.h
index f6bc8ce..d8d8b4a 100644
--- a/include/programmer.h
+++ b/include/programmer.h
@@ -312,7 +312,7 @@
int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
int (*write_aai)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
int (*shutdown)(void *data);
- bool (*probe_opcode)(const struct flashctx *flash, uint8_t opcode);
+ bool (*probe_opcode)(const struct flashctx *flash, uint8_t opcode); /* NULL func implies true. */
void (*delay) (const struct flashctx *flash, unsigned int usecs);
void (*get_region)(const struct flashctx *flash, unsigned int addr, struct flash_region *region);
void *data;
@@ -321,7 +321,6 @@
int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
int default_spi_write_aai(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
-bool default_spi_probe_opcode(const struct flashctx *flash, uint8_t opcode);
int register_spi_master(const struct spi_master *mst, void *data);
/* The following enum is needed by ich_descriptor_tool and ich* code as well as in chipset_enable.c. */
diff --git a/it87spi.c b/it87spi.c
index b2da875..9c64659 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -320,7 +320,6 @@
.write_256 = it8716f_spi_chip_write_256,
.write_aai = spi_chip_write_1,
.shutdown = it8716f_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static uint16_t it87spi_probe(const struct programmer_cfg *cfg, uint16_t port)
diff --git a/jlink_spi.c b/jlink_spi.c
index 7743c40..af61fb5 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -188,7 +188,6 @@
.write_256 = default_spi_write_256,
.features = SPI_MASTER_4BA,
.shutdown = jlink_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static int jlink_spi_init(const struct programmer_cfg *cfg)
diff --git a/linux_spi.c b/linux_spi.c
index d849fe4..ceca05f 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -119,7 +119,6 @@
.read = linux_spi_read,
.write_256 = linux_spi_write_256,
.shutdown = linux_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
/* Read max buffer size from sysfs, or use page size as fallback. */
diff --git a/mediatek_i2c_spi.c b/mediatek_i2c_spi.c
index e9c3c8c..d28e478 100644
--- a/mediatek_i2c_spi.c
+++ b/mediatek_i2c_spi.c
@@ -459,7 +459,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = mediatek_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static int get_params(const struct programmer_cfg *cfg, bool *allow_brick)
diff --git a/mstarddc_spi.c b/mstarddc_spi.c
index 1172cb2..44ebd05 100644
--- a/mstarddc_spi.c
+++ b/mstarddc_spi.c
@@ -145,7 +145,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = mstarddc_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
/* Returns 0 upon success, a negative number upon errors. */
diff --git a/ni845x_spi.c b/ni845x_spi.c
index dec6f6f..253025f 100644
--- a/ni845x_spi.c
+++ b/ni845x_spi.c
@@ -535,7 +535,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = ni845x_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static int ni845x_spi_init(const struct programmer_cfg *cfg)
diff --git a/parade_lspcon.c b/parade_lspcon.c
index 8b92789..dfcf659 100644
--- a/parade_lspcon.c
+++ b/parade_lspcon.c
@@ -436,7 +436,6 @@
.write_256 = parade_lspcon_write_256,
.write_aai = parade_lspcon_write_aai,
.shutdown = parade_lspcon_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static int get_params(const struct programmer_cfg *cfg, bool *allow_brick)
diff --git a/pickit2_spi.c b/pickit2_spi.c
index 56894d9..a072a20 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -383,7 +383,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = pickit2_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static int pickit2_spi_init(const struct programmer_cfg *cfg)
diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c
index 5111ae9..c5642ff 100644
--- a/raiden_debug_spi.c
+++ b/raiden_debug_spi.c
@@ -1323,7 +1323,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = raiden_debug_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static int match_endpoint(struct libusb_endpoint_descriptor const *descriptor,
diff --git a/realtek_mst_i2c_spi.c b/realtek_mst_i2c_spi.c
index ee6390c..57677ec 100644
--- a/realtek_mst_i2c_spi.c
+++ b/realtek_mst_i2c_spi.c
@@ -440,7 +440,6 @@
.write_256 = realtek_mst_i2c_spi_write_256,
.write_aai = realtek_mst_i2c_spi_write_aai,
.shutdown = realtek_mst_i2c_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static int get_params(const struct programmer_cfg *cfg, bool *reset, bool *enter_isp, bool *allow_brick)
diff --git a/sb600spi.c b/sb600spi.c
index 2e6c2ec..df7caed 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -604,7 +604,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = sb600spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static const struct spi_master spi_master_yangtze = {
@@ -616,7 +615,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = sb600spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static const struct spi_master spi_master_promontory = {
@@ -628,7 +626,6 @@
.read = promontory_read_memmapped,
.write_256 = default_spi_write_256,
.shutdown = sb600spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
int sb600_probe_spi(const struct programmer_cfg *cfg, struct pci_dev *dev)
diff --git a/serprog.c b/serprog.c
index 4d93e07..b51f0cf 100644
--- a/serprog.c
+++ b/serprog.c
@@ -463,7 +463,6 @@
.command = serprog_spi_send_command,
.read = default_spi_read,
.write_256 = default_spi_write_256,
- .probe_opcode = default_spi_probe_opcode,
.delay = serprog_delay,
};
diff --git a/spi.c b/spi.c
index 3b3f622..3e81da2 100644
--- a/spi.c
+++ b/spi.c
@@ -139,9 +139,11 @@
return default_spi_write_aai(flash, buf, start, len);
}
-bool default_spi_probe_opcode(const struct flashctx *flash, uint8_t opcode)
+bool spi_probe_opcode(const struct flashctx *flash, uint8_t opcode)
{
- return true;
+ if (!flash->mst->spi.probe_opcode)
+ return true; /* no probe_opcode implies default of supported. */
+ return flash->mst->spi.probe_opcode(flash, opcode);
}
int register_spi_master(const struct spi_master *mst, void *data)
@@ -155,8 +157,7 @@
}
}
- if (!mst->write_256 || !mst->read || !mst->probe_opcode ||
- (!mst->command && !mst->multicommand)) {
+ if (!mst->write_256 || !mst->read || (!mst->command && !mst->multicommand)) {
msg_perr("%s called with incomplete master definition. "
"Please report a bug at flashrom@flashrom.org\n",
__func__);
diff --git a/spi25_statusreg.c b/spi25_statusreg.c
index ec2c101..d452416 100644
--- a/spi25_statusreg.c
+++ b/spi25_statusreg.c
@@ -132,7 +132,7 @@
return 1;
}
- if (!flash->mst->spi.probe_opcode(flash, write_cmd[0])) {
+ if (!spi_probe_opcode(flash, write_cmd[0])) {
msg_pdbg("%s: write to register %d not supported by programmer, ignoring.\n", __func__, reg);
return SPI_INVALID_OPCODE;
}
@@ -246,7 +246,7 @@
return 1;
}
- if (!flash->mst->spi.probe_opcode(flash, read_cmd)) {
+ if (!spi_probe_opcode(flash, read_cmd)) {
msg_pdbg("%s: read from register %d not supported by programmer.\n", __func__, reg);
return SPI_INVALID_OPCODE;
}
diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c
index 726cdcf..f9046df 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -469,7 +469,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = stlinkv3_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
static int stlinkv3_spi_init(const struct programmer_cfg *cfg)
diff --git a/usbblaster_spi.c b/usbblaster_spi.c
index 958d4ea..43acaad 100644
--- a/usbblaster_spi.c
+++ b/usbblaster_spi.c
@@ -171,7 +171,6 @@
.read = default_spi_read,
.write_256 = default_spi_write_256,
.shutdown = usbblaster_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
/* Returns 0 upon success, a negative number upon errors. */
diff --git a/wbsio_spi.c b/wbsio_spi.c
index ee79ef2..febe6ed 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -192,7 +192,6 @@
.write_256 = spi_chip_write_1,
.write_aai = spi_chip_write_1,
.shutdown = wbsio_spi_shutdown,
- .probe_opcode = default_spi_probe_opcode,
};
int wbsio_check_for_spi(void)
To view, visit change 70264. To unsubscribe, or for help writing mail filters, visit settings.