openocd: src/target: replace the GPL-2.0-or-later license tag
[fw/openocd] / src / target / arm_dap.c
index d2e3f99972ab6518d177f975ff61c9c401b0f5fa..ad23e661108e0cd47091f221b93221a847e02cbb 100644 (file)
@@ -1,20 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
 /***************************************************************************
  *   Copyright (C) 2016 by Matthias Welwarsky                              *
  *                                                                         *
- *   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, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *                                                                         *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -50,7 +38,7 @@ static void dap_instance_init(struct adiv5_dap *dap)
        /* Set up with safe defaults */
        for (i = 0; i <= DP_APSEL_MAX; i++) {
                dap->ap[i].dap = dap;
-               dap->ap[i].ap_num = i;
+               dap->ap[i].ap_num = DP_APSEL_INVALID;
                /* memaccess_tck max is 255 */
                dap->ap[i].memaccess_tck = 255;
                /* Number of bits for tar autoincrement, impl. dep. at least 10 */
@@ -459,7 +447,7 @@ COMMAND_HANDLER(handle_dap_info_command)
        struct target *target = get_current_target(CMD_CTX);
        struct arm *arm = target_to_arm(target);
        struct adiv5_dap *dap = arm->dap;
-       uint32_t apsel;
+       uint64_t apsel;
 
        if (!dap) {
                LOG_ERROR("DAP instance not available. Probably a HLA target...");
@@ -471,8 +459,20 @@ COMMAND_HANDLER(handle_dap_info_command)
                        apsel = dap->apsel;
                        break;
                case 1:
-                       COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel);
-                       if (apsel > DP_APSEL_MAX)
+                       if (!strcmp(CMD_ARGV[0], "root")) {
+                               if (!is_adiv6(dap)) {
+                                       command_print(CMD, "Option \"root\" not allowed with ADIv5 DAP");
+                                       return ERROR_COMMAND_ARGUMENT_INVALID;
+                               }
+                               int retval = adiv6_dap_read_baseptr(CMD, dap, &apsel);
+                               if (retval != ERROR_OK) {
+                                       command_print(CMD, "Failed reading DAP baseptr");
+                                       return retval;
+                               }
+                               break;
+                       }
+                       COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], apsel);
+                       if (!is_ap_num_valid(dap, apsel))
                                return ERROR_COMMAND_SYNTAX_ERROR;
                        break;
                default:
@@ -515,9 +515,9 @@ static const struct command_registration dap_subcommand_handlers[] = {
                .name = "info",
                .handler = handle_dap_info_command,
                .mode = COMMAND_EXEC,
-               .help = "display ROM table for MEM-AP of current target "
-               "(default currently selected AP)",
-               .usage = "[ap_num]",
+               .help = "display ROM table for specified MEM-AP (default MEM-AP of current target) "
+                       "or the ADIv6 root ROM table of current target's DAP",
+               .usage = "[ap_num | 'root']",
        },
        COMMAND_REGISTRATION_DONE
 };