Add support for memory "fill" with arbitrary data too
If you run the following command: $ write eeprom 0x00 0x10 A B C ... It will write the following data to EEPROM: |ABCCCCCCCCCCCCCC| starting from address 0x00
This commit is contained in:
parent
c007dc7d24
commit
2a92b8cce4
62
src/term.c
62
src/term.c
|
@ -336,7 +336,7 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
unsigned char b;
|
unsigned char b;
|
||||||
int rc;
|
int rc;
|
||||||
int werror;
|
int werror;
|
||||||
int write_mode;
|
int write_mode, start_offset;
|
||||||
AVRMEM * mem;
|
AVRMEM * mem;
|
||||||
|
|
||||||
if (argc < 4) {
|
if (argc < 4) {
|
||||||
|
@ -370,8 +370,8 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out how many bytes to write to memory
|
// Figure out how many bytes there is to write to memory
|
||||||
if(strcmp(argv[5], "...") == 0) {
|
if(strcmp(argv[argc - 1], "...") == 0) {
|
||||||
write_mode = WRITE_MODE_FILL;
|
write_mode = WRITE_MODE_FILL;
|
||||||
len = strtoul(argv[3], &e, 0);
|
len = strtoul(argv[3], &e, 0);
|
||||||
if (*e || (e == argv[3])) {
|
if (*e || (e == argv[3])) {
|
||||||
|
@ -397,38 +397,34 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(write_mode == WRITE_MODE_STANDARD) {
|
if (write_mode == WRITE_MODE_STANDARD)
|
||||||
for (i=3; i<argc; i++) {
|
start_offset = 3; // Data to write from argument no. 3
|
||||||
unsigned char write_val = strtoul(argv[i], &e, 0);
|
else if (write_mode == WRITE_MODE_FILL)
|
||||||
if (*e || (e == argv[i])) {
|
start_offset = 4;
|
||||||
// If passed argument is a single character
|
else {
|
||||||
if(argv[i][1] == '\0') {
|
avrdude_message(MSG_INFO, "%s (write): invalid write mode %d\n",
|
||||||
write_val = argv[i][0];
|
progname, write_mode);
|
||||||
} else {
|
return -1;
|
||||||
avrdude_message(MSG_INFO, "%s (write): can't parse byte \"%s\"\n",
|
}
|
||||||
progname, argv[i]);
|
|
||||||
free(buf);
|
unsigned char write_val;
|
||||||
return -1;
|
for (i = start_offset; i < argc - start_offset + 3; i++) {
|
||||||
}
|
write_val = strtoul(argv[i], &e, 0);
|
||||||
|
if (*e || (e == argv[i])) {
|
||||||
|
// Accept if passed argument is a single character
|
||||||
|
if (argv[i][1] == '\0') {
|
||||||
|
write_val = argv[i][0];
|
||||||
|
} else {
|
||||||
|
avrdude_message(MSG_INFO, "%s (write ...): can't parse byte \"%s\"\n",
|
||||||
|
progname, argv[i]);
|
||||||
|
free(buf);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
buf[i-3] = write_val;
|
|
||||||
}
|
|
||||||
} else if(write_mode == WRITE_MODE_FILL) {
|
|
||||||
unsigned char fill_val = strtoul(argv[4], &e, 0);
|
|
||||||
if (*e || (e == argv[4])) {
|
|
||||||
// If passed argument is a single character
|
|
||||||
if(argv[4][1] == '\0') {
|
|
||||||
fill_val = argv[4][0];
|
|
||||||
} else {
|
|
||||||
avrdude_message(MSG_INFO, "%s (write ...): can't parse byte \"%s\"\n",
|
|
||||||
progname, argv[4]);
|
|
||||||
free(buf);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
buf[i] = fill_val;
|
|
||||||
}
|
}
|
||||||
|
buf[i - start_offset] = write_val;
|
||||||
|
}
|
||||||
|
for (; i < len + start_offset; i++) {
|
||||||
|
buf[i - start_offset] = write_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
pgm->err_led(pgm, OFF);
|
pgm->err_led(pgm, OFF);
|
||||||
|
|
Loading…
Reference in New Issue