ipdbg: fix double free of virtual-ir data
[openocd.git] / src / flash / nor / cc3220sf.c
index 88604dff4315ad217fec94ad6bc4740d47ab4969..74cb7aea572358bd67c0a71a9c54eaacb5c8cbeb 100644 (file)
@@ -1,18 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /***************************************************************************
  *   Copyright (C) 2017 by Texas Instruments, Inc.                         *
- *                                                                         *
- *   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
@@ -21,6 +10,7 @@
 
 #include "imp.h"
 #include "cc3220sf.h"
+#include <helper/binarybuffer.h>
 #include <helper/time_support.h>
 #include <target/algorithm.h>
 #include <target/armv7m.h>
@@ -32,6 +22,11 @@ struct cc3220sf_bank {
        struct armv7m_algorithm armv7m_info;
 };
 
+/* Flash helper algorithm for CC3220SF */
+static const uint8_t cc3220sf_algo[] = {
+#include "../../../contrib/loaders/flash/cc3220sf/cc3220sf.inc"
+};
+
 static int cc3220sf_mass_erase(struct flash_bank *bank)
 {
        struct target *target = bank->target;
@@ -42,7 +37,7 @@ static int cc3220sf_mass_erase(struct flash_bank *bank)
 
        int retval = ERROR_OK;
 
-       if (TARGET_HALTED != target->state) {
+       if (target->state != TARGET_HALTED) {
                LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
@@ -93,7 +88,7 @@ FLASH_BANK_COMMAND_HANDLER(cc3220sf_flash_bank_command)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        cc3220sf_bank = malloc(sizeof(struct cc3220sf_bank));
-       if (NULL == cc3220sf_bank)
+       if (!cc3220sf_bank)
                return ERROR_FAIL;
 
        /* Initialize private flash information */
@@ -101,7 +96,6 @@ FLASH_BANK_COMMAND_HANDLER(cc3220sf_flash_bank_command)
 
        /* Finish initialization of flash bank */
        bank->driver_priv = cc3220sf_bank;
-       bank->next = NULL;
 
        return ERROR_OK;
 }
@@ -118,7 +112,7 @@ static int cc3220sf_erase(struct flash_bank *bank, unsigned int first,
 
        int retval = ERROR_OK;
 
-       if (TARGET_HALTED != target->state) {
+       if (target->state != TARGET_HALTED) {
                LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
@@ -192,7 +186,7 @@ static int cc3220sf_write(struct flash_bank *bank, const uint8_t *buffer,
 
        int retval = ERROR_OK;
 
-       if (TARGET_HALTED != target->state) {
+       if (target->state != TARGET_HALTED) {
                LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
@@ -295,7 +289,7 @@ static int cc3220sf_write(struct flash_bank *bank, const uint8_t *buffer,
 
                        /* Check that the head value was written to flash */
                        result = buf_get_u32(reg_params[2].value, 0, 32);
-                       if (0 != result) {
+                       if (result != 0) {
                                retval = ERROR_FAIL;
                                LOG_ERROR("cc3220sf: Flash operation failed");
                        }
@@ -359,7 +353,7 @@ static int cc3220sf_write(struct flash_bank *bank, const uint8_t *buffer,
 
                /* Check that all words were written to flash */
                result = buf_get_u32(reg_params[2].value, 0, 32);
-               if (0 != result) {
+               if (result != 0) {
                        retval = ERROR_FAIL;
                        LOG_ERROR("cc3220sf: Flash operation failed");
                        break;
@@ -369,7 +363,7 @@ static int cc3220sf_write(struct flash_bank *bank, const uint8_t *buffer,
        }
 
        /* Do one word write for any final bytes less than a full word */
-       if ((retval == ERROR_OK) && (0 != tail_count)) {
+       if ((retval == ERROR_OK) && (tail_count != 0)) {
                uint8_t tail[4];
 
                /* Set starting byte offset for data to write */
@@ -409,7 +403,7 @@ static int cc3220sf_write(struct flash_bank *bank, const uint8_t *buffer,
 
                        /* Check that the tail was written to flash */
                        result = buf_get_u32(reg_params[2].value, 0, 32);
-                       if (0 != result) {
+                       if (result != 0) {
                                retval = ERROR_FAIL;
                                LOG_ERROR("cc3220sf: Flash operation failed");
                        }
@@ -441,7 +435,7 @@ static int cc3220sf_probe(struct flash_bank *bank)
        free(bank->sectors);
 
        bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
-       if (NULL == bank->sectors)
+       if (!bank->sectors)
                return ERROR_FAIL;
 
        bank->base = base;

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)