openocd: fix SPDX tag format for files .c
[fw/openocd] / src / jtag / drivers / stlink_usb.c
index ca2893ccc10141c527d66d8884f0d28792f9ed2f..5b051c1ff9dff034b3e71f9a2d1a083155bdbdff 100644 (file)
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /***************************************************************************
  *   Copyright (C) 2020 by Tarek Bochkati                                  *
  *   Tarek Bochkati <tarek.bouchkati@gmail.com>                            *
  *   spen@spen-soft.co.uk                                                  *
  *                                                                         *
  *   This code is based on https://github.com/texane/stlink                *
- *                                                                         *
- *   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/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -4152,7 +4141,7 @@ static int stlink_dap_reinit_interface(void)
        stlink_dap_handle->reconnect_pending = false;
        /* on new FW, calling mode-leave closes all the opened AP; reopen them! */
        if (stlink_dap_handle->version.flags & STLINK_F_HAS_AP_INIT)
-               for (int apsel = 0; apsel <= DP_APSEL_MAX; apsel++)
+               for (unsigned int apsel = 0; apsel <= DP_APSEL_MAX; apsel++)
                        if (test_bit(apsel, opened_ap)) {
                                clear_bit(apsel, opened_ap);
                                stlink_dap_open_ap(apsel);
@@ -4286,6 +4275,14 @@ static int stlink_dap_ap_read(struct adiv5_ap *ap, unsigned int reg, uint32_t *d
        uint32_t dummy;
        int retval;
 
+       if (is_adiv6(dap)) {
+               static bool error_flagged;
+               if (!error_flagged)
+                       LOG_ERROR("ADIv6 dap not supported by stlink dap-direct mode");
+               error_flagged = true;
+               return ERROR_FAIL;
+       }
+
        if (reg != ADIV5_AP_REG_IDR) {
                retval = stlink_dap_open_ap(ap->ap_num);
                if (retval != ERROR_OK)
@@ -4304,6 +4301,14 @@ static int stlink_dap_ap_write(struct adiv5_ap *ap, unsigned int reg, uint32_t d
        struct adiv5_dap *dap = ap->dap;
        int retval;
 
+       if (is_adiv6(dap)) {
+               static bool error_flagged;
+               if (!error_flagged)
+                       LOG_ERROR("ADIv6 dap not supported by stlink dap-direct mode");
+               error_flagged = true;
+               return ERROR_FAIL;
+       }
+
        retval = stlink_dap_open_ap(ap->ap_num);
        if (retval != ERROR_OK)
                return retval;
@@ -4332,7 +4337,7 @@ static int stlink_usb_misc_rw_segment(void *handle, const struct dap_queue *q, u
 
        LOG_DEBUG("Queue: %u commands in %u items", len, items);
 
-       int ap_num = DP_APSEL_INVALID;
+       uint32_t ap_num = DP_APSEL_INVALID;
        unsigned int cmd_index = 0;
        unsigned int val_index = ALIGN_UP(items, 4);
        for (unsigned int i = 0; i < len; i++) {
@@ -4481,7 +4486,7 @@ static int stlink_usb_count_misc_rw_queue(void *handle, const struct dap_queue *
 {
        struct stlink_usb_handle_s *h = handle;
        unsigned int i, items = 0;
-       int ap_num = DP_APSEL_INVALID;
+       uint32_t ap_num = DP_APSEL_INVALID;
        unsigned int misc_max_items = (h->version.stlink == 2) ? STLINK_V2_RW_MISC_SIZE : STLINK_V3_RW_MISC_SIZE;
 
        if (!(h->version.flags & STLINK_F_HAS_RW_MISC))
@@ -4848,9 +4853,10 @@ static int stlink_dap_op_queue_ap_write(struct adiv5_ap *ap, unsigned int reg,
                q->ap_w.reg = reg;
                q->ap_w.ap = ap;
                q->ap_w.data = data;
-               if (reg == ADIV5_MEM_AP_REG_CSW && ap->csw_default != last_csw_default[ap->ap_num]) {
+               uint8_t ap_num = ap->ap_num;
+               if (reg == ADIV5_MEM_AP_REG_CSW && ap->csw_default != last_csw_default[ap_num]) {
                        q->ap_w.changes_csw_default = true;
-                       last_csw_default[ap->ap_num] = ap->csw_default;
+                       last_csw_default[ap_num] = ap->csw_default;
                } else {
                        q->ap_w.changes_csw_default = false;
                }