openocd: fix SPDX tag format for files .c
[fw/openocd] / src / flash / nor / str9xpec.c
index 37d805344c6252c09dba5765a0242d4c5298b4ae..c39eb3aa84da81ab8964bb01d31c4138a4722592 100644 (file)
@@ -1,22 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /***************************************************************************
  *   Copyright (C) 2005 by Dominic Rath                                    *
  *   Dominic.Rath@gmx.de                                                   *
  *                                                                         *
  *   Copyright (C) 2008 by Spencer Oliver                                  *
  *   spen@spen-soft.co.uk                                                  *
- *                                                                         *
- *   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
@@ -74,13 +63,14 @@ struct str9xpec_flash_controller {
        uint8_t options[8];
 };
 
-static int str9xpec_erase_area(struct flash_bank *bank, int first, int last);
+static int str9xpec_erase_area(struct flash_bank *bank, unsigned int first,
+               unsigned int last);
 static int str9xpec_set_address(struct flash_bank *bank, uint8_t sector);
 static int str9xpec_write_options(struct flash_bank *bank);
 
 static int str9xpec_set_instr(struct jtag_tap *tap, uint32_t new_instr, tap_state_t end_state)
 {
-       if (tap == NULL)
+       if (!tap)
                return ERROR_TARGET_INVALID;
 
        if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
@@ -210,7 +200,7 @@ static int str9xpec_build_block_list(struct flash_bank *bank)
        struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
 
        int i;
-       int num_sectors;
+       unsigned int num_sectors;
        int b0_sectors = 0, b1_sectors = 0;
        uint32_t offset = 0;
        int b1_size = 0x2000;
@@ -303,12 +293,12 @@ FLASH_BANK_COMMAND_HANDLER(str9xpec_flash_bank_command)
        return ERROR_OK;
 }
 
-static int str9xpec_blank_check(struct flash_bank *bank, int first, int last)
+static int str9xpec_blank_check(struct flash_bank *bank, unsigned int first,
+               unsigned int last)
 {
        struct scan_field field;
        uint8_t status;
        struct jtag_tap *tap;
-       int i;
        uint8_t *buffer = NULL;
 
        struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
@@ -323,9 +313,9 @@ static int str9xpec_blank_check(struct flash_bank *bank, int first, int last)
 
        buffer = calloc(DIV_ROUND_UP(64, 8), 1);
 
-       LOG_DEBUG("blank check: first_bank: %i, last_bank: %i", first, last);
+       LOG_DEBUG("blank check: first_bank: %u, last_bank: %u", first, last);
 
-       for (i = first; i <= last; i++)
+       for (unsigned int i = first; i <= last; i++)
                buf_set_u32(buffer, str9xpec_info->sector_bits[i], 1, 1);
 
        /* execute ISC_BLANK_CHECK command */
@@ -348,7 +338,7 @@ static int str9xpec_blank_check(struct flash_bank *bank, int first, int last)
 
        status = str9xpec_isc_status(tap);
 
-       for (i = first; i <= last; i++) {
+       for (unsigned int i = first; i <= last; i++) {
                if (buf_get_u32(buffer, str9xpec_info->sector_bits[i], 1))
                        bank->sectors[i].is_erased = 0;
                else
@@ -367,13 +357,12 @@ static int str9xpec_blank_check(struct flash_bank *bank, int first, int last)
 static int str9xpec_protect_check(struct flash_bank *bank)
 {
        uint8_t status;
-       int i;
 
        struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
 
        status = str9xpec_read_config(bank);
 
-       for (i = 0; i < bank->num_sectors; i++) {
+       for (unsigned int i = 0; i < bank->num_sectors; i++) {
                if (buf_get_u32(str9xpec_info->options, str9xpec_info->sector_bits[i], 1))
                        bank->sectors[i].is_protected = 1;
                else
@@ -385,12 +374,12 @@ static int str9xpec_protect_check(struct flash_bank *bank)
        return ERROR_OK;
 }
 
-static int str9xpec_erase_area(struct flash_bank *bank, int first, int last)
+static int str9xpec_erase_area(struct flash_bank *bank, unsigned int first,
+               unsigned int last)
 {
        struct scan_field field;
        uint8_t status;
        struct jtag_tap *tap;
-       int i;
        uint8_t *buffer = NULL;
 
        struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
@@ -405,17 +394,17 @@ static int str9xpec_erase_area(struct flash_bank *bank, int first, int last)
 
        buffer = calloc(DIV_ROUND_UP(64, 8), 1);
 
-       LOG_DEBUG("erase: first_bank: %i, last_bank: %i", first, last);
+       LOG_DEBUG("erase: first_bank: %u, last_bank: %u", first, last);
 
        /* last bank: 0xFF signals a full erase (unlock complete device) */
        /* last bank: 0xFE signals a option byte erase */
        if (last == 0xFF) {
-               for (i = 0; i < 64; i++)
+               for (unsigned int i = 0; i < 64; i++)
                        buf_set_u32(buffer, i, 1, 1);
        } else if (last == 0xFE)
                buf_set_u32(buffer, 49, 1, 1);
        else {
-               for (i = first; i <= last; i++)
+               for (unsigned int i = first; i <= last; i++)
                        buf_set_u32(buffer, str9xpec_info->sector_bits[i], 1, 1);
        }
 
@@ -444,7 +433,8 @@ static int str9xpec_erase_area(struct flash_bank *bank, int first, int last)
        return status;
 }
 
-static int str9xpec_erase(struct flash_bank *bank, int first, int last)
+static int str9xpec_erase(struct flash_bank *bank, unsigned int first,
+               unsigned int last)
 {
        int status;
 
@@ -504,10 +494,10 @@ static int str9xpec_unlock_device(struct flash_bank *bank)
        return status;
 }
 
-static int str9xpec_protect(struct flash_bank *bank, int set, int first, int last)
+static int str9xpec_protect(struct flash_bank *bank, int set,
+               unsigned int first, unsigned int last)
 {
        uint8_t status;
-       int i;
 
        struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
 
@@ -516,7 +506,7 @@ static int str9xpec_protect(struct flash_bank *bank, int set, int first, int las
        if ((status & ISC_STATUS_ERROR) != STR9XPEC_ISC_SUCCESS)
                return ERROR_FLASH_OPERATION_FAILED;
 
-       LOG_DEBUG("protect: first_bank: %i, last_bank: %i", first, last);
+       LOG_DEBUG("protect: first_bank: %u, last_bank: %u", first, last);
 
        /* last bank: 0xFF signals a full device protect */
        if (last == 0xFF) {
@@ -527,7 +517,7 @@ static int str9xpec_protect(struct flash_bank *bank, int set, int first, int las
                        status = str9xpec_unlock_device(bank);
                }
        } else {
-               for (i = first; i <= last; i++) {
+               for (unsigned int i = first; i <= last; i++) {
                        if (set)
                                buf_set_u32(str9xpec_info->options, str9xpec_info->sector_bits[i], 1, 1);
                        else
@@ -575,9 +565,8 @@ static int str9xpec_write(struct flash_bank *bank, const uint8_t *buffer,
        struct jtag_tap *tap;
        struct scan_field field;
        uint8_t *scanbuf;
-       int i;
-       int first_sector = 0;
-       int last_sector = 0;
+       unsigned int first_sector = 0;
+       unsigned int last_sector = 0;
 
        tap = str9xpec_info->tap;
 
@@ -592,7 +581,7 @@ static int str9xpec_write(struct flash_bank *bank, const uint8_t *buffer,
                return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
        }
 
-       for (i = 0; i < bank->num_sectors; i++) {
+       for (unsigned int i = 0; i < bank->num_sectors; i++) {
                uint32_t sec_start = bank->sectors[i].offset;
                uint32_t sec_end = sec_start + bank->sectors[i].size;
 
@@ -621,7 +610,7 @@ static int str9xpec_write(struct flash_bank *bank, const uint8_t *buffer,
 
        LOG_DEBUG("ISC_PROGRAM");
 
-       for (i = first_sector; i <= last_sector; i++) {
+       for (unsigned int i = first_sector; i <= last_sector; i++) {
                str9xpec_set_address(bank, str9xpec_info->sector_bits[i]);
 
                dwords_remaining = dwords_remaining < (bank->sectors[i].size/8)
@@ -727,7 +716,7 @@ COMMAND_HANDLER(str9xpec_handle_part_id_command)
 
        struct flash_bank *bank;
        int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        str9xpec_info = bank->driver_priv;
@@ -746,7 +735,7 @@ COMMAND_HANDLER(str9xpec_handle_part_id_command)
 
        idcode = buf_get_u32(buffer, 0, 32);
 
-       command_print(CMD_CTX, "str9xpec part id: 0x%8.8" PRIx32 "", idcode);
+       command_print(CMD, "str9xpec part id: 0x%8.8" PRIx32 "", idcode);
 
        free(buffer);
 
@@ -768,7 +757,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_read_command)
 
        struct flash_bank *bank;
        int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        str9xpec_info = bank->driver_priv;
@@ -780,33 +769,33 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_read_command)
 
        /* boot bank */
        if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_CSMAPBIT, 1))
-               command_print(CMD_CTX, "CS Map: bank1");
+               command_print(CMD, "CS Map: bank1");
        else
-               command_print(CMD_CTX, "CS Map: bank0");
+               command_print(CMD, "CS Map: bank0");
 
        /* OTP lock */
        if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_OTPBIT, 1))
-               command_print(CMD_CTX, "OTP Lock: OTP Locked");
+               command_print(CMD, "OTP Lock: OTP Locked");
        else
-               command_print(CMD_CTX, "OTP Lock: OTP Unlocked");
+               command_print(CMD, "OTP Lock: OTP Unlocked");
 
        /* LVD Threshold */
        if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDTHRESBIT, 1))
-               command_print(CMD_CTX, "LVD Threshold: 2.7v");
+               command_print(CMD, "LVD Threshold: 2.7v");
        else
-               command_print(CMD_CTX, "LVD Threshold: 2.4v");
+               command_print(CMD, "LVD Threshold: 2.4v");
 
        /* LVD reset warning */
        if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDWARNBIT, 1))
-               command_print(CMD_CTX, "LVD Reset Warning: VDD or VDDQ Inputs");
+               command_print(CMD, "LVD Reset Warning: VDD or VDDQ Inputs");
        else
-               command_print(CMD_CTX, "LVD Reset Warning: VDD Input Only");
+               command_print(CMD, "LVD Reset Warning: VDD Input Only");
 
        /* LVD reset select */
        if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDSELBIT, 1))
-               command_print(CMD_CTX, "LVD Reset Selection: VDD or VDDQ Inputs");
+               command_print(CMD, "LVD Reset Selection: VDD or VDDQ Inputs");
        else
-               command_print(CMD_CTX, "LVD Reset Selection: VDD Input Only");
+               command_print(CMD, "LVD Reset Selection: VDD Input Only");
 
        return ERROR_OK;
 }
@@ -877,7 +866,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_write_command)
 
        struct flash_bank *bank;
        int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        status = str9xpec_write_options(bank);
@@ -885,7 +874,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_write_command)
        if ((status & ISC_STATUS_ERROR) != STR9XPEC_ISC_SUCCESS)
                return ERROR_FLASH_OPERATION_FAILED;
 
-       command_print(CMD_CTX, "str9xpec write options complete.\n"
+       command_print(CMD, "str9xpec write options complete.\n"
                        "INFO: a reset or power cycle is required "
                        "for the new settings to take effect.");
 
@@ -901,7 +890,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_cmap_command)
 
        struct flash_bank *bank;
        int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        str9xpec_info = bank->driver_priv;
@@ -923,7 +912,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_lvdthd_command)
 
        struct flash_bank *bank;
        int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        str9xpec_info = bank->driver_priv;
@@ -945,7 +934,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_lvdsel_command)
 
        struct flash_bank *bank;
        int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        str9xpec_info = bank->driver_priv;
@@ -967,7 +956,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_lvdwarn_command)
 
        struct flash_bank *bank;
        int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        str9xpec_info = bank->driver_priv;
@@ -989,7 +978,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_lock_command)
 
        struct flash_bank *bank;
        int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        status = str9xpec_lock_device(bank);
@@ -1009,7 +998,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_unlock_command)
 
        struct flash_bank *bank;
        int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        status = str9xpec_unlock_device(bank);
@@ -1017,7 +1006,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_unlock_command)
        if ((status & ISC_STATUS_ERROR) != STR9XPEC_ISC_SUCCESS)
                return ERROR_FLASH_OPERATION_FAILED;
 
-       command_print(CMD_CTX, "str9xpec unlocked.\n"
+       command_print(CMD, "str9xpec unlocked.\n"
                        "INFO: a reset or power cycle is required "
                        "for the new settings to take effect.");
 
@@ -1036,28 +1025,28 @@ COMMAND_HANDLER(str9xpec_handle_flash_enable_turbo_command)
 
        struct flash_bank *bank;
        int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        str9xpec_info = bank->driver_priv;
 
        /* remove arm core from chain - enter turbo mode */
        tap0 = str9xpec_info->tap;
-       if (tap0 == NULL) {
+       if (!tap0) {
                /* things are *WRONG* */
-               command_print(CMD_CTX, "**STR9FLASH** (tap0) invalid chain?");
+               command_print(CMD, "**STR9FLASH** (tap0) invalid chain?");
                return ERROR_FAIL;
        }
        tap1 = tap0->next_tap;
-       if (tap1 == NULL) {
+       if (!tap1) {
                /* things are *WRONG* */
-               command_print(CMD_CTX, "**STR9FLASH** (tap1) invalid chain?");
+               command_print(CMD, "**STR9FLASH** (tap1) invalid chain?");
                return ERROR_FAIL;
        }
        tap2 = tap1->next_tap;
-       if (tap2 == NULL) {
+       if (!tap2) {
                /* things are *WRONG* */
-               command_print(CMD_CTX, "**STR9FLASH** (tap2) invalid chain?");
+               command_print(CMD, "**STR9FLASH** (tap2) invalid chain?");
                return ERROR_FAIL;
        }
 
@@ -1083,13 +1072,13 @@ COMMAND_HANDLER(str9xpec_handle_flash_disable_turbo_command)
 
        struct flash_bank *bank;
        int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        str9xpec_info = bank->driver_priv;
        tap = str9xpec_info->tap;
 
-       if (tap == NULL)
+       if (!tap)
                return ERROR_FAIL;
 
        /* exit turbo mode via RESET */