From d3c25a45f6536b09917e0fc3e6e51a6adbd4f992 Mon Sep 17 00:00:00 2001 From: Samuel Obuch Date: Tue, 8 Jul 2025 22:04:08 +0200 Subject: [PATCH] target/xtensa: fix unaligned memory read on retry When we read unaligned memory there is an offset in the albuff buffer, that we account for when copying back to original buffer. But in case the first access failed, the retry call already removed the offset, so doing it a second time shifts the returned memory. Change-Id: Ie255c367ca6a001bfe7038a76cf8a6443e398c51 Signed-off-by: Samuel Obuch Reviewed-on: https://review.openocd.org/c/openocd/+/8987 Tested-by: jenkins Reviewed-by: Ian Thompson Reviewed-by: Antonio Borneo --- src/target/xtensa/xtensa.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/target/xtensa/xtensa.c b/src/target/xtensa/xtensa.c index 1a402743f..f8c36b01d 100644 --- a/src/target/xtensa/xtensa.c +++ b/src/target/xtensa/xtensa.c @@ -2077,17 +2077,16 @@ int xtensa_read_memory(struct target *target, target_addr_t address, uint32_t si /* Disable fast memory access instructions and retry before reporting an error */ LOG_TARGET_DEBUG(target, "Disabling LDDR32.P/SDDR32.P"); xtensa->probe_lsddr32p = 0; - res = xtensa_read_memory(target, address, size, count, albuff); - bswap = false; + res = xtensa_read_memory(target, address, size, count, buffer); } else { LOG_TARGET_WARNING(target, "Failed reading %d bytes at address "TARGET_ADDR_FMT, count * size, address); } + } else { + if (bswap) + buf_bswap32(albuff, albuff, addrend_al - addrstart_al); + memcpy(buffer, albuff + (address & 3), (size * count)); } - - if (bswap) - buf_bswap32(albuff, albuff, addrend_al - addrstart_al); - memcpy(buffer, albuff + (address & 3), (size * count)); free(albuff); return res; }