jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / src / flash / nor / fm3.c
index d3d143f60b35dc24d2af126ea439b9cc4086b58f..48f4493ab6140056eb8111229d874d4c862cefdb 100644 (file)
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /***************************************************************************
  *   Copyright (C) 2011 by Marc Willam, Holger Wech                        *
  *       openOCD.fseu(AT)de.fujitsu.com                                    *
@@ -5,21 +7,6 @@
  *                                                                         *
  *   Copyright (C) 2013 Nemui Trinomius                                    *
  *   nemuisan_kawausogasuki@live.jp                                        *
- *                                                                         *
- *   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.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
 #define FLASH_DQ5 0x20         /* Time limit exceeding flag bit (TLOV) position */
 
 enum fm3_variant {
-       mb9bfxx1,       /* Flash Type '1' */
-       mb9bfxx2,
-       mb9bfxx3,
-       mb9bfxx4,
-       mb9bfxx5,
-       mb9bfxx6,
-       mb9bfxx7,
-       mb9bfxx8,
-
-       mb9afxx1,       /* Flash Type '2' */
-       mb9afxx2,
-       mb9afxx3,
-       mb9afxx4,
-       mb9afxx5,
-       mb9afxx6,
-       mb9afxx7,
-       mb9afxx8,
+       MB9BFXX1,       /* Flash Type '1' */
+       MB9BFXX2,
+       MB9BFXX3,
+       MB9BFXX4,
+       MB9BFXX5,
+       MB9BFXX6,
+       MB9BFXX7,
+       MB9BFXX8,
+
+       MB9AFXX1,       /* Flash Type '2' */
+       MB9AFXX2,
+       MB9AFXX3,
+       MB9AFXX4,
+       MB9AFXX5,
+       MB9AFXX6,
+       MB9AFXX7,
+       MB9AFXX8,
 };
 
 enum fm3_flash_type {
-       fm3_no_flash_type = 0,
-       fm3_flash_type1   = 1,
-       fm3_flash_type2   = 2
+       FM3_NO_FLASH_TYPE = 0,
+       FM3_FLASH_TYPE1   = 1,
+       FM3_FLASH_TYPE2   = 2
 };
 
 struct fm3_flash_bank {
        enum fm3_variant variant;
        enum fm3_flash_type flashtype;
-       int probed;
+       bool probed;
 };
 
 FLASH_BANK_COMMAND_HANDLER(fm3_flash_bank_command)
@@ -78,53 +65,53 @@ FLASH_BANK_COMMAND_HANDLER(fm3_flash_bank_command)
 
        /* Flash type '1' */
        if (strcmp(CMD_ARGV[5], "mb9bfxx1.cpu") == 0) {
-               fm3_info->variant = mb9bfxx1;
-               fm3_info->flashtype = fm3_flash_type1;
+               fm3_info->variant = MB9BFXX1;
+               fm3_info->flashtype = FM3_FLASH_TYPE1;
        } else if (strcmp(CMD_ARGV[5], "mb9bfxx2.cpu") == 0) {
-               fm3_info->variant = mb9bfxx2;
-               fm3_info->flashtype = fm3_flash_type1;
+               fm3_info->variant = MB9BFXX2;
+               fm3_info->flashtype = FM3_FLASH_TYPE1;
        } else if (strcmp(CMD_ARGV[5], "mb9bfxx3.cpu") == 0) {
-               fm3_info->variant = mb9bfxx3;
-               fm3_info->flashtype = fm3_flash_type1;
+               fm3_info->variant = MB9BFXX3;
+               fm3_info->flashtype = FM3_FLASH_TYPE1;
        } else if (strcmp(CMD_ARGV[5], "mb9bfxx4.cpu") == 0) {
-               fm3_info->variant = mb9bfxx4;
-               fm3_info->flashtype = fm3_flash_type1;
+               fm3_info->variant = MB9BFXX4;
+               fm3_info->flashtype = FM3_FLASH_TYPE1;
        } else if (strcmp(CMD_ARGV[5], "mb9bfxx5.cpu") == 0) {
-               fm3_info->variant = mb9bfxx5;
-               fm3_info->flashtype = fm3_flash_type1;
+               fm3_info->variant = MB9BFXX5;
+               fm3_info->flashtype = FM3_FLASH_TYPE1;
        } else if (strcmp(CMD_ARGV[5], "mb9bfxx6.cpu") == 0) {
-               fm3_info->variant = mb9bfxx6;
-               fm3_info->flashtype = fm3_flash_type1;
+               fm3_info->variant = MB9BFXX6;
+               fm3_info->flashtype = FM3_FLASH_TYPE1;
        } else if (strcmp(CMD_ARGV[5], "mb9bfxx7.cpu") == 0) {
-               fm3_info->variant = mb9bfxx7;
-               fm3_info->flashtype = fm3_flash_type1;
+               fm3_info->variant = MB9BFXX7;
+               fm3_info->flashtype = FM3_FLASH_TYPE1;
        } else if (strcmp(CMD_ARGV[5], "mb9bfxx8.cpu") == 0) {
-               fm3_info->variant = mb9bfxx8;
-               fm3_info->flashtype = fm3_flash_type1;
+               fm3_info->variant = MB9BFXX8;
+               fm3_info->flashtype = FM3_FLASH_TYPE1;
        } else if (strcmp(CMD_ARGV[5], "mb9afxx1.cpu") == 0) {  /* Flash type '2' */
-               fm3_info->variant = mb9afxx1;
-               fm3_info->flashtype = fm3_flash_type2;
+               fm3_info->variant = MB9AFXX1;
+               fm3_info->flashtype = FM3_FLASH_TYPE2;
        } else if (strcmp(CMD_ARGV[5], "mb9afxx2.cpu") == 0) {
-               fm3_info->variant = mb9afxx2;
-               fm3_info->flashtype = fm3_flash_type2;
+               fm3_info->variant = MB9AFXX2;
+               fm3_info->flashtype = FM3_FLASH_TYPE2;
        } else if (strcmp(CMD_ARGV[5], "mb9afxx3.cpu") == 0) {
-               fm3_info->variant = mb9afxx3;
-               fm3_info->flashtype = fm3_flash_type2;
+               fm3_info->variant = MB9AFXX3;
+               fm3_info->flashtype = FM3_FLASH_TYPE2;
        } else if (strcmp(CMD_ARGV[5], "mb9afxx4.cpu") == 0) {
-               fm3_info->variant = mb9afxx4;
-               fm3_info->flashtype = fm3_flash_type2;
+               fm3_info->variant = MB9AFXX4;
+               fm3_info->flashtype = FM3_FLASH_TYPE2;
        } else if (strcmp(CMD_ARGV[5], "mb9afxx5.cpu") == 0) {
-               fm3_info->variant = mb9afxx5;
-               fm3_info->flashtype = fm3_flash_type2;
+               fm3_info->variant = MB9AFXX5;
+               fm3_info->flashtype = FM3_FLASH_TYPE2;
        } else if (strcmp(CMD_ARGV[5], "mb9afxx6.cpu") == 0) {
-               fm3_info->variant = mb9afxx6;
-               fm3_info->flashtype = fm3_flash_type2;
+               fm3_info->variant = MB9AFXX6;
+               fm3_info->flashtype = FM3_FLASH_TYPE2;
        } else if (strcmp(CMD_ARGV[5], "mb9afxx7.cpu") == 0) {
-               fm3_info->variant = mb9afxx7;
-               fm3_info->flashtype = fm3_flash_type2;
+               fm3_info->variant = MB9AFXX7;
+               fm3_info->flashtype = FM3_FLASH_TYPE2;
        } else if (strcmp(CMD_ARGV[5], "mb9afxx8.cpu") == 0) {
-               fm3_info->variant = mb9afxx8;
-               fm3_info->flashtype = fm3_flash_type2;
+               fm3_info->variant = MB9AFXX8;
+               fm3_info->flashtype = FM3_FLASH_TYPE2;
        }
 
        /* unknown Flash type */
@@ -134,7 +121,7 @@ FLASH_BANK_COMMAND_HANDLER(fm3_flash_bank_command)
                return ERROR_FLASH_BANK_INVALID;
        }
 
-       fm3_info->probed = 0;
+       fm3_info->probed = false;
 
        return ERROR_OK;
 }
@@ -203,29 +190,30 @@ static int fm3_busy_wait(struct target *target, uint32_t offset, int timeout_ms)
        return retval;
 }
 
-static int fm3_erase(struct flash_bank *bank, int first, int last)
+static int fm3_erase(struct flash_bank *bank, unsigned int first,
+               unsigned int last)
 {
        struct fm3_flash_bank *fm3_info = bank->driver_priv;
        struct target *target = bank->target;
        int retval = ERROR_OK;
-       uint32_t u32DummyRead;
-       int sector, odd;
-       uint32_t u32FlashType;
-       uint32_t u32FlashSeqAddress1;
-       uint32_t u32FlashSeqAddress2;
+       uint32_t u32_dummy_read;
+       int odd;
+       uint32_t u32_flash_type;
+       uint32_t u32_flash_seq_address1;
+       uint32_t u32_flash_seq_address2;
 
        struct working_area *write_algorithm;
        struct reg_param reg_params[3];
        struct armv7m_algorithm armv7m_info;
 
-       u32FlashType = (uint32_t) fm3_info->flashtype;
+       u32_flash_type = (uint32_t) fm3_info->flashtype;
 
-       if (u32FlashType == fm3_flash_type1) {
-               u32FlashSeqAddress1 = 0x00001550;
-               u32FlashSeqAddress2 = 0x00000AA8;
-       } else if (u32FlashType == fm3_flash_type2) {
-               u32FlashSeqAddress1 = 0x00000AA8;
-               u32FlashSeqAddress2 = 0x00000554;
+       if (u32_flash_type == FM3_FLASH_TYPE1) {
+               u32_flash_seq_address1 = 0x00001550;
+               u32_flash_seq_address2 = 0x00000AA8;
+       } else if (u32_flash_type == FM3_FLASH_TYPE2) {
+               u32_flash_seq_address1 = 0x00000AA8;
+               u32_flash_seq_address2 = 0x00000554;
        } else {
                LOG_ERROR("Flash/Device type unknown!");
                return ERROR_FLASH_OPERATION_FAILED;
@@ -262,7 +250,7 @@ static int fm3_erase(struct flash_bank *bank, int first, int last)
                0x00, 0xBE,             /*        BKPT  #0                     */
        };
 
-       LOG_INFO("Fujitsu MB9[A/B]FXXX: Sector Erase ... (%d to %d)", first, last);
+       LOG_INFO("Fujitsu MB9[A/B]FXXX: Sector Erase ... (%u to %u)", first, last);
 
        /* disable HW watchdog */
        retval = target_write_u32(target, 0x40011C00, 0x1ACCE551);
@@ -277,13 +265,13 @@ static int fm3_erase(struct flash_bank *bank, int first, int last)
        if (retval != ERROR_OK)
                return retval;
 
-       /* FASZR = 0x01, Enables CPU Programming Mode (16-bit Flash acccess) */
+       /* FASZR = 0x01, Enables CPU Programming Mode (16-bit Flash access) */
        retval = target_write_u32(target, 0x40000000, 0x0001);
        if (retval != ERROR_OK)
                return retval;
 
        /* dummy read of FASZR */
-       retval = target_read_u32(target, 0x40000000, &u32DummyRead);
+       retval = target_read_u32(target, 0x40000000, &u32_dummy_read);
        if (retval != ERROR_OK)
                return retval;
 
@@ -301,20 +289,20 @@ static int fm3_erase(struct flash_bank *bank, int first, int last)
        armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
        armv7m_info.core_mode = ARM_MODE_THREAD;
 
-       init_reg_param(&reg_params[0], "r0", 32, PARAM_OUT); /* u32FlashSeqAddress1 */
-       init_reg_param(&reg_params[1], "r1", 32, PARAM_OUT); /* u32FlashSeqAddress2 */
+       init_reg_param(&reg_params[0], "r0", 32, PARAM_OUT); /* u32_flash_seq_address1 */
+       init_reg_param(&reg_params[1], "r1", 32, PARAM_OUT); /* u32_flash_seq_address2 */
        init_reg_param(&reg_params[2], "r2", 32, PARAM_OUT); /* offset                          */
 
        /* write code buffer and use Flash sector erase code within fm3                         */
-       for (sector = first ; sector <= last ; sector++) {
+       for (unsigned int sector = first ; sector <= last ; sector++) {
                uint32_t offset = bank->sectors[sector].offset;
 
                for (odd = 0; odd < 2 ; odd++) {
                        if (odd)
                                offset += 4;
 
-                       buf_set_u32(reg_params[0].value, 0, 32, u32FlashSeqAddress1);
-                       buf_set_u32(reg_params[1].value, 0, 32, u32FlashSeqAddress2);
+                       buf_set_u32(reg_params[0].value, 0, 32, u32_flash_seq_address1);
+                       buf_set_u32(reg_params[1].value, 0, 32, u32_flash_seq_address2);
                        buf_set_u32(reg_params[2].value, 0, 32, offset);
 
                        retval = target_run_algorithm(target, 0, NULL, 3, reg_params,
@@ -329,7 +317,6 @@ static int fm3_erase(struct flash_bank *bank, int first, int last)
                        if (retval != ERROR_OK)
                                return retval;
                }
-               bank->sectors[sector].is_erased = 1;
        }
 
        target_free_working_area(target, write_algorithm);
@@ -337,12 +324,12 @@ static int fm3_erase(struct flash_bank *bank, int first, int last)
        destroy_reg_param(&reg_params[1]);
        destroy_reg_param(&reg_params[2]);
 
-       /* FASZR = 0x02, Enables CPU Run Mode (32-bit Flash acccess) */
+       /* FASZR = 0x02, Enables CPU Run Mode (32-bit Flash access) */
        retval = target_write_u32(target, 0x40000000, 0x0002);
        if (retval != ERROR_OK)
                return retval;
 
-       retval = target_read_u32(target, 0x40000000, &u32DummyRead); /* dummy read of FASZR */
+       retval = target_read_u32(target, 0x40000000, &u32_dummy_read); /* dummy read of FASZR */
 
        return retval;
 }
@@ -359,22 +346,22 @@ static int fm3_write_block(struct flash_bank *bank, const uint8_t *buffer,
        struct reg_param reg_params[6];
        struct armv7m_algorithm armv7m_info;
        int retval = ERROR_OK;
-       uint32_t u32FlashType;
-       uint32_t u32FlashSeqAddress1;
-       uint32_t u32FlashSeqAddress2;
+       uint32_t u32_flash_type;
+       uint32_t u32_flash_seq_address1;
+       uint32_t u32_flash_seq_address2;
 
        /* Increase buffer_size if needed */
        if (buffer_size < (target->working_area_size / 2))
                buffer_size = (target->working_area_size / 2);
 
-       u32FlashType = (uint32_t) fm3_info->flashtype;
+       u32_flash_type = (uint32_t) fm3_info->flashtype;
 
-       if (u32FlashType == fm3_flash_type1) {
-               u32FlashSeqAddress1 = 0x00001550;
-               u32FlashSeqAddress2 = 0x00000AA8;
-       } else if (u32FlashType == fm3_flash_type2) {
-               u32FlashSeqAddress1 = 0x00000AA8;
-               u32FlashSeqAddress2 = 0x00000554;
+       if (u32_flash_type == FM3_FLASH_TYPE1) {
+               u32_flash_seq_address1 = 0x00001550;
+               u32_flash_seq_address2 = 0x00000AA8;
+       } else if (u32_flash_type == FM3_FLASH_TYPE2) {
+               u32_flash_seq_address1 = 0x00000AA8;
+               u32_flash_seq_address2 = 0x00000554;
        } else {
                LOG_ERROR("Flash/Device type unknown!");
                return ERROR_FLASH_OPERATION_FAILED;
@@ -402,8 +389,8 @@ static int fm3_write_block(struct flash_bank *bank, const uint8_t *buffer,
        0x55, 0xF0, 0x01, 0x05,         /*        ORRS.W   R5, R5, #1                 */
        0x5F, 0xF0, 0x80, 0x46,         /*        MOVS.W   R6, #(fm3_FLASH_IF->FASZ)  */
        0x35, 0x60,                                     /*        STR      R5, [R6]                   */
-                                                               /*    u32DummyRead = fm3_FLASH_IF->FASZ;      */
-       0x28, 0x4D,                                     /*        LDR.N    R5, ??u32DummyRead         */
+                                                               /*    u32_dummy_read = fm3_FLASH_IF->FASZ;      */
+       0x28, 0x4D,                                     /*        LDR.N    R5, ??u32_dummy_read         */
        0x5F, 0xF0, 0x80, 0x46,         /*        MOVS.W   R6, #(fm3_FLASH_IF->FASZ)  */
        0x36, 0x68,                                     /*        LDR      R6, [R6]                   */
        0x2E, 0x60,                                     /*        STR      R6, [R5]                   */
@@ -493,8 +480,8 @@ static int fm3_write_block(struct flash_bank *bank, const uint8_t *buffer,
        0x55, 0xF0, 0x02, 0x05,         /*        ORRS.W   R5, R5, #2                 */
        0x5F, 0xF0, 0x80, 0x46,         /*        MOVS.W   R6, #(fm3_FLASH_IF->FASZ)  */
        0x35, 0x60,                                     /*        STR      R5, [R6]                   */
-                                                               /*    u32DummyRead = fm3_FLASH_IF->FASZ;      */
-       0x04, 0x4D,                                     /*        LDR.N    R5, ??u32DummyRead         */
+                                                               /*    u32_dummy_read = fm3_FLASH_IF->FASZ;      */
+       0x04, 0x4D,                                     /*        LDR.N    R5, ??u32_dummy_read         */
        0x5F, 0xF0, 0x80, 0x46,         /*        MOVS.W   R6, #(fm3_FLASH_IF->FASZ)  */
        0x36, 0x68,                                     /*        LDR      R6, [R6]                   */
        0x2E, 0x60,                                     /*        STR      R6, [R5]                   */
@@ -509,7 +496,7 @@ static int fm3_write_block(struct flash_bank *bank, const uint8_t *buffer,
        /* SRAM basic-address + 8.These address pointers will be patched, if a    */
        /* different start address in RAM is used (e.g. for Flash type 2)!        */
        /* Default SRAM basic-address is 0x20000000.                              */
-       0x00, 0x00, 0x00, 0x20,     /* u32DummyRead address in RAM (0x20000000)   */
+       0x00, 0x00, 0x00, 0x20,     /* u32_dummy_read address in RAM (0x20000000)   */
        0x04, 0x00, 0x00, 0x20      /* u32FlashResult address in RAM (0x20000004) */
        };
 
@@ -549,7 +536,7 @@ static int fm3_write_block(struct flash_bank *bank, const uint8_t *buffer,
                return retval;
 
        /* Patching 'local variable address' */
-       /* Algorithm: u32DummyRead: */
+       /* Algorithm: u32_dummy_read: */
        retval = target_write_u32(target, (write_algorithm->address + 8)
                        + sizeof(fm3_flash_write_code) - 8, (write_algorithm->address));
        if (retval != ERROR_OK)
@@ -596,8 +583,8 @@ static int fm3_write_block(struct flash_bank *bank, const uint8_t *buffer,
                buf_set_u32(reg_params[0].value, 0, 32, source->address);
                buf_set_u32(reg_params[1].value, 0, 32, address);
                buf_set_u32(reg_params[2].value, 0, 32, thisrun_count);
-               buf_set_u32(reg_params[3].value, 0, 32, u32FlashSeqAddress1);
-               buf_set_u32(reg_params[4].value, 0, 32, u32FlashSeqAddress2);
+               buf_set_u32(reg_params[3].value, 0, 32, u32_flash_seq_address1);
+               buf_set_u32(reg_params[4].value, 0, 32, u32_flash_seq_address2);
 
                retval = target_run_algorithm(target, 0, NULL, 6, reg_params,
                                (write_algorithm->address + 8), 0, 1000, &armv7m_info);
@@ -658,7 +645,7 @@ static int fm3_probe(struct flash_bank *bank)
  */
 
        num_pages = 10;                         /* max number of Flash pages for malloc */
-       fm3_info->probed = 0;
+       fm3_info->probed = false;
 
        bank->sectors = malloc(sizeof(struct flash_sector) * num_pages);
        bank->base = 0x00000000;
@@ -674,8 +661,8 @@ static int fm3_probe(struct flash_bank *bank)
        bank->sectors[1].is_erased = -1;
        bank->sectors[1].is_protected = -1;
 
-       if ((fm3_info->variant == mb9bfxx1)
-           || (fm3_info->variant == mb9afxx1)) {
+       if ((fm3_info->variant == MB9BFXX1)
+           || (fm3_info->variant == MB9AFXX1)) {
                num_pages = 3;
                bank->size = 64 * 1024; /* bytes */
                bank->num_sectors = num_pages;
@@ -686,18 +673,18 @@ static int fm3_probe(struct flash_bank *bank)
                bank->sectors[2].is_protected = -1;
        }
 
-       if ((fm3_info->variant == mb9bfxx2)
-               || (fm3_info->variant == mb9bfxx4)
-               || (fm3_info->variant == mb9bfxx5)
-               || (fm3_info->variant == mb9bfxx6)
-               || (fm3_info->variant == mb9bfxx7)
-               || (fm3_info->variant == mb9bfxx8)
-               || (fm3_info->variant == mb9afxx2)
-               || (fm3_info->variant == mb9afxx4)
-               || (fm3_info->variant == mb9afxx5)
-               || (fm3_info->variant == mb9afxx6)
-               || (fm3_info->variant == mb9afxx7)
-               || (fm3_info->variant == mb9afxx8)) {
+       if ((fm3_info->variant == MB9BFXX2)
+               || (fm3_info->variant == MB9BFXX4)
+               || (fm3_info->variant == MB9BFXX5)
+               || (fm3_info->variant == MB9BFXX6)
+               || (fm3_info->variant == MB9BFXX7)
+               || (fm3_info->variant == MB9BFXX8)
+               || (fm3_info->variant == MB9AFXX2)
+               || (fm3_info->variant == MB9AFXX4)
+               || (fm3_info->variant == MB9AFXX5)
+               || (fm3_info->variant == MB9AFXX6)
+               || (fm3_info->variant == MB9AFXX7)
+               || (fm3_info->variant == MB9AFXX8)) {
                num_pages = 3;
                bank->size = 128 * 1024; /* bytes */
                bank->num_sectors = num_pages;
@@ -708,16 +695,16 @@ static int fm3_probe(struct flash_bank *bank)
                bank->sectors[2].is_protected = -1;
        }
 
-       if ((fm3_info->variant == mb9bfxx4)
-               || (fm3_info->variant == mb9bfxx5)
-               || (fm3_info->variant == mb9bfxx6)
-               || (fm3_info->variant == mb9bfxx7)
-               || (fm3_info->variant == mb9bfxx8)
-               || (fm3_info->variant == mb9afxx4)
-               || (fm3_info->variant == mb9afxx5)
-               || (fm3_info->variant == mb9afxx6)
-               || (fm3_info->variant == mb9afxx7)
-               || (fm3_info->variant == mb9afxx8)) {
+       if ((fm3_info->variant == MB9BFXX4)
+               || (fm3_info->variant == MB9BFXX5)
+               || (fm3_info->variant == MB9BFXX6)
+               || (fm3_info->variant == MB9BFXX7)
+               || (fm3_info->variant == MB9BFXX8)
+               || (fm3_info->variant == MB9AFXX4)
+               || (fm3_info->variant == MB9AFXX5)
+               || (fm3_info->variant == MB9AFXX6)
+               || (fm3_info->variant == MB9AFXX7)
+               || (fm3_info->variant == MB9AFXX8)) {
                num_pages = 4;
                bank->size = 256 * 1024; /* bytes */
                bank->num_sectors = num_pages;
@@ -728,14 +715,14 @@ static int fm3_probe(struct flash_bank *bank)
                bank->sectors[3].is_protected = -1;
        }
 
-       if ((fm3_info->variant == mb9bfxx5)
-               || (fm3_info->variant == mb9bfxx6)
-               || (fm3_info->variant == mb9bfxx7)
-               || (fm3_info->variant == mb9bfxx8)
-               || (fm3_info->variant == mb9afxx5)
-               || (fm3_info->variant == mb9afxx6)
-               || (fm3_info->variant == mb9afxx7)
-               || (fm3_info->variant == mb9afxx8)) {
+       if ((fm3_info->variant == MB9BFXX5)
+               || (fm3_info->variant == MB9BFXX6)
+               || (fm3_info->variant == MB9BFXX7)
+               || (fm3_info->variant == MB9BFXX8)
+               || (fm3_info->variant == MB9AFXX5)
+               || (fm3_info->variant == MB9AFXX6)
+               || (fm3_info->variant == MB9AFXX7)
+               || (fm3_info->variant == MB9AFXX8)) {
                num_pages = 5;
                bank->size = 384 * 1024; /* bytes */
                bank->num_sectors = num_pages;
@@ -746,12 +733,12 @@ static int fm3_probe(struct flash_bank *bank)
                bank->sectors[4].is_protected = -1;
        }
 
-       if ((fm3_info->variant == mb9bfxx6)
-               || (fm3_info->variant == mb9bfxx7)
-               || (fm3_info->variant == mb9bfxx8)
-               || (fm3_info->variant == mb9afxx6)
-               || (fm3_info->variant == mb9afxx7)
-               || (fm3_info->variant == mb9afxx8)) {
+       if ((fm3_info->variant == MB9BFXX6)
+               || (fm3_info->variant == MB9BFXX7)
+               || (fm3_info->variant == MB9BFXX8)
+               || (fm3_info->variant == MB9AFXX6)
+               || (fm3_info->variant == MB9AFXX7)
+               || (fm3_info->variant == MB9AFXX8)) {
                num_pages = 6;
                bank->size = 512 * 1024; /* bytes */
                bank->num_sectors = num_pages;
@@ -762,10 +749,10 @@ static int fm3_probe(struct flash_bank *bank)
                bank->sectors[5].is_protected = -1;
        }
 
-       if ((fm3_info->variant == mb9bfxx7)
-               || (fm3_info->variant == mb9bfxx8)
-               || (fm3_info->variant == mb9afxx7)
-               || (fm3_info->variant == mb9afxx8)) {
+       if ((fm3_info->variant == MB9BFXX7)
+               || (fm3_info->variant == MB9BFXX8)
+               || (fm3_info->variant == MB9AFXX7)
+               || (fm3_info->variant == MB9AFXX8)) {
                num_pages = 8;
                bank->size = 768 * 1024; /* bytes */
                bank->num_sectors = num_pages;
@@ -781,8 +768,8 @@ static int fm3_probe(struct flash_bank *bank)
                bank->sectors[7].is_protected = -1;
        }
 
-       if ((fm3_info->variant == mb9bfxx8)
-               || (fm3_info->variant == mb9afxx8)) {
+       if ((fm3_info->variant == MB9BFXX8)
+               || (fm3_info->variant == MB9AFXX8)) {
                num_pages = 10;
                bank->size = 1024 * 1024; /* bytes */
                bank->num_sectors = num_pages;
@@ -798,7 +785,7 @@ static int fm3_probe(struct flash_bank *bank)
                bank->sectors[9].is_protected = -1;
        }
 
-       fm3_info->probed = 1;
+       fm3_info->probed = true;
 
        return ERROR_OK;
 }
@@ -817,25 +804,25 @@ static int fm3_chip_erase(struct flash_bank *bank)
        struct target *target = bank->target;
        struct fm3_flash_bank *fm3_info2 = bank->driver_priv;
        int retval = ERROR_OK;
-       uint32_t u32DummyRead;
-       uint32_t u32FlashType;
-       uint32_t u32FlashSeqAddress1;
-       uint32_t u32FlashSeqAddress2;
+       uint32_t u32_dummy_read;
+       uint32_t u32_flash_type;
+       uint32_t u32_flash_seq_address1;
+       uint32_t u32_flash_seq_address2;
 
        struct working_area *write_algorithm;
        struct reg_param reg_params[3];
        struct armv7m_algorithm armv7m_info;
 
-       u32FlashType = (uint32_t) fm3_info2->flashtype;
+       u32_flash_type = (uint32_t) fm3_info2->flashtype;
 
-       if (u32FlashType == fm3_flash_type1) {
+       if (u32_flash_type == FM3_FLASH_TYPE1) {
                LOG_INFO("*** Erasing mb9bfxxx type");
-               u32FlashSeqAddress1 = 0x00001550;
-               u32FlashSeqAddress2 = 0x00000AA8;
-       } else if (u32FlashType == fm3_flash_type2) {
+               u32_flash_seq_address1 = 0x00001550;
+               u32_flash_seq_address2 = 0x00000AA8;
+       } else if (u32_flash_type == FM3_FLASH_TYPE2) {
                LOG_INFO("*** Erasing mb9afxxx type");
-               u32FlashSeqAddress1 = 0x00000AA8;
-               u32FlashSeqAddress2 = 0x00000554;
+               u32_flash_seq_address1 = 0x00000AA8;
+               u32_flash_seq_address2 = 0x00000554;
        } else {
                LOG_ERROR("Flash/Device type unknown!");
                return ERROR_FLASH_OPERATION_FAILED;
@@ -892,7 +879,7 @@ static int fm3_chip_erase(struct flash_bank *bank)
                return retval;
 
        /* dummy read of FASZR */
-       retval = target_read_u32(target, 0x40000000, &u32DummyRead);
+       retval = target_read_u32(target, 0x40000000, &u32_dummy_read);
        if (retval != ERROR_OK)
                return retval;
 
@@ -910,11 +897,11 @@ static int fm3_chip_erase(struct flash_bank *bank)
        armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
        armv7m_info.core_mode = ARM_MODE_THREAD;
 
-       init_reg_param(&reg_params[0], "r0", 32, PARAM_OUT); /* u32FlashSeqAddress1 */
-       init_reg_param(&reg_params[1], "r1", 32, PARAM_OUT); /* u32FlashSeqAddress2 */
+       init_reg_param(&reg_params[0], "r0", 32, PARAM_OUT); /* u32_flash_seq_address1 */
+       init_reg_param(&reg_params[1], "r1", 32, PARAM_OUT); /* u32_flash_seq_address2 */
 
-       buf_set_u32(reg_params[0].value, 0, 32, u32FlashSeqAddress1);
-       buf_set_u32(reg_params[1].value, 0, 32, u32FlashSeqAddress2);
+       buf_set_u32(reg_params[0].value, 0, 32, u32_flash_seq_address1);
+       buf_set_u32(reg_params[1].value, 0, 32, u32_flash_seq_address2);
 
        retval = target_run_algorithm(target, 0, NULL, 2, reg_params,
                        write_algorithm->address, 0, 100000, &armv7m_info);
@@ -929,7 +916,7 @@ static int fm3_chip_erase(struct flash_bank *bank)
        destroy_reg_param(&reg_params[0]);
        destroy_reg_param(&reg_params[1]);
 
-       retval = fm3_busy_wait(target, u32FlashSeqAddress2, 20000);     /* 20s timeout */
+       retval = fm3_busy_wait(target, u32_flash_seq_address2, 20000);  /* 20s timeout */
        if (retval != ERROR_OK)
                return retval;
 
@@ -938,31 +925,25 @@ static int fm3_chip_erase(struct flash_bank *bank)
        if (retval != ERROR_OK)
                return retval;
 
-       retval = target_read_u32(target, 0x40000000, &u32DummyRead); /* dummy read of FASZR */
+       retval = target_read_u32(target, 0x40000000, &u32_dummy_read); /* dummy read of FASZR */
 
        return retval;
 }
 
 COMMAND_HANDLER(fm3_handle_chip_erase_command)
 {
-       int i;
-
        if (CMD_ARGC < 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        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;
 
        if (fm3_chip_erase(bank) == ERROR_OK) {
-               /* set all sectors as erased */
-               for (i = 0; i < bank->num_sectors; i++)
-                       bank->sectors[i].is_erased = 1;
-
-               command_print(CMD_CTX, "fm3 chip erase complete");
+               command_print(CMD, "fm3 chip erase complete");
        } else {
-               command_print(CMD_CTX, "fm3 chip erase failed");
+               command_print(CMD, "fm3 chip erase failed");
        }
 
        return ERROR_OK;
@@ -990,7 +971,7 @@ static const struct command_registration fm3_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
-struct flash_driver fm3_flash = {
+const struct flash_driver fm3_flash = {
        .name = "fm3",
        .commands = fm3_command_handlers,
        .flash_bank_command = fm3_flash_bank_command,
@@ -999,4 +980,5 @@ struct flash_driver fm3_flash = {
        .probe = fm3_probe,
        .auto_probe = fm3_auto_probe,
        .erase_check = default_flash_blank_check,
+       .free_driver_priv = default_flash_free_driver_priv,
 };

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)