arm_adi_v5: separate ROM table parsing from command output [1/3]

In OpenOCD arm_adi_v5 we have already two implementations of code
for parsing the ADIv5 ROM table:
- in the commands "dap info" and "$dap_name info";
- in the function dap_lookup_cs_component().
Adding support for ADIv6 requires extending both implementations.

Moreover, current code does not handle few aspects of the ROM
parsing, e.g. the "Power Domain IDs".
To add such extensions both implementations should be touched.

I plan to add a command to parses (again) the ROM table and dump a
simple prototype of a configuration script for the target, useful
while analysing a new target.

Keeping aligned all these implementation would be too complex.

With focus to "dap info" command, decouple the part of code to
walk-through the ROM table from the code that creates the command
output.
The idea is to keep a single implementation for the walk-through
code, while parametrizing the output code to handle the generation
of a configuration script or the result of the function
dap_lookup_cs_component().

This change only targets the output of MEM-AP header
Further changes will target other parts of the code.

While there, add a message if MEM-AP is not accessible.

Change-Id: I112f637edfdb8688afb4e631297f6536da9604f1
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6819
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2022-01-14 18:20:09 +01:00
parent a73adb5241
commit 21f7885d1c
1 changed files with 44 additions and 6 deletions

View File

@ -1477,6 +1477,11 @@ static int dap_devtype_display(struct command_invocation *cmd, uint32_t devtype)
return ERROR_OK;
}
/* TODO: these prototypes will be removed in a following patch */
static int dap_info_mem_ap_header(struct command_invocation *cmd,
int retval, struct adiv5_ap *ap,
target_addr_t dbgbase, uint32_t apid);
static int rtp_cs_component(struct command_invocation *cmd,
struct adiv5_ap *ap, target_addr_t dbgbase, int depth);
@ -1634,13 +1639,48 @@ int dap_info_command(struct command_invocation *cmd,
int retval;
uint32_t apid;
target_addr_t dbgbase;
target_addr_t dbgaddr;
target_addr_t invalid_entry;
/* Now we read ROM table ID registers, ref. ARM IHI 0029B sec */
retval = dap_get_debugbase(ap, &dbgbase, &apid);
retval = dap_info_mem_ap_header(cmd, retval, ap, dbgbase, apid);
if (retval != ERROR_OK)
return retval;
if (apid == 0)
return ERROR_FAIL;
/* NOTE: a MEM-AP may have a single CoreSight component that's
* not a ROM table ... or have no such components at all.
*/
const unsigned int class = (apid & AP_REG_IDR_CLASS_MASK) >> AP_REG_IDR_CLASS_SHIFT;
if (class == AP_REG_IDR_CLASS_MEM_AP) {
if (is_64bit_ap(ap))
invalid_entry = 0xFFFFFFFFFFFFFFFFull;
else
invalid_entry = 0xFFFFFFFFul;
if (dbgbase != invalid_entry && (dbgbase & 0x3) != 0x2)
rtp_cs_component(cmd, ap, dbgbase & 0xFFFFFFFFFFFFF000ull, 0);
}
return ERROR_OK;
}
/* Actions for command "dap info" */
static int dap_info_mem_ap_header(struct command_invocation *cmd,
int retval, struct adiv5_ap *ap,
target_addr_t dbgbase, uint32_t apid)
{
target_addr_t invalid_entry;
if (retval != ERROR_OK) {
command_print(cmd, "\t\tCan't read MEM-AP, the corresponding core might be turned off");
return retval;
}
command_print(cmd, "AP ID register 0x%8.8" PRIx32, apid);
if (apid == 0) {
command_print(cmd, "No AP found at this ap 0x%x", ap->ap_num);
@ -1656,21 +1696,19 @@ int dap_info_command(struct command_invocation *cmd,
if (class == AP_REG_IDR_CLASS_MEM_AP) {
if (is_64bit_ap(ap))
dbgaddr = 0xFFFFFFFFFFFFFFFFull;
invalid_entry = 0xFFFFFFFFFFFFFFFFull;
else
dbgaddr = 0xFFFFFFFFul;
invalid_entry = 0xFFFFFFFFul;
command_print(cmd, "MEM-AP BASE " TARGET_ADDR_FMT, dbgbase);
if (dbgbase == dbgaddr || (dbgbase & 0x3) == 0x2) {
if (dbgbase == invalid_entry || (dbgbase & 0x3) == 0x2) {
command_print(cmd, "\tNo ROM table present");
} else {
if (dbgbase & 0x01)
command_print(cmd, "\tValid ROM table present");
else
command_print(cmd, "\tROM table in legacy format");
rtp_cs_component(cmd, ap, dbgbase & 0xFFFFFFFFFFFFF000ull, 0);
}
}