flash: fix typos and duplicated words
[openocd.git] / src / flash / nor / cfi.c
index 224f1749a607438a07e76bb915c50463047816bf..887821b79c66cbe86c43011d38b006c69fdba8e4 100644 (file)
@@ -100,9 +100,8 @@ static const struct cfi_fixup cfi_0001_fixups[] = {
 static void cfi_fixup(struct flash_bank *bank, const struct cfi_fixup *fixups)
 {
        struct cfi_flash_bank *cfi_info = bank->driver_priv;
-       const struct cfi_fixup *f;
 
-       for (f = fixups; f->fixup; f++) {
+       for (const struct cfi_fixup *f = fixups; f->fixup; f++) {
                if (((f->mfr == CFI_MFR_ANY) || (f->mfr == cfi_info->manufacturer)) &&
                                ((f->id  == CFI_ID_ANY)  || (f->id  == cfi_info->device_id)))
                        f->fixup(bank, f->param);
@@ -154,20 +153,19 @@ int cfi_target_read_memory(struct flash_bank *bank, target_addr_t addr,
 
 static void cfi_command(struct flash_bank *bank, uint8_t cmd, uint8_t *cmd_buf)
 {
-       int i;
        struct cfi_flash_bank *cfi_info = bank->driver_priv;
 
        /* clear whole buffer, to ensure bits that exceed the bus_width
         * are set to zero
         */
-       for (i = 0; i < CFI_MAX_BUS_WIDTH; i++)
+       for (size_t i = 0; i < CFI_MAX_BUS_WIDTH; i++)
                cmd_buf[i] = 0;
 
        if (cfi_info->endianness == TARGET_LITTLE_ENDIAN) {
-               for (i = bank->bus_width; i > 0; i--)
+               for (unsigned int i = bank->bus_width; i > 0; i--)
                        *cmd_buf++ = (i & (bank->chip_width - 1)) ? 0x0 : cmd;
        } else {
-               for (i = 1; i <= bank->bus_width; i++)
+               for (unsigned int i = 1; i <= bank->bus_width; i++)
                        *cmd_buf++ = (i & (bank->chip_width - 1)) ? 0x0 : cmd;
        }
 }
@@ -211,7 +209,6 @@ static int cfi_get_u8(struct flash_bank *bank, int sector, uint32_t offset, uint
 {
        struct cfi_flash_bank *cfi_info = bank->driver_priv;
        uint8_t data[CFI_MAX_BUS_WIDTH];
-       int i;
 
        int retval;
        retval = cfi_target_read_memory(bank, cfi_flash_address(bank, sector, offset),
@@ -220,13 +217,13 @@ static int cfi_get_u8(struct flash_bank *bank, int sector, uint32_t offset, uint
                return retval;
 
        if (cfi_info->endianness == TARGET_LITTLE_ENDIAN) {
-               for (i = 0; i < bank->bus_width / bank->chip_width; i++)
+               for (unsigned int i = 0; i < bank->bus_width / bank->chip_width; i++)
                        data[0] |= data[i];
 
                *val = data[0];
        } else {
                uint8_t value = 0;
-               for (i = 0; i < bank->bus_width / bank->chip_width; i++)
+               for (unsigned int i = 0; i < bank->bus_width / bank->chip_width; i++)
                        value |= data[bank->bus_width - 1 - i];
 
                *val = value;
@@ -241,8 +238,7 @@ static int cfi_query_u16(struct flash_bank *bank, int sector, uint32_t offset, u
        int retval;
 
        if (cfi_info->x16_as_x8) {
-               uint8_t i;
-               for (i = 0; i < 2; i++) {
+               for (uint8_t i = 0; i < 2; i++) {
                        retval = cfi_target_read_memory(bank, cfi_flash_address(bank, sector, offset + i),
                                                        1, &data[i * bank->bus_width]);
                        if (retval != ERROR_OK)
@@ -270,8 +266,7 @@ static int cfi_query_u32(struct flash_bank *bank, int sector, uint32_t offset, u
        int retval;
 
        if (cfi_info->x16_as_x8) {
-               uint8_t i;
-               for (i = 0; i < 4; i++) {
+               for (uint8_t i = 0; i < 4; i++) {
                        retval = cfi_target_read_memory(bank, cfi_flash_address(bank, sector, offset + i),
                                                        1, &data[i * bank->bus_width]);
                        if (retval != ERROR_OK)
@@ -819,7 +814,7 @@ static int cfi_intel_info(struct flash_bank *bank, char *buf, int buf_size)
 int cfi_flash_bank_cmd(struct flash_bank *bank, unsigned int argc, const char **argv)
 {
        struct cfi_flash_bank *cfi_info;
-       int bus_swap = 0;
+       bool bus_swap = false;
 
        if (argc < 6)
                return ERROR_COMMAND_SYNTAX_ERROR;
@@ -841,25 +836,25 @@ int cfi_flash_bank_cmd(struct flash_bank *bank, unsigned int argc, const char **
        }
 
        cfi_info = malloc(sizeof(struct cfi_flash_bank));
-       cfi_info->probed = 0;
+       cfi_info->probed = false;
        cfi_info->erase_region_info = NULL;
        cfi_info->pri_ext = NULL;
        bank->driver_priv = cfi_info;
 
-       cfi_info->x16_as_x8 = 0;
-       cfi_info->jedec_probe = 0;
-       cfi_info->not_cfi = 0;
-       cfi_info->data_swap = 0;
+       cfi_info->x16_as_x8 = false;
+       cfi_info->jedec_probe = false;
+       cfi_info->not_cfi = false;
+       cfi_info->data_swap = false;
 
        for (unsigned i = 6; i < argc; i++) {
                if (strcmp(argv[i], "x16_as_x8") == 0)
-                       cfi_info->x16_as_x8 = 1;
+                       cfi_info->x16_as_x8 = true;
                else if (strcmp(argv[i], "data_swap") == 0)
-                       cfi_info->data_swap = 1;
+                       cfi_info->data_swap = true;
                else if (strcmp(argv[i], "bus_swap") == 0)
-                       bus_swap = 1;
+                       bus_swap = true;
                else if (strcmp(argv[i], "jedec_probe") == 0)
-                       cfi_info->jedec_probe = 1;
+                       cfi_info->jedec_probe = true;
        }
 
        if (bus_swap)
@@ -882,15 +877,15 @@ FLASH_BANK_COMMAND_HANDLER(cfi_flash_bank_command)
        return cfi_flash_bank_cmd(bank, CMD_ARGC, CMD_ARGV);
 }
 
-static int cfi_intel_erase(struct flash_bank *bank, int first, int last)
+static int cfi_intel_erase(struct flash_bank *bank, unsigned int first,
+               unsigned int last)
 {
        int retval;
        struct cfi_flash_bank *cfi_info = bank->driver_priv;
-       int i;
 
        cfi_intel_clear_status_register(bank);
 
-       for (i = first; i <= last; i++) {
+       for (unsigned int i = first; i <= last; i++) {
                retval = cfi_send_command(bank, 0x20, cfi_flash_address(bank, i, 0x0));
                if (retval != ERROR_OK)
                        return retval;
@@ -911,7 +906,7 @@ static int cfi_intel_erase(struct flash_bank *bank, int first, int last)
                        if (retval != ERROR_OK)
                                return retval;
 
-                       LOG_ERROR("couldn't erase block %i of flash bank at base "
+                       LOG_ERROR("couldn't erase block %u of flash bank at base "
                                        TARGET_ADDR_FMT, i, bank->base);
                        return ERROR_FLASH_OPERATION_FAILED;
                }
@@ -937,14 +932,14 @@ int cfi_spansion_unlock_seq(struct flash_bank *bank)
        return ERROR_OK;
 }
 
-static int cfi_spansion_erase(struct flash_bank *bank, int first, int last)
+static int cfi_spansion_erase(struct flash_bank *bank, unsigned int first,
+               unsigned int last)
 {
        int retval;
        struct cfi_flash_bank *cfi_info = bank->driver_priv;
        struct cfi_spansion_pri_ext *pri_ext = cfi_info->pri_ext;
-       int i;
 
-       for (i = first; i <= last; i++) {
+       for (unsigned int i = first; i <= last; i++) {
                retval = cfi_spansion_unlock_seq(bank);
                if (retval != ERROR_OK)
                        return retval;
@@ -977,7 +972,8 @@ static int cfi_spansion_erase(struct flash_bank *bank, int first, int last)
        return cfi_send_command(bank, 0xf0, cfi_flash_address(bank, 0, 0x0));
 }
 
-int cfi_erase(struct flash_bank *bank, int first, int last)
+int cfi_erase(struct flash_bank *bank, unsigned int first,
+               unsigned int last)
 {
        struct cfi_flash_bank *cfi_info = bank->driver_priv;
 
@@ -986,7 +982,7 @@ int cfi_erase(struct flash_bank *bank, int first, int last)
                return ERROR_TARGET_NOT_HALTED;
        }
 
-       if ((first < 0) || (last < first) || (last >= bank->num_sectors))
+       if ((last < first) || (last >= bank->num_sectors))
                return ERROR_FLASH_SECTOR_INVALID;
 
        if (cfi_info->qry[0] != 'Q')
@@ -996,10 +992,8 @@ int cfi_erase(struct flash_bank *bank, int first, int last)
                case 1:
                case 3:
                        return cfi_intel_erase(bank, first, last);
-                       break;
                case 2:
                        return cfi_spansion_erase(bank, first, last);
-                       break;
                default:
                        LOG_ERROR("cfi primary command set %i unsupported", cfi_info->pri_id);
                        break;
@@ -1008,13 +1002,13 @@ int cfi_erase(struct flash_bank *bank, int first, int last)
        return ERROR_OK;
 }
 
-static int cfi_intel_protect(struct flash_bank *bank, int set, int first, int last)
+static int cfi_intel_protect(struct flash_bank *bank, int set,
+               unsigned int first, unsigned int last)
 {
        int retval;
        struct cfi_flash_bank *cfi_info = bank->driver_priv;
        struct cfi_intel_pri_ext *pri_ext = cfi_info->pri_ext;
        int retry = 0;
-       int i;
 
        /* if the device supports neither legacy lock/unlock (bit 3) nor
         * instant individual block locking (bit 5).
@@ -1026,7 +1020,7 @@ static int cfi_intel_protect(struct flash_bank *bank, int set, int first, int la
 
        cfi_intel_clear_status_register(bank);
 
-       for (i = first; i <= last; i++) {
+       for (unsigned int i = first; i <= last; i++) {
                retval = cfi_send_command(bank, 0x60, cfi_flash_address(bank, i, 0x0));
                if (retval != ERROR_OK)
                        return retval;
@@ -1097,7 +1091,7 @@ static int cfi_intel_protect(struct flash_bank *bank, int set, int first, int la
                 * 3. re-protect what should be protected.
                 *
                 */
-               for (i = 0; i < bank->num_sectors; i++) {
+               for (unsigned int i = 0; i < bank->num_sectors; i++) {
                        if (bank->sectors[i].is_protected == 1) {
                                cfi_intel_clear_status_register(bank);
 
@@ -1120,7 +1114,8 @@ static int cfi_intel_protect(struct flash_bank *bank, int set, int first, int la
        return cfi_send_command(bank, 0xff, cfi_flash_address(bank, 0, 0x0));
 }
 
-int cfi_protect(struct flash_bank *bank, int set, int first, int last)
+int cfi_protect(struct flash_bank *bank, int set, unsigned int first,
+               unsigned int last)
 {
        struct cfi_flash_bank *cfi_info = bank->driver_priv;
 
@@ -1136,7 +1131,6 @@ int cfi_protect(struct flash_bank *bank, int set, int first, int last)
                case 1:
                case 3:
                        return cfi_intel_protect(bank, set, first, last);
-                       break;
                default:
                        LOG_WARNING("protect: cfi primary command set %i unsupported", cfi_info->pri_id);
                        return ERROR_OK;
@@ -1152,15 +1146,12 @@ static uint32_t cfi_command_val(struct flash_bank *bank, uint8_t cmd)
        switch (bank->bus_width) {
                case 1:
                        return buf[0];
-                       break;
                case 2:
                        return target_buffer_get_u16(target, buf);
-                       break;
                case 4:
                        return target_buffer_get_u32(target, buf);
-                       break;
                default:
-                       LOG_ERROR("Unsupported bank buswidth %d, can't do block memory writes",
+                       LOG_ERROR("Unsupported bank buswidth %u, can't do block memory writes",
                                        bank->bus_width);
                        return 0;
        }
@@ -1187,7 +1178,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
         * r6: error test pattern
         */
 
-       /* see contib/loaders/flash/armv4_5_cfi_intel_32.s for src */
+       /* see contrib/loaders/flash/armv4_5_cfi_intel_32.s for src */
        static const uint32_t word_32_code[] = {
                0xe4904004,     /* loop: ldr r4, [r0], #4 */
                0xe5813000,     /*       str r3, [r1] */
@@ -1205,7 +1196,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
                0xeafffffe      /* done: b -2 */
        };
 
-       /* see contib/loaders/flash/armv4_5_cfi_intel_16.s for src */
+       /* see contrib/loaders/flash/armv4_5_cfi_intel_16.s for src */
        static const uint32_t word_16_code[] = {
                0xe0d040b2,     /* loop: ldrh r4, [r0], #2 */
                0xe1c130b0,     /*       strh r3, [r1] */
@@ -1223,7 +1214,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
                0xeafffffe      /* done:        b -2 */
        };
 
-       /* see contib/loaders/flash/armv4_5_cfi_intel_8.s for src */
+       /* see contrib/loaders/flash/armv4_5_cfi_intel_8.s for src */
        static const uint32_t word_8_code[] = {
                0xe4d04001,     /* loop: ldrb r4, [r0], #1 */
                0xe5c13000,     /*       strb r3, [r1] */
@@ -1258,7 +1249,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
 
        cfi_intel_clear_status_register(bank);
 
-       /* If we are setting up the write_algorith, we need target_code_src
+       /* If we are setting up the write_algorithm, we need target_code_src
         * if not we only need target_code_size. */
 
        /* However, we don't want to create multiple code paths, so we
@@ -1280,7 +1271,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
                        target_code_size = sizeof(word_32_code);
                        break;
                default:
-                       LOG_ERROR("Unsupported bank buswidth %d, can't do block memory writes",
+                       LOG_ERROR("Unsupported bank buswidth %u, can't do block memory writes",
                                        bank->bus_width);
                        return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
        }
@@ -1373,7 +1364,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
                if (retval != ERROR_OK) {
                        cfi_intel_clear_status_register(bank);
                        LOG_ERROR(
-                               "Execution of flash algorythm failed. Can't fall back. Please report.");
+                               "Execution of flash algorithm failed. Can't fall back. Please report.");
                        retval = ERROR_FLASH_OPERATION_FAILED;
                        /* retval = ERROR_TARGET_RESOURCE_NOT_AVAILABLE; */
                        /* FIXME To allow fall back or recovery, we must save the actual status
@@ -1516,7 +1507,7 @@ static int cfi_spansion_write_block_mips(struct flash_bank *bank, const uint8_t
                        }
                        break;
                default:
-                       LOG_ERROR("Unsupported bank buswidth %d, can't do block memory writes",
+                       LOG_ERROR("Unsupported bank buswidth %u, can't do block memory writes",
                                        bank->bus_width);
                        return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
        }
@@ -1662,7 +1653,7 @@ static int cfi_spansion_write_block(struct flash_bank *bank, const uint8_t *buff
         *  R10 = unlock2_addr
         *  R11 = unlock2_cmd */
 
-       /* see contib/loaders/flash/armv4_5_cfi_span_32.s for src */
+       /* see contrib/loaders/flash/armv4_5_cfi_span_32.s for src */
        static const uint32_t armv4_5_word_32_code[] = {
                /* 00008100 <sp_32_code>:               */
                0xe4905004,             /* ldr  r5, [r0], #4                    */
@@ -1694,7 +1685,7 @@ static int cfi_spansion_write_block(struct flash_bank *bank, const uint8_t *buff
                0xeafffffe              /* b    8154 <sp_32_done>               */
        };
 
-       /* see contib/loaders/flash/armv4_5_cfi_span_16.s for src */
+       /* see contrib/loaders/flash/armv4_5_cfi_span_16.s for src */
        static const uint32_t armv4_5_word_16_code[] = {
                /* 00008158 <sp_16_code>:               */
                0xe0d050b2,             /* ldrh r5, [r0], #2                    */
@@ -1895,7 +1886,7 @@ static int cfi_spansion_write_block(struct flash_bank *bank, const uint8_t *buff
                        target_code_size = sizeof(armv4_5_word_32_code);
                        break;
                default:
-                       LOG_ERROR("Unsupported bank buswidth %d, can't do block memory writes",
+                       LOG_ERROR("Unsupported bank buswidth %u, can't do block memory writes",
                                        bank->bus_width);
                        return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
        }
@@ -2230,10 +2221,8 @@ int cfi_write_word(struct flash_bank *bank, uint8_t *word, uint32_t address)
                case 1:
                case 3:
                        return cfi_intel_write_word(bank, word, address);
-                       break;
                case 2:
                        return cfi_spansion_write_word(bank, word, address);
-                       break;
                default:
                        LOG_ERROR("cfi primary command set %i unsupported", cfi_info->pri_id);
                        break;
@@ -2257,10 +2246,8 @@ static int cfi_write_words(struct flash_bank *bank, const uint8_t *word,
                case 1:
                case 3:
                        return cfi_intel_write_words(bank, word, wordcount, address);
-                       break;
                case 2:
                        return cfi_spansion_write_words(bank, word, wordcount, address);
-                       break;
                default:
                        LOG_ERROR("cfi primary command set %i unsupported", cfi_info->pri_id);
                        break;
@@ -2276,7 +2263,6 @@ static int cfi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, u
        uint32_t read_p;
        int align;      /* number of unaligned bytes */
        uint8_t current_word[CFI_MAX_BUS_WIDTH];
-       int i;
        int retval;
 
        LOG_DEBUG("reading buffer of %i byte at 0x%8.8x",
@@ -2305,7 +2291,7 @@ static int cfi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, u
                        return retval;
 
                /* take only bytes we need */
-               for (i = align; (i < bank->bus_width) && (count > 0); i++, count--)
+               for (unsigned int i = align; (i < bank->bus_width) && (count > 0); i++, count--)
                        *buffer++ = current_word[i];
 
                read_p += bank->bus_width;
@@ -2331,7 +2317,7 @@ static int cfi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, u
                        return retval;
 
                /* take only bytes we need */
-               for (i = 0; (i < bank->bus_width) && (count > 0); i++, count--)
+               for (unsigned int i = 0; (i < bank->bus_width) && (count > 0); i++, count--)
                        *buffer++ = current_word[i];
        }
 
@@ -2349,7 +2335,6 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
                                                         *programmed */
        uint8_t *swapped_buffer = NULL;
        const uint8_t *real_buffer = NULL;
-       int i;
        int retval;
 
        if (bank->target->state != TARGET_HALTED) {
@@ -2375,9 +2360,7 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
                        return retval;
 
                /* replace only bytes that must be written */
-               for (i = align;
-                    (i < bank->bus_width) && (count > 0);
-                    i++, count--)
+               for (unsigned int i = align; (i < bank->bus_width) && (count > 0); i++, count--)
                        if (cfi_info->data_swap)
                                /* data bytes are swapped (reverse endianness) */
                                current_word[bank->bus_width - i] = *buffer++;
@@ -2423,7 +2406,7 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
                        break;
        }
        if (retval == ERROR_OK) {
-               /* Increment pointers and decrease count on succesful block write */
+               /* Increment pointers and decrease count on successful block write */
                buffer += blk_count;
                write_p += blk_count;
                count -= blk_count;
@@ -2441,12 +2424,12 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
 
                        /* fall back to memory writes */
                        while (count >= (uint32_t)bank->bus_width) {
-                               int fallback;
+                               bool fallback;
                                if ((write_p & 0xff) == 0) {
                                        LOG_INFO("Programming at 0x%08" PRIx32 ", count 0x%08"
                                                PRIx32 " bytes remaining", write_p, count);
                                }
-                               fallback = 1;
+                               fallback = true;
                                if ((bufferwsize > 0) && (count >= buffersize) &&
                                                !(write_p & buffermask)) {
                                        retval = cfi_write_words(bank, buffer, bufferwsize, write_p);
@@ -2454,13 +2437,13 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
                                                buffer += buffersize;
                                                write_p += buffersize;
                                                count -= buffersize;
-                                               fallback = 0;
+                                               fallback = false;
                                        } else if (retval != ERROR_FLASH_OPER_UNSUPPORTED)
                                                return retval;
                                }
                                /* try the slow way? */
                                if (fallback) {
-                                       for (i = 0; i < bank->bus_width; i++)
+                                       for (unsigned int i = 0; i < bank->bus_width; i++)
                                                current_word[i] = *buffer++;
 
                                        retval = cfi_write_word(bank, current_word, write_p);
@@ -2495,7 +2478,7 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
                        return retval;
 
                /* replace only bytes that must be written */
-               for (i = 0; (i < bank->bus_width) && (count > 0); i++, count--)
+               for (unsigned int i = 0; (i < bank->bus_width) && (count > 0); i++, count--)
                        if (cfi_info->data_swap)
                                /* data bytes are swapped (reverse endianness) */
                                current_word[bank->bus_width - i] = *buffer++;
@@ -2522,7 +2505,6 @@ static void cfi_fixup_reversed_erase_regions(struct flash_bank *bank, const void
 
 static void cfi_fixup_0002_erase_regions(struct flash_bank *bank, const void *param)
 {
-       int i;
        struct cfi_flash_bank *cfi_info = bank->driver_priv;
        struct cfi_spansion_pri_ext *pri_ext = cfi_info->pri_ext;
        (void) param;
@@ -2530,7 +2512,7 @@ static void cfi_fixup_0002_erase_regions(struct flash_bank *bank, const void *pa
        if ((pri_ext->_reversed_geometry) || (pri_ext->TopBottom == 3)) {
                LOG_DEBUG("swapping reversed erase region information on cmdset 0002 device");
 
-               for (i = 0; i < cfi_info->num_erase_regions / 2; i++) {
+               for (unsigned int i = 0; i < cfi_info->num_erase_regions / 2; i++) {
                        int j = (cfi_info->num_erase_regions - 1) - i;
                        uint32_t swap;
 
@@ -2597,8 +2579,7 @@ int cfi_probe(struct flash_bank *bank)
 {
        struct cfi_flash_bank *cfi_info = bank->driver_priv;
        struct target *target = bank->target;
-       int num_sectors = 0;
-       int i;
+       unsigned int num_sectors = 0;
        int sector = 0;
        uint32_t unlock1 = 0x555;
        uint32_t unlock2 = 0x2aa;
@@ -2610,7 +2591,7 @@ int cfi_probe(struct flash_bank *bank)
                return ERROR_TARGET_NOT_HALTED;
        }
 
-       cfi_info->probed = 0;
+       cfi_info->probed = false;
        cfi_info->num_erase_regions = 0;
        if (bank->sectors) {
                free(bank->sectors);
@@ -2662,7 +2643,7 @@ int cfi_probe(struct flash_bank *bank)
                        cfi_info->device_id = target_buffer_get_u32(target, value_buf1);
                        break;
                default:
-                       LOG_ERROR("Unsupported bank chipwidth %d, can't probe memory",
+                       LOG_ERROR("Unsupported bank chipwidth %u, can't probe memory",
                                        bank->chip_width);
                        return ERROR_FLASH_OPERATION_FAILED;
        }
@@ -2680,7 +2661,7 @@ int cfi_probe(struct flash_bank *bank)
        /* query only if this is a CFI compatible flash,
         * otherwise the relevant info has already been filled in
         */
-       if (cfi_info->not_cfi == 0) {
+       if (!cfi_info->not_cfi) {
                /* enter CFI query mode
                 * according to JEDEC Standard No. 68.01,
                 * a single bus sequence with address = 0x55, data = 0x98 should put
@@ -2782,7 +2763,7 @@ int cfi_probe(struct flash_bank *bank)
                if (cfi_info->num_erase_regions) {
                        cfi_info->erase_region_info = malloc(sizeof(*cfi_info->erase_region_info)
                                        * cfi_info->num_erase_regions);
-                       for (i = 0; i < cfi_info->num_erase_regions; i++) {
+                       for (unsigned int i = 0; i < cfi_info->num_erase_regions; i++) {
                                retval = cfi_query_u32(bank,
                                                0,
                                                0x2d + (4 * i),
@@ -2814,7 +2795,7 @@ int cfi_probe(struct flash_bank *bank)
                                                                                                 *for
                                                                                                 *all
                                                                                                 *CFI
-                                                                                                *flashs
+                                                                                                *flashes
                                                                                                 **/
                                cfi_read_0002_pri_ext(bank);
                                break;
@@ -2897,15 +2878,14 @@ int cfi_probe(struct flash_bank *bank)
        } else {
                uint32_t offset = 0;
 
-               for (i = 0; i < cfi_info->num_erase_regions; i++)
+               for (unsigned int i = 0; i < cfi_info->num_erase_regions; i++)
                        num_sectors += (cfi_info->erase_region_info[i] & 0xffff) + 1;
 
                bank->num_sectors = num_sectors;
                bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
 
-               for (i = 0; i < cfi_info->num_erase_regions; i++) {
-                       uint32_t j;
-                       for (j = 0; j < (cfi_info->erase_region_info[i] & 0xffff) + 1; j++) {
+               for (unsigned int i = 0; i < cfi_info->num_erase_regions; i++) {
+                       for (uint32_t j = 0; j < (cfi_info->erase_region_info[i] & 0xffff) + 1; j++) {
                                bank->sectors[sector].offset = offset;
                                bank->sectors[sector].size =
                                        ((cfi_info->erase_region_info[i] >> 16) * 256)
@@ -2918,13 +2898,13 @@ int cfi_probe(struct flash_bank *bank)
                }
                if (offset != (cfi_info->dev_size * bank->bus_width / bank->chip_width)) {
                        LOG_WARNING(
-                               "CFI size is 0x%" PRIx32 ", but total sector size is 0x%" PRIx32 "", \
+                               "CFI size is 0x%" PRIx32 ", but total sector size is 0x%" PRIx32 "",
                                (cfi_info->dev_size * bank->bus_width / bank->chip_width),
                                offset);
                }
        }
 
-       cfi_info->probed = 1;
+       cfi_info->probed = true;
 
        return ERROR_OK;
 }
@@ -2942,7 +2922,6 @@ static int cfi_intel_protect_check(struct flash_bank *bank)
        int retval;
        struct cfi_flash_bank *cfi_info = bank->driver_priv;
        struct cfi_intel_pri_ext *pri_ext = cfi_info->pri_ext;
-       int i;
 
        /* check if block lock bits are supported on this device */
        if (!(pri_ext->blk_status_reg_mask & 0x1))
@@ -2952,7 +2931,7 @@ static int cfi_intel_protect_check(struct flash_bank *bank)
        if (retval != ERROR_OK)
                return retval;
 
-       for (i = 0; i < bank->num_sectors; i++) {
+       for (unsigned int i = 0; i < bank->num_sectors; i++) {
                uint8_t block_status;
                retval = cfi_get_u8(bank, i, 0x2, &block_status);
                if (retval != ERROR_OK)
@@ -2972,7 +2951,6 @@ static int cfi_spansion_protect_check(struct flash_bank *bank)
        int retval;
        struct cfi_flash_bank *cfi_info = bank->driver_priv;
        struct cfi_spansion_pri_ext *pri_ext = cfi_info->pri_ext;
-       int i;
 
        retval = cfi_spansion_unlock_seq(bank);
        if (retval != ERROR_OK)
@@ -2982,7 +2960,7 @@ static int cfi_spansion_protect_check(struct flash_bank *bank)
        if (retval != ERROR_OK)
                return retval;
 
-       for (i = 0; i < bank->num_sectors; i++) {
+       for (unsigned int i = 0; i < bank->num_sectors; i++) {
                uint8_t block_status;
                retval = cfi_get_u8(bank, i, 0x2, &block_status);
                if (retval != ERROR_OK)
@@ -3013,10 +2991,8 @@ int cfi_protect_check(struct flash_bank *bank)
                case 1:
                case 3:
                        return cfi_intel_protect_check(bank);
-                       break;
                case 2:
                        return cfi_spansion_protect_check(bank);
-                       break;
                default:
                        LOG_ERROR("cfi primary command set %i unsupported", cfi_info->pri_id);
                        break;
@@ -3035,7 +3011,7 @@ int cfi_get_info(struct flash_bank *bank, char *buf, int buf_size)
                return ERROR_OK;
        }
 
-       if (cfi_info->not_cfi == 0)
+       if (!cfi_info->not_cfi)
                printed = snprintf(buf, buf_size, "\nCFI flash: ");
        else
                printed = snprintf(buf, buf_size, "\nnon-CFI flash: ");

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)