arm_adi_v5: separate ROM table parsing from command output [1/3] 19/6819/3
authorAntonio Borneo <borneo.antonio@gmail.com>
Fri, 14 Jan 2022 17:20:09 +0000 (18:20 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 14 May 2022 08:54:02 +0000 (08:54 +0000)
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
src/target/arm_adi_v5.c

index 4d24e8f2fc5ca7f8caebd43383ad618d06732754..333b1889af301d36b533c46720587403a49d0e2a 100644 (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);
                }
        }
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)