1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 15:12:36 +02:00

spi: Add function to probe erase command opcode for all spi_master

Add a field, probe_opcode, to struct spi_master which points to a
function returning a bool by checking if a given command is supported by
the programmer in use. This is used for getting a whitelist of commands
supported by the programmer, as some programmers like ichspi don't
support all opcodes.

Most programmers use the default function, which just returns true.
ICHSPI and dummyflasher use their specialized function.

Change-Id: I6852ef92788221f471a859c879f8aff42558d36d
Signed-off-by: Aarya Chaumal <aarya.chaumal@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/65183
Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Aarya Chaumal 2022-07-04 18:21:50 +05:30 committed by Thomas Heijligen
parent d0ae8686b1
commit edcea80d68
25 changed files with 50 additions and 1 deletions

View File

@ -148,6 +148,7 @@ static const struct spi_master spi_master_bitbang = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = bitbang_spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
int register_spi_bitbang_master(const struct bitbang_spi_master *master, void *spi_data)

View File

@ -182,6 +182,7 @@ static struct spi_master spi_master_buspirate = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = buspirate_spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
static const struct buspirate_speeds spispeeds[] = {

View File

@ -417,6 +417,7 @@ static const struct spi_master spi_master_ch341a_spi = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = ch341a_spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
static int ch341a_spi_init(void)

View File

@ -1039,6 +1039,7 @@ 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,
};
/*

View File

@ -338,6 +338,7 @@ static const struct spi_master spi_master_digilent_spi = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = digilent_spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
static bool default_reset(struct libusb_device_handle *handle)

View File

@ -121,6 +121,17 @@ static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsig
emu_data->spi_write_256_chunksize);
}
static bool dummy_spi_probe_opcode(struct flashctx *flash, uint8_t opcode)
{
size_t i;
struct emu_data *emu_data = flash->mst->spi.data;
for (i = 0; i < emu_data->spi_blacklist_size; i++) {
if (emu_data->spi_blacklist[i] == opcode)
return false;
}
return true;
}
static int probe_variable_size(struct flashctx *flash)
{
const struct emu_data *emu_data = flash->mst->opaque.data;
@ -916,6 +927,7 @@ static const struct spi_master spi_master_dummyflasher = {
.read = default_spi_read,
.write_256 = dummy_spi_write_256,
.write_aai = default_spi_write_aai,
.probe_opcode = dummy_spi_probe_opcode,
};
static const struct par_master par_master_dummyflasher = {

View File

@ -298,6 +298,7 @@ static const struct spi_master spi_master_ft2232 = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = ft2232_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
/* Returns 0 upon success, a negative number upon errors. */

View File

@ -1670,6 +1670,11 @@ static int ich_spi_send_multicommand(const struct flashctx *flash,
return ret;
}
static bool ich_spi_probe_opcode(struct flashctx *flash, uint8_t opcode)
{
return find_opcode(curopcodes, opcode) >= 0;
}
#define ICH_BMWAG(x) ((x >> 24) & 0xff)
#define ICH_BMRAG(x) ((x >> 16) & 0xff)
#define ICH_BRWA(x) ((x >> 8) & 0xff)
@ -1802,6 +1807,7 @@ static const struct spi_master spi_master_ich9 = {
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.probe_opcode = ich_spi_probe_opcode,
};
static const struct opaque_master opaque_master_ich_hwseq = {
@ -2215,6 +2221,7 @@ static const struct spi_master spi_master_via = {
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.probe_opcode = ich_spi_probe_opcode,
};
int via_init_spi(uint32_t mmio_base)

View File

@ -311,6 +311,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)(struct flashctx *flash, uint8_t opcode);
void *data;
};
@ -320,6 +321,7 @@ int default_spi_send_multicommand(const struct flashctx *flash, struct spi_comma
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(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. */

View File

@ -318,6 +318,7 @@ 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(uint16_t port)

View File

@ -190,6 +190,7 @@ static const struct spi_master spi_master_jlink_spi = {
.write_aai = default_spi_write_aai,
.features = SPI_MASTER_4BA,
.shutdown = jlink_spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
static int jlink_spi_init(void)

View File

@ -121,6 +121,7 @@ static const struct spi_master spi_master_linux = {
.write_256 = linux_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = linux_spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
/* Read max buffer size from sysfs, or use page size as fallback. */

View File

@ -437,6 +437,7 @@ static const struct spi_master spi_master_i2c_lspcon = {
.write_256 = lspcon_i2c_spi_write_256,
.write_aai = lspcon_i2c_spi_write_aai,
.shutdown = lspcon_i2c_spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
static int lspcon_i2c_spi_init(void)

View File

@ -448,6 +448,7 @@ static const struct spi_master spi_master_i2c_mediatek = {
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.probe_opcode = default_spi_probe_opcode,
};
static int mediatek_shutdown(void *data)

View File

@ -146,6 +146,7 @@ static const struct spi_master spi_master_mstarddc = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = mstarddc_spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
/* Returns 0 upon success, a negative number upon errors. */

View File

@ -537,6 +537,7 @@ static const struct spi_master spi_programmer_ni845x = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = ni845x_spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
static int ni845x_spi_init(void)

View File

@ -385,6 +385,7 @@ static const struct spi_master spi_master_pickit2 = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = pickit2_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
static int pickit2_spi_init(void)

View File

@ -1320,6 +1320,7 @@ static const struct spi_master spi_master_raiden_debug = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = raiden_debug_spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
static int match_endpoint(struct libusb_endpoint_descriptor const *descriptor,

View File

@ -441,6 +441,7 @@ 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(int *reset, int *enter_isp)

View File

@ -603,6 +603,7 @@ static const struct spi_master spi_master_sb600 = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = sb600spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
static const struct spi_master spi_master_yangtze = {
@ -614,6 +615,7 @@ static const struct spi_master spi_master_yangtze = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = sb600spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
static const struct spi_master spi_master_promontory = {
@ -625,6 +627,7 @@ static const struct spi_master spi_master_promontory = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = sb600spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
int sb600_probe_spi(struct pci_dev *dev)

View File

@ -446,6 +446,7 @@ static struct spi_master spi_master_serprog = {
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.probe_opcode = default_spi_probe_opcode,
};
static int sp_check_opbuf_usage(int bytes_to_be_added)

7
spi.c
View File

@ -134,6 +134,11 @@ int spi_aai_write(struct flashctx *flash, const uint8_t *buf, unsigned int start
return flash->mst->spi.write_aai(flash, buf, start, len);
}
bool default_spi_probe_opcode(struct flashctx *flash, uint8_t opcode)
{
return true;
}
int register_spi_master(const struct spi_master *mst, void *data)
{
struct registered_master rmst = {0};
@ -146,7 +151,7 @@ int register_spi_master(const struct spi_master *mst, void *data)
}
if (!mst->write_aai || !mst->write_256 || !mst->read || !mst->command ||
!mst->multicommand ||
!mst->multicommand || !mst->probe_opcode ||
((mst->command == default_spi_send_command) &&
(mst->multicommand == default_spi_send_multicommand))) {
msg_perr("%s called with incomplete master definition. "

View File

@ -468,6 +468,7 @@ static const struct spi_master spi_programmer_stlinkv3 = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = stlinkv3_spi_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
static int stlinkv3_spi_init(void)

View File

@ -173,6 +173,7 @@ static const struct spi_master spi_master_usbblaster = {
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.shutdown = usbblaster_shutdown,
.probe_opcode = default_spi_probe_opcode,
};
/* Returns 0 upon success, a negative number upon errors. */

View File

@ -191,6 +191,7 @@ 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)