const'ify flashctx to align signatures with cros flashrom
The ChromiumOS flashrom fork has since const'ify flashctx
in a few places. This aligns the function signatures to
match with downstream to ease forward porting patches
out of downstream back into mainline flashrom.
This patch is minimum viable alignment and so feedback is
welcome.
Change-Id: Iff6dbda13cb0d941481c0d204b9c30895630fbd1
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/40324
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/70933
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/bitbang_spi.c b/bitbang_spi.c
index 7c183c3..ac50e67 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -64,7 +64,7 @@
return master->get_miso();
}
-static int bitbang_spi_send_command(struct flashctx *flash,
+static int bitbang_spi_send_command(const struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr);
@@ -145,7 +145,7 @@
}
}
-static int bitbang_spi_send_command(struct flashctx *flash,
+static int bitbang_spi_send_command(const struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr)
diff --git a/buspirate_spi.c b/buspirate_spi.c
index 826bd84..fdfc0e4 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -128,9 +128,9 @@
return ret;
}
-static int buspirate_spi_send_command_v1(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
+static int buspirate_spi_send_command_v1(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr);
-static int buspirate_spi_send_command_v2(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
+static int buspirate_spi_send_command_v2(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr);
static struct spi_master spi_master_buspirate = {
@@ -572,7 +572,7 @@
return 0;
}
-static int buspirate_spi_send_command_v1(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
+static int buspirate_spi_send_command_v1(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr)
{
unsigned int i = 0;
@@ -625,7 +625,7 @@
return ret;
}
-static int buspirate_spi_send_command_v2(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
+static int buspirate_spi_send_command_v2(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr)
{
int i = 0, ret = 0;
diff --git a/ch341a_spi.c b/ch341a_spi.c
index d3af32f..17c37eb 100644
--- a/ch341a_spi.c
+++ b/ch341a_spi.c
@@ -335,7 +335,7 @@
stored_delay_us += usecs;
}
-static int ch341a_spi_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr)
+static int ch341a_spi_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr)
{
if (handle == NULL)
return -1;
diff --git a/chipdrivers.h b/chipdrivers.h
index cb1e877..3c7d146 100644
--- a/chipdrivers.h
+++ b/chipdrivers.h
@@ -62,8 +62,8 @@
/* spi25_statusreg.c */
-uint8_t spi_read_status_register(struct flashctx *flash);
-int spi_write_status_register(struct flashctx *flash, int status);
+uint8_t spi_read_status_register(const struct flashctx *flash);
+int spi_write_status_register(const struct flashctx *flash, int status);
void spi_prettyprint_status_register_bit(uint8_t status, int bit);
int spi_prettyprint_status_register_plain(struct flashctx *flash);
int spi_prettyprint_status_register_default_welwip(struct flashctx *flash);
diff --git a/dediprog.c b/dediprog.c
index 99df7b0..bacb6b8 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -714,7 +714,7 @@
return dediprog_spi_write(flash, buf, start, len, WRITE_MODE_2B_AAI);
}
-static int dediprog_spi_send_command(struct flashctx *flash,
+static int dediprog_spi_send_command(const struct flashctx *flash,
unsigned int writecnt,
unsigned int readcnt,
const unsigned char *writearr,
diff --git a/digilent_spi.c b/digilent_spi.c
index 13a876e..0f7a9da 100644
--- a/digilent_spi.c
+++ b/digilent_spi.c
@@ -257,7 +257,7 @@
return 0;
}
-static int digilent_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
+static int digilent_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr)
{
int ret;
diff --git a/dummyflasher.c b/dummyflasher.c
index b9f6126..e1a1d80 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -93,7 +93,7 @@
static unsigned int spi_write_256_chunksize = 256;
-static int dummy_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
+static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr);
static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf,
unsigned int start, unsigned int len);
@@ -818,7 +818,7 @@
}
#endif
-static int dummy_spi_send_command(struct flashctx *flash, unsigned int writecnt,
+static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr)
diff --git a/flash.h b/flash.h
index 1a9bd9f..2f0143b 100644
--- a/flash.h
+++ b/flash.h
@@ -415,8 +415,8 @@
unsigned char *readarr;
};
#define NULL_SPI_CMD { 0, 0, NULL, NULL, }
-int spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
-int spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
+int spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
+int spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
enum chipbustype get_buses_supported(void);
#endif /* !__FLASH_H__ */
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 5bdc2a7..d63aa8d 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -148,7 +148,7 @@
return 0;
}
-static int ft2232_spi_send_command(struct flashctx *flash,
+static int ft2232_spi_send_command(const struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr);
@@ -447,7 +447,7 @@
}
/* Returns 0 upon success, a negative number upon errors. */
-static int ft2232_spi_send_command(struct flashctx *flash,
+static int ft2232_spi_send_command(const struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr)
diff --git a/ichspi.c b/ichspi.c
index 725bfb3..15222d8 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -1103,7 +1103,7 @@
}
}
-static int ich_spi_send_command(struct flashctx *flash, unsigned int writecnt,
+static int ich_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr)
@@ -1507,7 +1507,7 @@
return 0;
}
-static int ich_spi_send_multicommand(struct flashctx *flash,
+static int ich_spi_send_multicommand(const struct flashctx *flash,
struct spi_command *cmds)
{
int ret = 0;
diff --git a/it85spi.c b/it85spi.c
index 5ce9193..b998790 100644
--- a/it85spi.c
+++ b/it85spi.c
@@ -270,7 +270,7 @@
return 0;
}
-static int it85xx_spi_send_command(struct flashctx *flash,
+static int it85xx_spi_send_command(const struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr);
@@ -322,7 +322,7 @@
* 3. read date from LPC/FWH address 0xffff_fdxxh (drive CE# low and get
* data from MISO)
*/
-static int it85xx_spi_send_command(struct flashctx *flash,
+static int it85xx_spi_send_command(const struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr)
diff --git a/it87spi.c b/it87spi.c
index 7b38492..c1ed29c 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -98,7 +98,7 @@
return;
}
-static int it8716f_spi_send_command(struct flashctx *flash,
+static int it8716f_spi_send_command(const struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr);
@@ -276,7 +276,7 @@
* commands with the address in inverse wire order. That's why the register
* ordering in case 4 and 5 may seem strange.
*/
-static int it8716f_spi_send_command(struct flashctx *flash,
+static int it8716f_spi_send_command(const struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr)
diff --git a/jlink_spi.c b/jlink_spi.c
index 00e9c6d..3a73c01 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -101,7 +101,7 @@
return true;
}
-static int jlink_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
+static int jlink_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr)
{
uint32_t length;
diff --git a/linux_spi.c b/linux_spi.c
index aa73c18..1ef8f2b 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -49,7 +49,7 @@
static size_t max_kernel_buf_size;
static int linux_spi_shutdown(void *data);
-static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt,
+static int linux_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
unsigned int readcnt,
const unsigned char *txbuf,
unsigned char *rxbuf);
@@ -183,7 +183,7 @@
return 0;
}
-static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt,
+static int linux_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
unsigned int readcnt,
const unsigned char *txbuf,
unsigned char *rxbuf)
diff --git a/mstarddc_spi.c b/mstarddc_spi.c
index db11157..48d6204 100644
--- a/mstarddc_spi.c
+++ b/mstarddc_spi.c
@@ -153,7 +153,7 @@
}
/* Returns 0 upon success, a negative number upon errors. */
-static int mstarddc_spi_send_command(struct flashctx *flash,
+static int mstarddc_spi_send_command(const struct flashctx *flash,
unsigned int writecnt,
unsigned int readcnt,
const unsigned char *writearr,
diff --git a/pickit2_spi.c b/pickit2_spi.c
index 2936ee8..0bc17af 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -195,7 +195,7 @@
return 0;
}
-static int pickit2_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
+static int pickit2_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr)
{
diff --git a/programmer.h b/programmer.h
index 3cf53b9..f1915df 100644
--- a/programmer.h
+++ b/programmer.h
@@ -600,9 +600,9 @@
uint32_t features;
unsigned int max_data_read; // (Ideally,) maximum data read size in one go (excluding opcode+address).
unsigned int max_data_write; // (Ideally,) maximum data write size in one go (excluding opcode+address).
- int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
+ int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr);
- int (*multicommand)(struct flashctx *flash, struct spi_command *cmds);
+ int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
/* Optimized functions for this master */
int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
@@ -611,9 +611,9 @@
const void *data;
};
-int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
+int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr);
-int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
+int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
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);
diff --git a/sb600spi.c b/sb600spi.c
index cb5c4a4..21f22f6 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -56,9 +56,9 @@
#define FIFO_SIZE_OLD 8
#define FIFO_SIZE_YANGTZE 71
-static int sb600_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
+static int sb600_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr);
-static int spi100_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
+static int spi100_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr);
static struct spi_master spi_master_sb600 = {
@@ -190,7 +190,7 @@
}
/* Check the number of bytes to be transmitted and extract opcode. */
-static int check_readwritecnt(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt)
+static int check_readwritecnt(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt)
{
unsigned int maxwritecnt = flash->mst->spi.max_data_write + 3;
if (writecnt > maxwritecnt) {
@@ -217,7 +217,7 @@
msg_pspew("done\n");
}
-static int sb600_spi_send_command(struct flashctx *flash, unsigned int writecnt,
+static int sb600_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr)
@@ -303,7 +303,7 @@
return 0;
}
-static int spi100_spi_send_command(struct flashctx *flash, unsigned int writecnt,
+static int spi100_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr)
diff --git a/serprog.c b/serprog.c
index 37a9db4..1befce1 100644
--- a/serprog.c
+++ b/serprog.c
@@ -295,7 +295,7 @@
return 0;
}
-static int serprog_spi_send_command(struct flashctx *flash,
+static int serprog_spi_send_command(const struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr);
@@ -894,7 +894,7 @@
sp_prev_was_write = 0;
}
-static int serprog_spi_send_command(struct flashctx *flash,
+static int serprog_spi_send_command(const struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr)
diff --git a/spi.c b/spi.c
index 489baf3..aed2a92 100644
--- a/spi.c
+++ b/spi.c
@@ -26,7 +26,7 @@
#include "programmer.h"
#include "spi.h"
-int spi_send_command(struct flashctx *flash, unsigned int writecnt,
+int spi_send_command(const struct flashctx *flash, unsigned int writecnt,
unsigned int readcnt, const unsigned char *writearr,
unsigned char *readarr)
{
@@ -34,12 +34,12 @@
readarr);
}
-int spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds)
+int spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds)
{
return flash->mst->spi.multicommand(flash, cmds);
}
-int default_spi_send_command(struct flashctx *flash, unsigned int writecnt,
+int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr)
@@ -60,7 +60,7 @@
return spi_send_multicommand(flash, cmd);
}
-int default_spi_send_multicommand(struct flashctx *flash,
+int default_spi_send_multicommand(const struct flashctx *flash,
struct spi_command *cmds)
{
int result = 0;
diff --git a/spi25_statusreg.c b/spi25_statusreg.c
index bb09e58..34f9ad4 100644
--- a/spi25_statusreg.c
+++ b/spi25_statusreg.c
@@ -22,7 +22,7 @@
#include "spi.h"
/* === Generic functions === */
-static int spi_write_status_register_flag(struct flashctx *flash, int status, const unsigned char enable_opcode)
+static int spi_write_status_register_flag(const struct flashctx *flash, int status, const unsigned char enable_opcode)
{
int result;
int i = 0;
@@ -73,7 +73,7 @@
return 0;
}
-int spi_write_status_register(struct flashctx *flash, int status)
+int spi_write_status_register(const struct flashctx *flash, int status)
{
int feature_bits = flash->chip->feature_bits;
int ret = 1;
@@ -90,7 +90,7 @@
return ret;
}
-uint8_t spi_read_status_register(struct flashctx *flash)
+uint8_t spi_read_status_register(const struct flashctx *flash)
{
static const unsigned char cmd[JEDEC_RDSR_OUTSIZE] = { JEDEC_RDSR };
/* FIXME: No workarounds for driver/hardware bugs in generic code. */
diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c
index d2988b6..d56f305 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -323,7 +323,7 @@
return 0;
}
-static int stlinkv3_spi_transmit(struct flashctx *flash,
+static int stlinkv3_spi_transmit(const struct flashctx *flash,
unsigned int write_cnt,
unsigned int read_cnt,
const unsigned char *write_arr,
diff --git a/usbblaster_spi.c b/usbblaster_spi.c
index e2a0a4f..46de86c 100644
--- a/usbblaster_spi.c
+++ b/usbblaster_spi.c
@@ -179,7 +179,7 @@
}
/* Returns 0 upon success, a negative number upon errors. */
-static int usbblaster_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
+static int usbblaster_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr)
{
uint8_t cmd;
diff --git a/wbsio_spi.c b/wbsio_spi.c
index f4f6af9..1674825 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -57,7 +57,7 @@
return flashport;
}
-static int wbsio_spi_send_command(struct flashctx *flash, unsigned int writecnt,
+static int wbsio_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr);
@@ -110,7 +110,7 @@
* Would one more byte of RAM in the chip (to get all 24 bits) really make
* such a big difference?
*/
-static int wbsio_spi_send_command(struct flashctx *flash, unsigned int writecnt,
+static int wbsio_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr)