Skip to content

Commit

Permalink
spi: Add function to probe erase command opcode for all spi_master
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/65183
Reviewed-by: Thomas Heijligen <[email protected]>
Reviewed-by: Anastasia Klimchuk <[email protected]>
Reviewed-by: Nico Huber <[email protected]>
Reviewed-by: Felix Singer <[email protected]>
Tested-by: build bot (Jenkins) <[email protected]>
  • Loading branch information
light2802 authored and heijligen committed Jul 11, 2022
1 parent d0ae868 commit edcea80
Show file tree
Hide file tree
Showing 25 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions bitbang_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions buspirate_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down
1 change: 1 addition & 0 deletions ch341a_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions dediprog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

/*
Expand Down
1 change: 1 addition & 0 deletions digilent_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions dummyflasher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions ft2232_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
7 changes: 7 additions & 0 deletions ichspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/programmer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions it87spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions jlink_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions linux_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions lspcon_i2c_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions mediatek_i2c_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions mstarddc_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions ni845x_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pickit2_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions raiden_debug_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions realtek_mst_i2c_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions sb600spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions serprog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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. "
Expand Down
1 change: 1 addition & 0 deletions stlinkv3_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions usbblaster_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions wbsio_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit edcea80

Please sign in to comment.