Improve error messaging in linuxspi.c

This commit is contained in:
Stefan Rueger 2022-09-23 16:53:52 +01:00
parent aa789d4662
commit ca154f812f
No known key found for this signature in database
GPG Key ID: B0B4F1FD86B1EC55
1 changed files with 26 additions and 20 deletions

View File

@ -90,11 +90,16 @@ static int linuxspi_spi_duplex(const PROGRAMMER *pgm, const unsigned char *tx, u
.bits_per_word = 8, .bits_per_word = 8,
}; };
errno = 0;
ret = ioctl(fd_spidev, SPI_IOC_MESSAGE(1), &tr); ret = ioctl(fd_spidev, SPI_IOC_MESSAGE(1), &tr);
if (ret != len) if (ret != len) {
avrdude_message(MSG_INFO, "\n%s: error, unable to send SPI message\n", progname); avrdude_message(MSG_INFO, "\n%s: unable to send SPI message", progname);
if (errno)
avrdude_message(MSG_INFO, ". %s", strerror(errno));
avrdude_message(MSG_INFO, "\n");
}
return (ret == -1) ? -1 : 0; return ret == -1? -1: 0;
} }
static void linuxspi_setup(PROGRAMMER *pgm) { static void linuxspi_setup(PROGRAMMER *pgm) {
@ -127,8 +132,8 @@ static int linuxspi_reset_mcu(const PROGRAMMER *pgm, bool active) {
#endif #endif
if (ret == -1) { if (ret == -1) {
ret = -errno; ret = -errno;
avrdude_message(MSG_INFO, "%s: error, unable to set GPIO line %d value\n", avrdude_message(MSG_INFO, "%s: unable to set GPIO line %d value. %s\n",
progname, pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE); progname, pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE, strerror(errno));
return ret; return ret;
} }
@ -169,7 +174,8 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
strcpy(pgm->port, port); strcpy(pgm->port, port);
fd_spidev = open(pgm->port, O_RDWR); fd_spidev = open(pgm->port, O_RDWR);
if (fd_spidev < 0) { if (fd_spidev < 0) {
avrdude_message(MSG_INFO, "\n%s: error, unable to open the spidev device %s", progname, pgm->port); avrdude_message(MSG_INFO, "\n%s: unable to open the spidev device %s. %s",
progname, pgm->port, strerror(errno));
return -1; return -1;
} }
@ -180,15 +186,16 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
ret = ioctl(fd_spidev, SPI_IOC_WR_MODE32, &mode); ret = ioctl(fd_spidev, SPI_IOC_WR_MODE32, &mode);
if (ret == -1) { if (ret == -1) {
int ioctl_errno = errno; int ioctl_errno = errno;
avrdude_message(MSG_INFO, "%s: error, unable to set SPI mode %02X on %s\n", avrdude_message(MSG_INFO, "%s: unable to set SPI mode %02X on %s. %s\n",
progname, mode, spidev); progname, mode, spidev, strerror(errno));
if(ioctl_errno == EINVAL || !PDATA(pgm)->disable_no_cs) if(ioctl_errno == EINVAL && !PDATA(pgm)->disable_no_cs)
avrdude_message(MSG_INFO, "%s: try -x disable_no_cs\n", progname); avrdude_message(MSG_INFO, "%s: try -x disable_no_cs\n", progname);
goto close_spidev; goto close_spidev;
} }
fd_gpiochip = open(gpiochip, 0); fd_gpiochip = open(gpiochip, 0);
if (fd_gpiochip < 0) { if (fd_gpiochip < 0) {
avrdude_message(MSG_INFO, "\n%s: error, unable to open the gpiochip %s", progname, gpiochip); avrdude_message(MSG_INFO, "\n%s: unable to open the gpiochip %s. %s\n",
progname, gpiochip, strerror(errno));
ret = -1; ret = -1;
goto close_spidev; goto close_spidev;
} }
@ -223,8 +230,8 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
#endif #endif
if (ret == -1) { if (ret == -1) {
ret = -errno; ret = -errno;
avrdude_message(MSG_INFO, "%s: error, unable to get GPIO line %d\n", avrdude_message(MSG_INFO, "%s: unable to get GPIO line %d. %s\n",
progname, pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE); progname, pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE, strerror(errno));
goto close_gpiochip; goto close_gpiochip;
} }
@ -233,15 +240,15 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
goto close_out; goto close_out;
if (pgm->baudrate != 0) { if (pgm->baudrate != 0) {
avrdude_message(MSG_INFO, avrdude_message(MSG_INFO,
"%s: obsolete use of -b <clock> option for bit clock; use -B <clock>\n", "%s: obsolete use of -b <clock> option for bit clock; use -B <clock>\n",
progname); progname);
pgm->bitclock = 1.0 / pgm->baudrate; pgm->bitclock = 1.0 / pgm->baudrate;
} }
if (pgm->bitclock == 0) { if (pgm->bitclock == 0) {
avrdude_message(MSG_NOTICE, avrdude_message(MSG_NOTICE,
"%s: defaulting bit clock to 200 kHz\n", progname); "%s: defaulting bit clock to 200 kHz\n", progname);
pgm->bitclock = 5E-6; // 200 kHz - 5 µs pgm->bitclock = 5E-6; // 200 kHz - 5 µs
} }
return 0; return 0;
@ -408,8 +415,7 @@ static int linuxspi_parseextparams(const PROGRAMMER *pgm, const LISTID extparms)
} }
avrdude_message(MSG_INFO, "%s: linuxspi_parseextparams(): " avrdude_message(MSG_INFO, "%s: linuxspi_parseextparams(): "
"invalid extended parameter '%s'\n", "invalid extended parameter '%s'\n", progname, extended_param);
progname, extended_param);
rc = -1; rc = -1;
} }