target/arm: do not expose 'arm reg', 'arm mcr/mrc' commands on Cortex-M
[fw/openocd] / src / flash / nor / fespi.c
index 11da818547ea3289c64097e6e12eaf025cad2adb..c61b708b1f1be3a9c4de3ef9a508745815d0d26d 100644 (file)
@@ -1,19 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
 /***************************************************************************
  *   Copyright (C) 2010 by Antonio Borneo <borneo.antonio@gmail.com>       *
  *   Modified by Megan Wachs <megan@sifive.com> from the original stmsmi.c *
- *                                                                         *
- *   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/>. *
  ***************************************************************************/
 
 /* The Freedom E SPI controller is a SPI bus controller
@@ -523,6 +512,12 @@ static int fespi_write(struct flash_bank *bank, const uint8_t *buffer,
                }
        }
 
+       struct riscv_info *riscv = riscv_info(target);
+       if (!is_riscv(riscv)) {
+               LOG_ERROR("Unexpected target type");
+               return ERROR_FAIL;
+       }
+
        unsigned int xlen = riscv_xlen(target);
        struct working_area *algorithm_wa = NULL;
        struct working_area *data_wa = NULL;
@@ -661,10 +656,8 @@ static int fespi_write(struct flash_bank *bank, const uint8_t *buffer,
        return ERROR_OK;
 
 err:
-       if (algorithm_wa) {
-               target_free_working_area(target, data_wa);
-               target_free_working_area(target, algorithm_wa);
-       }
+       target_free_working_area(target, data_wa);
+       target_free_working_area(target, algorithm_wa);
 
        /* Switch to HW mode before return to prompt */
        if (fespi_enable_hw_mode(bank) != ERROR_OK)