Initialise memory before avr_set_bits() calls in stk500.c and stk500v2.c

This commit is contained in:
Stefan Rueger 2022-07-24 18:20:35 +01:00
parent affe4cb50a
commit 4babe183da
No known key found for this signature in database
GPG Key ID: B0B4F1FD86B1EC55
2 changed files with 11 additions and 5 deletions

View File

@ -212,7 +212,6 @@ static int stk500_chip_erase(PROGRAMMER * pgm, AVRPART * p)
pgm->pgm_led(pgm, ON); pgm->pgm_led(pgm, ON);
memset(cmd, 0, sizeof(cmd)); memset(cmd, 0, sizeof(cmd));
avr_set_bits(p->op[AVR_OP_CHIP_ERASE], cmd); avr_set_bits(p->op[AVR_OP_CHIP_ERASE], cmd);
pgm->cmd(pgm, cmd, res); pgm->cmd(pgm, cmd, res);
usleep(p->chip_erase_delay); usleep(p->chip_erase_delay);
@ -745,8 +744,8 @@ static int stk500_loadaddr(PROGRAMMER * pgm, AVRMEM * mem, unsigned int addr)
if (lext != NULL) { if (lext != NULL) {
ext_byte = (addr >> 16) & 0xff; ext_byte = (addr >> 16) & 0xff;
if (ext_byte != PDATA(pgm)->ext_addr_byte) { if (ext_byte != PDATA(pgm)->ext_addr_byte) {
/* Either this is the first addr load, or a 64K word boundary is /* Either this is the first addr load, or a different 64K word section */
* crossed, so set the ext addr byte */ memset(buf, 0, 4);
avr_set_bits(lext, buf); avr_set_bits(lext, buf);
avr_set_addr(lext, buf, addr); avr_set_addr(lext, buf, addr);
stk500_cmd(pgm, buf, buf); stk500_cmd(pgm, buf, buf);

View File

@ -991,6 +991,7 @@ static int stk500v2_chip_erase(PROGRAMMER * pgm, AVRPART * p)
buf[0] = CMD_CHIP_ERASE_ISP; buf[0] = CMD_CHIP_ERASE_ISP;
buf[1] = p->chip_erase_delay / 1000; buf[1] = p->chip_erase_delay / 1000;
buf[2] = 0; // use delay (?) buf[2] = 0; // use delay (?)
memset(buf+3, 0, 4);
avr_set_bits(p->op[AVR_OP_CHIP_ERASE], buf+3); avr_set_bits(p->op[AVR_OP_CHIP_ERASE], buf+3);
result = stk500v2_command(pgm, buf, 7, sizeof(buf)); result = stk500v2_command(pgm, buf, 7, sizeof(buf));
usleep(p->chip_erase_delay); usleep(p->chip_erase_delay);
@ -1121,8 +1122,8 @@ retry:
buf[5] = p->bytedelay; buf[5] = p->bytedelay;
buf[6] = p->pollvalue; buf[6] = p->pollvalue;
buf[7] = p->pollindex; buf[7] = p->pollindex;
memset(buf+8, 0, 4);
avr_set_bits(p->op[AVR_OP_PGM_ENABLE], buf+8); avr_set_bits(p->op[AVR_OP_PGM_ENABLE], buf+8);
buf[10] = buf[11] = 0;
rv = stk500v2_command(pgm, buf, 12, sizeof(buf)); rv = stk500v2_command(pgm, buf, 12, sizeof(buf));
@ -1957,12 +1958,12 @@ static int stk500isp_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
buf[0] = CMD_READ_SIGNATURE_ISP; buf[0] = CMD_READ_SIGNATURE_ISP;
} }
memset(buf + 1, 0, 5);
if ((op = mem->op[AVR_OP_READ]) == NULL) { if ((op = mem->op[AVR_OP_READ]) == NULL) {
avrdude_message(MSG_INFO, "%s: stk500isp_read_byte(): invalid operation AVR_OP_READ on %s memory\n", avrdude_message(MSG_INFO, "%s: stk500isp_read_byte(): invalid operation AVR_OP_READ on %s memory\n",
progname, mem->desc); progname, mem->desc);
return -1; return -1;
} }
memset(buf+2, 0, 4);
avr_set_bits(op, buf + 2); avr_set_bits(op, buf + 2);
if ((pollidx = avr_get_output_index(op)) == -1) { if ((pollidx = avr_get_output_index(op)) == -1) {
avrdude_message(MSG_INFO, "%s: stk500isp_read_byte(): cannot determine pollidx to read %s memory\n", avrdude_message(MSG_INFO, "%s: stk500isp_read_byte(): cannot determine pollidx to read %s memory\n",
@ -2314,6 +2315,7 @@ static int stk500v2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
progname, p->desc); progname, p->desc);
return -1; return -1;
} }
memset(cmds, 0, sizeof cmds);
avr_set_bits(m->op[AVR_OP_LOADPAGE_LO], cmds); avr_set_bits(m->op[AVR_OP_LOADPAGE_LO], cmds);
commandbuf[5] = cmds[0]; commandbuf[5] = cmds[0];
@ -2322,6 +2324,8 @@ static int stk500v2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
progname, p->desc); progname, p->desc);
return -1; return -1;
} }
memset(cmds, 0, sizeof cmds);
avr_set_bits(m->op[AVR_OP_WRITEPAGE], cmds); avr_set_bits(m->op[AVR_OP_WRITEPAGE], cmds);
commandbuf[6] = cmds[0]; commandbuf[6] = cmds[0];
@ -2335,6 +2339,7 @@ static int stk500v2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
progname, p->desc); progname, p->desc);
return -1; return -1;
} }
memset(cmds, 0, sizeof cmds);
avr_set_bits(wop, cmds); avr_set_bits(wop, cmds);
commandbuf[5] = cmds[0]; commandbuf[5] = cmds[0];
commandbuf[6] = 0; commandbuf[6] = 0;
@ -2346,6 +2351,7 @@ static int stk500v2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
progname, p->desc); progname, p->desc);
return -1; return -1;
} }
memset(cmds, 0, sizeof cmds);
avr_set_bits(rop, cmds); avr_set_bits(rop, cmds);
commandbuf[7] = cmds[0]; commandbuf[7] = cmds[0];
@ -2549,6 +2555,7 @@ static int stk500v2_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
progname, p->desc); progname, p->desc);
return -1; return -1;
} }
memset(cmds, 0, sizeof cmds);
avr_set_bits(rop, cmds); avr_set_bits(rop, cmds);
commandbuf[3] = cmds[0]; commandbuf[3] = cmds[0];