Merge pull request #1989 from stefanrueger/warnings

Supress compiler warnings
This commit is contained in:
Stefan Rueger
2025-05-21 08:06:36 +02:00
committed by GitHub
4 changed files with 40 additions and 41 deletions

View File

@@ -84,8 +84,8 @@ static void butterfly_teardown(PROGRAMMER *pgm) {
pgm->cookie = NULL;
}
static int butterfly_send(const PROGRAMMER *pgm, char *buf, size_t len) {
return serial_send(&pgm->fd, (unsigned char *) buf, len);
static int butterfly_send(const PROGRAMMER *pgm, const char *buf, size_t len) {
return serial_send(&pgm->fd, (const unsigned char *) buf, len);
}
static int butterfly_recv(const PROGRAMMER *pgm, char *buf, size_t len) {
@@ -174,11 +174,11 @@ static int butterfly_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
*/
msg_notice("connecting to programmer: ");
if(pgm->flag & IS_BUTTERFLY_MK) {
char mk_reset_cmd[6] = { "#aR@S\r" };
const char * const mk_reset_cmd = "#aR@S\r";
unsigned char mk_timeout = 0;
msg_notice(".");
EI(butterfly_send(pgm, mk_reset_cmd, sizeof(mk_reset_cmd)));
EI(butterfly_send(pgm, mk_reset_cmd, strlen(mk_reset_cmd)));
usleep(20000);
do {

View File

@@ -253,7 +253,7 @@ static int ft245r_flush(const PROGRAMMER *pgm) {
len -= avail;
my.rx.pending += avail;
}
my.tx.len = 0;
return 0;
}
@@ -263,8 +263,10 @@ static int ft245r_send2(const PROGRAMMER *pgm, unsigned char *buf, size_t len, b
if(discard_rx_data)
++my.rx.discard;
my.tx.buf[my.tx.len++] = buf[i];
if(my.tx.len >= FT245R_MIN_FIFO_SIZE)
if(my.tx.len >= FT245R_MIN_FIFO_SIZE) {
ft245r_flush(pgm);
my.tx.len = 0;
}
}
}
return 0;
@@ -280,6 +282,7 @@ static int ft245r_send_and_discard(const PROGRAMMER *pgm, unsigned char *buf, si
static int ft245r_recv(const PROGRAMMER *pgm, unsigned char *buf, size_t len) {
ft245r_flush(pgm);
my.tx.len = 0;
ft245r_fill(pgm);
#if FT245R_DEBUG
@@ -289,9 +292,8 @@ static int ft245r_recv(const PROGRAMMER *pgm, unsigned char *buf, size_t len) {
while(my.rx.discard > 0) {
int result = ft245r_rx_buf_fill_and_get(pgm);
if(result < 0) {
if(result < 0)
return result;
}
--my.rx.discard;
}
@@ -299,17 +301,17 @@ static int ft245r_recv(const PROGRAMMER *pgm, unsigned char *buf, size_t len) {
for(size_t i = 0; i < len; ++i) {
int result = ft245r_rx_buf_fill_and_get(pgm);
if(result < 0) {
if(result < 0)
return result;
}
buf[i] = (uint8_t) result;
#if FT245R_BITBANG_VARIABLE_PULSE_WIDTH_WORKAROUND
for(int j = 1; j < baud_multiplier; ++j) {
result = ft245r_rx_buf_fill_and_get(pgm);
if(result < 0) {
if(result < 0)
return result;
}
}
#endif
}
return 0;
}
@@ -333,6 +335,7 @@ static int ft245r_drain(const PROGRAMMER *pgm, int display) {
// Ensure any pending writes are sent to the FTDI chip before sleeping
static void ft245r_usleep(const PROGRAMMER *pgm, useconds_t usec) {
ft245r_flush(pgm);
my.tx.len = 0;
usleep(usec);
}
@@ -388,6 +391,7 @@ static int get_pin(const PROGRAMMER *pgm, int pinname) {
uint8_t byte;
ft245r_flush(pgm);
my.tx.len = 0;
if(ftdi_read_pins(my.handle, &byte) != 0)
return -1;
@@ -629,9 +633,8 @@ static inline unsigned char extract_data(const PROGRAMMER *pgm, unsigned char *b
buf += offset*(8*FT245R_CYCLES);
for(j = 0; j < 8; j++) {
if(GET_BITS_0(buf[buf_pos], pgm, PIN_AVR_SDI)) {
if(GET_BITS_0(buf[buf_pos], pgm, PIN_AVR_SDI))
r |= bit;
}
buf_pos += FT245R_CYCLES;
bit >>= 1;
}
@@ -649,9 +652,8 @@ static inline unsigned char extract_data_out(const PROGRAMMER *pgm, unsigned cha
buf += offset*(8*FT245R_CYCLES);
for(j = 0; j < 8; j++) {
if(GET_BITS_0(buf[buf_pos], pgm, PIN_AVR_SDO)) {
if(GET_BITS_0(buf[buf_pos], pgm, PIN_AVR_SDO))
r |= bit;
}
buf_pos += FT245R_CYCLES;
bit >>= 1;
}
@@ -668,9 +670,8 @@ static int ft245r_cmd(const PROGRAMMER *pgm, const unsigned char *cmd, unsigned
unsigned char buf[128];
buf_pos = 0;
for(i = 0; i < 4; i++) {
for(i = 0; i < 4; i++)
buf_pos += set_data(pgm, buf + buf_pos, cmd[i]);
}
buf[buf_pos] = 0;
buf_pos++;
@@ -836,9 +837,8 @@ static int ft245r_open(PROGRAMMER *pgm, const char *port) {
char *endptr = NULL;
devnum = strtol(startptr, &endptr, 10);
if((startptr == endptr) || (*endptr != '\0')) {
if((startptr == endptr) || (*endptr != '\0'))
devnum = -1;
}
pmsg_notice2("%s(): device number parsed as: %d\n", __func__, devnum);
}
}
@@ -904,9 +904,8 @@ static int ft245r_open(PROGRAMMER *pgm, const char *port) {
}
rv = ft245r_set_bitclock(pgm);
if(rv) {
if(rv)
goto cleanup;
}
// Drain any extraneous input
ft245r_drain(pgm, 0);
@@ -993,9 +992,8 @@ static int do_request(const PROGRAMMER *pgm, const AVRMEM *m) {
my.req_pool = p;
ft245r_recv(pgm, buf, bytes);
for(j = 0; j < n; j++) {
for(j = 0; j < n; j++)
m->buf[addr++] = extract_data(pgm, buf, (j*4 + 3));
}
return 1;
}

View File

@@ -166,18 +166,18 @@ static const struct {
};
# define _ok(c) ((c) && (uint8_t) (c) <= 0x7f)
#define _ok(c) ((c) > 0 && (c) < 0x7f)
// Is s a ^[0-9]+k[0-9]+$ pattern for baud rate?
static int is_baudrate_k(const char *s) {
int pre=0, post=0;
while(_ok(*s) && isdigit(*s))
while(_ok(*s) && isdigit((int) *s))
pre++, s++;
if(*s != 'k')
return 0;
s++;
while(_ok(*s) && isdigit(*s))
while(_ok(*s) && isdigit((int) *s))
post++, s++;
return !*s && pre && post;
}
@@ -217,12 +217,12 @@ static int is_fcpu_m(const char *s) {
if(is_fcpu_type(*s))
s++;
while(_ok(*s) && isdigit(*s))
while(_ok(*s) && isdigit((int) *s))
pre++, s++;
if(*s != 'm')
return 0;
s++;
while(_ok(*s) && isdigit(*s))
while(_ok(*s) && isdigit((int) *s))
post++, s++;
return !*s && pre && post;
}
@@ -239,11 +239,11 @@ static int is_num_unit(const char *s, const char *unit) {
while(*s == '+') // Ignore leading + (used as fillers for sorting)
s++;
while(_ok(*s) && isdigit(*s))
while(_ok(*s) && isdigit((int) *s))
pre++, s++;
if(*s == '.')
s++;
while(_ok(*s) && isdigit(*s))
while(_ok(*s) && isdigit((int) *s))
post++, s++;
if(!pre && !post)
return 0;
@@ -252,12 +252,12 @@ static int is_num_unit(const char *s, const char *unit) {
s++;
if(*s == '-' || *s == '+')
s++;
while(_ok(*s) && isdigit(*s))
while(_ok(*s) && isdigit((int) *s))
ee++, s++;
if(!ee)
return 0;
}
while(_ok(*s) && isspace(*s))
while(_ok(*s) && isspace((int) *s))
s++;
size_t ulen = strlen(unit);

View File

@@ -9,8 +9,8 @@
* Published under GNU General Public License, version 3 (GPL-3.0)
* Meta-author Stefan Rueger <stefan.rueger@urclocks.com>
*
* v 1.2
* 29.04.2025
* v 1.21
* 18.05.2025
*
*/
@@ -260398,7 +260398,7 @@ static uint16_t *ul_urtemplate(const uint64_t *bl) {
hn = 0;
}
// Move 1 bit from Huffman bootloader bit string to a single Huffman code variable
hc = (hc<<1) | (h64 & 1), hcn++;
hc = ((uint64_t) hc << 1) | (h64 & 1), hcn++;
h64 >>= 1, hn++;
if(hcn > 27) {
pmsg_error("unexpected problem decoding bootloader code");
@@ -260519,7 +260519,7 @@ static int blcmp(const void *v1, const void *v2) {
}
int urbootexists(const char *mcu, const char *io, const char *blt, int req_feats) {
size_t m, i, b, c;
int m, i, b, c;
for(m=0; m<UL_MCU_N; m++)
if(str_eq(mcus[m], mcu))
@@ -260553,7 +260553,7 @@ int urbootexists(const char *mcu, const char *io, const char *blt, int req_feats
Urboot_template **urboottemplate(const Avrintel *up, const char *mcu, const char *io, const char *blt,
int req_feats, int req_ulevel, int showall, int *np) {
size_t m, i, b, c, req_c, n = -1U;
int m, i, b;
Urboot_template **ret = NULL;
for(m=0; m<UL_MCU_N; m++)
@@ -260576,14 +260576,14 @@ Urboot_template **urboottemplate(const Avrintel *up, const char *mcu, const char
if(req_feats < 0 || req_feats >= (int) (sizeof urfeat/sizeof*urfeat))
Return("unexpected feature request");
req_c = urfeat[req_feats];
int req_c = urfeat[req_feats];
// Specific feature set chosen? Then only one bootloader needs decoding and requesting
int spec = !showall && (req_ulevel == 0 || req_ulevel == 4) ;
ret = mmt_malloc(sizeof *ret * UL_CONFIG_N);
*np = 0;
for(c = 0; c < UL_CONFIG_N; c++) {
for(int c = 0; c < UL_CONFIG_N; c++) {
if(!spec || c == req_c) {
const char *cfg = configs[c];
@@ -260608,7 +260608,8 @@ Urboot_template **urboottemplate(const Avrintel *up, const char *mcu, const char
goto error;
ret[*np] = mmt_malloc(sizeof **ret);
ret[n = (*np)++]->tofree = ut;
int n = (*np)++;
ret[n]->tofree = ut;
int size = ut[0]; // Bootloader size including 6-byte-table in top flash
int usage = ut[1]; // Flash usage, ie, boot section size or multiple of flash pages