jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / src / target / cortex_a.c
index faed2d531360c341296b37b97c4d5472b7f4848c..7fa0c4e8b72a51cfa6b526151b21a05d3620482b 100644 (file)
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /***************************************************************************
  *   Copyright (C) 2005 by Dominic Rath                                    *
  *   Dominic.Rath@gmx.de                                                   *
  *   Copyright (C) 2016 Chengyu Zheng                                      *
  *   chengyu.zheng@polimi.it : watchpoint support                          *
  *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
- *                                                                         *
  *   Cortex-A8(tm) TRM, ARM DDI 0344H                                      *
  *   Cortex-A9(tm) TRM, ARM DDI 0407F                                      *
  *   Cortex-A4(tm) TRM, ARM DDI 0363E                                      *
 #include "armv7a_mmu.h"
 #include "target_request.h"
 #include "target_type.h"
+#include "arm_coresight.h"
 #include "arm_opcodes.h"
 #include "arm_semihosting.h"
 #include "jtag/interface.h"
 #include "transport/transport.h"
 #include "smp.h"
 #include <helper/bits.h>
+#include <helper/nvp.h>
 #include <helper/time_support.h>
 
 static int cortex_a_poll(struct target *target);
@@ -480,6 +471,28 @@ static int cortex_a_instr_write_data_r0(struct arm_dpm *dpm,
        return retval;
 }
 
+static int cortex_a_instr_write_data_r0_r1(struct arm_dpm *dpm,
+       uint32_t opcode, uint64_t data)
+{
+       struct cortex_a_common *a = dpm_to_a(dpm);
+       uint32_t dscr = DSCR_INSTR_COMP;
+       int retval;
+
+       retval = cortex_a_instr_write_data_rt_dcc(dpm, 0, data & 0xffffffffULL);
+       if (retval != ERROR_OK)
+               return retval;
+
+       retval = cortex_a_instr_write_data_rt_dcc(dpm, 1, data >> 32);
+       if (retval != ERROR_OK)
+               return retval;
+
+       /* then the opcode, taking data from R0, R1 */
+       retval = cortex_a_exec_opcode(a->armv7a_common.arm.target,
+                       opcode,
+                       &dscr);
+       return retval;
+}
+
 static int cortex_a_instr_cpsr_sync(struct arm_dpm *dpm)
 {
        struct target *target = dpm->arm->target;
@@ -548,6 +561,29 @@ static int cortex_a_instr_read_data_r0(struct arm_dpm *dpm,
        return cortex_a_instr_read_data_rt_dcc(dpm, 0, data);
 }
 
+static int cortex_a_instr_read_data_r0_r1(struct arm_dpm *dpm,
+       uint32_t opcode, uint64_t *data)
+{
+       uint32_t lo, hi;
+       int retval;
+
+       /* the opcode, writing data to RO, R1 */
+       retval = cortex_a_instr_read_data_r0(dpm, opcode, &lo);
+       if (retval != ERROR_OK)
+               return retval;
+
+       *data = lo;
+
+       /* write R1 to DCC */
+       retval = cortex_a_instr_read_data_rt_dcc(dpm, 1, &hi);
+       if (retval != ERROR_OK)
+               return retval;
+
+       *data |= (uint64_t)hi << 32;
+
+       return retval;
+}
+
 static int cortex_a_bpwp_enable(struct arm_dpm *dpm, unsigned index_t,
        uint32_t addr, uint32_t control)
 {
@@ -621,10 +657,12 @@ static int cortex_a_dpm_setup(struct cortex_a_common *a, uint32_t didr)
 
        dpm->instr_write_data_dcc = cortex_a_instr_write_data_dcc;
        dpm->instr_write_data_r0 = cortex_a_instr_write_data_r0;
+       dpm->instr_write_data_r0_r1 = cortex_a_instr_write_data_r0_r1;
        dpm->instr_cpsr_sync = cortex_a_instr_cpsr_sync;
 
        dpm->instr_read_data_dcc = cortex_a_instr_read_data_dcc;
        dpm->instr_read_data_r0 = cortex_a_instr_read_data_r0;
+       dpm->instr_read_data_r0_r1 = cortex_a_instr_read_data_r0_r1;
 
        dpm->bpwp_enable = cortex_a_bpwp_enable;
        dpm->bpwp_disable = cortex_a_bpwp_disable;
@@ -638,14 +676,11 @@ static int cortex_a_dpm_setup(struct cortex_a_common *a, uint32_t didr)
 static struct target *get_cortex_a(struct target *target, int32_t coreid)
 {
        struct target_list *head;
-       struct target *curr;
 
-       head = target->head;
-       while (head != (struct target_list *)NULL) {
-               curr = head->target;
+       foreach_smp_target(head, target->smp_targets) {
+               struct target *curr = head->target;
                if ((curr->coreid == coreid) && (curr->state == TARGET_HALTED))
                        return curr;
-               head = head->next;
        }
        return target;
 }
@@ -655,14 +690,12 @@ static int cortex_a_halt_smp(struct target *target)
 {
        int retval = 0;
        struct target_list *head;
-       struct target *curr;
-       head = target->head;
-       while (head != (struct target_list *)NULL) {
-               curr = head->target;
+
+       foreach_smp_target(head, target->smp_targets) {
+               struct target *curr = head->target;
                if ((curr != target) && (curr->state != TARGET_HALTED)
                        && target_was_examined(curr))
                        retval += cortex_a_halt(curr);
-               head = head->next;
        }
        return retval;
 }
@@ -683,7 +716,7 @@ static int update_halt_gdb(struct target *target)
        if (target->gdb_service)
                gdb_target = target->gdb_service->target;
 
-       foreach_smp_target(head, target->head) {
+       foreach_smp_target(head, target->smp_targets) {
                curr = head->target;
                /* skip calling context */
                if (curr == target)
@@ -704,7 +737,7 @@ static int update_halt_gdb(struct target *target)
        }
 
        /* after all targets were updated, poll the gdb serving target */
-       if (gdb_target != NULL && gdb_target != target)
+       if (gdb_target && gdb_target != target)
                cortex_a_poll(gdb_target);
        return retval;
 }
@@ -726,7 +759,7 @@ static int cortex_a_poll(struct target *target)
        /*  the next polling trigger an halt event sent to gdb */
        if ((target->state == TARGET_HALTED) && (target->smp) &&
                (target->gdb_service) &&
-               (target->gdb_service->target == NULL)) {
+               (!target->gdb_service->target)) {
                target->gdb_service->target =
                        get_cortex_a(target, target->gdb_service->core[1]);
                target_call_event_callbacks(target, TARGET_EVENT_HALTED);
@@ -822,11 +855,11 @@ static int cortex_a_internal_restore(struct target *target, int current,
                armv7m->core_cache->reg_list[ARMV7M_PRIMASK].valid = true;
 
                /* Make sure we are in Thumb mode */
-               buf_set_u32(armv7m->core_cache->reg_list[ARMV7M_xPSR].value, 0, 32,
-                       buf_get_u32(armv7m->core_cache->reg_list[ARMV7M_xPSR].value, 0,
+               buf_set_u32(armv7m->core_cache->reg_list[ARMV7M_XPSR].value, 0, 32,
+                       buf_get_u32(armv7m->core_cache->reg_list[ARMV7M_XPSR].value, 0,
                        32) | (1 << 24));
-               armv7m->core_cache->reg_list[ARMV7M_xPSR].dirty = true;
-               armv7m->core_cache->reg_list[ARMV7M_xPSR].valid = true;
+               armv7m->core_cache->reg_list[ARMV7M_XPSR].dirty = true;
+               armv7m->core_cache->reg_list[ARMV7M_XPSR].valid = true;
        }
 #endif
 
@@ -950,11 +983,10 @@ static int cortex_a_restore_smp(struct target *target, int handle_breakpoints)
 {
        int retval = 0;
        struct target_list *head;
-       struct target *curr;
        target_addr_t address;
-       head = target->head;
-       while (head != (struct target_list *)NULL) {
-               curr = head->target;
+
+       foreach_smp_target(head, target->smp_targets) {
+               struct target *curr = head->target;
                if ((curr != target) && (curr->state != TARGET_RUNNING)
                        && target_was_examined(curr)) {
                        /*  resume current address , not in step mode */
@@ -962,8 +994,6 @@ static int cortex_a_restore_smp(struct target *target, int handle_breakpoints)
                                        handle_breakpoints, 0);
                        retval += cortex_a_internal_restart(curr);
                }
-               head = head->next;
-
        }
        return retval;
 }
@@ -1164,7 +1194,7 @@ static int cortex_a_step(struct target *target, int current, target_addr_t addre
        int retval;
 
        if (target->state != TARGET_HALTED) {
-               LOG_WARNING("target not halted");
+               LOG_TARGET_ERROR(target, "not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
 
@@ -1192,7 +1222,7 @@ static int cortex_a_step(struct target *target, int current, target_addr_t addre
        stepbreakpoint.length = (arm->core_state == ARM_STATE_THUMB)
                ? 2 : 4;
        stepbreakpoint.type = BKPT_HARD;
-       stepbreakpoint.set = 0;
+       stepbreakpoint.is_set = false;
 
        /* Disable interrupts during single step if requested */
        if (cortex_a->isrmasking_mode == CORTEX_A_ISRMASK_ON) {
@@ -1272,7 +1302,7 @@ static int cortex_a_set_breakpoint(struct target *target,
        struct armv7a_common *armv7a = &cortex_a->armv7a_common;
        struct cortex_a_brp *brp_list = cortex_a->brp_list;
 
-       if (breakpoint->set) {
+       if (breakpoint->is_set) {
                LOG_WARNING("breakpoint already set");
                return ERROR_OK;
        }
@@ -1284,7 +1314,7 @@ static int cortex_a_set_breakpoint(struct target *target,
                        LOG_ERROR("ERROR Can not find free Breakpoint Register Pair");
                        return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
                }
-               breakpoint->set = brp_i + 1;
+               breakpoint_hw_set(breakpoint, brp_i);
                if (breakpoint->length == 2)
                        byte_addr_select = (3 << (breakpoint->address & 0x02));
                control = ((matchmode & 0x7) << 20)
@@ -1349,7 +1379,7 @@ static int cortex_a_set_breakpoint(struct target *target,
                armv7a_l1_i_cache_inval_virt(target, breakpoint->address,
                                                 breakpoint->length);
 
-               breakpoint->set = 0x11; /* Any nice value but 0 */
+               breakpoint->is_set = true;
        }
 
        return ERROR_OK;
@@ -1366,7 +1396,7 @@ static int cortex_a_set_context_breakpoint(struct target *target,
        struct armv7a_common *armv7a = &cortex_a->armv7a_common;
        struct cortex_a_brp *brp_list = cortex_a->brp_list;
 
-       if (breakpoint->set) {
+       if (breakpoint->is_set) {
                LOG_WARNING("breakpoint already set");
                return retval;
        }
@@ -1380,7 +1410,7 @@ static int cortex_a_set_context_breakpoint(struct target *target,
                return ERROR_FAIL;
        }
 
-       breakpoint->set = brp_i + 1;
+       breakpoint_hw_set(breakpoint, brp_i);
        control = ((matchmode & 0x7) << 20)
                | (byte_addr_select << 5)
                | (3 << 1) | 1;
@@ -1418,7 +1448,7 @@ static int cortex_a_set_hybrid_breakpoint(struct target *target, struct breakpoi
        struct armv7a_common *armv7a = &cortex_a->armv7a_common;
        struct cortex_a_brp *brp_list = cortex_a->brp_list;
 
-       if (breakpoint->set) {
+       if (breakpoint->is_set) {
                LOG_WARNING("breakpoint already set");
                return retval;
        }
@@ -1443,7 +1473,7 @@ static int cortex_a_set_hybrid_breakpoint(struct target *target, struct breakpoi
                return ERROR_FAIL;
        }
 
-       breakpoint->set = brp_1 + 1;
+       breakpoint_hw_set(breakpoint, brp_1);
        breakpoint->linked_brp = brp_2;
        control_ctx = ((ctx_machmode & 0x7) << 20)
                | (brp_2 << 16)
@@ -1492,16 +1522,16 @@ static int cortex_a_unset_breakpoint(struct target *target, struct breakpoint *b
        struct armv7a_common *armv7a = &cortex_a->armv7a_common;
        struct cortex_a_brp *brp_list = cortex_a->brp_list;
 
-       if (!breakpoint->set) {
+       if (!breakpoint->is_set) {
                LOG_WARNING("breakpoint not set");
                return ERROR_OK;
        }
 
        if (breakpoint->type == BKPT_HARD) {
                if ((breakpoint->address != 0) && (breakpoint->asid != 0)) {
-                       int brp_i = breakpoint->set - 1;
+                       int brp_i = breakpoint->number;
                        int brp_j = breakpoint->linked_brp;
-                       if ((brp_i < 0) || (brp_i >= cortex_a->brp_num)) {
+                       if (brp_i >= cortex_a->brp_num) {
                                LOG_DEBUG("Invalid BRP number in breakpoint");
                                return ERROR_OK;
                        }
@@ -1540,12 +1570,12 @@ static int cortex_a_unset_breakpoint(struct target *target, struct breakpoint *b
                        if (retval != ERROR_OK)
                                return retval;
                        breakpoint->linked_brp = 0;
-                       breakpoint->set = 0;
+                       breakpoint->is_set = false;
                        return ERROR_OK;
 
                } else {
-                       int brp_i = breakpoint->set - 1;
-                       if ((brp_i < 0) || (brp_i >= cortex_a->brp_num)) {
+                       int brp_i = breakpoint->number;
+                       if (brp_i >= cortex_a->brp_num) {
                                LOG_DEBUG("Invalid BRP number in breakpoint");
                                return ERROR_OK;
                        }
@@ -1564,7 +1594,7 @@ static int cortex_a_unset_breakpoint(struct target *target, struct breakpoint *b
                                        brp_list[brp_i].value);
                        if (retval != ERROR_OK)
                                return retval;
-                       breakpoint->set = 0;
+                       breakpoint->is_set = false;
                        return ERROR_OK;
                }
        } else {
@@ -1596,7 +1626,7 @@ static int cortex_a_unset_breakpoint(struct target *target, struct breakpoint *b
                armv7a_l1_i_cache_inval_virt(target, breakpoint->address,
                                                 breakpoint->length);
        }
-       breakpoint->set = 0;
+       breakpoint->is_set = false;
 
        return ERROR_OK;
 }
@@ -1662,7 +1692,7 @@ static int cortex_a_remove_breakpoint(struct target *target, struct breakpoint *
        }
 #endif
 
-       if (breakpoint->set) {
+       if (breakpoint->is_set) {
                cortex_a_unset_breakpoint(target, breakpoint);
                if (breakpoint->type == BKPT_HARD)
                        cortex_a->brp_num_available++;
@@ -1695,7 +1725,7 @@ static int cortex_a_set_watchpoint(struct target *target, struct watchpoint *wat
        struct armv7a_common *armv7a = &cortex_a->armv7a_common;
        struct cortex_a_wrp *wrp_list = cortex_a->wrp_list;
 
-       if (watchpoint->set) {
+       if (watchpoint->is_set) {
                LOG_WARNING("watchpoint already set");
                return retval;
        }
@@ -1748,7 +1778,7 @@ static int cortex_a_set_watchpoint(struct target *target, struct watchpoint *wat
                break;
        }
 
-       watchpoint->set = wrp_i + 1;
+       watchpoint_set(watchpoint, wrp_i);
        control = (address_mask << 24) |
                (byte_address_select << 5) |
                (load_store_access_control << 3) |
@@ -1791,13 +1821,13 @@ static int cortex_a_unset_watchpoint(struct target *target, struct watchpoint *w
        struct armv7a_common *armv7a = &cortex_a->armv7a_common;
        struct cortex_a_wrp *wrp_list = cortex_a->wrp_list;
 
-       if (!watchpoint->set) {
+       if (!watchpoint->is_set) {
                LOG_WARNING("watchpoint not set");
                return ERROR_OK;
        }
 
-       int wrp_i = watchpoint->set - 1;
-       if (wrp_i < 0 || wrp_i >= cortex_a->wrp_num) {
+       int wrp_i = watchpoint->number;
+       if (wrp_i >= cortex_a->wrp_num) {
                LOG_DEBUG("Invalid WRP number in watchpoint");
                return ERROR_OK;
        }
@@ -1816,7 +1846,7 @@ static int cortex_a_unset_watchpoint(struct target *target, struct watchpoint *w
                        wrp_list[wrp_i].value);
        if (retval != ERROR_OK)
                return retval;
-       watchpoint->set = 0;
+       watchpoint->is_set = false;
 
        return ERROR_OK;
 }
@@ -1858,7 +1888,7 @@ static int cortex_a_remove_watchpoint(struct target *target, struct watchpoint *
 {
        struct cortex_a_common *cortex_a = target_to_cortex_a(target);
 
-       if (watchpoint->set) {
+       if (watchpoint->is_set) {
                cortex_a->wrp_num_available++;
                cortex_a_unset_watchpoint(target, watchpoint);
        }
@@ -2242,7 +2272,7 @@ static int cortex_a_write_cpu_memory(struct target *target,
        LOG_DEBUG("Writing CPU memory address 0x%" PRIx32 " size %"  PRIu32 " count %"  PRIu32,
                          address, size, count);
        if (target->state != TARGET_HALTED) {
-               LOG_WARNING("target not halted");
+               LOG_TARGET_ERROR(target, "not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
 
@@ -2264,7 +2294,7 @@ static int cortex_a_write_cpu_memory(struct target *target,
        /* Switch to non-blocking mode if not already in that mode. */
        retval = cortex_a_set_dcc_mode(target, DSCR_EXT_DCC_NON_BLOCKING, &dscr);
        if (retval != ERROR_OK)
-               goto out;
+               return retval;
 
        /* Mark R0 as dirty. */
        arm_reg_current(arm, 0)->dirty = true;
@@ -2272,16 +2302,16 @@ static int cortex_a_write_cpu_memory(struct target *target,
        /* Read DFAR and DFSR, as they will be modified in the event of a fault. */
        retval = cortex_a_read_dfar_dfsr(target, &orig_dfar, &orig_dfsr, &dscr);
        if (retval != ERROR_OK)
-               goto out;
+               return retval;
 
        /* Get the memory address into R0. */
        retval = mem_ap_write_atomic_u32(armv7a->debug_ap,
                        armv7a->debug_base + CPUDBG_DTRRX, address);
        if (retval != ERROR_OK)
-               goto out;
+               return retval;
        retval = cortex_a_exec_opcode(target, ARMV4_5_MRC(14, 0, 0, 0, 5, 0), &dscr);
        if (retval != ERROR_OK)
-               goto out;
+               return retval;
 
        if (size == 4 && (address % 4) == 0) {
                /* We are doing a word-aligned transfer, so use fast mode. */
@@ -2306,7 +2336,6 @@ static int cortex_a_write_cpu_memory(struct target *target,
                retval = cortex_a_write_cpu_memory_slow(target, size, count, buffer, &dscr);
        }
 
-out:
        final_retval = retval;
 
        /* Switch to non-blocking mode if not already in that mode. */
@@ -2560,7 +2589,7 @@ static int cortex_a_read_cpu_memory(struct target *target,
        LOG_DEBUG("Reading CPU memory address 0x%" PRIx32 " size %"  PRIu32 " count %"  PRIu32,
                          address, size, count);
        if (target->state != TARGET_HALTED) {
-               LOG_WARNING("target not halted");
+               LOG_TARGET_ERROR(target, "not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
 
@@ -2582,7 +2611,7 @@ static int cortex_a_read_cpu_memory(struct target *target,
        /* Switch to non-blocking mode if not already in that mode. */
        retval = cortex_a_set_dcc_mode(target, DSCR_EXT_DCC_NON_BLOCKING, &dscr);
        if (retval != ERROR_OK)
-               goto out;
+               return retval;
 
        /* Mark R0 as dirty. */
        arm_reg_current(arm, 0)->dirty = true;
@@ -2590,16 +2619,16 @@ static int cortex_a_read_cpu_memory(struct target *target,
        /* Read DFAR and DFSR, as they will be modified in the event of a fault. */
        retval = cortex_a_read_dfar_dfsr(target, &orig_dfar, &orig_dfsr, &dscr);
        if (retval != ERROR_OK)
-               goto out;
+               return retval;
 
        /* Get the memory address into R0. */
        retval = mem_ap_write_atomic_u32(armv7a->debug_ap,
                        armv7a->debug_base + CPUDBG_DTRRX, address);
        if (retval != ERROR_OK)
-               goto out;
+               return retval;
        retval = cortex_a_exec_opcode(target, ARMV4_5_MRC(14, 0, 0, 0, 5, 0), &dscr);
        if (retval != ERROR_OK)
-               goto out;
+               return retval;
 
        if (size == 4 && (address % 4) == 0) {
                /* We are doing a word-aligned transfer, so use fast mode. */
@@ -2625,7 +2654,6 @@ static int cortex_a_read_cpu_memory(struct target *target,
                retval = cortex_a_read_cpu_memory_slow(target, size, count, buffer, &dscr);
        }
 
-out:
        final_retval = retval;
 
        /* Switch to non-blocking mode if not already in that mode. */
@@ -2886,16 +2914,27 @@ static int cortex_a_examine_first(struct target *target)
        struct cortex_a_common *cortex_a = target_to_cortex_a(target);
        struct armv7a_common *armv7a = &cortex_a->armv7a_common;
        struct adiv5_dap *swjdp = armv7a->arm.dap;
+       struct adiv5_private_config *pc = target->private_config;
 
        int i;
        int retval = ERROR_OK;
        uint32_t didr, cpuid, dbg_osreg, dbg_idpfr1;
 
-       /* Search for the APB-AP - it is needed for access to debug registers */
-       retval = dap_find_ap(swjdp, AP_TYPE_APB_AP, &armv7a->debug_ap);
-       if (retval != ERROR_OK) {
-               LOG_ERROR("Could not find APB-AP for debug access");
-               return retval;
+       if (!armv7a->debug_ap) {
+               if (pc->ap_num == DP_APSEL_INVALID) {
+                       /* Search for the APB-AP - it is needed for access to debug registers */
+                       retval = dap_find_get_ap(swjdp, AP_TYPE_APB_AP, &armv7a->debug_ap);
+                       if (retval != ERROR_OK) {
+                               LOG_ERROR("Could not find APB-AP for debug access");
+                               return retval;
+                       }
+               } else {
+                       armv7a->debug_ap = dap_get_ap(swjdp, pc->ap_num);
+                       if (!armv7a->debug_ap) {
+                               LOG_ERROR("Cannot get AP");
+                               return ERROR_FAIL;
+                       }
+               }
        }
 
        retval = mem_ap_init(armv7a->debug_ap);
@@ -2907,18 +2946,11 @@ static int cortex_a_examine_first(struct target *target)
        armv7a->debug_ap->memaccess_tck = 80;
 
        if (!target->dbgbase_set) {
-               target_addr_t dbgbase;
-               /* Get ROM Table base */
-               uint32_t apid;
-               int32_t coreidx = target->coreid;
                LOG_DEBUG("%s's dbgbase is not set, trying to detect using the ROM table",
                          target->cmd_name);
-               retval = dap_get_debugbase(armv7a->debug_ap, &dbgbase, &apid);
-               if (retval != ERROR_OK)
-                       return retval;
-               /* Lookup 0x15 -- Processor DAP */
-               retval = dap_lookup_cs_component(armv7a->debug_ap, dbgbase, 0x15,
-                               &armv7a->debug_base, &coreidx);
+               /* Lookup Processor DAP */
+               retval = dap_lookup_cs_component(armv7a->debug_ap, ARM_CS_C9_DEVTYPE_CORE_DEBUG,
+                               &armv7a->debug_base, target->coreid);
                if (retval != ERROR_OK) {
                        LOG_ERROR("Can't detect %s's dbgbase from the ROM table; you need to specify it explicitly.",
                                  target->cmd_name);
@@ -2957,29 +2989,29 @@ static int cortex_a_examine_first(struct target *target)
                                    armv7a->debug_base + CPUDBG_PRSR, &dbg_osreg);
        if (retval != ERROR_OK)
                return retval;
-       LOG_DEBUG("target->coreid %" PRId32 " DBGPRSR  0x%" PRIx32, target->coreid, dbg_osreg);
+       LOG_TARGET_DEBUG(target, "DBGPRSR  0x%" PRIx32, dbg_osreg);
 
        if ((dbg_osreg & PRSR_POWERUP_STATUS) == 0) {
-               LOG_ERROR("target->coreid %" PRId32 " powered down!", target->coreid);
+               LOG_TARGET_ERROR(target, "powered down!");
                target->state = TARGET_UNKNOWN; /* TARGET_NO_POWER? */
                return ERROR_TARGET_INIT_FAILED;
        }
 
        if (dbg_osreg & PRSR_STICKY_RESET_STATUS)
-               LOG_DEBUG("target->coreid %" PRId32 " was reset!", target->coreid);
+               LOG_TARGET_DEBUG(target, "was reset!");
 
        /* Read DBGOSLSR and check if OSLK is implemented */
        retval = mem_ap_read_atomic_u32(armv7a->debug_ap,
                                armv7a->debug_base + CPUDBG_OSLSR, &dbg_osreg);
        if (retval != ERROR_OK)
                return retval;
-       LOG_DEBUG("target->coreid %" PRId32 " DBGOSLSR 0x%" PRIx32, target->coreid, dbg_osreg);
+       LOG_TARGET_DEBUG(target, "DBGOSLSR 0x%" PRIx32, dbg_osreg);
 
        /* check if OS Lock is implemented */
        if ((dbg_osreg & OSLSR_OSLM) == OSLSR_OSLM0 || (dbg_osreg & OSLSR_OSLM) == OSLSR_OSLM1) {
                /* check if OS Lock is set */
                if (dbg_osreg & OSLSR_OSLK) {
-                       LOG_DEBUG("target->coreid %" PRId32 " OSLock set! Trying to unlock", target->coreid);
+                       LOG_TARGET_DEBUG(target, "OSLock set! Trying to unlock");
 
                        retval = mem_ap_write_atomic_u32(armv7a->debug_ap,
                                                        armv7a->debug_base + CPUDBG_OSLAR,
@@ -2990,8 +3022,7 @@ static int cortex_a_examine_first(struct target *target)
 
                        /* if we fail to access the register or cannot reset the OSLK bit, bail out */
                        if (retval != ERROR_OK || (dbg_osreg & OSLSR_OSLK) != 0) {
-                               LOG_ERROR("target->coreid %" PRId32 " OSLock sticky, core not powered?",
-                                               target->coreid);
+                               LOG_TARGET_ERROR(target, "OSLock sticky, core not powered?");
                                target->state = TARGET_UNKNOWN; /* TARGET_NO_POWER? */
                                return ERROR_TARGET_INIT_FAILED;
                        }
@@ -3004,13 +3035,11 @@ static int cortex_a_examine_first(struct target *target)
                return retval;
 
        if (dbg_idpfr1 & 0x000000f0) {
-               LOG_DEBUG("target->coreid %" PRId32 " has security extensions",
-                               target->coreid);
+               LOG_TARGET_DEBUG(target, "has security extensions");
                armv7a->arm.core_type = ARM_CORE_TYPE_SEC_EXT;
        }
        if (dbg_idpfr1 & 0x0000f000) {
-               LOG_DEBUG("target->coreid %" PRId32 " has virtualization extensions",
-                               target->coreid);
+               LOG_TARGET_DEBUG(target, "has virtualization extensions");
                /*
                 * overwrite and simplify the checks.
                 * virtualization extensions require implementation of security extension
@@ -3126,13 +3155,13 @@ static int cortex_a_target_create(struct target *target, Jim_Interp *interp)
        struct cortex_a_common *cortex_a;
        struct adiv5_private_config *pc;
 
-       if (target->private_config == NULL)
+       if (!target->private_config)
                return ERROR_FAIL;
 
        pc = (struct adiv5_private_config *)target->private_config;
 
        cortex_a = calloc(1, sizeof(struct cortex_a_common));
-       if (cortex_a == NULL) {
+       if (!cortex_a) {
                LOG_ERROR("Out of memory");
                return ERROR_FAIL;
        }
@@ -3153,7 +3182,7 @@ static int cortex_r4_target_create(struct target *target, Jim_Interp *interp)
                return ERROR_FAIL;
 
        cortex_a = calloc(1, sizeof(struct cortex_a_common));
-       if (cortex_a == NULL) {
+       if (!cortex_a) {
                LOG_ERROR("Out of memory");
                return ERROR_FAIL;
        }
@@ -3181,6 +3210,9 @@ static void cortex_a_deinit_target(struct target *target)
                                        dscr & ~DSCR_HALT_DBG_MODE);
        }
 
+       if (armv7a->debug_ap)
+               dap_put_ap(armv7a->debug_ap);
+
        free(cortex_a->wrp_list);
        free(cortex_a->brp_list);
        arm_free_reg_cache(dpm->arm);
@@ -3195,8 +3227,8 @@ static int cortex_a_mmu(struct target *target, int *enabled)
        struct armv7a_common *armv7a = target_to_armv7a(target);
 
        if (target->state != TARGET_HALTED) {
-               LOG_ERROR("%s: target not halted", __func__);
-               return ERROR_TARGET_INVALID;
+               LOG_TARGET_ERROR(target, "not halted");
+               return ERROR_TARGET_NOT_HALTED;
        }
 
        if (armv7a->is_armv7r)
@@ -3259,16 +3291,16 @@ COMMAND_HANDLER(handle_cortex_a_mask_interrupts_command)
        struct target *target = get_current_target(CMD_CTX);
        struct cortex_a_common *cortex_a = target_to_cortex_a(target);
 
-       static const struct jim_nvp nvp_maskisr_modes[] = {
+       static const struct nvp nvp_maskisr_modes[] = {
                { .name = "off", .value = CORTEX_A_ISRMASK_OFF },
                { .name = "on", .value = CORTEX_A_ISRMASK_ON },
                { .name = NULL, .value = -1 },
        };
-       const struct jim_nvp *n;
+       const struct nvp *n;
 
        if (CMD_ARGC > 0) {
-               n = jim_nvp_name2value_simple(nvp_maskisr_modes, CMD_ARGV[0]);
-               if (n->name == NULL) {
+               n = nvp_name2value(nvp_maskisr_modes, CMD_ARGV[0]);
+               if (!n->name) {
                        LOG_ERROR("Unknown parameter: %s - should be off or on", CMD_ARGV[0]);
                        return ERROR_COMMAND_SYNTAX_ERROR;
                }
@@ -3276,7 +3308,7 @@ COMMAND_HANDLER(handle_cortex_a_mask_interrupts_command)
                cortex_a->isrmasking_mode = n->value;
        }
 
-       n = jim_nvp_value2name_simple(nvp_maskisr_modes, cortex_a->isrmasking_mode);
+       n = nvp_value2name(nvp_maskisr_modes, cortex_a->isrmasking_mode);
        command_print(CMD, "cortex_a interrupt mask %s", n->name);
 
        return ERROR_OK;
@@ -3287,22 +3319,22 @@ COMMAND_HANDLER(handle_cortex_a_dacrfixup_command)
        struct target *target = get_current_target(CMD_CTX);
        struct cortex_a_common *cortex_a = target_to_cortex_a(target);
 
-       static const struct jim_nvp nvp_dacrfixup_modes[] = {
+       static const struct nvp nvp_dacrfixup_modes[] = {
                { .name = "off", .value = CORTEX_A_DACRFIXUP_OFF },
                { .name = "on", .value = CORTEX_A_DACRFIXUP_ON },
                { .name = NULL, .value = -1 },
        };
-       const struct jim_nvp *n;
+       const struct nvp *n;
 
        if (CMD_ARGC > 0) {
-               n = jim_nvp_name2value_simple(nvp_dacrfixup_modes, CMD_ARGV[0]);
-               if (n->name == NULL)
+               n = nvp_name2value(nvp_dacrfixup_modes, CMD_ARGV[0]);
+               if (!n->name)
                        return ERROR_COMMAND_SYNTAX_ERROR;
                cortex_a->dacrfixup_mode = n->value;
 
        }
 
-       n = jim_nvp_value2name_simple(nvp_dacrfixup_modes, cortex_a->dacrfixup_mode);
+       n = nvp_value2name(nvp_dacrfixup_modes, cortex_a->dacrfixup_mode);
        command_print(CMD, "cortex_a domain access control fixup %s", n->name);
 
        return ERROR_OK;

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)