Add 'const' to the data block passed to 'write' functions. This is as much for documentation as anything else, but should allow the compiler to make a few basic checks for us.
Signed-off-by: Mark Marshall mark.marshall@omicron.at --- 82802ab.c | 4 ++-- chipdrivers.h | 24 ++++++++++++------------ dummyflasher.c | 8 ++++---- en29lv640b.c | 4 ++-- flash.h | 12 ++++++------ flashrom.c | 26 +++++++++++++------------- ichspi.c | 2 +- it87spi.c | 6 +++--- layout.c | 4 ++-- linux_spi.c | 4 ++-- m29f400bt.c | 4 ++-- opaque.c | 2 +- programmer.c | 2 +- programmer.h | 16 ++++++++-------- serial.c | 2 +- spi.c | 8 ++++---- spi25.c | 16 +++++++++------- sst28sf040.c | 4 ++-- 18 files changed, 75 insertions(+), 73 deletions(-)
diff --git a/82802ab.c b/82802ab.c index 608995d..a1096ea 100644 --- a/82802ab.c +++ b/82802ab.c @@ -141,8 +141,8 @@ int erase_block_82802ab(struct flashctx *flash, unsigned int page, }
/* chunksize is 1 */ -int write_82802ab(struct flashctx *flash, uint8_t *src, unsigned int start, - unsigned int len) +int write_82802ab(struct flashctx *flash, const uint8_t *src, + unsigned int start, unsigned int len) { int i; chipaddr dst = flash->virtual_memory + start; diff --git a/chipdrivers.h b/chipdrivers.h index 244d421..e9d0b7f 100644 --- a/chipdrivers.h +++ b/chipdrivers.h @@ -28,8 +28,8 @@ #include "flash.h" /* for chipaddr and flashctx */
/* spi.c */ -int spi_aai_write(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); -int spi_chip_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); +int spi_aai_write(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); +int spi_chip_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, int unsigned len);
/* spi25.c */ @@ -52,12 +52,12 @@ int spi_block_erase_60(struct flashctx *flash, unsigned int addr, unsigned int b int spi_block_erase_62(struct flashctx *flash, unsigned int addr, unsigned int blocklen); int spi_block_erase_c7(struct flashctx *flash, unsigned int addr, unsigned int blocklen); erasefunc_t *spi_get_erasefn_from_opcode(uint8_t opcode); -int spi_chip_write_1(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); +int spi_chip_write_1(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); int spi_byte_program(struct flashctx *flash, unsigned int addr, uint8_t databyte); -int spi_nbyte_program(struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len); +int spi_nbyte_program(struct flashctx *flash, unsigned int addr, const uint8_t *bytes, unsigned int len); int spi_nbyte_read(struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len); int spi_read_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize); -int spi_write_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize); +int spi_write_chunked(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize);
/* spi25_statusreg.c */ uint8_t spi_read_status_register(struct flashctx *flash); @@ -97,14 +97,14 @@ int probe_spi_sfdp(struct flashctx *flash); /* opaque.c */ int probe_opaque(struct flashctx *flash); int read_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); -int write_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); +int write_opaque(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); int erase_opaque(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
/* 82802ab.c */ uint8_t wait_82802ab(struct flashctx *flash); int probe_82802ab(struct flashctx *flash); int erase_block_82802ab(struct flashctx *flash, unsigned int page, unsigned int pagesize); -int write_82802ab(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); +int write_82802ab(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); void print_status_82802ab(uint8_t status); int unlock_82802ab(struct flashctx *flash); int unlock_28f004s5(struct flashctx *flash); @@ -117,8 +117,8 @@ void data_polling_jedec(struct flashctx *flash, chipaddr dst, uint8_t data); int write_byte_program_jedec(struct flashctx *flash, chipaddr bios, uint8_t *src, chipaddr dst); int probe_jedec(struct flashctx *flash); -int write_jedec(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); -int write_jedec_1(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); +int write_jedec(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); +int write_jedec_1(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); int erase_sector_jedec(struct flashctx *flash, unsigned int page, unsigned int pagesize); int erase_block_jedec(struct flashctx *flash, unsigned int page, unsigned int blocksize); int erase_chip_block_jedec(struct flashctx *flash, unsigned int page, unsigned int blocksize); @@ -127,7 +127,7 @@ int erase_chip_block_jedec(struct flashctx *flash, unsigned int page, unsigned i int probe_m29f400bt(struct flashctx *flash); int block_erase_m29f400bt(struct flashctx *flash, unsigned int start, unsigned int len); int block_erase_chip_m29f400bt(struct flashctx *flash, unsigned int start, unsigned int len); -int write_m29f400bt(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); +int write_m29f400bt(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); void protect_m29f400bt(struct flashctx *flash, chipaddr bios);
/* pm49fl00x.c */ @@ -137,7 +137,7 @@ int lock_49fl00x(struct flashctx *flash); /* sst28sf040.c */ int erase_chip_28sf040(struct flashctx *flash, unsigned int addr, unsigned int blocklen); int erase_sector_28sf040(struct flashctx *flash, unsigned int address, unsigned int sector_size); -int write_28sf040(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); +int write_28sf040(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); int unprotect_28sf040(struct flashctx *flash); int protect_28sf040(struct flashctx *flash);
@@ -178,6 +178,6 @@ int unlock_stm50flw0x0x(struct flashctx *flash); int probe_en29lv640b(struct flashctx *flash); int block_erase_en29lv640b(struct flashctx *flash, unsigned int start, unsigned int len); int block_erase_chip_en29lv640b(struct flashctx *flash, unsigned int start, unsigned int len); -int write_en29lv640b(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); +int write_en29lv640b(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
#endif /* !__CHIPDRIVERS_H__ */ diff --git a/dummyflasher.c b/dummyflasher.c index 383ca58..5cb1c35 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -100,7 +100,7 @@ static int dummy_spi_send_command(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, uint8_t *buf, +static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr); @@ -108,7 +108,7 @@ static void dummy_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr); static void dummy_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr); -static void dummy_chip_writen(const struct flashctx *flash, uint8_t *buf, +static void dummy_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len); static uint8_t dummy_chip_readb(const struct flashctx *flash, const chipaddr addr); @@ -443,7 +443,7 @@ static void dummy_chip_writel(const struct flashctx *flash, uint32_t val, msg_pspew("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val); }
-static void dummy_chip_writen(const struct flashctx *flash, uint8_t *buf, +static void dummy_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len) { size_t i; @@ -846,7 +846,7 @@ static int dummy_spi_send_command(struct flashctx *flash, unsigned int writecnt, return 0; }
-static int dummy_spi_write_256(struct flashctx *flash, uint8_t *buf, +static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len) { return spi_write_chunked(flash, buf, start, len, diff --git a/en29lv640b.c b/en29lv640b.c index e79415a..eb53630 100644 --- a/en29lv640b.c +++ b/en29lv640b.c @@ -31,8 +31,8 @@ */
/* chunksize is 1 */ -int write_en29lv640b(struct flashctx *flash, uint8_t *src, unsigned int start, - unsigned int len) +int write_en29lv640b(struct flashctx *flash, const uint8_t *src, + unsigned int start, unsigned int len) { int i; chipaddr bios = flash->virtual_memory; diff --git a/flash.h b/flash.h index f73f12e..0181798 100644 --- a/flash.h +++ b/flash.h @@ -157,7 +157,7 @@ struct flashchip {
int (*printlock) (struct flashctx *flash); int (*unlock) (struct flashctx *flash); - int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); + int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); struct voltage { uint16_t min; @@ -209,7 +209,7 @@ extern const struct flashchip flashchips[]; void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr); void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr); void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr); -void chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len); +void chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len); uint8_t chip_readb(const struct flashctx *flash, const chipaddr addr); uint16_t chip_readw(const struct flashctx *flash, const chipaddr addr); uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr); @@ -234,8 +234,8 @@ int min(int a, int b); int max(int a, int b); void tolower_string(char *str); char *extract_param(const char *const *haystack, const char *needle, const char *delim); -int verify_range(struct flashctx *flash, uint8_t *cmpbuf, unsigned int start, unsigned int len); -int need_erase(uint8_t *have, uint8_t *want, unsigned int len, enum write_granularity gran); +int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len); +int need_erase(const uint8_t *have, const uint8_t *want, unsigned int len, enum write_granularity gran); char *strcat_realloc(char *dest, const char *src); void print_version(void); void print_buildinfo(void); @@ -244,7 +244,7 @@ void list_programmers_linebreak(int startcol, int cols, int paren); int selfcheck(void); int doit(struct flashctx *flash, int force, const char *filename, int read_it, int write_it, int erase_it, int verify_it); int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename); -int write_buf_to_file(unsigned char *buf, unsigned long size, const char *filename); +int write_buf_to_file(const unsigned char *buf, unsigned long size, const char *filename);
enum test_state { OK = 0, @@ -303,7 +303,7 @@ int print(enum msglevel level, const char *fmt, ...) __attribute__((format(print /* layout.c */ int register_include_arg(char *name); int process_include_args(void); -int read_romlayout(char *name); +int read_romlayout(const char *name); int handle_romentries(const struct flashctx *flash, uint8_t *oldcontents, uint8_t *newcontents);
/* spi.c */ diff --git a/flashrom.c b/flashrom.c index 6a117b2..b682923 100644 --- a/flashrom.c +++ b/flashrom.c @@ -443,7 +443,7 @@ void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr) flash->pgm->par.chip_writel(flash, val, addr); }
-void chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, +void chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len) { flash->pgm->par.chip_writen(flash, buf, addr, len); @@ -606,7 +606,7 @@ static unsigned int count_usable_erasers(const struct flashctx *flash) return usable_erasefunctions; }
-int compare_range(uint8_t *wantbuf, uint8_t *havebuf, unsigned int start, unsigned int len) +static int compare_range(const uint8_t *wantbuf, const uint8_t *havebuf, unsigned int start, unsigned int len) { int ret = 0, failcount = 0; unsigned int i; @@ -650,7 +650,7 @@ int check_erased_range(struct flashctx *flash, unsigned int start, * @len length of the verified area * @return 0 for success, -1 for failure */ -int verify_range(struct flashctx *flash, uint8_t *cmpbuf, unsigned int start, unsigned int len) +int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len) { uint8_t *readbuf = malloc(len); int ret = 0; @@ -702,7 +702,7 @@ out_free: * @gran write granularity (enum, not count) * @return 0 if no erase is needed, 1 otherwise */ -int need_erase(uint8_t *have, uint8_t *want, unsigned int len, enum write_granularity gran) +int need_erase(const uint8_t *have, const uint8_t *want, unsigned int len, enum write_granularity gran) { int result = 0; unsigned int i, j, limit; @@ -768,9 +768,9 @@ int need_erase(uint8_t *have, uint8_t *want, unsigned int len, enum write_granul * in relation to the max write length of the programmer and the max write * length of the chip. */ -static unsigned int get_next_write(uint8_t *have, uint8_t *want, unsigned int len, - unsigned int *first_start, - enum write_granularity gran) +static unsigned int get_next_write(const uint8_t *have, const uint8_t *want, unsigned int len, + unsigned int *first_start, + enum write_granularity gran) { int need_write = 0; unsigned int rel_start = 0, first_len = 0; @@ -1151,7 +1151,7 @@ int read_buf_from_file(unsigned char *buf, unsigned long size, return 0; }
-int write_buf_to_file(unsigned char *buf, unsigned long size, +int write_buf_to_file(const unsigned char *buf, unsigned long size, const char *filename) { unsigned long numbytes; @@ -1278,7 +1278,7 @@ static int selfcheck_eraseblocks(const struct flashchip *chip) static int erase_and_write_block_helper(struct flashctx *flash, unsigned int start, unsigned int len, uint8_t *curcontents, - uint8_t *newcontents, + const uint8_t *newcontents, int (*erasefn) (struct flashctx *flash, unsigned int addr, unsigned int len)) @@ -1330,12 +1330,12 @@ static int walk_eraseregions(struct flashctx *flash, int erasefunction, unsigned int addr, unsigned int len, uint8_t *param1, - uint8_t *param2, + const uint8_t *param2, int (*erasefn) ( struct flashctx *flash, unsigned int addr, unsigned int len)), - void *param1, void *param2) + void *param1, const void *param2) { int i, j; unsigned int start = 0; @@ -1389,8 +1389,8 @@ static int check_block_eraser(const struct flashctx *flash, int k, int log) return 0; }
-int erase_and_write_flash(struct flashctx *flash, uint8_t *oldcontents, - uint8_t *newcontents) +int erase_and_write_flash(struct flashctx *flash, const uint8_t *oldcontents, + const uint8_t *newcontents) { int k, ret = 1; uint8_t *curcontents; diff --git a/ichspi.c b/ichspi.c index 12f4584..72942f6 100644 --- a/ichspi.c +++ b/ichspi.c @@ -1319,7 +1319,7 @@ static int ich_hwseq_read(struct flashctx *flash, uint8_t *buf, return 0; }
-static int ich_hwseq_write(struct flashctx *flash, uint8_t *buf, +static int ich_hwseq_write(struct flashctx *flash, const uint8_t *buf, unsigned int addr, unsigned int len) { uint16_t hsfc; diff --git a/it87spi.c b/it87spi.c index 8e4e0ad..5320bc7 100644 --- a/it87spi.c +++ b/it87spi.c @@ -107,7 +107,7 @@ static int it8716f_spi_send_command(struct flashctx *flash, unsigned char *readarr); static int it8716f_spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); -static int it8716f_spi_chip_write_256(struct flashctx *flash, uint8_t *buf, +static int it8716f_spi_chip_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
static const struct spi_programmer spi_programmer_it87xx = { @@ -315,7 +315,7 @@ static int it8716f_spi_send_command(struct flashctx *flash, }
/* Page size is usually 256 bytes */ -static int it8716f_spi_page_program(struct flashctx *flash, uint8_t *buf, +static int it8716f_spi_page_program(struct flashctx *flash, const uint8_t *buf, unsigned int start) { unsigned int i; @@ -361,7 +361,7 @@ static int it8716f_spi_chip_read(struct flashctx *flash, uint8_t *buf, return 0; }
-static int it8716f_spi_chip_write_256(struct flashctx *flash, uint8_t *buf, +static int it8716f_spi_chip_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len) { const struct flashchip *chip = flash->chip; diff --git a/layout.c b/layout.c index 1bd3152..2bc7749 100644 --- a/layout.c +++ b/layout.c @@ -45,7 +45,7 @@ static int num_include_args = 0; /* the number of valid entries. */ static romlayout_t rom_entries[MAX_ROMLAYOUT];
#ifndef __LIBPAYLOAD__ -int read_romlayout(char *name) +int read_romlayout(const char *name) { FILE *romlayout; char tempstr[256]; @@ -101,7 +101,7 @@ int read_romlayout(char *name) #endif
/* returns the index of the entry (or a negative value if it is not found) */ -int find_include_arg(const char *const name) +static int find_include_arg(const char *const name) { unsigned int i; for (i = 0; i < num_include_args; i++) { diff --git a/linux_spi.c b/linux_spi.c index 2f46463..a09d06b 100644 --- a/linux_spi.c +++ b/linux_spi.c @@ -43,7 +43,7 @@ static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned char *rxbuf); static int linux_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); -static int linux_spi_write_256(struct flashctx *flash, uint8_t *buf, +static int linux_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
static const struct spi_programmer spi_programmer_linux = { @@ -174,7 +174,7 @@ static int linux_spi_read(struct flashctx *flash, uint8_t *buf, (unsigned int)getpagesize()); }
-static int linux_spi_write_256(struct flashctx *flash, uint8_t *buf, +static int linux_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len) { return spi_write_chunked(flash, buf, start, len, diff --git a/m29f400bt.c b/m29f400bt.c index 8f0329e..407caf7 100644 --- a/m29f400bt.c +++ b/m29f400bt.c @@ -28,8 +28,8 @@ functions. */
/* chunksize is 1 */ -int write_m29f400bt(struct flashctx *flash, uint8_t *src, unsigned int start, - unsigned int len) +int write_m29f400bt(struct flashctx *flash, const uint8_t *src, + unsigned int start, unsigned int len) { int i; chipaddr bios = flash->virtual_memory; diff --git a/opaque.c b/opaque.c index 6acaa63..c63919f 100644 --- a/opaque.c +++ b/opaque.c @@ -40,7 +40,7 @@ int read_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsign return flash->pgm->opaque.read(flash, buf, start, len); }
-int write_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) +int write_opaque(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len) { return flash->pgm->opaque.write(flash, buf, start, len); } diff --git a/programmer.c b/programmer.c index 3b4def0..ffa0d48 100644 --- a/programmer.c +++ b/programmer.c @@ -78,7 +78,7 @@ uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr) return val; }
-void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, +void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len) { size_t i; diff --git a/programmer.h b/programmer.h index b10f568..5ba5855 100644 --- a/programmer.h +++ b/programmer.h @@ -536,8 +536,8 @@ struct spi_programmer {
/* Optimized functions for this programmer */ int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); - int (*write_256)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); - int (*write_aai)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); + 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); const void *data; };
@@ -545,8 +545,8 @@ int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsi const unsigned char *writearr, unsigned char *readarr); int default_spi_send_multicommand(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, uint8_t *buf, unsigned int start, unsigned int len); -int default_spi_write_aai(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); int register_spi_programmer(const struct spi_programmer *programmer);
/* The following enum is needed by ich_descriptor_tool and ich* code. */ @@ -597,7 +597,7 @@ struct opaque_programmer { /* Specific functions for this programmer */ int (*probe) (struct flashctx *flash); int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); - int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); + int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen); const void *data; }; @@ -610,7 +610,7 @@ void fallback_unmap(void *virt_addr, size_t len); void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr); void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr); void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr); -void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len); +void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len); uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr); uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr); void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len); @@ -618,7 +618,7 @@ struct par_programmer { void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr); void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr); void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr); - void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len); + void (*chip_writen) (const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len); uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr); uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr); uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr); @@ -659,7 +659,7 @@ void __attribute__((noreturn)) sp_die(char *msg); extern fdtype sp_fd; /* expose serialport_shutdown as it's currently used by buspirate */ int serialport_shutdown(void *data); -int serialport_write(unsigned char *buf, unsigned int writecnt); +int serialport_write(const unsigned char *buf, unsigned int writecnt); int serialport_read(unsigned char *buf, unsigned int readcnt);
/* Serial port/pin mapping: diff --git a/serial.c b/serial.c index 9446ce3..d2a9a8e 100644 --- a/serial.c +++ b/serial.c @@ -255,7 +255,7 @@ int serialport_shutdown(void *data) return 0; }
-int serialport_write(unsigned char *buf, unsigned int writecnt) +int serialport_write(const unsigned char *buf, unsigned int writecnt) { #ifdef _WIN32 DWORD tmp = 0; diff --git a/spi.c b/spi.c index f670c8f..2b10eab 100644 --- a/spi.c +++ b/spi.c @@ -88,7 +88,7 @@ int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, return spi_read_chunked(flash, buf, start, len, max_data); }
-int default_spi_write_256(struct flashctx *flash, uint8_t *buf, +int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len) { unsigned int max_data = flash->pgm->spi.max_data_write; @@ -137,8 +137,8 @@ int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, * .write_256 = spi_chip_write_1 */ /* real chunksize is up to 256, logical chunksize is 256 */ -int spi_chip_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, - unsigned int len) +int spi_chip_write_256(struct flashctx *flash, const uint8_t *buf, + unsigned int start, unsigned int len) { return flash->pgm->spi.write_256(flash, buf, start, len); } @@ -164,7 +164,7 @@ uint32_t spi_get_valid_read_addr(struct flashctx *flash) } }
-int spi_aai_write(struct flashctx *flash, uint8_t *buf, +int spi_aai_write(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len) { return flash->pgm->spi.write_aai(flash, buf, start, len); diff --git a/spi25.c b/spi25.c index 3beab3a..06584bc 100644 --- a/spi25.c +++ b/spi25.c @@ -829,8 +829,8 @@ int spi_byte_program(struct flashctx *flash, unsigned int addr, return result; }
-int spi_nbyte_program(struct flashctx *flash, unsigned int addr, uint8_t *bytes, - unsigned int len) +int spi_nbyte_program(struct flashctx *flash, unsigned int addr, + const uint8_t *bytes, unsigned int len) { int result; uint8_t cmd[JEDEC_4_BYTE_PROGRAM_OUTSIZE - 1 + 512]; @@ -966,8 +966,9 @@ int spi_read_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, * FIXME: Use the chunk code from Michael Karcher instead. * Each page is written separately in chunks with a maximum size of chunksize. */ -int spi_write_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, - unsigned int len, unsigned int chunksize) +int spi_write_chunked(struct flashctx *flash, const uint8_t *buf, + unsigned int start, unsigned int len, + unsigned int chunksize) { int rc = 0; unsigned int pos, j, lenhere, towrite, page_end; @@ -1009,8 +1010,8 @@ int spi_write_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, * (e.g. due to size constraints in IT87* for over 512 kB) */ /* real chunksize is 1, logical chunksize is 1 */ -int spi_chip_write_1(struct flashctx *flash, uint8_t *buf, unsigned int start, - unsigned int len) +int spi_chip_write_1(struct flashctx *flash, const uint8_t *buf, + unsigned int start, unsigned int len) { unsigned int i; int result = 0; @@ -1026,7 +1027,8 @@ int spi_chip_write_1(struct flashctx *flash, uint8_t *buf, unsigned int start, return 0; }
-int default_spi_write_aai(struct flashctx *flash, 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) { uint32_t pos = start; int result; diff --git a/sst28sf040.c b/sst28sf040.c index 52e4256..3715b61 100644 --- a/sst28sf040.c +++ b/sst28sf040.c @@ -77,8 +77,8 @@ int erase_sector_28sf040(struct flashctx *flash, unsigned int address, }
/* chunksize is 1 */ -int write_28sf040(struct flashctx *flash, uint8_t *src, unsigned int start, - unsigned int len) +int write_28sf040(struct flashctx *flash, const uint8_t *src, + unsigned int start, unsigned int len) { int i; chipaddr bios = flash->virtual_memory;