rem: buf[1] = (page_size >> 8) & 0xff; buf[2] = page_size & 0xff;
add: buf[1] = (block_size >> 8) & 0xff; buf[2] = block_size & 0xff;
context: static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,                               int page_size, int n_bytes){  unsigned char buf[16];  int memtype;  unsigned int addr;  int a_div;  int i;  int tries;  unsigned int n;  int flash;  if (page_size == 0) {    page_size = 128;  }  if (strcmp(m->desc, "flash") == 0) {    memtype = 'F';    flash = 1;  }  else if (strcmp(m->desc, "eeprom") == 0) {    memtype = 'E';    flash = 0;  }  else {    return -2;  }  if ((m->op[AVR_OP_LOADPAGE_LO]) || (m->op[AVR_OP_READ_LO]))    a_div = 2;  else    a_div = 1;  if (n_bytes > m->size) {    n_bytes = m->size;    n = m->size;  }  else {    if ((n_bytes % page_size) != 0) {      n = n_bytes + page_size - (n_bytes % page_size);    }    else {      n = n_bytes;    }  }#if 0  fprintf(stderr,           "n_bytes   = %d\n"          "n         = %u\n"          "a_div     = %d\n"          "page_size = %d\n",          n_bytes, n, a_div, page_size);#endif       for (addr = 0; addr < n; addr += page_size) {    report_progress (addr, n_bytes, NULL);        /* Only skip on empty page if programming flash. */    if (flash) {      if (stk500_is_page_empty(addr, page_size, m->buf)) {          continue;      }    }    tries = 0;  retry:    tries++;    stk500_loadaddr(pgm, addr/a_div);    buf[0] = Cmnd_STK_PROG_PAGE;    buf[1] = (page_size >> 8) & 0xff;    buf[2] = page_size & 0xff;    buf[3] = memtype;    stk500_send(pgm, buf, 4);    for (i=0; i<page_size; i++) {      buf[0] = m->buf[addr + i];      stk500_send(pgm, buf, 1);    }    buf[0] = Sync_CRC_EOP;    stk500_send(pgm, buf, 1);    stk500_recv(pgm, buf, 1);    if (buf[0] == Resp_STK_NOSYNC) {      if (tries > 33) {        fprintf(stderr, "\n%s: stk500_paged_write(): can't get into sync\n",                progname);        return -3;      }      stk500_getsync(pgm);      goto retry;    }    else if (buf[0] != Resp_STK_INSYNC) {      fprintf(stderr,              "\n%s: stk500_paged_write(): (a) protocol error, "              "expect=0x%02x, resp=0x%02x\n",               progname, Resp_STK_INSYNC, buf[0]);      return -4;    }        stk500_recv(pgm, buf, 1);    if (buf[0] != Resp_STK_OK) {      fprintf(stderr,              "\n%s: stk500_paged_write(): (a) protocol error, "              "expect=0x%02x, resp=0x%02x\n",               progname, Resp_STK_INSYNC, buf[0]);      return -5;    }  }  return n;}