Replace all occurences of exit() in potential library code

by appropriate return values.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1301 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
joerg_wunsch 2014-05-16 15:52:25 +00:00
parent a74dbff9a4
commit 8113ad8a87
26 changed files with 257 additions and 166 deletions

View File

@ -1,3 +1,32 @@
2014-05-16 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
* avr910.c: Replace all occurences of exit() in potential library
functions by appropriate return values
* avrftdi.c: (Dito.)
* bitbang.c: (Dito.)
* bitbang.h: (Dito.)
* buspirate.c: (Dito.)
* butterfly.c: (Dito.)
* config.c: (Dito.)
* flip2.c: (Dito.)
* ft245r.c: (Dito.)
* jtagmkI.c: (Dito.)
* jtagmkII.c: (Dito.)
* linuxgpio.c: (Dito.)
* main.c: (Dito.)
* par.c: (Dito.)
* pgm.c: (Dito.)
* pickit2.c: (Dito.)
* pindefs.c: (Dito.)
* pindefs.h: (Dito.)
* ser_avrdoper.c: (Dito.)
* ser_posix.c: (Dito.)
* ser_win32.c: (Dito.)
* serbb_posix.c: (Dito.)
* serbb_win32.c: (Dito.)
* stk500.c: (Dito.)
* stk500v2.c: (Dito.)
2014-05-07 Rene Liebscher <R.Liebscher@gmx.de> 2014-05-07 Rene Liebscher <R.Liebscher@gmx.de>
bug #42310: New part description for AT90PWM216 bug #42310: New part description for AT90PWM216

View File

@ -89,7 +89,7 @@ static int avr910_recv(PROGRAMMER * pgm, char * buf, size_t len)
fprintf(stderr, fprintf(stderr,
"%s: avr910_recv(): programmer is not responding\n", "%s: avr910_recv(): programmer is not responding\n",
progname); progname);
exit(1); return 1;
} }
return 0; return 0;
} }
@ -101,7 +101,7 @@ static int avr910_drain(PROGRAMMER * pgm, int display)
} }
static void avr910_vfy_cmd_sent(PROGRAMMER * pgm, char * errmsg) static int avr910_vfy_cmd_sent(PROGRAMMER * pgm, char * errmsg)
{ {
char c; char c;
@ -109,8 +109,9 @@ static void avr910_vfy_cmd_sent(PROGRAMMER * pgm, char * errmsg)
if (c != '\r') { if (c != '\r') {
fprintf(stderr, "%s: error: programmer did not respond to command: %s\n", fprintf(stderr, "%s: error: programmer did not respond to command: %s\n",
progname, errmsg); progname, errmsg);
exit(1); return 1;
} }
return 0;
} }
@ -120,7 +121,8 @@ static void avr910_vfy_cmd_sent(PROGRAMMER * pgm, char * errmsg)
static int avr910_chip_erase(PROGRAMMER * pgm, AVRPART * p) static int avr910_chip_erase(PROGRAMMER * pgm, AVRPART * p)
{ {
avr910_send(pgm, "e", 1); avr910_send(pgm, "e", 1);
avr910_vfy_cmd_sent(pgm, "chip erase"); if (avr910_vfy_cmd_sent(pgm, "chip erase") < 0)
return -1;
/* /*
* avr910 firmware may not delay long enough * avr910 firmware may not delay long enough
@ -131,17 +133,17 @@ static int avr910_chip_erase(PROGRAMMER * pgm, AVRPART * p)
} }
static void avr910_enter_prog_mode(PROGRAMMER * pgm) static int avr910_enter_prog_mode(PROGRAMMER * pgm)
{ {
avr910_send(pgm, "P", 1); avr910_send(pgm, "P", 1);
avr910_vfy_cmd_sent(pgm, "enter prog mode"); return avr910_vfy_cmd_sent(pgm, "enter prog mode");
} }
static void avr910_leave_prog_mode(PROGRAMMER * pgm) static int avr910_leave_prog_mode(PROGRAMMER * pgm)
{ {
avr910_send(pgm, "L", 1); avr910_send(pgm, "L", 1);
avr910_vfy_cmd_sent(pgm, "leave prog mode"); return avr910_vfy_cmd_sent(pgm, "leave prog mode");
} }
@ -251,7 +253,7 @@ static int avr910_initialize(PROGRAMMER * pgm, AVRPART * p)
"%s: %s: selected device is not supported by programmer: %s\n", "%s: %s: selected device is not supported by programmer: %s\n",
progname, ovsigck? "warning": "error", p->id); progname, ovsigck? "warning": "error", p->id);
if (!ovsigck) if (!ovsigck)
exit(1); return -1;
} }
/* If the user forced the selection, use the first device /* If the user forced the selection, use the first device
type that is supported by the programmer. */ type that is supported by the programmer. */

View File

@ -1210,7 +1210,7 @@ avrftdi_setup(PROGRAMMER * pgm)
if(!pdata->ftdic) if(!pdata->ftdic)
{ {
log_err("Error allocating memory.\n"); log_err("Error allocating memory.\n");
exit(-ENOMEM); exit(1);
} }
E_VOID(ftdi_init(pdata->ftdic), pdata->ftdic); E_VOID(ftdi_init(pdata->ftdic), pdata->ftdic);

View File

@ -40,6 +40,7 @@
#include "par.h" #include "par.h"
#include "serbb.h" #include "serbb.h"
#include "tpi.h" #include "tpi.h"
#include "bitbang.h"
static int delay_decrement; static int delay_decrement;
@ -140,7 +141,7 @@ static void bitbang_calibrate_delay(void)
* usleep()'s granularity is usually like 1 ms or 10 ms, so it's not * usleep()'s granularity is usually like 1 ms or 10 ms, so it's not
* really suitable for short delays in bit-bang algorithms. * really suitable for short delays in bit-bang algorithms.
*/ */
void bitbang_delay(int us) void bitbang_delay(unsigned int us)
{ {
#if defined(WIN32NATIVE) #if defined(WIN32NATIVE)
LARGE_INTEGER countNow, countEnd; LARGE_INTEGER countNow, countEnd;
@ -156,7 +157,7 @@ void bitbang_delay(int us)
else /* no performance counters -- run normal uncalibrated delay */ else /* no performance counters -- run normal uncalibrated delay */
{ {
#endif /* WIN32NATIVE */ #endif /* WIN32NATIVE */
volatile int del = us * delay_decrement; volatile unsigned int del = us * delay_decrement;
while (del > 0) while (del > 0)
del--; del--;
@ -630,30 +631,36 @@ int bitbang_initialize(PROGRAMMER * pgm, AVRPART * p)
return 0; return 0;
} }
static void verify_pin_assigned(PROGRAMMER * pgm, int pin, char * desc) static int verify_pin_assigned(PROGRAMMER * pgm, int pin, char * desc)
{ {
if (pgm->pinno[pin] == 0) { if (pgm->pinno[pin] == 0) {
fprintf(stderr, "%s: error: no pin has been assigned for %s\n", fprintf(stderr, "%s: error: no pin has been assigned for %s\n",
progname, desc); progname, desc);
exit(1); return -1;
} }
return 0;
} }
/* /*
* Verify all prerequisites for a bit-bang programmer are present. * Verify all prerequisites for a bit-bang programmer are present.
*/ */
void bitbang_check_prerequisites(PROGRAMMER *pgm) int bitbang_check_prerequisites(PROGRAMMER *pgm)
{ {
verify_pin_assigned(pgm, PIN_AVR_RESET, "AVR RESET"); if (verify_pin_assigned(pgm, PIN_AVR_RESET, "AVR RESET") < 0)
verify_pin_assigned(pgm, PIN_AVR_SCK, "AVR SCK"); return -1;
verify_pin_assigned(pgm, PIN_AVR_MISO, "AVR MISO"); if (verify_pin_assigned(pgm, PIN_AVR_SCK, "AVR SCK") < 0)
verify_pin_assigned(pgm, PIN_AVR_MOSI, "AVR MOSI"); return -1;
if (verify_pin_assigned(pgm, PIN_AVR_MISO, "AVR MISO") < 0)
return -1;
if (verify_pin_assigned(pgm, PIN_AVR_MOSI, "AVR MOSI") < 0)
return -1;
if (pgm->cmd == NULL) { if (pgm->cmd == NULL) {
fprintf(stderr, "%s: error: no cmd() method defined for bitbang programmer\n", fprintf(stderr, "%s: error: no cmd() method defined for bitbang programmer\n",
progname); progname);
exit(1); return -1;
} }
return 0;
} }

View File

@ -31,7 +31,7 @@ int bitbang_getpin(int fd, int pin);
int bitbang_highpulsepin(int fd, int pin); int bitbang_highpulsepin(int fd, int pin);
void bitbang_delay(unsigned int us); void bitbang_delay(unsigned int us);
void bitbang_check_prerequisites(PROGRAMMER *pgm); int bitbang_check_prerequisites(PROGRAMMER *pgm);
int bitbang_rdy_led (PROGRAMMER * pgm, int value); int bitbang_rdy_led (PROGRAMMER * pgm, int value);
int bitbang_err_led (PROGRAMMER * pgm, int value); int bitbang_err_led (PROGRAMMER * pgm, int value);

View File

@ -145,7 +145,7 @@ static int buspirate_expect_bin(struct programmer_t *pgm,
char *recv_buf = alloca(expect_len); char *recv_buf = alloca(expect_len);
if (!pgm->flag & BP_FLAG_IN_BINMODE) { if (!pgm->flag & BP_FLAG_IN_BINMODE) {
fprintf(stderr, "BusPirate: Internal error: buspirate_send_bin() called from ascii mode"); fprintf(stderr, "BusPirate: Internal error: buspirate_send_bin() called from ascii mode");
exit(1); return -1;
} }
buspirate_send_bin(pgm, send_data, send_len); buspirate_send_bin(pgm, send_data, send_len);
@ -170,7 +170,7 @@ static int buspirate_getc(struct programmer_t *pgm)
if (pgm->flag & BP_FLAG_IN_BINMODE) { if (pgm->flag & BP_FLAG_IN_BINMODE) {
fprintf(stderr, "BusPirate: Internal error: buspirate_getc() called from binmode"); fprintf(stderr, "BusPirate: Internal error: buspirate_getc() called from binmode");
exit(1); return EOF;
} }
rc = serial_recv(&pgm->fd, &ch, 1); rc = serial_recv(&pgm->fd, &ch, 1);
@ -226,7 +226,7 @@ static char *buspirate_readline(struct programmer_t *pgm, char *buf, size_t len)
fprintf(stderr, fprintf(stderr,
"%s: buspirate_readline(): programmer is not responding\n", "%s: buspirate_readline(): programmer is not responding\n",
progname); progname);
exit(1); return NULL;
} }
return ret; return ret;
} }
@ -239,7 +239,7 @@ static int buspirate_send(struct programmer_t *pgm, char *str)
if (pgm->flag & BP_FLAG_IN_BINMODE) { if (pgm->flag & BP_FLAG_IN_BINMODE) {
fprintf(stderr, "BusPirate: Internal error: buspirate_send() called from binmode"); fprintf(stderr, "BusPirate: Internal error: buspirate_send() called from binmode");
exit(1); return -1;
} }
rc = serial_send(&pgm->fd, (unsigned char *)str, strlen(str)); rc = serial_send(&pgm->fd, (unsigned char *)str, strlen(str));
@ -466,7 +466,7 @@ static void buspirate_reset_from_binmode(struct programmer_t *pgm)
if (pgm->flag & BP_FLAG_IN_BINMODE) { if (pgm->flag & BP_FLAG_IN_BINMODE) {
fprintf(stderr, "BusPirate reset failed. You may need to powercycle it.\n"); fprintf(stderr, "BusPirate reset failed. You may need to powercycle it.\n");
exit(1); return;
} }
if (verbose) if (verbose)
@ -574,14 +574,17 @@ static int buspirate_start_mode_bin(struct programmer_t *pgm)
/* 0b0100wxyz - Configure peripherals w=power, x=pull-ups/aux2, y=AUX, z=CS /* 0b0100wxyz - Configure peripherals w=power, x=pull-ups/aux2, y=AUX, z=CS
* we want power (0x48) and all reset pins high. */ * we want power (0x48) and all reset pins high. */
PDATA(pgm)->current_peripherals_config = 0x48 | PDATA(pgm)->reset; PDATA(pgm)->current_peripherals_config = 0x48 | PDATA(pgm)->reset;
buspirate_expect_bin_byte(pgm, PDATA(pgm)->current_peripherals_config, 0x01); if (buspirate_expect_bin_byte(pgm, PDATA(pgm)->current_peripherals_config, 0x01) < 0)
return -1;
usleep(50000); // sleep for 50ms after power up usleep(50000); // sleep for 50ms after power up
/* 01100xxx - Set speed */ /* 01100xxx - Set speed */
buspirate_expect_bin_byte(pgm, 0x60 | PDATA(pgm)->spifreq, 0x01); if (buspirate_expect_bin_byte(pgm, 0x60 | PDATA(pgm)->spifreq, 0x01) < 0)
return -1;
/* Submode config */ /* Submode config */
buspirate_expect_bin_byte(pgm, submode->config, 0x01); if (buspirate_expect_bin_byte(pgm, submode->config, 0x01) < 0)
return -1;
/* AVR Extended Commands - test for existence */ /* AVR Extended Commands - test for existence */
if (pgm->flag & BP_FLAG_NOPAGEDREAD) { if (pgm->flag & BP_FLAG_NOPAGEDREAD) {
@ -589,7 +592,10 @@ static int buspirate_start_mode_bin(struct programmer_t *pgm)
fprintf(stderr, "%s: Paged flash read disabled.\n", progname); fprintf(stderr, "%s: Paged flash read disabled.\n", progname);
pgm->paged_load = NULL; pgm->paged_load = NULL;
} else { } else {
if (buspirate_expect_bin_byte(pgm, 0x06, 0x01)) { int rv = buspirate_expect_bin_byte(pgm, 0x06, 0x01);
if (rv < 0)
return -1;
if (rv) {
strncpy(buf, "\x1\x0\x0", 3); strncpy(buf, "\x1\x0\x0", 3);
buspirate_send_bin(pgm, buf, 1); buspirate_send_bin(pgm, buf, 1);
buspirate_recv_bin(pgm, buf, 3); buspirate_recv_bin(pgm, buf, 3);
@ -666,7 +672,7 @@ static void buspirate_enable(struct programmer_t *pgm)
/* Ensure configuration is self-consistant: */ /* Ensure configuration is self-consistant: */
if (buspirate_verifyconfig(pgm)<0) if (buspirate_verifyconfig(pgm)<0)
exit(1); return; /* XXX should handle error */
/* Attempt to start binary SPI mode unless explicitly told otherwise: */ /* Attempt to start binary SPI mode unless explicitly told otherwise: */
if (!buspirate_uses_ascii(pgm)) { if (!buspirate_uses_ascii(pgm)) {
@ -692,14 +698,14 @@ static void buspirate_enable(struct programmer_t *pgm)
rc = buspirate_send_bin(pgm, reset_str, strlen(reset_str)); rc = buspirate_send_bin(pgm, reset_str, strlen(reset_str));
if (rc) { if (rc) {
fprintf(stderr, "BusPirate is not responding. Serial port error: %d\n", rc); fprintf(stderr, "BusPirate is not responding. Serial port error: %d\n", rc);
exit(1); return;
} }
while(1) { while(1) {
rcvd = buspirate_readline_noexit(pgm, NULL, 0); rcvd = buspirate_readline_noexit(pgm, NULL, 0);
if (! rcvd) { if (! rcvd) {
fprintf(stderr, "%s: Fatal: Programmer is not responding.\n", progname); fprintf(stderr, "%s: Fatal: Programmer is not responding.\n", progname);
exit(1); return;
} }
if (strncmp(rcvd, "Are you sure?", 13) == 0) { if (strncmp(rcvd, "Are you sure?", 13) == 0) {
buspirate_send_bin(pgm, accept_str, strlen(accept_str)); buspirate_send_bin(pgm, accept_str, strlen(accept_str));
@ -720,7 +726,7 @@ static void buspirate_enable(struct programmer_t *pgm)
fprintf(stderr, "BusPirate: using ASCII mode\n"); fprintf(stderr, "BusPirate: using ASCII mode\n");
if (buspirate_start_spi_mode_ascii(pgm) < 0) { if (buspirate_start_spi_mode_ascii(pgm) < 0) {
fprintf(stderr, "%s: Failed to start ascii SPI mode\n", progname); fprintf(stderr, "%s: Failed to start ascii SPI mode\n", progname);
exit(1); return;
} }
} }
} }
@ -797,7 +803,10 @@ static int buspirate_cmd_bin(struct programmer_t *pgm,
{ {
/* 0001xxxx - Bulk transfer, send/read 1-16 bytes (0=1byte!) /* 0001xxxx - Bulk transfer, send/read 1-16 bytes (0=1byte!)
* we are sending 4 bytes -> 0x13 */ * we are sending 4 bytes -> 0x13 */
if (!buspirate_expect_bin_byte(pgm, 0x13, 0x01)) int rv = buspirate_expect_bin_byte(pgm, 0x13, 0x01);
if (rv < 0)
return -1;
if (rv == 0)
return -1; return -1;
buspirate_send_bin(pgm, (char *)cmd, 4); buspirate_send_bin(pgm, (char *)cmd, 4);
@ -1013,7 +1022,7 @@ static int buspirate_paged_write(struct programmer_t *pgm,
fprintf(stderr, "BusPirate: Fatal error: Write Then Read did not succeed.\n"); fprintf(stderr, "BusPirate: Fatal error: Write Then Read did not succeed.\n");
pgm->pgm_led(pgm, OFF); pgm->pgm_led(pgm, OFF);
pgm->err_led(pgm, ON); pgm->err_led(pgm, ON);
exit(1); return -1;
} }
/* Unset programming LED: */ /* Unset programming LED: */
@ -1034,7 +1043,8 @@ static int buspirate_program_enable(struct programmer_t *pgm, AVRPART * p)
if (pgm->flag & BP_FLAG_IN_BINMODE) { if (pgm->flag & BP_FLAG_IN_BINMODE) {
/* Clear configured reset pin(s): CS and/or AUX and/or AUX2 */ /* Clear configured reset pin(s): CS and/or AUX and/or AUX2 */
PDATA(pgm)->current_peripherals_config &= ~PDATA(pgm)->reset; PDATA(pgm)->current_peripherals_config &= ~PDATA(pgm)->reset;
buspirate_expect_bin_byte(pgm, PDATA(pgm)->current_peripherals_config, 0x01); if (buspirate_expect_bin_byte(pgm, PDATA(pgm)->current_peripherals_config, 0x01) < 0)
return -1;
} }
else else
buspirate_expect(pgm, "{\n", "CS ENABLED", 1); buspirate_expect(pgm, "{\n", "CS ENABLED", 1);
@ -1138,7 +1148,8 @@ static void buspirate_bb_enable(struct programmer_t *pgm)
{ {
char buf[20] = { '\0' }; char buf[20] = { '\0' };
bitbang_check_prerequisites(pgm); if (bitbang_check_prerequisites(pgm) < 0)
return; /* XXX should treat as error */
fprintf(stderr, "Attempting to initiate BusPirate bitbang binary mode...\n"); fprintf(stderr, "Attempting to initiate BusPirate bitbang binary mode...\n");
@ -1157,7 +1168,7 @@ static void buspirate_bb_enable(struct programmer_t *pgm)
if (sscanf(buf, "BBIO%d", &PDATA(pgm)->binmode_version) != 1) { if (sscanf(buf, "BBIO%d", &PDATA(pgm)->binmode_version) != 1) {
fprintf(stderr, "Binary mode not confirmed: '%s'\n", buf); fprintf(stderr, "Binary mode not confirmed: '%s'\n", buf);
buspirate_reset_from_binmode(pgm); buspirate_reset_from_binmode(pgm);
exit(1); return;
} }
fprintf(stderr, "BusPirate binmode version: %d\n", fprintf(stderr, "BusPirate binmode version: %d\n",
PDATA(pgm)->binmode_version); PDATA(pgm)->binmode_version);

View File

@ -92,7 +92,7 @@ static int butterfly_recv(PROGRAMMER * pgm, char * buf, size_t len)
fprintf(stderr, fprintf(stderr,
"%s: butterfly_recv(): programmer is not responding\n", "%s: butterfly_recv(): programmer is not responding\n",
progname); progname);
exit(1); return -1;
} }
return 0; return 0;
} }
@ -104,7 +104,7 @@ static int butterfly_drain(PROGRAMMER * pgm, int display)
} }
static void butterfly_vfy_cmd_sent(PROGRAMMER * pgm, char * errmsg) static int butterfly_vfy_cmd_sent(PROGRAMMER * pgm, char * errmsg)
{ {
char c; char c;
@ -112,8 +112,9 @@ static void butterfly_vfy_cmd_sent(PROGRAMMER * pgm, char * errmsg)
if (c != '\r') { if (c != '\r') {
fprintf(stderr, "%s: error: programmer did not respond to command: %s\n", fprintf(stderr, "%s: error: programmer did not respond to command: %s\n",
progname, errmsg); progname, errmsg);
exit(1); return -1;
} }
return 0;
} }
@ -155,7 +156,8 @@ static int butterfly_vfy_led(PROGRAMMER * pgm, int value)
static int butterfly_chip_erase(PROGRAMMER * pgm, AVRPART * p) static int butterfly_chip_erase(PROGRAMMER * pgm, AVRPART * p)
{ {
butterfly_send(pgm, "e", 1); butterfly_send(pgm, "e", 1);
butterfly_vfy_cmd_sent(pgm, "chip erase"); if (butterfly_vfy_cmd_sent(pgm, "chip erase") < 0)
return -1;
return 0; return 0;
} }
@ -248,7 +250,7 @@ static int butterfly_initialize(PROGRAMMER * pgm, AVRPART * p)
if ( c != 'M' && c != '?') if ( c != 'M' && c != '?')
{ {
fprintf(stderr, "\nConnection FAILED."); fprintf(stderr, "\nConnection FAILED.");
exit(1); return -1;
} }
else else
{ {
@ -317,7 +319,7 @@ static int butterfly_initialize(PROGRAMMER * pgm, AVRPART * p)
fprintf(stderr, fprintf(stderr,
"%s: error: buffered memory access not supported. Maybe it isn't\n"\ "%s: error: buffered memory access not supported. Maybe it isn't\n"\
"a butterfly/AVR109 but a AVR910 device?\n", progname); "a butterfly/AVR109 but a AVR910 device?\n", progname);
exit(1); return -1;
}; };
butterfly_recv(pgm, &c, 1); butterfly_recv(pgm, &c, 1);
PDATA(pgm)->buffersize = (unsigned int)(unsigned char)c<<8; PDATA(pgm)->buffersize = (unsigned int)(unsigned char)c<<8;
@ -355,7 +357,8 @@ static int butterfly_initialize(PROGRAMMER * pgm, AVRPART * p)
buf[1] = devtype_1st; buf[1] = devtype_1st;
butterfly_send(pgm, buf, 2); butterfly_send(pgm, buf, 2);
butterfly_vfy_cmd_sent(pgm, "select device"); if (butterfly_vfy_cmd_sent(pgm, "select device") < 0)
return -1;
if (verbose) if (verbose)
fprintf(stderr, fprintf(stderr,
@ -490,7 +493,8 @@ static int butterfly_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
return -1; return -1;
butterfly_send(pgm, cmd, size); butterfly_send(pgm, cmd, size);
butterfly_vfy_cmd_sent(pgm, "write byte"); if (butterfly_vfy_cmd_sent(pgm, "write byte") < 0)
return -1;
return 0; return 0;
} }
@ -619,7 +623,8 @@ static int butterfly_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
#if 0 #if 0
usleep(1000000); usleep(1000000);
butterfly_send(pgm, "y", 1); butterfly_send(pgm, "y", 1);
butterfly_vfy_cmd_sent(pgm, "clear LED"); if (butterfly_vfy_cmd_sent(pgm, "clear LED") < 0)
return -1;
#endif #endif
cmd = malloc(4+blocksize); cmd = malloc(4+blocksize);
@ -636,7 +641,8 @@ static int butterfly_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
cmd[2] = blocksize & 0xff; cmd[2] = blocksize & 0xff;
butterfly_send(pgm, cmd, 4+blocksize); butterfly_send(pgm, cmd, 4+blocksize);
butterfly_vfy_cmd_sent(pgm, "write block"); if (butterfly_vfy_cmd_sent(pgm, "write block") < 0)
return -1;
addr += blocksize; addr += blocksize;
} /* while */ } /* while */

View File

@ -87,13 +87,6 @@ int yywrap()
} }
int yyerror(char * errmsg)
{
fprintf(stderr, "%s: %s at %s:%d\n", progname, errmsg, infile, lineno);
exit(1);
}
TOKEN * new_token(int primary) TOKEN * new_token(int primary)
{ {
TOKEN * tkn; TOKEN * tkn;
@ -184,7 +177,6 @@ TOKEN * hexnumber(char * text)
if ((e == text) || (*e != 0)) { if ((e == text) || (*e != 0)) {
fprintf(stderr, "error at %s:%d: can't scan hex number \"%s\"\n", fprintf(stderr, "error at %s:%d: can't scan hex number \"%s\"\n",
infile, lineno, text); infile, lineno, text);
exit(1);
} }
#if DEBUG #if DEBUG

View File

@ -830,7 +830,7 @@ int flip2_write_max1k(struct dfu_dev *dfu,
if (size > 0x400) { if (size > 0x400) {
fprintf(stderr, "%s: Error: Write block too large (%hu > 1024)\n", fprintf(stderr, "%s: Error: Write block too large (%hu > 1024)\n",
progname, size); progname, size);
exit(1); return -1;
} }
/* There are some special padding requirements for writes. The first packet /* There are some special padding requirements for writes. The first packet

View File

@ -171,7 +171,6 @@ static void add_to_buf (unsigned char c) {
if (nh == tail) { if (nh == tail) {
fprintf (stderr, "buffer overflow. Cannot happen!\n"); fprintf (stderr, "buffer overflow. Cannot happen!\n");
//exit (1);
} }
buffer[head] = c; buffer[head] = c;
head = nh; head = nh;

View File

@ -218,7 +218,7 @@ static int jtagmkI_send(PROGRAMMER * pgm, unsigned char * data, size_t len)
fprintf(stderr, fprintf(stderr,
"%s: jtagmkI_send(): failed to send command to serial port\n", "%s: jtagmkI_send(): failed to send command to serial port\n",
progname); progname);
exit(1); return -1;
} }
free(buf); free(buf);
@ -226,18 +226,19 @@ static int jtagmkI_send(PROGRAMMER * pgm, unsigned char * data, size_t len)
return 0; return 0;
} }
static void jtagmkI_recv(PROGRAMMER * pgm, unsigned char * buf, size_t len) static int jtagmkI_recv(PROGRAMMER * pgm, unsigned char * buf, size_t len)
{ {
if (serial_recv(&pgm->fd, buf, len) != 0) { if (serial_recv(&pgm->fd, buf, len) != 0) {
fprintf(stderr, fprintf(stderr,
"\n%s: jtagmkI_recv(): failed to send command to serial port\n", "\n%s: jtagmkI_recv(): failed to send command to serial port\n",
progname); progname);
exit(1); return -1;
} }
if (verbose >= 3) { if (verbose >= 3) {
putc('\n', stderr); putc('\n', stderr);
jtagmkI_prmsg(pgm, buf, len); jtagmkI_prmsg(pgm, buf, len);
} }
return 0;
} }
@ -345,7 +346,8 @@ static int jtagmkI_getsync(PROGRAMMER * pgm)
buf[0] = CMD_GET_SIGNON; buf[0] = CMD_GET_SIGNON;
jtagmkI_send(pgm, buf, 1); jtagmkI_send(pgm, buf, 1);
jtagmkI_recv(pgm, resp, 9); if (jtagmkI_recv(pgm, resp, 9) < 0)
return -1;
if (verbose >= 2) { if (verbose >= 2) {
resp[8] = '\0'; resp[8] = '\0';
fprintf(stderr, "got %s\n", resp + 1); fprintf(stderr, "got %s\n", resp + 1);
@ -366,7 +368,8 @@ static int jtagmkI_chip_erase(PROGRAMMER * pgm, AVRPART * p)
fprintf(stderr, "%s: jtagmkI_chip_erase(): Sending chip erase command: ", fprintf(stderr, "%s: jtagmkI_chip_erase(): Sending chip erase command: ",
progname); progname);
jtagmkI_send(pgm, buf, 1); jtagmkI_send(pgm, buf, 1);
jtagmkI_recv(pgm, resp, 2); if (jtagmkI_recv(pgm, resp, 2) < 0)
return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
@ -416,7 +419,8 @@ static void jtagmkI_set_devdescr(PROGRAMMER * pgm, AVRPART * p)
progname); progname);
jtagmkI_send(pgm, (unsigned char *)&sendbuf, sizeof(sendbuf)); jtagmkI_send(pgm, (unsigned char *)&sendbuf, sizeof(sendbuf));
jtagmkI_recv(pgm, resp, 2); if (jtagmkI_recv(pgm, resp, 2) < 0)
return;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
@ -443,7 +447,8 @@ static int jtagmkI_reset(PROGRAMMER * pgm)
progname); progname);
jtagmkI_send(pgm, buf, 1); jtagmkI_send(pgm, buf, 1);
jtagmkI_recv(pgm, resp, 2); if (jtagmkI_recv(pgm, resp, 2) < 0)
return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
@ -480,7 +485,8 @@ static int jtagmkI_program_enable(PROGRAMMER * pgm)
progname); progname);
jtagmkI_send(pgm, buf, 1); jtagmkI_send(pgm, buf, 1);
jtagmkI_recv(pgm, resp, 2); if (jtagmkI_recv(pgm, resp, 2) < 0)
return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
@ -514,7 +520,8 @@ static int jtagmkI_program_disable(PROGRAMMER * pgm)
progname); progname);
jtagmkI_send(pgm, buf, 1); jtagmkI_send(pgm, buf, 1);
jtagmkI_recv(pgm, resp, 2); if (jtagmkI_recv(pgm, resp, 2) < 0)
return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
@ -588,7 +595,8 @@ static int jtagmkI_initialize(PROGRAMMER * pgm, AVRPART * p)
cmd[0] = CMD_STOP; cmd[0] = CMD_STOP;
jtagmkI_send(pgm, cmd, 1); jtagmkI_send(pgm, cmd, 1);
jtagmkI_recv(pgm, resp, 5); if (jtagmkI_recv(pgm, resp, 5) < 0)
return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
@ -822,7 +830,8 @@ static int jtagmkI_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
/* First part, send the write command. */ /* First part, send the write command. */
jtagmkI_send(pgm, cmd, 6); jtagmkI_send(pgm, cmd, 6);
jtagmkI_recv(pgm, resp, 1); if (jtagmkI_recv(pgm, resp, 1) < 0)
return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
@ -851,7 +860,8 @@ static int jtagmkI_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
/* Second, send the data command. */ /* Second, send the data command. */
jtagmkI_send(pgm, datacmd, send_size + 1); jtagmkI_send(pgm, datacmd, send_size + 1);
jtagmkI_recv(pgm, resp, 2); if (jtagmkI_recv(pgm, resp, 2) < 0)
return -1;
if (resp[1] != RESP_OK) { if (resp[1] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
@ -944,7 +954,8 @@ static int jtagmkI_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
progname); progname);
jtagmkI_send(pgm, cmd, 6); jtagmkI_send(pgm, cmd, 6);
jtagmkI_recv(pgm, resp, read_size + 3); if (jtagmkI_recv(pgm, resp, read_size + 3) < 0)
return -1;
if (resp[read_size + 3 - 1] != RESP_OK) { if (resp[read_size + 3 - 1] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
@ -1060,7 +1071,8 @@ static int jtagmkI_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
} }
jtagmkI_send(pgm, cmd, 6); jtagmkI_send(pgm, cmd, 6);
jtagmkI_recv(pgm, resp, respsize); if (jtagmkI_recv(pgm, resp, respsize) < 0)
return -1;
if (resp[respsize - 1] != RESP_OK) { if (resp[respsize - 1] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
@ -1069,7 +1081,7 @@ static int jtagmkI_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
"%s: jtagmkI_read_byte(): " "%s: jtagmkI_read_byte(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[respsize - 1]); progname, resp[respsize - 1]);
exit(1); return -1;
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); fprintf(stderr, "OK\n");
@ -1146,7 +1158,8 @@ static int jtagmkI_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
} }
/* First part, send the write command. */ /* First part, send the write command. */
jtagmkI_send(pgm, cmd, 6); jtagmkI_send(pgm, cmd, 6);
jtagmkI_recv(pgm, resp, 1); if (jtagmkI_recv(pgm, resp, 1) < 0)
return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
@ -1176,7 +1189,8 @@ static int jtagmkI_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
datacmd[1] = writedata; datacmd[1] = writedata;
} }
jtagmkI_send(pgm, datacmd, len); jtagmkI_send(pgm, datacmd, len);
jtagmkI_recv(pgm, resp, 1); if (jtagmkI_recv(pgm, resp, 1) < 0)
return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
@ -1242,7 +1256,8 @@ static int jtagmkI_getparm(PROGRAMMER * pgm, unsigned char parm,
progname, parm); progname, parm);
jtagmkI_send(pgm, buf, 2); jtagmkI_send(pgm, buf, 2);
jtagmkI_recv(pgm, resp, 3); if (jtagmkI_recv(pgm, resp, 3) < 0)
return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
@ -1288,7 +1303,8 @@ static int jtagmkI_setparm(PROGRAMMER * pgm, unsigned char parm,
"Sending set parameter command (parm 0x%02x): ", "Sending set parameter command (parm 0x%02x): ",
progname, parm); progname, parm);
jtagmkI_send(pgm, buf, 3); jtagmkI_send(pgm, buf, 3);
jtagmkI_recv(pgm, resp, 2); if (jtagmkI_recv(pgm, resp, 2) < 0)
return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);

View File

@ -449,7 +449,7 @@ int jtagmkII_send(PROGRAMMER * pgm, unsigned char * data, size_t len)
fprintf(stderr, fprintf(stderr,
"%s: jtagmkII_send(): failed to send command to serial port\n", "%s: jtagmkII_send(): failed to send command to serial port\n",
progname); progname);
exit(1); return -1;
} }
free(buf); free(buf);

View File

@ -247,7 +247,8 @@ static int linuxgpio_open(PROGRAMMER *pgm, char *port)
{ {
int r, i, pin; int r, i, pin;
bitbang_check_prerequisites(pgm); if (bitbang_check_prerequisites(pgm) < 0
return -1;
for (i=0; i<N_GPIO; i++) for (i=0; i<N_GPIO; i++)

7
main.c
View File

@ -65,6 +65,13 @@ char progbuf[PATH_MAX]; /* temporary buffer of spaces the same
length as progname; used for lining up length as progname; used for lining up
multiline messages */ multiline messages */
int yyerror(char * errmsg)
{
fprintf(stderr, "%s: %s at %s:%d\n", progname, errmsg, infile, lineno);
exit(1);
}
struct list_walk_cookie struct list_walk_cookie
{ {
FILE *f; FILE *f;

5
par.c
View File

@ -237,13 +237,14 @@ static int par_open(PROGRAMMER * pgm, char * port)
{ {
int rc; int rc;
bitbang_check_prerequisites(pgm); if (bitbang_check_prerequisites(pgm) < 0)
return -1;
ppi_open(port, &pgm->fd); ppi_open(port, &pgm->fd);
if (pgm->fd.ifd < 0) { if (pgm->fd.ifd < 0) {
fprintf(stderr, "%s: failed to open parallel port \"%s\"\n\n", fprintf(stderr, "%s: failed to open parallel port \"%s\"\n\n",
progname, port); progname, port);
exit(1); return -1;
} }
/* /*

2
pgm.c
View File

@ -41,7 +41,7 @@ static int pgm_default_open (struct programmer_t *pgm, char * name)
{ {
fprintf (stderr, "\n%s: Fatal error: Programmer does not support open()", fprintf (stderr, "\n%s: Fatal error: Programmer does not support open()",
progname); progname);
exit(1); return -1;
} }
static int pgm_default_led (struct programmer_t * pgm, int value) static int pgm_default_led (struct programmer_t * pgm, int value)

View File

@ -196,7 +196,7 @@ static int pickit2_open(PROGRAMMER * pgm, char * port)
fprintf(stderr, fprintf(stderr,
"%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n", "%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n",
progname, PICKIT2_VID, PICKIT2_PID); progname, PICKIT2_VID, PICKIT2_PID);
exit(1); return -1;
} }
else else
{ {
@ -218,7 +218,7 @@ static int pickit2_open(PROGRAMMER * pgm, char * port)
fprintf(stderr, fprintf(stderr,
"%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n", "%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n",
progname, PICKIT2_VID, PICKIT2_PID); progname, PICKIT2_VID, PICKIT2_PID);
exit(1); return -1;
} }
#endif #endif
@ -1340,8 +1340,6 @@ static int pickit2_nousb_open (struct programmer_t *pgm, char * name) {
"%s: error: no usb support. Please compile again with libusb installed.\n", "%s: error: no usb support. Please compile again with libusb installed.\n",
#endif #endif
progname); progname);
exit(1);
} }
void pickit2_initpgm (PROGRAMMER * pgm) void pickit2_initpgm (PROGRAMMER * pgm)

View File

@ -57,14 +57,14 @@ void pin_clear_all(struct pindef_t * const pindef) {
* @param[in] pindef new pin definition structure * @param[in] pindef new pin definition structure
* @param[out] pinno old pin definition integer * @param[out] pinno old pin definition integer
*/ */
static void pin_fill_old_pinno(const struct pindef_t * const pindef, unsigned int * const pinno) { static int pin_fill_old_pinno(const struct pindef_t * const pindef, unsigned int * const pinno) {
bool found = false; bool found = false;
int i; int i;
for(i = 0; i < PIN_MAX; i++) { for(i = 0; i < PIN_MAX; i++) {
if(pindef->mask[i / PIN_FIELD_ELEMENT_SIZE] & (1 << (i % PIN_FIELD_ELEMENT_SIZE))) { if(pindef->mask[i / PIN_FIELD_ELEMENT_SIZE] & (1 << (i % PIN_FIELD_ELEMENT_SIZE))) {
if(found) { if(found) {
fprintf(stderr, "Multiple pins found\n"); //TODO fprintf(stderr, "Multiple pins found\n"); //TODO
exit(1); return -1;
} }
found = true; found = true;
*pinno = i; *pinno = i;
@ -73,6 +73,7 @@ static void pin_fill_old_pinno(const struct pindef_t * const pindef, unsigned in
} }
} }
} }
return 0;
} }
/** /**
@ -81,14 +82,14 @@ static void pin_fill_old_pinno(const struct pindef_t * const pindef, unsigned in
* @param[in] pindef new pin definition structure * @param[in] pindef new pin definition structure
* @param[out] pinno old pin definition integer * @param[out] pinno old pin definition integer
*/ */
static void pin_fill_old_pinlist(const struct pindef_t * const pindef, unsigned int * const pinno) { static int pin_fill_old_pinlist(const struct pindef_t * const pindef, unsigned int * const pinno) {
int i; int i;
for(i = 0; i < PIN_FIELD_SIZE; i++) { for(i = 0; i < PIN_FIELD_SIZE; i++) {
if(i == 0) { if(i == 0) {
if((pindef->mask[i] & ~PIN_MASK) != 0) { if((pindef->mask[i] & ~PIN_MASK) != 0) {
fprintf(stderr, "Pins of higher index than max field size for old pinno found\n"); fprintf(stderr, "Pins of higher index than max field size for old pinno found\n");
exit(1); return -1;
} }
if (pindef->mask[i] == 0) { if (pindef->mask[i] == 0) {
/* this pin function is not using any pins */ /* this pin function is not using any pins */
@ -100,13 +101,14 @@ static void pin_fill_old_pinlist(const struct pindef_t * const pindef, unsigned
*pinno = pindef->mask[i]; *pinno = pindef->mask[i];
} else { } else {
fprintf(stderr, "pins have different polarity set\n"); fprintf(stderr, "pins have different polarity set\n");
exit(1); return -1;
} }
} else if(pindef->mask[i] != 0) { } else if(pindef->mask[i] != 0) {
fprintf(stderr, "Pins have higher number than fit in old format\n"); fprintf(stderr, "Pins have higher number than fit in old format\n");
exit(1); return -1;
} }
} }
return 0;
} }
@ -115,19 +117,30 @@ static void pin_fill_old_pinlist(const struct pindef_t * const pindef, unsigned
* *
* @param[inout] pgm programmer whose pins shall be converted. * @param[inout] pgm programmer whose pins shall be converted.
*/ */
void pgm_fill_old_pins(struct programmer_t * const pgm) { int pgm_fill_old_pins(struct programmer_t * const pgm) {
pin_fill_old_pinlist(&(pgm->pin[PPI_AVR_VCC]), &(pgm->pinno[PPI_AVR_VCC])); if (pin_fill_old_pinlist(&(pgm->pin[PPI_AVR_VCC]), &(pgm->pinno[PPI_AVR_VCC])) < 0)
pin_fill_old_pinlist(&(pgm->pin[PPI_AVR_BUFF]), &(pgm->pinno[PPI_AVR_BUFF])); return -1;
pin_fill_old_pinno(&(pgm->pin[PIN_AVR_RESET]), &(pgm->pinno[PIN_AVR_RESET])); if (pin_fill_old_pinlist(&(pgm->pin[PPI_AVR_BUFF]), &(pgm->pinno[PPI_AVR_BUFF])) < 0)
pin_fill_old_pinno(&(pgm->pin[PIN_AVR_SCK]), &(pgm->pinno[PIN_AVR_SCK])); return -1;
pin_fill_old_pinno(&(pgm->pin[PIN_AVR_MOSI]), &(pgm->pinno[PIN_AVR_MOSI])); if (pin_fill_old_pinno(&(pgm->pin[PIN_AVR_RESET]), &(pgm->pinno[PIN_AVR_RESET])) < 0)
pin_fill_old_pinno(&(pgm->pin[PIN_AVR_MISO]), &(pgm->pinno[PIN_AVR_MISO])); return -1;
pin_fill_old_pinno(&(pgm->pin[PIN_LED_ERR]), &(pgm->pinno[PIN_LED_ERR])); if (pin_fill_old_pinno(&(pgm->pin[PIN_AVR_SCK]), &(pgm->pinno[PIN_AVR_SCK])) < 0)
pin_fill_old_pinno(&(pgm->pin[PIN_LED_RDY]), &(pgm->pinno[PIN_LED_RDY])); return -1;
pin_fill_old_pinno(&(pgm->pin[PIN_LED_PGM]), &(pgm->pinno[PIN_LED_PGM])); if (pin_fill_old_pinno(&(pgm->pin[PIN_AVR_MOSI]), &(pgm->pinno[PIN_AVR_MOSI])) < 0)
pin_fill_old_pinno(&(pgm->pin[PIN_LED_VFY]), &(pgm->pinno[PIN_LED_VFY])); return -1;
if (pin_fill_old_pinno(&(pgm->pin[PIN_AVR_MISO]), &(pgm->pinno[PIN_AVR_MISO])) < 0)
return -1;
if (pin_fill_old_pinno(&(pgm->pin[PIN_LED_ERR]), &(pgm->pinno[PIN_LED_ERR])) < 0)
return -1;
if (pin_fill_old_pinno(&(pgm->pin[PIN_LED_RDY]), &(pgm->pinno[PIN_LED_RDY])) < 0)
return -1;
if (pin_fill_old_pinno(&(pgm->pin[PIN_LED_PGM]), &(pgm->pinno[PIN_LED_PGM])) < 0)
return -1;
if (pin_fill_old_pinno(&(pgm->pin[PIN_LED_VFY]), &(pgm->pinno[PIN_LED_VFY])) < 0)
return -1;
return 0;
} }
/** /**

View File

@ -148,7 +148,7 @@ struct programmer_t; /* forward declaration */
* *
* @param[inout] pgm programmer whose pins shall be converted. * @param[inout] pgm programmer whose pins shall be converted.
*/ */
void pgm_fill_old_pins(struct programmer_t * const pgm); int pgm_fill_old_pins(struct programmer_t * const pgm);
/** /**
* This function checks all pin of pgm against the constraints given in the checklist. * This function checks all pin of pgm against the constraints given in the checklist.

View File

@ -519,8 +519,7 @@ static int avrdoper_open(char *port, union pinfo pinfo, union filedescriptor *fd
rval = usbOpenDevice(fdp, USB_VENDOR_ID, vname, USB_PRODUCT_ID, devname, 1); rval = usbOpenDevice(fdp, USB_VENDOR_ID, vname, USB_PRODUCT_ID, devname, 1);
if(rval != 0){ if(rval != 0){
fprintf(stderr, "%s: avrdoper_open(): %s\n", progname, usbErrorText(rval)); fprintf(stderr, "%s: avrdoper_open(): %s\n", progname, usbErrorText(rval));
exit(1); return -1;
//return -1;
} }
return 0; return 0;
} }
@ -563,7 +562,7 @@ static int avrdoper_send(union filedescriptor *fdp, unsigned char *buf, size_t b
reportDataSizes[lenIndex] + 2); reportDataSizes[lenIndex] + 2);
if(rval != 0){ if(rval != 0){
fprintf(stderr, "%s: avrdoper_send(): %s\n", progname, usbErrorText(rval)); fprintf(stderr, "%s: avrdoper_send(): %s\n", progname, usbErrorText(rval));
exit(1); return -1;
} }
buflen -= thisLen; buflen -= thisLen;
buf += thisLen; buf += thisLen;
@ -573,7 +572,7 @@ static int avrdoper_send(union filedescriptor *fdp, unsigned char *buf, size_t b
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
static void avrdoperFillBuffer(union filedescriptor *fdp) static int avrdoperFillBuffer(union filedescriptor *fdp)
{ {
int bytesPending = reportDataSizes[1]; /* guess how much data is buffered in device */ int bytesPending = reportDataSizes[1]; /* guess how much data is buffered in device */
@ -589,7 +588,7 @@ static void avrdoperFillBuffer(union filedescriptor *fdp)
(char *)buffer, &len); (char *)buffer, &len);
if(usbErr != 0){ if(usbErr != 0){
fprintf(stderr, "%s: avrdoperFillBuffer(): %s\n", progname, usbErrorText(usbErr)); fprintf(stderr, "%s: avrdoperFillBuffer(): %s\n", progname, usbErrorText(usbErr));
exit(1); return -1;
} }
if(verbose > 3) if(verbose > 3)
fprintf(stderr, "Received %d bytes data chunk of total %d\n", len - 2, buffer[1]); fprintf(stderr, "Received %d bytes data chunk of total %d\n", len - 2, buffer[1]);
@ -601,11 +600,12 @@ static void avrdoperFillBuffer(union filedescriptor *fdp)
fprintf(stderr, fprintf(stderr,
"%s: avrdoperFillBuffer(): internal error: buffer overflow\n", "%s: avrdoperFillBuffer(): internal error: buffer overflow\n",
progname); progname);
exit(1); return -1;
} }
memcpy(avrdoperRxBuffer + avrdoperRxLength, buffer + 2, len); memcpy(avrdoperRxBuffer + avrdoperRxLength, buffer + 2, len);
avrdoperRxLength += len; avrdoperRxLength += len;
} }
return 0;
} }
static int avrdoper_recv(union filedescriptor *fdp, unsigned char *buf, size_t buflen) static int avrdoper_recv(union filedescriptor *fdp, unsigned char *buf, size_t buflen)
@ -616,7 +616,8 @@ static int avrdoper_recv(union filedescriptor *fdp, unsigned char *buf, size_t b
while(remaining > 0){ while(remaining > 0){
int len, available = avrdoperRxLength - avrdoperRxPosition; int len, available = avrdoperRxLength - avrdoperRxPosition;
if(available <= 0){ /* buffer is empty */ if(available <= 0){ /* buffer is empty */
avrdoperFillBuffer(fdp); if (avrdoperFillBuffer(fdp) < 0)
return -1;
continue; continue;
} }
len = remaining < available ? remaining : available; len = remaining < available ? remaining : available;
@ -635,7 +636,8 @@ static int avrdoper_recv(union filedescriptor *fdp, unsigned char *buf, size_t b
static int avrdoper_drain(union filedescriptor *fdp, int display) static int avrdoper_drain(union filedescriptor *fdp, int display)
{ {
do{ do{
avrdoperFillBuffer(fdp); if (avrdoperFillBuffer(fdp) < 0)
return -1;
}while(avrdoperRxLength > 0); }while(avrdoperRxLength > 0);
return 0; return 0;
} }

View File

@ -347,7 +347,7 @@ static int ser_send(union filedescriptor *fd, unsigned char * buf, size_t buflen
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: ser_send(): write error: %s\n", fprintf(stderr, "%s: ser_send(): write error: %s\n",
progname, strerror(errno)); progname, strerror(errno));
exit(1); return -1;
} }
p += rc; p += rc;
len -= rc; len -= rc;
@ -393,7 +393,7 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
else { else {
fprintf(stderr, "%s: ser_recv(): select(): %s\n", fprintf(stderr, "%s: ser_recv(): select(): %s\n",
progname, strerror(errno)); progname, strerror(errno));
exit(1); return -1;
} }
} }
@ -401,7 +401,7 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: ser_recv(): read error: %s\n", fprintf(stderr, "%s: ser_recv(): read error: %s\n",
progname, strerror(errno)); progname, strerror(errno));
exit(1); return -1;
} }
p += rc; p += rc;
len += rc; len += rc;
@ -468,7 +468,7 @@ static int ser_drain(union filedescriptor *fd, int display)
else { else {
fprintf(stderr, "%s: ser_drain(): select(): %s\n", fprintf(stderr, "%s: ser_drain(): select(): %s\n",
progname, strerror(errno)); progname, strerror(errno));
exit(1); return -1;
} }
} }
@ -476,7 +476,7 @@ static int ser_drain(union filedescriptor *fd, int display)
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: ser_drain(): read error: %s\n", fprintf(stderr, "%s: ser_drain(): read error: %s\n",
progname, strerror(errno)); progname, strerror(errno));
exit(1); return -1;
} }
if (display) { if (display) {
fprintf(stderr, "%02x ", buf); fprintf(stderr, "%02x ", buf);

View File

@ -236,7 +236,7 @@ static int ser_send(union filedescriptor *fd, unsigned char * buf, size_t buflen
if (hComPort == INVALID_HANDLE_VALUE) { if (hComPort == INVALID_HANDLE_VALUE) {
fprintf(stderr, "%s: ser_send(): port not open\n", fprintf(stderr, "%s: ser_send(): port not open\n",
progname); progname);
exit(1); return -1;
} }
if (!len) if (!len)
@ -266,13 +266,13 @@ static int ser_send(union filedescriptor *fd, unsigned char * buf, size_t buflen
if (!WriteFile (hComPort, buf, buflen, &written, NULL)) { if (!WriteFile (hComPort, buf, buflen, &written, NULL)) {
fprintf(stderr, "%s: ser_send(): write error: %s\n", fprintf(stderr, "%s: ser_send(): write error: %s\n",
progname, "sorry no info avail"); // TODO progname, "sorry no info avail"); // TODO
exit(1); return -1;
} }
if (written != buflen) { if (written != buflen) {
fprintf(stderr, "%s: ser_send(): size/send mismatch\n", fprintf(stderr, "%s: ser_send(): size/send mismatch\n",
progname); progname);
exit(1); return -1;
} }
return 0; return 0;
@ -290,7 +290,7 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
if (hComPort == INVALID_HANDLE_VALUE) { if (hComPort == INVALID_HANDLE_VALUE) {
fprintf(stderr, "%s: ser_read(): port not open\n", fprintf(stderr, "%s: ser_read(): port not open\n",
progname); progname);
exit(1); return -1;
} }
serial_w32SetTimeOut(hComPort, serial_recv_timeout); serial_w32SetTimeOut(hComPort, serial_recv_timeout);
@ -310,7 +310,7 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
fprintf(stderr, "%s: ser_recv(): read error: %s\n", fprintf(stderr, "%s: ser_recv(): read error: %s\n",
progname, (char*)lpMsgBuf); progname, (char*)lpMsgBuf);
LocalFree( lpMsgBuf ); LocalFree( lpMsgBuf );
exit(1); return -1;
} }
/* time out detected */ /* time out detected */
@ -359,7 +359,7 @@ static int ser_drain(union filedescriptor *fd, int display)
if (hComPort == INVALID_HANDLE_VALUE) { if (hComPort == INVALID_HANDLE_VALUE) {
fprintf(stderr, "%s: ser_drain(): port not open\n", fprintf(stderr, "%s: ser_drain(): port not open\n",
progname); progname);
exit(1); return -1;
} }
serial_w32SetTimeOut(hComPort,250); serial_w32SetTimeOut(hComPort,250);
@ -385,7 +385,7 @@ static int ser_drain(union filedescriptor *fd, int display)
fprintf(stderr, "%s: ser_drain(): read error: %s\n", fprintf(stderr, "%s: ser_drain(): read error: %s\n",
progname, (char*)lpMsgBuf); progname, (char*)lpMsgBuf);
LocalFree( lpMsgBuf ); LocalFree( lpMsgBuf );
exit(1); return -1;
} }
if (read) { // data avail if (read) { // data avail

View File

@ -225,7 +225,8 @@ static int serbb_open(PROGRAMMER *pgm, char *port)
int flags; int flags;
int r; int r;
bitbang_check_prerequisites(pgm); if (bitbang_check_prerequisites(pgm) < 0)
return -1;
/* adapted from uisp code */ /* adapted from uisp code */

View File

@ -124,7 +124,7 @@ static int serbb_setpin(PROGRAMMER * pgm, int pinfunc, int value)
progname, (char *)lpMsgBuf); progname, (char *)lpMsgBuf);
CloseHandle(hComPort); CloseHandle(hComPort);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
exit(1); return -1;
} }
if (pgm->ispdelay > 1) if (pgm->ispdelay > 1)
@ -171,7 +171,7 @@ static int serbb_getpin(PROGRAMMER * pgm, int pinfunc)
progname, (char *)lpMsgBuf); progname, (char *)lpMsgBuf);
CloseHandle(hComPort); CloseHandle(hComPort);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
exit(1); return -1;
} }
if (verbose > 4) if (verbose > 4)
fprintf(stderr, fprintf(stderr,
@ -271,7 +271,8 @@ static int serbb_open(PROGRAMMER *pgm, char *port)
LPVOID lpMsgBuf; LPVOID lpMsgBuf;
HANDLE hComPort = INVALID_HANDLE_VALUE; HANDLE hComPort = INVALID_HANDLE_VALUE;
bitbang_check_prerequisites(pgm); if (bitbang_check_prerequisites(pgm) < 0
return -1;
hComPort = CreateFile(port, GENERIC_READ | GENERIC_WRITE, 0, NULL, hComPort = CreateFile(port, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

View File

@ -154,23 +154,23 @@ static int stk500_cmd(PROGRAMMER * pgm, const unsigned char *cmd,
stk500_send(pgm, buf, 6); stk500_send(pgm, buf, 6);
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] != Resp_STK_INSYNC) { if (buf[0] != Resp_STK_INSYNC) {
fprintf(stderr, "%s: stk500_cmd(): programmer is out of sync\n", progname); fprintf(stderr, "%s: stk500_cmd(): programmer is out of sync\n", progname);
exit(1); return -1;
} }
res[0] = cmd[1]; res[0] = cmd[1];
res[1] = cmd[2]; res[1] = cmd[2];
res[2] = cmd[3]; res[2] = cmd[3];
if (stk500_recv(pgm, &res[3], 1) < 0) if (stk500_recv(pgm, &res[3], 1) < 0)
exit(1); return -1;
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] != Resp_STK_OK) { if (buf[0] != Resp_STK_OK) {
fprintf(stderr, "%s: stk500_cmd(): protocol error\n", progname); fprintf(stderr, "%s: stk500_cmd(): protocol error\n", progname);
exit(1); return -1;
} }
return 0; return 0;
@ -231,7 +231,7 @@ static int stk500_program_enable(PROGRAMMER * pgm, AVRPART * p)
stk500_send(pgm, buf, 2); stk500_send(pgm, buf, 2);
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "%s: stk500_program_enable(): can't get into sync\n", fprintf(stderr, "%s: stk500_program_enable(): can't get into sync\n",
@ -251,7 +251,7 @@ static int stk500_program_enable(PROGRAMMER * pgm, AVRPART * p)
} }
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_OK) { if (buf[0] == Resp_STK_OK) {
return 0; return 0;
} }
@ -298,7 +298,7 @@ static int stk500_set_extended_parms(PROGRAMMER * pgm, int n,
stk500_send(pgm, buf, i+1); stk500_send(pgm, buf, i+1);
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "%s: stk500_set_extended_parms(): can't get into sync\n", fprintf(stderr, "%s: stk500_set_extended_parms(): can't get into sync\n",
@ -318,7 +318,7 @@ static int stk500_set_extended_parms(PROGRAMMER * pgm, int n,
} }
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_OK) { if (buf[0] == Resp_STK_OK) {
return 0; return 0;
} }
@ -370,7 +370,7 @@ static int mib510_isp(PROGRAMMER * pgm, unsigned char cmd)
stk500_send(pgm, buf, 9); stk500_send(pgm, buf, 9);
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "%s: mib510_isp(): can't get into sync\n", fprintf(stderr, "%s: mib510_isp(): can't get into sync\n",
@ -390,7 +390,7 @@ static int mib510_isp(PROGRAMMER * pgm, unsigned char cmd)
} }
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_OK) { if (buf[0] == Resp_STK_OK) {
return 0; return 0;
} }
@ -542,7 +542,7 @@ static int stk500_initialize(PROGRAMMER * pgm, AVRPART * p)
stk500_send(pgm, buf, 22); stk500_send(pgm, buf, 22);
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
fprintf(stderr, fprintf(stderr,
"%s: stk500_initialize(): programmer not in sync, resp=0x%02x\n", "%s: stk500_initialize(): programmer not in sync, resp=0x%02x\n",
@ -562,7 +562,7 @@ static int stk500_initialize(PROGRAMMER * pgm, AVRPART * p)
} }
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] != Resp_STK_OK) { if (buf[0] != Resp_STK_OK) {
fprintf(stderr, fprintf(stderr,
"%s: stk500_initialize(): (b) protocol error, " "%s: stk500_initialize(): (b) protocol error, "
@ -606,7 +606,7 @@ static int stk500_initialize(PROGRAMMER * pgm, AVRPART * p)
rc = stk500_set_extended_parms(pgm, n_extparms+1, buf); rc = stk500_set_extended_parms(pgm, n_extparms+1, buf);
if (rc) { if (rc) {
fprintf(stderr, "%s: stk500_initialize(): failed\n", progname); fprintf(stderr, "%s: stk500_initialize(): failed\n", progname);
exit(1); return -1;
} }
} }
@ -628,7 +628,7 @@ static void stk500_disable(PROGRAMMER * pgm)
stk500_send(pgm, buf, 2); stk500_send(pgm, buf, 2);
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "%s: stk500_disable(): can't get into sync\n", fprintf(stderr, "%s: stk500_disable(): can't get into sync\n",
@ -648,7 +648,7 @@ static void stk500_disable(PROGRAMMER * pgm)
} }
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return;
if (buf[0] == Resp_STK_OK) { if (buf[0] == Resp_STK_OK) {
return; return;
} }
@ -740,7 +740,7 @@ static int stk500_loadaddr(PROGRAMMER * pgm, AVRMEM * mem, unsigned int addr)
stk500_send(pgm, buf, 4); stk500_send(pgm, buf, 4);
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "%s: stk500_loadaddr(): can't get into sync\n", fprintf(stderr, "%s: stk500_loadaddr(): can't get into sync\n",
@ -760,7 +760,7 @@ static int stk500_loadaddr(PROGRAMMER * pgm, AVRMEM * mem, unsigned int addr)
} }
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_OK) { if (buf[0] == Resp_STK_OK) {
return 0; return 0;
} }
@ -839,7 +839,7 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
stk500_send( pgm, buf, i); stk500_send( pgm, buf, i);
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "\n%s: stk500_paged_write(): can't get into sync\n", fprintf(stderr, "\n%s: stk500_paged_write(): can't get into sync\n",
@ -859,7 +859,7 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
} }
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] != Resp_STK_OK) { if (buf[0] != Resp_STK_OK) {
fprintf(stderr, fprintf(stderr,
"\n%s: stk500_paged_write(): (a) protocol error, " "\n%s: stk500_paged_write(): (a) protocol error, "
@ -922,7 +922,7 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
stk500_send(pgm, buf, 5); stk500_send(pgm, buf, 5);
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "\n%s: stk500_paged_load(): can't get into sync\n", fprintf(stderr, "\n%s: stk500_paged_load(): can't get into sync\n",
@ -942,10 +942,10 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
} }
if (stk500_recv(pgm, &m->buf[addr], block_size) < 0) if (stk500_recv(pgm, &m->buf[addr], block_size) < 0)
exit(1); return -1;
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if(strcmp(ldata(lfirst(pgm->id)), "mib510") == 0) { if(strcmp(ldata(lfirst(pgm->id)), "mib510") == 0) {
if (buf[0] != Resp_STK_INSYNC) { if (buf[0] != Resp_STK_INSYNC) {
@ -1118,7 +1118,7 @@ static int stk500_getparm(PROGRAMMER * pgm, unsigned parm, unsigned * value)
stk500_send(pgm, buf, 3); stk500_send(pgm, buf, 3);
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "\n%s: stk500_getparm(): can't get into sync\n", fprintf(stderr, "\n%s: stk500_getparm(): can't get into sync\n",
@ -1138,11 +1138,11 @@ static int stk500_getparm(PROGRAMMER * pgm, unsigned parm, unsigned * value)
} }
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
v = buf[0]; v = buf[0];
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_FAILED) { if (buf[0] == Resp_STK_FAILED) {
fprintf(stderr, fprintf(stderr,
"\n%s: stk500_getparm(): parameter 0x%02x failed\n", "\n%s: stk500_getparm(): parameter 0x%02x failed\n",
@ -1178,7 +1178,7 @@ static int stk500_setparm(PROGRAMMER * pgm, unsigned parm, unsigned value)
stk500_send(pgm, buf, 4); stk500_send(pgm, buf, 4);
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "\n%s: stk500_setparm(): can't get into sync\n", fprintf(stderr, "\n%s: stk500_setparm(): can't get into sync\n",
@ -1198,13 +1198,13 @@ static int stk500_setparm(PROGRAMMER * pgm, unsigned parm, unsigned value)
} }
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_OK) if (buf[0] == Resp_STK_OK)
return 0; return 0;
parm = buf[0]; /* if not STK_OK, we've been echoed parm here */ parm = buf[0]; /* if not STK_OK, we've been echoed parm here */
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
exit(1); return -1;
if (buf[0] == Resp_STK_FAILED) { if (buf[0] == Resp_STK_FAILED) {
fprintf(stderr, fprintf(stderr,
"\n%s: stk500_setparm(): parameter 0x%02x failed\n", "\n%s: stk500_setparm(): parameter 0x%02x failed\n",
@ -1310,7 +1310,7 @@ static void stk500_setup(PROGRAMMER * pgm)
fprintf(stderr, fprintf(stderr,
"%s: stk500_setup(): Out of memory allocating private data\n", "%s: stk500_setup(): Out of memory allocating private data\n",
progname); progname);
exit(1); return;
} }
memset(pgm->cookie, 0, sizeof(struct pdata)); memset(pgm->cookie, 0, sizeof(struct pdata));
PDATA(pgm)->ext_addr_byte = 0xff; /* Ensures it is programmed before PDATA(pgm)->ext_addr_byte = 0xff; /* Ensures it is programmed before

View File

@ -393,7 +393,7 @@ static int stk500v2_send_mk2(PROGRAMMER * pgm, unsigned char * data, size_t len)
{ {
if (serial_send(&pgm->fd, data, len) != 0) { if (serial_send(&pgm->fd, data, len) != 0) {
fprintf(stderr,"%s: stk500_send_mk2(): failed to send command to serial port\n",progname); fprintf(stderr,"%s: stk500_send_mk2(): failed to send command to serial port\n",progname);
exit(1); return -1;
} }
return 0; return 0;
@ -518,7 +518,7 @@ static int stk500v2_send(PROGRAMMER * pgm, unsigned char * data, size_t len)
if (serial_send(&pgm->fd, buf, len+6) != 0) { if (serial_send(&pgm->fd, buf, len+6) != 0) {
fprintf(stderr,"%s: stk500_send(): failed to send command to serial port\n",progname); fprintf(stderr,"%s: stk500_send(): failed to send command to serial port\n",progname);
exit(1); return -1;
} }
return 0; return 0;
@ -1562,7 +1562,6 @@ static void stk500hv_disable(PROGRAMMER * pgm, enum hvmode mode)
"%s: stk500hv_disable(): " "%s: stk500hv_disable(): "
"failed to leave programming mode\n", "failed to leave programming mode\n",
progname); progname);
exit(1);
} }
return; return;
@ -2086,7 +2085,10 @@ static int stk500hv_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
*/ */
buf[3] = 0x80 | 0x40; buf[3] = 0x80 | 0x40;
if (pagesize > 2) { if (pagesize > 2) {
buf[3] |= stk500v2_mode_for_pagesize(pagesize); unsigned int rv = stk500v2_mode_for_pagesize(pagesize);
if (rv == 0)
return -1;
buf[3] |= rv;
buf[3] |= 0x01; buf[3] |= 0x01;
} }
buf[4] = mem->delay; buf[4] = mem->delay;
@ -2441,7 +2443,10 @@ static int stk500hv_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
*/ */
commandbuf[3] = 0x80 | 0x40; commandbuf[3] = 0x80 | 0x40;
if (page_size > 2) { if (page_size > 2) {
commandbuf[3] |= stk500v2_mode_for_pagesize(page_size); unsigned int rv = stk500v2_mode_for_pagesize(page_size);
if (rv == 0)
return -1;
commandbuf[3] |= rv;
commandbuf[3] |= 0x01; commandbuf[3] |= 0x01;
} }
commandbuf[4] = m->delay; commandbuf[4] = m->delay;
@ -2867,7 +2872,7 @@ static unsigned int stk500v2_mode_for_pagesize(unsigned int pagesize)
fprintf(stderr, fprintf(stderr,
"%s: stk500v2_mode_for_pagesize(): invalid pagesize: %u\n", "%s: stk500v2_mode_for_pagesize(): invalid pagesize: %u\n",
progname, pagesize); progname, pagesize);
exit(1); return 0;
} }
/* /*