arm_adi_v5: Clean up dap info command 50/3150/3
authorAndreas Fritiofson <andreas.fritiofson@gmail.com>
Sun, 6 Dec 2015 12:06:12 +0000 (13:06 +0100)
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>
Tue, 29 Dec 2015 20:29:32 +0000 (20:29 +0000)
Reduce use of magic numbers and add AXI type MEM-AP detection. Don't try
to call dap_rom_display on a non-existent AP.

AP identification is unique per designer, so make sure the JEDEC code
matches ARM when interpreting the AP type.

Change-Id: I8e86b7de61811382afe99bf15094ab71b43f5fdf
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/3150
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
src/target/arm_adi_v5.c
src/target/arm_adi_v5.h

index 1e0594942ed59cd32582535a70177f4c48021af1..5d55d516114f5e3c9a264843c81df7db1c8958e9 100644 (file)
@@ -835,8 +835,8 @@ int dap_find_ap(struct adiv5_dap *dap, enum ap_type type_to_find, struct adiv5_a
                 * but just to be sure, try to continue searching if an error does happen.
                 */
                if ((retval == ERROR_OK) &&                  /* Register read success */
-                       ((id_val & 0x0FFF0000) == 0x04770000) && /* Jedec codes match */
-                       ((id_val & 0xF) == type_to_find)) {      /* type matches*/
+                       ((id_val & IDR_JEP106) == IDR_JEP106_ARM) && /* Jedec codes match */
+                       ((id_val & IDR_TYPE) == type_to_find)) {      /* type matches*/
 
                        LOG_DEBUG("Found %s at AP index: %d (IDR=0x%08" PRIX32 ")",
                                                (type_to_find == AP_TYPE_AHB_AP)  ? "AHB-AP"  :
@@ -1417,53 +1417,53 @@ static int dap_rom_display(struct command_context *cmd_ctx,
 static int dap_info_command(struct command_context *cmd_ctx,
                struct adiv5_ap *ap)
 {
-       struct adiv5_dap *dap = ap->dap;
        int retval;
        uint32_t dbgbase, apid;
        int romtable_present = 0;
        uint8_t mem_ap;
-       uint32_t ap_old;
 
+       /* Now we read ROM table ID registers, ref. ARM IHI 0029B sec  */
        retval = dap_get_debugbase(ap, &dbgbase, &apid);
        if (retval != ERROR_OK)
                return retval;
 
-       ap_old = dap_ap_get_select(dap);
-       dap_ap_select(dap, ap->ap_num);
-
-       /* Now we read ROM table ID registers, ref. ARM IHI 0029B sec  */
-       mem_ap = ((apid&0x10000) && ((apid&0x0F) != 0));
        command_print(cmd_ctx, "AP ID register 0x%8.8" PRIx32, apid);
-       if (apid) {
-               switch (apid&0x0F) {
-                       case 0:
-                               command_print(cmd_ctx, "\tType is JTAG-AP");
-                               break;
-                       case 1:
-                               command_print(cmd_ctx, "\tType is MEM-AP AHB");
-                               break;
-                       case 2:
-                               command_print(cmd_ctx, "\tType is MEM-AP APB");
-                               break;
-                       default:
-                               command_print(cmd_ctx, "\tUnknown AP type");
-                               break;
-               }
-
-               /* NOTE: a MEM-AP may have a single CoreSight component that's
-                * not a ROM table ... or have no such components at all.
-                */
-               if (mem_ap)
-                       command_print(cmd_ctx, "AP BASE 0x%8.8" PRIx32, dbgbase);
-       } else
+       if (apid == 0) {
                command_print(cmd_ctx, "No AP found at this ap 0x%x", ap->ap_num);
+               return ERROR_FAIL;
+       }
 
-       romtable_present = ((mem_ap) && (dbgbase != 0xFFFFFFFF));
-       if (romtable_present)
-               dap_rom_display(cmd_ctx, ap, dbgbase, 0);
-       else
-               command_print(cmd_ctx, "\tNo ROM table present");
-       dap_ap_select(dap, ap_old);
+       switch (apid & (IDR_JEP106 | IDR_TYPE)) {
+       case IDR_JEP106_ARM | AP_TYPE_JTAG_AP:
+               command_print(cmd_ctx, "\tType is JTAG-AP");
+               break;
+       case IDR_JEP106_ARM | AP_TYPE_AHB_AP:
+               command_print(cmd_ctx, "\tType is MEM-AP AHB");
+               break;
+       case IDR_JEP106_ARM | AP_TYPE_APB_AP:
+               command_print(cmd_ctx, "\tType is MEM-AP APB");
+               break;
+       case IDR_JEP106_ARM | AP_TYPE_AXI_AP:
+               command_print(cmd_ctx, "\tType is MEM-AP AXI");
+               break;
+       default:
+               command_print(cmd_ctx, "\tUnknown AP type");
+               break;
+       }
+
+       /* NOTE: a MEM-AP may have a single CoreSight component that's
+        * not a ROM table ... or have no such components at all.
+        */
+       mem_ap = (apid & IDR_CLASS) == AP_CLASS_MEM_AP;
+       if (mem_ap) {
+               command_print(cmd_ctx, "MEM-AP BASE 0x%8.8" PRIx32, dbgbase);
+
+               romtable_present = dbgbase != 0xFFFFFFFF;
+               if (romtable_present)
+                       dap_rom_display(cmd_ctx, ap, dbgbase, 0);
+               else
+                       command_print(cmd_ctx, "\tNo ROM table present");
+       }
 
        return ERROR_OK;
 }
index 884399a53f0801b8d7f953bb65d0bbf767599090..faf725fca816c52c19d2e9f0569ef6eca186f245 100644 (file)
 #define CSW_SPROT           (1UL << 30)
 #define CSW_DBGSWENABLE     (1UL << 31)
 
+/* Fields of the MEM-AP's IDR register */
+#define IDR_REV     (0xFUL << 28)
+#define IDR_JEP106  (0x7FFUL << 17)
+#define IDR_CLASS   (0xFUL << 13)
+#define IDR_VARIANT (0xFUL << 4)
+#define IDR_TYPE    (0xFUL << 0)
+
+#define IDR_JEP106_ARM 0x04760000
+
 /**
  * This represents an ARM Debug Interface (v5) Access Port (AP).
  * Most common is a MEM-AP, for memory access.
@@ -275,6 +284,14 @@ struct dap_ops {
        int (*run)(struct adiv5_dap *dap);
 };
 
+/*
+ * Access Port classes
+ */
+enum ap_class {
+       AP_CLASS_NONE   = 0x00000,  /* No class defined */
+       AP_CLASS_MEM_AP = 0x10000,  /* MEM-AP */
+};
+
 /*
  * Access Port types
  */

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)