Anastasia Klimchuk submitted this change.

View Change


Approvals: build bot (Jenkins): Verified Felix Singer: Looks good to me, approved Anastasia Klimchuk: Looks good to me, approved
tree: Allow passing programmer_cfg directly to programmer

Modify the type signature of each programmer entry-point
xxx_init() functions to allow for the consumption of the
programmer parameterisation string data.

```
$ find -name '*.c' -exec sed -i 's/_init(void)/_init(const char *prog_param)/g' '{}' \;
$ find -name '*.c' -exec sed -i 's/get_params(/get_params(const char *prog_param, /g' '{}' \;
$ find -name '*.c' -exec sed -i 's/const char \*prog_param)/const struct programmer_cfg *cfg)/g' '{}' \;
$ find -name '*.c' -exec sed -i 's/const char \*prog_param,/const struct programmer_cfg *cfg,/g' '{}' \;
```
and manually fix up any remaining parts.

Change-Id: I8bab51a635b9d3a43e1619a7a32b334f4ce2cdd2
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/66655
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
---
M atahpt.c
M atapromise.c
M atavia.c
M buspirate_spi.c
M ch341a_spi.c
M dediprog.c
M developerbox_spi.c
M digilent_spi.c
M drkaiser.c
M dummyflasher.c
M flashrom.c
M ft2232_spi.c
M gfxnvidia.c
M include/programmer.h
M internal.c
M it8212.c
M jlink_spi.c
M linux_mtd.c
M linux_spi.c
M mediatek_i2c_spi.c
M mstarddc_spi.c
M ni845x_spi.c
M nic3com.c
M nicintel.c
M nicintel_eeprom.c
M nicintel_spi.c
M nicnatsemi.c
M nicrealtek.c
M ogp_spi.c
M parade_lspcon.c
M pickit2_spi.c
M pony_spi.c
M raiden_debug_spi.c
M rayer_spi.c
M realtek_mst_i2c_spi.c
M satamv.c
M satasii.c
M serprog.c
M stlinkv3_spi.c
M usbblaster_spi.c
40 files changed, 79 insertions(+), 51 deletions(-)

diff --git a/atahpt.c b/atahpt.c
index 1cefef3..2ab51a8 100644
--- a/atahpt.c
+++ b/atahpt.c
@@ -84,7 +84,7 @@
.shutdown = atahpt_shutdown,
};

-static int atahpt_init(void)
+static int atahpt_init(const struct programmer_cfg *cfg)
{
struct pci_dev *dev = NULL;
uint32_t io_base_addr;
diff --git a/atapromise.c b/atapromise.c
index a901e8b..4be2f71 100644
--- a/atapromise.c
+++ b/atapromise.c
@@ -129,7 +129,7 @@
.shutdown = atapromise_shutdown,
};

-static int atapromise_init(void)
+static int atapromise_init(const struct programmer_cfg *cfg)
{
struct pci_dev *dev = NULL;
uint32_t io_base_addr;
diff --git a/atavia.c b/atavia.c
index fe86664..4507820 100644
--- a/atavia.c
+++ b/atavia.c
@@ -143,7 +143,7 @@
.chip_writen = fallback_chip_writen,
};

-static int atavia_init(void)
+static int atavia_init(const struct programmer_cfg *cfg)
{
char *arg = extract_programmer_param_str(NULL, "offset");
if (arg) {
diff --git a/buspirate_spi.c b/buspirate_spi.c
index 2fcf445..8aa7243 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -314,7 +314,7 @@
*/
#define BP_DIVISOR(baud) ((4000000/(baud)) - 1)

-static int buspirate_spi_init(void)
+static int buspirate_spi_init(const struct programmer_cfg *cfg)
{
char *tmp;
char *dev;
diff --git a/ch341a_spi.c b/ch341a_spi.c
index 3978d99..78b9cee 100644
--- a/ch341a_spi.c
+++ b/ch341a_spi.c
@@ -420,7 +420,7 @@
.probe_opcode = default_spi_probe_opcode,
};

-static int ch341a_spi_init(void)
+static int ch341a_spi_init(const struct programmer_cfg *cfg)
{
if (handle != NULL) {
msg_cerr("%s: handle already set! Please report a bug at flashrom@flashrom.org\n", __func__);
diff --git a/dediprog.c b/dediprog.c
index 86d72aa..cd11505 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -1076,7 +1076,7 @@
return 0;
}

-static int dediprog_init(void)
+static int dediprog_init(const struct programmer_cfg *cfg)
{
char *param_str;
int spispeed_idx = 1;
diff --git a/developerbox_spi.c b/developerbox_spi.c
index d585418..16fa351 100644
--- a/developerbox_spi.c
+++ b/developerbox_spi.c
@@ -142,7 +142,7 @@
return 0;
}

-static int developerbox_spi_init(void)
+static int developerbox_spi_init(const struct programmer_cfg *cfg)
{
struct libusb_context *usb_ctx;
libusb_device_handle *cp210x_handle;
diff --git a/digilent_spi.c b/digilent_spi.c
index a16ae7b..b6e998d 100644
--- a/digilent_spi.c
+++ b/digilent_spi.c
@@ -374,7 +374,7 @@
{ NULL, 0 },
};

-static int digilent_spi_init(void)
+static int digilent_spi_init(const struct programmer_cfg *cfg)
{
char *param_str;
uint32_t speed_hz = spispeeds[0].speed;
diff --git a/drkaiser.c b/drkaiser.c
index 9267dfe..2fb6b91 100644
--- a/drkaiser.c
+++ b/drkaiser.c
@@ -81,7 +81,7 @@
.shutdown = drkaiser_shutdown,
};

-static int drkaiser_init(void)
+static int drkaiser_init(const struct programmer_cfg *cfg)
{
struct pci_dev *dev = NULL;
uint32_t addr;
diff --git a/dummyflasher.c b/dummyflasher.c
index 03c7f27..f27ad46 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -1338,7 +1338,7 @@
return 0;
}

-static int dummy_init(void)
+static int dummy_init(const struct programmer_cfg *cfg)
{
struct stat image_stat;

diff --git a/flashrom.c b/flashrom.c
index 5b7bbbd..0e2fa42 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -151,7 +151,7 @@

programmer_param = param;
msg_pdbg("Initializing %s programmer\n", programmer->name);
- ret = programmer->init();
+ ret = programmer->init(NULL);
if (programmer_param && strlen(programmer_param)) {
if (ret != 0) {
/* It is quite possible that any unhandled programmer parameter would have been valid,
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 7c31013..c7dbbb2 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -304,7 +304,7 @@
};

/* Returns 0 upon success, a negative number upon errors. */
-static int ft2232_spi_init(void)
+static int ft2232_spi_init(const struct programmer_cfg *cfg)
{
int ret = 0;
unsigned char buf[512];
diff --git a/gfxnvidia.c b/gfxnvidia.c
index 0da3e8d..19fa2b6 100644
--- a/gfxnvidia.c
+++ b/gfxnvidia.c
@@ -105,7 +105,7 @@
.shutdown = gfxnvidia_shutdown,
};

-static int gfxnvidia_init(void)
+static int gfxnvidia_init(const struct programmer_cfg *cfg)
{
struct pci_dev *dev = NULL;
uint32_t reg32;
diff --git a/include/programmer.h b/include/programmer.h
index c58459f..95e25ca 100644
--- a/include/programmer.h
+++ b/include/programmer.h
@@ -47,7 +47,7 @@
const char *const note;
} devs;

- int (*init) (void);
+ int (*init) (const struct programmer_cfg *cfg);

void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
void (*unmap_flash_region) (void *virt_addr, size_t len);
@@ -376,7 +376,7 @@

#if CONFIG_LINUX_MTD == 1
/* trivial wrapper to avoid cluttering internal_init() with #if */
-static inline int try_mtd(void) { return programmer_linux_mtd.init(); };
+static inline int try_mtd(void) { return programmer_linux_mtd.init(NULL); };
#else
static inline int try_mtd(void) { return 1; };
#endif
diff --git a/internal.c b/internal.c
index 8e267cd..66eebdc 100644
--- a/internal.c
+++ b/internal.c
@@ -116,7 +116,8 @@
.chip_writen = fallback_chip_writen,
};

-static int get_params(int *boardenable, int *boardmismatch,
+static int get_params(const struct programmer_cfg *cfg,
+ int *boardenable, int *boardmismatch,
int *force_laptop, int *not_a_laptop,
char **board_vendor, char **board_model)
{
@@ -188,7 +189,7 @@
return 0;
}

-static int internal_init(void)
+static int internal_init(const struct programmer_cfg *cfg)
{
int ret = 0;
int force_laptop;
@@ -200,7 +201,8 @@
const char *cb_model = NULL;
#endif

- ret = get_params(&force_boardenable, &force_boardmismatch,
+ ret = get_params(cfg,
+ &force_boardenable, &force_boardmismatch,
&force_laptop, &not_a_laptop,
&board_vendor, &board_model);
if (ret)
diff --git a/it8212.c b/it8212.c
index ac8126c..4d73665 100644
--- a/it8212.c
+++ b/it8212.c
@@ -74,7 +74,7 @@
.shutdown = it8212_shutdown,
};

-static int it8212_init(void)
+static int it8212_init(const struct programmer_cfg *cfg)
{
uint8_t *bar;

diff --git a/jlink_spi.c b/jlink_spi.c
index eba8dbc..48239f3 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -193,7 +193,7 @@
.probe_opcode = default_spi_probe_opcode,
};

-static int jlink_spi_init(void)
+static int jlink_spi_init(const struct programmer_cfg *cfg)
{
char *arg;
unsigned long speed = 0;
diff --git a/linux_mtd.c b/linux_mtd.c
index 414a6b4..ef90885 100644
--- a/linux_mtd.c
+++ b/linux_mtd.c
@@ -493,7 +493,7 @@
return ret;
}

-static int linux_mtd_init(void)
+static int linux_mtd_init(const struct programmer_cfg *cfg)
{
char *param_str;
int dev_num = 0;
diff --git a/linux_spi.c b/linux_spi.c
index cef7909..b54ab17 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -165,7 +165,7 @@
return result;
}

-static int linux_spi_init(void)
+static int linux_spi_init(const struct programmer_cfg *cfg)
{
char *param_str, *endp;
uint32_t speed_hz = 2 * 1000 * 1000;
diff --git a/mediatek_i2c_spi.c b/mediatek_i2c_spi.c
index 4133edb..c460da1 100644
--- a/mediatek_i2c_spi.c
+++ b/mediatek_i2c_spi.c
@@ -464,7 +464,7 @@
.probe_opcode = default_spi_probe_opcode,
};

-static int get_params(bool *allow_brick)
+static int get_params(const struct programmer_cfg *cfg, bool *allow_brick)
{
char *brick_str = NULL;
int ret = 0;
@@ -484,12 +484,12 @@
return ret;
}

-static int mediatek_init(void)
+static int mediatek_init(const struct programmer_cfg *cfg)
{
int ret;
bool allow_brick;

- if (get_params(&allow_brick))
+ if (get_params(cfg, &allow_brick))
return SPI_GENERIC_ERROR;

/*
diff --git a/mstarddc_spi.c b/mstarddc_spi.c
index 50a75d3..5b9e40e 100644
--- a/mstarddc_spi.c
+++ b/mstarddc_spi.c
@@ -150,7 +150,7 @@
};

/* Returns 0 upon success, a negative number upon errors. */
-static int mstarddc_spi_init(void)
+static int mstarddc_spi_init(const struct programmer_cfg *cfg)
{
int ret = 0;
int mstarddc_fd = -1;
diff --git a/ni845x_spi.c b/ni845x_spi.c
index f75c399..0096307 100644
--- a/ni845x_spi.c
+++ b/ni845x_spi.c
@@ -540,7 +540,7 @@
.probe_opcode = default_spi_probe_opcode,
};

-static int ni845x_spi_init(void)
+static int ni845x_spi_init(const struct programmer_cfg *cfg)
{
char *speed_str = NULL;
char *CS_str = NULL;
diff --git a/nic3com.c b/nic3com.c
index de7a5e5..fd4fe2b 100644
--- a/nic3com.c
+++ b/nic3com.c
@@ -101,7 +101,7 @@
.shutdown = nic3com_shutdown,
};

-static int nic3com_init(void)
+static int nic3com_init(const struct programmer_cfg *cfg)
{
struct pci_dev *dev = NULL;
uint32_t io_base_addr = 0;
diff --git a/nicintel.c b/nicintel.c
index e165611..9ef0315 100644
--- a/nicintel.c
+++ b/nicintel.c
@@ -77,7 +77,7 @@
.shutdown = nicintel_shutdown,
};

-static int nicintel_init(void)
+static int nicintel_init(const struct programmer_cfg *cfg)
{
struct pci_dev *dev = NULL;
uintptr_t addr;
diff --git a/nicintel_eeprom.c b/nicintel_eeprom.c
index c09c1d1..8e59a45 100644
--- a/nicintel_eeprom.c
+++ b/nicintel_eeprom.c
@@ -479,7 +479,7 @@
.shutdown = nicintel_ee_shutdown_i210,
};

-static int nicintel_ee_init(void)
+static int nicintel_ee_init(const struct programmer_cfg *cfg)
{
const struct opaque_master *mst;
uint32_t eec = 0;
diff --git a/nicintel_spi.c b/nicintel_spi.c
index 54d1c3c..74cb122 100644
--- a/nicintel_spi.c
+++ b/nicintel_spi.c
@@ -285,7 +285,7 @@
return 0;
}

-static int nicintel_spi_init(void)
+static int nicintel_spi_init(const struct programmer_cfg *cfg)
{
struct pci_dev *dev = NULL;

diff --git a/nicnatsemi.c b/nicnatsemi.c
index 9d98155..b9c58bc 100644
--- a/nicnatsemi.c
+++ b/nicnatsemi.c
@@ -88,7 +88,7 @@
.shutdown = nicnatsemi_shutdown,
};

-static int nicnatsemi_init(void)
+static int nicnatsemi_init(const struct programmer_cfg *cfg)
{
struct pci_dev *dev = NULL;
uint32_t io_base_addr;
diff --git a/nicrealtek.c b/nicrealtek.c
index ebe9dab..61eb38b 100644
--- a/nicrealtek.c
+++ b/nicrealtek.c
@@ -97,7 +97,7 @@
.shutdown = nicrealtek_shutdown,
};

-static int nicrealtek_init(void)
+static int nicrealtek_init(const struct programmer_cfg *cfg)
{
struct pci_dev *dev = NULL;
uint32_t io_base_addr = 0;
diff --git a/ogp_spi.c b/ogp_spi.c
index b3c404c..a994cb9 100644
--- a/ogp_spi.c
+++ b/ogp_spi.c
@@ -107,7 +107,7 @@
return 0;
}

-static int ogp_spi_init(void)
+static int ogp_spi_init(const struct programmer_cfg *cfg)
{
struct pci_dev *dev = NULL;
char *type;
diff --git a/parade_lspcon.c b/parade_lspcon.c
index 815f398..a82cc31 100644
--- a/parade_lspcon.c
+++ b/parade_lspcon.c
@@ -440,7 +440,7 @@
.probe_opcode = default_spi_probe_opcode,
};

-static int get_params(bool *allow_brick)
+static int get_params(const struct programmer_cfg *cfg, bool *allow_brick)
{
char *brick_str = NULL;
int ret = 0;
@@ -460,11 +460,11 @@
return ret;
}

-static int parade_lspcon_init(void)
+static int parade_lspcon_init(const struct programmer_cfg *cfg)
{
bool allow_brick;

- if (get_params(&allow_brick))
+ if (get_params(cfg, &allow_brick))
return SPI_GENERIC_ERROR;

/*
diff --git a/pickit2_spi.c b/pickit2_spi.c
index 7c84d96..312eaea 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -388,7 +388,7 @@
.probe_opcode = default_spi_probe_opcode,
};

-static int pickit2_spi_init(void)
+static int pickit2_spi_init(const struct programmer_cfg *cfg)
{
uint8_t buf[CMD_LENGTH] = {
CMD_EXEC_SCRIPT,
diff --git a/pony_spi.c b/pony_spi.c
index 50f44da..69be3aa 100644
--- a/pony_spi.c
+++ b/pony_spi.c
@@ -120,7 +120,7 @@
return ret;
}

-static int get_params(enum pony_type *type, int *have_device)
+static int get_params(const struct programmer_cfg *cfg, enum pony_type *type, int *have_device)
{
char *arg = NULL;
int ret = 0;
@@ -159,7 +159,7 @@
return ret;
}

-static int pony_spi_init(void)
+static int pony_spi_init(const struct programmer_cfg *cfg)
{
int i, data_out;
enum pony_type type;
@@ -167,7 +167,7 @@
int have_device;
int have_prog = 0;

- if (get_params(&type, &have_device)) {
+ if (get_params(cfg, &type, &have_device)) {
serialport_shutdown(NULL);
return 1;
}
diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c
index 3382b9e..c6689ac 100644
--- a/raiden_debug_spi.c
+++ b/raiden_debug_spi.c
@@ -1482,7 +1482,7 @@
dev = usb_device_free(dev);
}

-static int raiden_debug_spi_init(void)
+static int raiden_debug_spi_init(const struct programmer_cfg *cfg)
{
struct usb_match match;
char *serial = extract_programmer_param_str(NULL, "serial");
diff --git a/rayer_spi.c b/rayer_spi.c
index 82c49b3..95f7bbc 100644
--- a/rayer_spi.c
+++ b/rayer_spi.c
@@ -235,7 +235,7 @@
.half_period = 0,
};

-static int rayer_spi_init(void)
+static int rayer_spi_init(const struct programmer_cfg *cfg)
{
const struct rayer_programmer *prog = rayer_spi_types;
char *arg = NULL;
diff --git a/realtek_mst_i2c_spi.c b/realtek_mst_i2c_spi.c
index 6c2b86f..c4482ac 100644
--- a/realtek_mst_i2c_spi.c
+++ b/realtek_mst_i2c_spi.c
@@ -444,7 +444,7 @@
.probe_opcode = default_spi_probe_opcode,
};

-static int get_params(bool *reset, bool *enter_isp, bool *allow_brick)
+static int get_params(const struct programmer_cfg *cfg, bool *reset, bool *enter_isp, bool *allow_brick)
{
char *param_str;
int ret = 0;
@@ -492,12 +492,12 @@
return ret;
}

-static int realtek_mst_i2c_spi_init(void)
+static int realtek_mst_i2c_spi_init(const struct programmer_cfg *cfg)
{
int ret = 0;
bool reset, enter_isp, allow_brick;

- if (get_params(&reset, &enter_isp, &allow_brick))
+ if (get_params(cfg, &reset, &enter_isp, &allow_brick))
return SPI_GENERIC_ERROR;

/*
diff --git a/satamv.c b/satamv.c
index 8c79f08..19ecf22 100644
--- a/satamv.c
+++ b/satamv.c
@@ -114,7 +114,7 @@
* 0xc08 PCI BAR2 (Flash/NVRAM) Control
* 0x1046c Flash Parameters
*/
-static int satamv_init(void)
+static int satamv_init(const struct programmer_cfg *cfg)
{
struct pci_dev *dev = NULL;
uintptr_t addr;
diff --git a/satasii.c b/satasii.c
index 7e795c2..a56171b 100644
--- a/satasii.c
+++ b/satasii.c
@@ -105,7 +105,7 @@
.shutdown = satasii_shutdown,
};

-static int satasii_init(void)
+static int satasii_init(const struct programmer_cfg *cfg)
{
struct pci_dev *dev = NULL;
uint32_t addr;
diff --git a/serprog.c b/serprog.c
index 4480285..e025893 100644
--- a/serprog.c
+++ b/serprog.c
@@ -564,7 +564,7 @@

static enum chipbustype serprog_buses_supported = BUS_NONE;

-static int serprog_init(void)
+static int serprog_init(const struct programmer_cfg *cfg)
{
uint16_t iface;
unsigned char pgmname[17];
diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c
index ccba1d9..07fdedd 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -474,7 +474,7 @@
.probe_opcode = default_spi_probe_opcode,
};

-static int stlinkv3_spi_init(void)
+static int stlinkv3_spi_init(const struct programmer_cfg *cfg)
{
uint16_t sck_freq_kHz = 1000; // selecting 1 MHz SCK is a good bet
char *param_str;
diff --git a/usbblaster_spi.c b/usbblaster_spi.c
index b1ab80a..2880a3c 100644
--- a/usbblaster_spi.c
+++ b/usbblaster_spi.c
@@ -177,7 +177,7 @@
};

/* Returns 0 upon success, a negative number upon errors. */
-static int usbblaster_spi_init(void)
+static int usbblaster_spi_init(const struct programmer_cfg *cfg)
{
uint8_t buf[BUF_SIZE + 1] = { 0 };
struct ftdi_context ftdic;

To view, visit change 66655. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I8bab51a635b9d3a43e1619a7a32b334f4ce2cdd2
Gerrit-Change-Number: 66655
Gerrit-PatchSet: 9
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Felix Singer <felixsinger@posteo.net>
Gerrit-Reviewer: Nikolai Artemiev <nartemiev@google.com>
Gerrit-Reviewer: Peter Marheine <pmarheine@chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-MessageType: merged