Change Segment_t * to const Segment_t * where appropriate

This commit is contained in:
Stefan Rueger
2023-06-11 11:40:13 +01:00
parent dbbed4d115
commit 4ab9bda302
2 changed files with 28 additions and 16 deletions

View File

@@ -176,7 +176,7 @@ static void print_ihex_extended_addr(int n_64k, FILE *outf) {
* Return the maximum memory address within mem->buf that was read from
* plus one. If an error occurs, return -1.
*/
static int b2ihex(const unsigned char *buf, Segment_t *segp, Segorder_t where,
static int b2ihex(const unsigned char *buf, const Segment_t *segp, Segorder_t where,
int recsize, int startaddr, const char *outfile_unused, FILE *outf,
FILEFMT ffmt) {
@@ -339,7 +339,7 @@ static int ihex_readrec(struct ihexsrec *ihex, char * rec) {
* plus one. If an error occurs, return -1.
*/
static int ihex2b(const char *infile, FILE *inf, const AVRMEM *mem,
Segment_t *segp, unsigned int fileoffset, FILEFMT ffmt) {
const Segment_t *segp, unsigned int fileoffset, FILEFMT ffmt) {
const char *errstr;
unsigned int nextaddr, baseaddr, maxaddr;
@@ -458,7 +458,7 @@ static unsigned int cksum_srec(const unsigned char *buf, int n, unsigned addr, i
// Binary to Motorola S-Record, see https://en.wikipedia.org/wiki/SREC_(file_format)
static int b2srec(const AVRMEM *mem, Segment_t *segp, Segorder_t where,
static int b2srec(const AVRMEM *mem, const Segment_t *segp, Segorder_t where,
int recsize, int startaddr, const char *outfile_unused, FILE *outf) {
const unsigned char *buf;
@@ -609,7 +609,7 @@ static int srec_readrec(struct ihexsrec *srec, char *rec) {
// Motorola S-Record to binary
static int srec2b(const char *infile, FILE * inf,
const AVRMEM *mem, Segment_t *segp, unsigned int fileoffset) {
const AVRMEM *mem, const Segment_t *segp, unsigned int fileoffset) {
const char *errstr;
unsigned int nextaddr, maxaddr;
@@ -823,7 +823,7 @@ static int elf_mem_limits(const AVRMEM *mem, const AVRPART *p,
// ELF format to binary (the memory segment to read into is ignored)
static int elf2b(const char *infile, FILE *inf, const AVRMEM *mem,
const AVRPART *p, Segment_t *segp_unused, unsigned int fileoffset_unused) {
const AVRPART *p, const Segment_t *segp_unused, unsigned int fileoffset_unused) {
Elf *e;
int rv = 0, size = 0;
@@ -1033,7 +1033,7 @@ done:
// Read/write binary files and return highest memory addr set + 1
static int fileio_rbin(struct fioparms *fio, const char *filename, FILE *f,
const AVRMEM *mem, Segment_t *segp) {
const AVRMEM *mem, const Segment_t *segp) {
int rc;
switch (fio->op) {
@@ -1061,7 +1061,7 @@ static int fileio_rbin(struct fioparms *fio, const char *filename, FILE *f,
static int fileio_imm(struct fioparms *fio, const char *fname, FILE *f_unused,
const AVRMEM *mem, Segment_t *segp) {
const AVRMEM *mem, const Segment_t *segp) {
char *tok, *p, *line;
const char *errstr;
@@ -1100,7 +1100,7 @@ static int fileio_imm(struct fioparms *fio, const char *fname, FILE *f_unused,
static int fileio_ihex(struct fioparms *fio, const char *filename, FILE *f,
const AVRMEM *mem, Segment_t *segp, FILEFMT ffmt, Segorder_t where) {
const AVRMEM *mem, const Segment_t *segp, FILEFMT ffmt, Segorder_t where) {
int rc;
@@ -1123,7 +1123,7 @@ static int fileio_ihex(struct fioparms *fio, const char *filename, FILE *f,
static int fileio_srec(struct fioparms *fio, const char *filename, FILE *f,
const AVRMEM *mem, Segment_t *segp, Segorder_t where) {
const AVRMEM *mem, const Segment_t *segp, Segorder_t where) {
int rc;
@@ -1147,7 +1147,7 @@ static int fileio_srec(struct fioparms *fio, const char *filename, FILE *f,
#ifdef HAVE_LIBELF
static int fileio_elf(struct fioparms *fio, const char *filename, FILE *f,
const AVRMEM *mem, const AVRPART *p, Segment_t *segp) {
const AVRMEM *mem, const AVRPART *p, const Segment_t *segp) {
int rc;
@@ -1171,7 +1171,7 @@ static int fileio_elf(struct fioparms *fio, const char *filename, FILE *f,
#endif
static int b2num(const char *filename, FILE *f, const AVRMEM *mem, Segment_t *segp, FILEFMT fmt) {
static int b2num(const char *filename, FILE *f, const AVRMEM *mem, const Segment_t *segp, FILEFMT fmt) {
const char *prefix;
int base;
@@ -1235,7 +1235,7 @@ static int b2num(const char *filename, FILE *f, const AVRMEM *mem, Segment_t *se
}
static int num2b(const char *filename, FILE *f, const AVRMEM *mem, Segment_t *segp) {
static int num2b(const char *filename, FILE *f, const AVRMEM *mem, const Segment_t *segp) {
const char *geterr = NULL;
char *line;
int n = segp->addr, end = segp->addr + segp->len;
@@ -1271,7 +1271,7 @@ static int num2b(const char *filename, FILE *f, const AVRMEM *mem, Segment_t *se
static int fileio_num(struct fioparms *fio, const char *filename, FILE *f,
const AVRMEM *mem, Segment_t *segp, FILEFMT fmt) {
const AVRMEM *mem, const Segment_t *segp, FILEFMT fmt) {
switch (fio->op) {
case FIO_WRITE:
@@ -1443,7 +1443,7 @@ int fileio(int op, const char *filename, FILEFMT format,
if(size < 0 || op == FIO_READ || FIO_READ_FOR_VERIFY)
size = mem->size;
Segment_t seg = {0, size};
const Segment_t seg = {0, size};
return fileio_segments(op, filename, format, p, mem, 1, &seg);
}
@@ -1478,7 +1478,7 @@ int segmemt_normalise(AVRMEM *mem, Segment_t *segp) {
}
int fileio_segments(int oprwv, const char *filename, FILEFMT format,
static int fileio_segments_normalise(int oprwv, const char *filename, FILEFMT format,
const AVRPART *p, AVRMEM *mem, int n, Segment_t *seglist) {
int op, rc;
@@ -1628,3 +1628,15 @@ int fileio_segments(int oprwv, const char *filename, FILEFMT format,
return rc;
}
int fileio_segments(int oprwv, const char *filename, FILEFMT format,
const AVRPART *p, AVRMEM *mem, int n, const Segment_t *list) {
Segment_t *seglist = cfg_malloc(__func__, n*sizeof*seglist);
memcpy(seglist, list, n*sizeof*seglist);
int ret = fileio_segments_normalise(oprwv, filename, format, p, mem, n, seglist);
free(seglist);
return ret;
}

View File

@@ -1039,7 +1039,7 @@ int fileio(int oprwv, const char *filename, FILEFMT format,
int segmemt_normalise(AVRMEM *mem, Segment_t *segp);
int fileio_segments(int oprwv, const char *filename, FILEFMT format,
const AVRPART *p, AVRMEM *mem, int n, Segment_t *seglist);
const AVRPART *p, AVRMEM *mem, int n, const Segment_t *seglist);
#ifdef __cplusplus
}