add: if (rc == -1) fprintf(stderr, "read operation not supported on memory type \"%s\"\n", mem->desc);
context: int cmd_dump(int fd, struct avrpart * p, int argc, char * argv[]){  static char prevmem[128] = {0};  char * e;  unsigned char * buf;  int maxsize;  unsigned long i;  static unsigned long addr=0;  static int len=64;  AVRMEM * mem;  char * memtype = NULL;  int rc;  if (!((argc == 2) || (argc == 4))) {    fprintf(stderr, "Usage: dump <memtype> [<addr> <len>]\n");    return -1;  }  memtype = argv[1];  if (strncmp(prevmem, memtype, strlen(memtype)) != 0) {    addr = 0;    len  = 64;    strncpy(prevmem, memtype, sizeof(prevmem)-1);    prevmem[sizeof(prevmem)-1] = 0;  }  mem = avr_locate_mem(p, memtype);  if (mem == NULL) {    fprintf(stderr, "\"%s\" memory type not defined for part \"%s\"\n",            memtype, p->desc);    return -1;  }  if (argc == 4) {    addr = strtoul(argv[2], &e, 0);    if (*e || (e == argv[2])) {      fprintf(stderr, "%s (dump): can't parse address \"%s\"\n",              progname, argv[2]);      return -1;    }    len = strtol(argv[3], &e, 0);    if (*e || (e == argv[3])) {      fprintf(stderr, "%s (dump): can't parse length \"%s\"\n",              progname, argv[3]);      return -1;    }  }  maxsize = mem->size;  if (addr > maxsize) {    fprintf(stderr,             "%s (dump): address 0x%05lx is out of range for %s memory\n",            progname, addr, mem->desc);    return -1;  }  /* trim len if nessary to not read past the end of memory */  if ((addr + len) > maxsize)    len = maxsize - addr;  buf = malloc(len);  if (buf == NULL) {    fprintf(stderr, "%s (dump): out of memory\n", progname);    return -1;  }  for (i=0; i<len; i++) {    rc = avr_read_byte(fd, p, mem, addr+i, &buf[i]);    if (rc != 0) {      fprintf(stderr, "error reading %s address 0x%05lx of part %s\n",              mem->desc, addr+i, p->desc);      return -1;    }  }  hexdump_buf(stdout, addr, buf, len);  fprintf(stdout, "\n");  free(buf);  addr = addr + len;  return 0;}