summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2022-12-20 12:33:13 +1100
committerThomas Heijligen <src@posteo.de>2023-03-03 17:35:50 +0000
commite1f30bbce7a603d518ecec9d7e6885719f396719 (patch)
tree8eb630273f026b859d29a9b7854d447cb43c122f
parentc66d2bd1ca384dd673b24420e11865fde86060fc (diff)
downloadflashrom-e1f30bbce7a603d518ecec9d7e6885719f396719.tar.gz
flashrom-e1f30bbce7a603d518ecec9d7e6885719f396719.tar.bz2
flashrom-e1f30bbce7a603d518ecec9d7e6885719f396719.zip
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>
-rw-r--r--asm106x.c1
-rw-r--r--bitbang_spi.c1
-rw-r--r--buspirate_spi.c1
-rw-r--r--ch341a_spi.c1
-rw-r--r--ch347_spi.c1
-rw-r--r--dediprog.c1
-rw-r--r--digilent_spi.c1
-rw-r--r--dirtyjtag_spi.c1
-rw-r--r--flashrom.c2
-rw-r--r--ft2232_spi.c1
-rw-r--r--include/chipdrivers.h1
-rw-r--r--include/programmer.h3
-rw-r--r--it87spi.c1
-rw-r--r--jlink_spi.c1
-rw-r--r--linux_spi.c1
-rw-r--r--mediatek_i2c_spi.c1
-rw-r--r--mstarddc_spi.c1
-rw-r--r--ni845x_spi.c1
-rw-r--r--parade_lspcon.c1
-rw-r--r--pickit2_spi.c1
-rw-r--r--raiden_debug_spi.c1
-rw-r--r--realtek_mst_i2c_spi.c1
-rw-r--r--sb600spi.c3
-rw-r--r--serprog.c1
-rw-r--r--spi.c9
-rw-r--r--spi25_statusreg.c4
-rw-r--r--stlinkv3_spi.c1
-rw-r--r--usbblaster_spi.c1
-rw-r--r--wbsio_spi.c1
29 files changed, 10 insertions, 35 deletions
diff --git a/asm106x.c b/asm106x.c
index 78c0b74cd..0c9cf111d 100644
--- a/asm106x.c
+++ b/asm106x.c
@@ -125,7 +125,6 @@ static const struct spi_master asm106x_spi_master = {
.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 6488650c1..dde5dbc42 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -146,7 +146,6 @@ static const struct spi_master spi_master_bitbang = {
.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 192d27433..d3114c415 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -181,7 +181,6 @@ static struct spi_master spi_master_buspirate = {
.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 b9be18e5a..a66503d94 100644
--- a/ch341a_spi.c
+++ b/ch341a_spi.c
@@ -416,7 +416,6 @@ static const struct spi_master spi_master_ch341a_spi = {
.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 e828f0089..570e25be6 100644
--- a/ch347_spi.c
+++ b/ch347_spi.c
@@ -257,7 +257,6 @@ static const struct spi_master spi_master_ch347_spi = {
.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 60ce6e6e8..734fcfa11 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -1038,7 +1038,6 @@ static struct spi_master spi_master_dediprog = {
.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 5fa60b928..ef0d23cf7 100644
--- a/digilent_spi.c
+++ b/digilent_spi.c
@@ -336,7 +336,6 @@ static const struct spi_master spi_master_digilent_spi = {
.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 9f0e43bf6..19764f62b 100644
--- a/dirtyjtag_spi.c
+++ b/dirtyjtag_spi.c
@@ -197,7 +197,6 @@ static const struct spi_master spi_master_dirtyjtag_spi = {
.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 62e575761..3cf67f1d0 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -470,7 +470,7 @@ int check_block_eraser(const struct flashctx *flash, int k, int log)
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 16bcfe310..7d7283bc9 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -299,7 +299,6 @@ static const struct spi_master spi_master_ft2232 = {
.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 71b879548..c485aafa0 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 f6bc8ce62..d8d8b4a20 100644
--- a/include/programmer.h
+++ b/include/programmer.h
@@ -312,7 +312,7 @@ struct spi_master {
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 @@ struct spi_master {
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 b2da8751b..9c64659f1 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -320,7 +320,6 @@ static const struct spi_master spi_master_it87xx = {
.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 7743c40b6..af61fb595 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -188,7 +188,6 @@ static const struct spi_master spi_master_jlink_spi = {
.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 d849fe4b5..ceca05f9a 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -119,7 +119,6 @@ static const struct spi_master spi_master_linux = {
.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 e9c3c8c82..d28e47818 100644
--- a/mediatek_i2c_spi.c
+++ b/mediatek_i2c_spi.c
@@ -459,7 +459,6 @@ static const struct spi_master spi_master_i2c_mediatek = {
.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 1172cb20b..44ebd0545 100644
--- a/mstarddc_spi.c
+++ b/mstarddc_spi.c
@@ -145,7 +145,6 @@ static const struct spi_master spi_master_mstarddc = {
.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 dec6f6f3f..253025f0a 100644
--- a/ni845x_spi.c
+++ b/ni845x_spi.c
@@ -535,7 +535,6 @@ static const struct spi_master spi_programmer_ni845x = {
.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 8b9278934..dfcf65962 100644
--- a/parade_lspcon.c
+++ b/parade_lspcon.c
@@ -436,7 +436,6 @@ static const struct spi_master spi_master_parade_lspcon = {
.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 56894d9a1..a072a2059 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -383,7 +383,6 @@ static const struct spi_master spi_master_pickit2 = {
.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 5111ae98b..c5642ff43 100644
--- a/raiden_debug_spi.c
+++ b/raiden_debug_spi.c
@@ -1323,7 +1323,6 @@ static const struct spi_master spi_master_raiden_debug = {
.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 ee6390c4f..57677ec67 100644
--- a/realtek_mst_i2c_spi.c
+++ b/realtek_mst_i2c_spi.c
@@ -440,7 +440,6 @@ static const struct spi_master spi_master_i2c_realtek_mst = {
.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 2e6c2eca7..df7caedbd 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -604,7 +604,6 @@ static const struct spi_master spi_master_sb600 = {
.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 @@ static const struct spi_master spi_master_yangtze = {
.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 @@ static const struct spi_master spi_master_promontory = {
.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 4d93e0757..b51f0cfe3 100644
--- a/serprog.c
+++ b/serprog.c
@@ -463,7 +463,6 @@ static struct spi_master spi_master_serprog = {
.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 3b3f6229e..3e81da2a5 100644
--- a/spi.c
+++ b/spi.c
@@ -139,9 +139,11 @@ int spi_aai_write(struct flashctx *flash, const uint8_t *buf, unsigned int start
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 @@ int register_spi_master(const struct spi_master *mst, void *data)
}
}
- 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 ec2c101cf..d452416c7 100644
--- a/spi25_statusreg.c
+++ b/spi25_statusreg.c
@@ -132,7 +132,7 @@ int spi_write_register(const struct flashctx *flash, enum flash_reg reg, uint8_t
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 @@ int spi_read_register(const struct flashctx *flash, enum flash_reg reg, uint8_t
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 726cdcfdf..f9046df01 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -469,7 +469,6 @@ static const struct spi_master spi_programmer_stlinkv3 = {
.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 958d4ea54..43acaad8e 100644
--- a/usbblaster_spi.c
+++ b/usbblaster_spi.c
@@ -171,7 +171,6 @@ static const struct spi_master spi_master_usbblaster = {
.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 ee79ef2a8..febe6ed26 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -192,7 +192,6 @@ static const struct spi_master spi_master_wbsio = {
.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)