From 2f97856c5b3097199c23ddbfe53a98d25895b500 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 4 Aug 2021 12:25:18 +0200 Subject: [PATCH] arm_adi_v5: fix signed offset in Class 0x1 ROM tables MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In both arm ADIv5 and ADIv6 documentation, for both Class 0x1 and Class 0x9 ROM tables, the offset field from ROM tables is supposed to be a signed value: "Negative values of OFFSET are permitted, using two’s complement." The commit ac22cdc57322 ("target/adiv5: Large Physical Address Extension") extends to 64 bits the addresses while managing the ROM tables. The offset is read as unsigned and in the former 32 bits implementation the wrap-around was hiding the need for converting the offset to signed. The new implementation requires the proper cast to the offset. On a STM32F411, without this fix the ROM table dump is incorrectly reporting addresses out of the 32 bit bus range: MEM-AP BASE 0xe00ff003 Valid ROM table present Component base address 0xe00ff000 Peripheral ID 0x00000a0411 Designer is 0x0a0, STMicroelectronics Part is 0x411, Unrecognized Component class is 0x1, ROM table MEMTYPE system memory present on bus ROMTABLE[0x0] = 0xfff0f003 Component base address 0x1e000e000 ^^^^^^^^^^^ Cast the offset before adding it to the base address of the ROM table. Change-Id: I8d31fd2b3d657286cb96f8e22fb00842baa728f7 Signed-off-by: Antonio Borneo Fixes: ac22cdc57322 ("target/adiv5: Large Physical Address Extension") Reviewed-on: http://openocd.zylin.com/6410 Tested-by: jenkins Reviewed-by: Daniel Goehring --- src/target/arm_adi_v5.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c index c421fe6a39..21788af793 100644 --- a/src/target/arm_adi_v5.c +++ b/src/target/arm_adi_v5.c @@ -1310,8 +1310,8 @@ static int dap_rom_display(struct command_invocation *cmd, command_print(cmd, "\t%sROMTABLE[0x%x] = 0x%" PRIx32 "", tabs, entry_offset, romentry); if (romentry & 0x01) { - /* Recurse */ - retval = dap_rom_display(cmd, ap, base_addr + (romentry & 0xFFFFF000), depth + 1); + /* Recurse. "romentry" is signed */ + retval = dap_rom_display(cmd, ap, base_addr + (int32_t)(romentry & 0xFFFFF000), depth + 1); if (retval != ERROR_OK) return retval; } else if (romentry != 0) { -- 2.30.2