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,
};
errno = 0;
ret = ioctl(fd_spidev, SPI_IOC_MESSAGE(1), &tr);
if (ret != len)
avrdude_message(MSG_INFO, "\n%s: error, unable to send SPI message\n", progname);
if (ret != len) {
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) {
@ -127,8 +132,8 @@ static int linuxspi_reset_mcu(const PROGRAMMER *pgm, bool active) {
#endif
if (ret == -1) {
ret = -errno;
avrdude_message(MSG_INFO, "%s: error, unable to set GPIO line %d value\n",
progname, pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE);
avrdude_message(MSG_INFO, "%s: unable to set GPIO line %d value. %s\n",
progname, pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE, strerror(errno));
return ret;
}
@ -169,7 +174,8 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
strcpy(pgm->port, port);
fd_spidev = open(pgm->port, O_RDWR);
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;
}
@ -180,15 +186,16 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
ret = ioctl(fd_spidev, SPI_IOC_WR_MODE32, &mode);
if (ret == -1) {
int ioctl_errno = errno;
avrdude_message(MSG_INFO, "%s: error, unable to set SPI mode %02X on %s\n",
progname, mode, spidev);
if(ioctl_errno == EINVAL || !PDATA(pgm)->disable_no_cs)
avrdude_message(MSG_INFO, "%s: unable to set SPI mode %02X on %s. %s\n",
progname, mode, spidev, strerror(errno));
if(ioctl_errno == EINVAL && !PDATA(pgm)->disable_no_cs)
avrdude_message(MSG_INFO, "%s: try -x disable_no_cs\n", progname);
goto close_spidev;
}
fd_gpiochip = open(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;
goto close_spidev;
}
@ -223,8 +230,8 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
#endif
if (ret == -1) {
ret = -errno;
avrdude_message(MSG_INFO, "%s: error, unable to get GPIO line %d\n",
progname, pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE);
avrdude_message(MSG_INFO, "%s: unable to get GPIO line %d. %s\n",
progname, pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE, strerror(errno));
goto close_gpiochip;
}
@ -408,8 +415,7 @@ static int linuxspi_parseextparams(const PROGRAMMER *pgm, const LISTID extparms)
}
avrdude_message(MSG_INFO, "%s: linuxspi_parseextparams(): "
"invalid extended parameter '%s'\n",
progname, extended_param);
"invalid extended parameter '%s'\n", progname, extended_param);
rc = -1;
}