Pass programmer context to programmer->init()
Change-Id: I064eb4e25c3d382e4e5bde802306698fafe5e1d0
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/72526
diff --git a/atahpt.c b/atahpt.c
index 42741a7..5b375a0 100644
--- a/atahpt.c
+++ b/atahpt.c
@@ -53,7 +53,7 @@
.chip_writen = fallback_chip_writen,
};
-static int atahpt_init(void)
+static int atahpt_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = NULL;
uint32_t reg32;
diff --git a/atapromise.c b/atapromise.c
index 0dcb8c2..dcdf4c2 100644
--- a/atapromise.c
+++ b/atapromise.c
@@ -108,7 +108,7 @@
}
}
-static int atapromise_init(void)
+static int atapromise_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = NULL;
diff --git a/atavia.c b/atavia.c
index 34d7b73..dc7317c 100644
--- a/atavia.c
+++ b/atavia.c
@@ -121,7 +121,7 @@
return (atavia_offset != 0) ? atavia_offset : (void *)phys_addr;
}
-static int atavia_init(void)
+static int atavia_init(struct flashprog_programmer *const prog)
{
char *arg = extract_programmer_param("offset");
if (arg) {
diff --git a/buspirate_spi.c b/buspirate_spi.c
index 27bca8a..b2c58c6 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -221,7 +221,7 @@
*/
#define BP_DIVISOR(baud) ((4000000/(baud)) - 1)
-static int buspirate_spi_init(void)
+static int buspirate_spi_init(struct flashprog_programmer *const prog)
{
char *tmp;
char *dev;
diff --git a/ch341a_spi.c b/ch341a_spi.c
index 2b6413b..6a2bdfb 100644
--- a/ch341a_spi.c
+++ b/ch341a_spi.c
@@ -421,7 +421,7 @@
return 0;
}
-static int ch341a_spi_init(void)
+static int ch341a_spi_init(struct flashprog_programmer *const prog)
{
if (handle != NULL) {
msg_cerr("%s: handle already set! Please report a bug at flashprog@flashprog.org\n",
diff --git a/ch347_spi.c b/ch347_spi.c
index 98ae28e..aa1ee0b 100644
--- a/ch347_spi.c
+++ b/ch347_spi.c
@@ -269,7 +269,7 @@
}
/* Largely copied from ch341a_spi.c */
-static int ch347_spi_init(void)
+static int ch347_spi_init(struct flashprog_programmer *const prog)
{
struct ch347_spi_data *ch347_data = calloc(1, sizeof(*ch347_data));
if (!ch347_data) {
diff --git a/dediprog.c b/dediprog.c
index 64caa8a..60bea4c 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -1098,7 +1098,7 @@
return ret;
}
-static int dediprog_init(void)
+static int dediprog_init(struct flashprog_programmer *const prog)
{
char *voltage, *id_str, *device, *spispeed, *target_str;
int spispeed_idx = 1;
diff --git a/developerbox_spi.c b/developerbox_spi.c
index ae0961e..3a9059e 100644
--- a/developerbox_spi.c
+++ b/developerbox_spi.c
@@ -134,7 +134,7 @@
return 0;
}
-static int developerbox_spi_init(void)
+static int developerbox_spi_init(struct flashprog_programmer *const prog)
{
if (libusb_init(&usb_ctx)) {
msg_perr("Could not initialize libusb!\n");
diff --git a/digilent_spi.c b/digilent_spi.c
index f563bdc..afdbcd3 100644
--- a/digilent_spi.c
+++ b/digilent_spi.c
@@ -371,7 +371,7 @@
{ NULL, 0 },
};
-static int digilent_spi_init(void)
+static int digilent_spi_init(struct flashprog_programmer *const prog)
{
char *p;
uint32_t speed_hz = spispeeds[0].speed;
diff --git a/dirtyjtag_spi.c b/dirtyjtag_spi.c
index adedc0d..06099de 100644
--- a/dirtyjtag_spi.c
+++ b/dirtyjtag_spi.c
@@ -279,7 +279,7 @@
.probe_opcode = default_spi_probe_opcode,
};
-static int dirtyjtag_spi_init(void)
+static int dirtyjtag_spi_init(struct flashprog_programmer *const prog)
{
struct spi_master dirtyjtag_spi = spi_master_dirtyjtag_spi;
struct libusb_device_handle *handle = NULL;
diff --git a/drkaiser.c b/drkaiser.c
index 40cd157..0a67f09 100644
--- a/drkaiser.c
+++ b/drkaiser.c
@@ -53,7 +53,7 @@
.chip_writen = fallback_chip_writen,
};
-static int drkaiser_init(void)
+static int drkaiser_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = NULL;
uint32_t addr;
diff --git a/dummyflasher.c b/dummyflasher.c
index a469d6d..548c16f 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -436,7 +436,7 @@
return 0;
}
-static int dummy_init(void)
+static int dummy_init(struct flashprog_programmer *const prog)
{
int ret = 0;
struct stat image_stat;
diff --git a/flashprog.c b/flashprog.c
index e8ab305..4e669c7 100644
--- a/flashprog.c
+++ b/flashprog.c
@@ -156,7 +156,7 @@
programmer_may_write = true;
msg_pdbg("Initializing %s programmer\n", programmer->name);
- ret = programmer->init();
+ ret = programmer->init(prog);
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 4f9fbeb..020eadc 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -300,7 +300,7 @@
};
/* Returns 0 upon success, a negative number upon errors. */
-static int ft2232_spi_init(void)
+static int ft2232_spi_init(struct flashprog_programmer *const prog)
{
int ret;
unsigned char buf[512];
diff --git a/gfxnvidia.c b/gfxnvidia.c
index 7eb633d..5055b8b 100644
--- a/gfxnvidia.c
+++ b/gfxnvidia.c
@@ -75,7 +75,7 @@
.chip_writen = fallback_chip_writen,
};
-static int gfxnvidia_init(void)
+static int gfxnvidia_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = NULL;
uint32_t reg32;
diff --git a/include/programmer.h b/include/programmer.h
index f45aab9..2684b08 100644
--- a/include/programmer.h
+++ b/include/programmer.h
@@ -40,6 +40,7 @@
const char *device_name;
};
+struct flashprog_programmer;
struct programmer_entry {
const char *name;
const enum programmer_type type;
@@ -48,7 +49,7 @@
const char *const note;
} devs;
- int (*init) (void);
+ int (*init) (struct flashprog_programmer *);
void (*delay) (unsigned int usecs);
};
@@ -377,9 +378,9 @@
#if CONFIG_LINUX_MTD == 1 && LINUX_MTD_AS_INTERNAL == 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(struct flashprog_programmer *prog) { return programmer_linux_mtd.init(prog); };
#else
-static inline int try_mtd(void) { return 1; };
+static inline int try_mtd(struct flashprog_programmer *prog) { return 1; };
#endif
/* mcp6x_spi.c */
diff --git a/internal.c b/internal.c
index 5d85758..57064a7 100644
--- a/internal.c
+++ b/internal.c
@@ -162,7 +162,7 @@
return 0;
}
-static int internal_init(void)
+static int internal_init(struct flashprog_programmer *const prog)
{
int ret = 0;
bool force_laptop;
@@ -189,7 +189,7 @@
*/
internal_buses_supported = BUS_NONSPI;
- if (try_mtd() == 0) {
+ if (try_mtd(prog) == 0) {
ret = 0;
goto internal_init_exit;
}
diff --git a/it8212.c b/it8212.c
index 5657bca..4cf0e80 100644
--- a/it8212.c
+++ b/it8212.c
@@ -46,7 +46,7 @@
.chip_writen = fallback_chip_writen,
};
-static int it8212_init(void)
+static int it8212_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = pcidev_init(devs_it8212, PCI_ROM_ADDRESS);
if (!dev)
diff --git a/jlink_spi.c b/jlink_spi.c
index beabe63..b234b0e 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -195,7 +195,7 @@
return 0;
}
-static int jlink_spi_init(void)
+static int jlink_spi_init(struct flashprog_programmer *const prog)
{
char *arg;
unsigned long speed = 0;
diff --git a/linux_gpio2_spi.c b/linux_gpio2_spi.c
index fd3cdf1..ef162b8 100644
--- a/linux_gpio2_spi.c
+++ b/linux_gpio2_spi.c
@@ -108,7 +108,7 @@
return 0;
}
-static int linux_gpio_spi_init(void)
+static int linux_gpio_spi_init(struct flashprog_programmer *const prog)
{
struct linux_gpio_spi *gpio_spi = NULL;
const char *param_str[] = { "cs", "sck", "mosi", "miso", "gpiochip" };
diff --git a/linux_gpio_spi.c b/linux_gpio_spi.c
index 1e95c16..8ce5b07 100644
--- a/linux_gpio_spi.c
+++ b/linux_gpio_spi.c
@@ -83,7 +83,7 @@
return 0;
}
-static int linux_gpio_spi_init(void)
+static int linux_gpio_spi_init(struct flashprog_programmer *const prog)
{
struct linux_gpio_spi *data = NULL;
struct gpiod_chip *chip = NULL;
diff --git a/linux_mtd.c b/linux_mtd.c
index 0960025..ca05305 100644
--- a/linux_mtd.c
+++ b/linux_mtd.c
@@ -374,7 +374,7 @@
return 0;
}
-static int linux_mtd_init(void)
+static int linux_mtd_init(struct flashprog_programmer *const prog)
{
char *param;
int dev_num = 0;
diff --git a/linux_spi.c b/linux_spi.c
index e8353d5..aac232a 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -112,7 +112,7 @@
return result;
}
-static int linux_spi_init(void)
+static int linux_spi_init(struct flashprog_programmer *const prog)
{
char *p, *endp, *dev;
uint32_t speed_hz = 2 * 1000 * 1000;
diff --git a/mstarddc_spi.c b/mstarddc_spi.c
index 911c450..9888d1f 100644
--- a/mstarddc_spi.c
+++ b/mstarddc_spi.c
@@ -66,7 +66,7 @@
}
/* Returns 0 upon success, a negative number upon errors. */
-static int mstarddc_spi_init(void)
+static int mstarddc_spi_init(struct flashprog_programmer *const prog)
{
int ret = 0;
diff --git a/ni845x_spi.c b/ni845x_spi.c
index 0e71e21..beb5ea5 100644
--- a/ni845x_spi.c
+++ b/ni845x_spi.c
@@ -389,7 +389,7 @@
ni845x_report_error("ni845xCloseFindDeviceHandle", tmp);
}
-int ni845x_spi_init(void)
+int ni845x_spi_init(struct flashprog_programmer *const prog)
{
char *speed_str = NULL;
char *CS_str = NULL;
diff --git a/nic3com.c b/nic3com.c
index a8b612e..64cb259 100644
--- a/nic3com.c
+++ b/nic3com.c
@@ -82,7 +82,7 @@
return 0;
}
-static int nic3com_init(void)
+static int nic3com_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = NULL;
diff --git a/nicintel.c b/nicintel.c
index f564dc2..1c63081 100644
--- a/nicintel.c
+++ b/nicintel.c
@@ -56,7 +56,7 @@
.chip_writen = fallback_chip_writen,
};
-static int nicintel_init(void)
+static int nicintel_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = NULL;
uintptr_t addr;
diff --git a/nicintel_eeprom.c b/nicintel_eeprom.c
index 0128d08..ca301e0 100644
--- a/nicintel_eeprom.c
+++ b/nicintel_eeprom.c
@@ -465,7 +465,7 @@
return ret;
}
-static int nicintel_ee_init(void)
+static int nicintel_ee_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = pcidev_init(nics_intel_ee, PCI_BASE_ADDRESS_0);
if (!dev)
diff --git a/nicintel_spi.c b/nicintel_spi.c
index ed94d93..1de3fd0 100644
--- a/nicintel_spi.c
+++ b/nicintel_spi.c
@@ -265,7 +265,7 @@
return 0;
}
-static int nicintel_spi_init(void)
+static int nicintel_spi_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = NULL;
diff --git a/nicnatsemi.c b/nicnatsemi.c
index 8b0b68f..65a42fa 100644
--- a/nicnatsemi.c
+++ b/nicnatsemi.c
@@ -48,7 +48,7 @@
.chip_writen = fallback_chip_writen,
};
-static int nicnatsemi_init(void)
+static int nicnatsemi_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = NULL;
diff --git a/nicrealtek.c b/nicrealtek.c
index d635705..2f51495 100644
--- a/nicrealtek.c
+++ b/nicrealtek.c
@@ -55,7 +55,7 @@
return 0;
}
-static int nicrealtek_init(void)
+static int nicrealtek_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = NULL;
diff --git a/ogp_spi.c b/ogp_spi.c
index 5a1b969..5eeda98 100644
--- a/ogp_spi.c
+++ b/ogp_spi.c
@@ -93,7 +93,7 @@
.half_period = 0,
};
-static int ogp_spi_init(void)
+static int ogp_spi_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = NULL;
char *type;
diff --git a/pickit2_spi.c b/pickit2_spi.c
index 50e6017..13a47f9 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -389,7 +389,7 @@
return ret;
}
-static int pickit2_spi_init(void)
+static int pickit2_spi_init(struct flashprog_programmer *const prog)
{
uint8_t buf[CMD_LENGTH] = {
CMD_EXEC_SCRIPT,
diff --git a/pony_spi.c b/pony_spi.c
index 2d423ef..1b1f939 100644
--- a/pony_spi.c
+++ b/pony_spi.c
@@ -110,7 +110,7 @@
return ret;
}
-static int pony_spi_init(void)
+static int pony_spi_init(struct flashprog_programmer *const prog)
{
int i, data_out;
char *arg = NULL;
diff --git a/rayer_spi.c b/rayer_spi.c
index 009e02f..f8bac35 100644
--- a/rayer_spi.c
+++ b/rayer_spi.c
@@ -163,7 +163,7 @@
.half_period = 0,
};
-static int rayer_spi_init(void)
+static int rayer_spi_init(struct flashprog_programmer *const flashprog)
{
const struct rayer_programmer *prog = rayer_spi_types;
char *arg = NULL;
diff --git a/satamv.c b/satamv.c
index 735495c..cefe4c4 100644
--- a/satamv.c
+++ b/satamv.c
@@ -70,7 +70,7 @@
* 0xc08 PCI BAR2 (Flash/NVRAM) Control
* 0x1046c Flash Parameters
*/
-static int satamv_init(void)
+static int satamv_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = NULL;
uintptr_t addr;
diff --git a/satasii.c b/satasii.c
index 21ea879..a638cdb 100644
--- a/satasii.c
+++ b/satasii.c
@@ -65,7 +65,7 @@
return ctrl_reg;
}
-static int satasii_init(void)
+static int satasii_init(struct flashprog_programmer *const prog)
{
struct pci_dev *dev = NULL;
uint32_t addr;
diff --git a/serprog.c b/serprog.c
index 458fa91..50ec327 100644
--- a/serprog.c
+++ b/serprog.c
@@ -358,7 +358,7 @@
static enum chipbustype serprog_buses_supported = BUS_NONE;
-static int serprog_init(void)
+static int serprog_init(struct flashprog_programmer *const prog)
{
uint16_t iface;
unsigned char pgmname[17];
diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c
index a1d062b..b15c703 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -448,7 +448,7 @@
.probe_opcode = default_spi_probe_opcode,
};
-static int stlinkv3_spi_init(void)
+static int stlinkv3_spi_init(struct flashprog_programmer *const prog)
{
uint16_t sck_freq_kHz = 1000; // selecting 1 MHz SCK is a good bet
char *speed_str = NULL;
diff --git a/usbblaster_spi.c b/usbblaster_spi.c
index 954967e..5be423b 100644
--- a/usbblaster_spi.c
+++ b/usbblaster_spi.c
@@ -72,7 +72,7 @@
/* Returns 0 upon success, a negative number upon errors. */
-static int usbblaster_spi_init(void)
+static int usbblaster_spi_init(struct flashprog_programmer *const prog)
{
uint8_t buf[BUF_SIZE + 1] = { 0 };