jtaglib: properly handle USB ram (cannot use quick memory access routines here)

This commit is contained in:
Triss 2022-07-31 20:21:51 +02:00
parent c801faeb80
commit cf8b986772
1 changed files with 10 additions and 10 deletions

View File

@ -655,7 +655,8 @@ static int read_words(device_t dev_base, const struct chipinfo_memory *m,
struct jtdev *p = (struct jtdev*)dev_base;
dbg_printc("read_words: ram: len=%d addr=%06x\n", len, addr);
if (len > 2 && !(len & 1)) {
/* USB ram cannot be accssed using the 'quick' routines */
if (len > 2 && !(len & 1) && !!strcmp(m->name, "UsbRam")) {
uint16_t* word = malloc((len>>1) * sizeof(*word));
if (!word) {
pr_error("jtaglib: read_words: failed to allocate memory");
@ -669,14 +670,12 @@ static int read_words(device_t dev_base, const struct chipinfo_memory *m,
data[2*i+1] = word[i] >> 8;
}
free(word);
return p->failed ? -1 : len;
}
for (unsigned int index = 0; index < len; index += 2) {
unsigned int word = jtag_read_mem(p, 16, addr+index);
data[index ] = word & 0x00ff;
data[index+1] = (word >> 8) & 0x00ff;
} else {
for (unsigned int index = 0; index < len; index += 2) {
unsigned int word = jtag_read_mem(p, 16, addr+index);
data[index ] = word & 0x00ff;
data[index+1] = (word >> 8) & 0x00ff;
}
}
return p->failed ? -1 : len;
@ -688,7 +687,8 @@ static int write_words(device_t dev_base, const struct chipinfo_memory *m,
if (m->type != CHIPINFO_MEMTYPE_FLASH) {
dbg_printc("write_words: ram: len=%d addr=%06x\n", len, addr);
if ((len > 2) && !(len & 1)) {
/* USB ram cannot be accssed using the 'quick' routines */
if ((len > 2) && !(len & 1) && !!strcmp(m->name, "UsbRam")) {
uint16_t* word = malloc((len>>1) * sizeof(*word));
if (!word) {
pr_error("jtaglib: write_words: failed to allocate memory");