flash/stm32l4x: add support of STM32WB1x
[openocd.git] / src / flash / nor / jtagspi.c
index 73b1c7a26ee994e623d876b5b50e0414f4b5508a..dc49fda6153ddf31e2b97c820cc58d5c42e48c7d 100644 (file)
@@ -30,7 +30,7 @@
 struct jtagspi_flash_bank {
        struct jtag_tap *tap;
        const struct flash_device *dev;
-       int probed;
+       bool probed;
        uint32_t ir;
 };
 
@@ -42,14 +42,14 @@ FLASH_BANK_COMMAND_HANDLER(jtagspi_flash_bank_command)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        info = malloc(sizeof(struct jtagspi_flash_bank));
-       if (info == NULL) {
+       if (!info) {
                LOG_ERROR("no memory for flash bank info");
                return ERROR_FAIL;
        }
        bank->driver_priv = info;
 
        info->tap = NULL;
-       info->probed = 0;
+       info->probed = false;
        COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], info->ir);
 
        return ERROR_OK;
@@ -129,7 +129,7 @@ static int jtagspi_cmd(struct flash_bank *bank, uint8_t cmd,
        lenb = DIV_ROUND_UP(len, 8);
        data_buf = malloc(lenb);
        if (lenb > 0) {
-               if (data_buf == NULL) {
+               if (!data_buf) {
                        LOG_ERROR("no memory for spi buffer");
                        return ERROR_FAIL;
                }
@@ -153,12 +153,12 @@ static int jtagspi_cmd(struct flash_bank *bank, uint8_t cmd,
        jtagspi_set_ir(bank);
        /* passing from an IR scan to SHIFT-DR clears BYPASS registers */
        jtag_add_dr_scan(info->tap, n, fields, TAP_IDLE);
-       jtag_execute_queue();
+       int retval = jtag_execute_queue();
 
        if (is_read)
                flip_u8(data_buf, data, lenb);
        free(data_buf);
-       return ERROR_OK;
+       return retval;
 }
 
 static int jtagspi_probe(struct flash_bank *bank)
@@ -170,9 +170,9 @@ static int jtagspi_probe(struct flash_bank *bank)
 
        if (info->probed)
                free(bank->sectors);
-       info->probed = 0;
+       info->probed = false;
 
-       if (bank->target->tap == NULL) {
+       if (!bank->target->tap) {
                LOG_ERROR("Target has no JTAG tap");
                return ERROR_FAIL;
        }
@@ -211,12 +211,12 @@ static int jtagspi_probe(struct flash_bank *bank)
        /* create and fill sectors array */
        bank->num_sectors = info->dev->size_in_bytes / sectorsize;
        sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
-       if (sectors == NULL) {
+       if (!sectors) {
                LOG_ERROR("not enough memory");
                return ERROR_FAIL;
        }
 
-       for (int sector = 0; sector < bank->num_sectors; sector++) {
+       for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
                sectors[sector].offset = sector * sectorsize;
                sectors[sector].size = sectorsize;
                sectors[sector].is_erased = -1;
@@ -224,7 +224,7 @@ static int jtagspi_probe(struct flash_bank *bank)
        }
 
        bank->sectors = sectors;
-       info->probed = 1;
+       info->probed = true;
        return ERROR_OK;
 }
 
@@ -299,7 +299,7 @@ static int jtagspi_bulk_erase(struct flash_bank *bank)
        return retval;
 }
 
-static int jtagspi_sector_erase(struct flash_bank *bank, int sector)
+static int jtagspi_sector_erase(struct flash_bank *bank, unsigned int sector)
 {
        struct jtagspi_flash_bank *info = bank->driver_priv;
        int retval;
@@ -310,19 +310,19 @@ static int jtagspi_sector_erase(struct flash_bank *bank, int sector)
                return retval;
        jtagspi_cmd(bank, info->dev->erase_cmd, &bank->sectors[sector].offset, NULL, 0);
        retval = jtagspi_wait(bank, JTAGSPI_MAX_TIMEOUT);
-       LOG_INFO("sector %d took %" PRId64 " ms", sector, timeval_ms() - t0);
+       LOG_INFO("sector %u took %" PRId64 " ms", sector, timeval_ms() - t0);
        return retval;
 }
 
-static int jtagspi_erase(struct flash_bank *bank, int first, int last)
+static int jtagspi_erase(struct flash_bank *bank, unsigned int first,
+               unsigned int last)
 {
-       int sector;
        struct jtagspi_flash_bank *info = bank->driver_priv;
        int retval = ERROR_OK;
 
-       LOG_DEBUG("erase from sector %d to sector %d", first, last);
+       LOG_DEBUG("erase from sector %u to sector %u", first, last);
 
-       if ((first < 0) || (last < first) || (last >= bank->num_sectors)) {
+       if ((last < first) || (last >= bank->num_sectors)) {
                LOG_ERROR("Flash sector invalid");
                return ERROR_FLASH_SECTOR_INVALID;
        }
@@ -332,9 +332,9 @@ static int jtagspi_erase(struct flash_bank *bank, int first, int last)
                return ERROR_FLASH_BANK_NOT_PROBED;
        }
 
-       for (sector = first; sector <= last; sector++) {
+       for (unsigned int sector = first; sector <= last; sector++) {
                if (bank->sectors[sector].is_protected) {
-                       LOG_ERROR("Flash sector %d protected", sector);
+                       LOG_ERROR("Flash sector %u protected", sector);
                        return ERROR_FAIL;
                }
        }
@@ -352,7 +352,7 @@ static int jtagspi_erase(struct flash_bank *bank, int first, int last)
        if (info->dev->erase_cmd == 0x00)
                return ERROR_FLASH_OPER_UNSUPPORTED;
 
-       for (sector = first; sector <= last; sector++) {
+       for (unsigned int sector = first; sector <= last; sector++) {
                retval = jtagspi_sector_erase(bank, sector);
                if (retval != ERROR_OK) {
                        LOG_ERROR("Sector erase failed.");
@@ -363,11 +363,10 @@ static int jtagspi_erase(struct flash_bank *bank, int first, int last)
        return retval;
 }
 
-static int jtagspi_protect(struct flash_bank *bank, int set, int first, int last)
+static int jtagspi_protect(struct flash_bank *bank, int set, unsigned int first,
+               unsigned int last)
 {
-       int sector;
-
-       for (sector = first; sector <= last; sector++)
+       for (unsigned int sector = first; sector <= last; sector++)
                bank->sectors[sector].is_protected = set;
        return ERROR_OK;
 }
@@ -422,16 +421,16 @@ static int jtagspi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_
        return ERROR_OK;
 }
 
-static int jtagspi_info(struct flash_bank *bank, char *buf, int buf_size)
+static int jtagspi_info(struct flash_bank *bank, struct command_invocation *cmd)
 {
        struct jtagspi_flash_bank *info = bank->driver_priv;
 
        if (!(info->probed)) {
-               snprintf(buf, buf_size, "\nJTAGSPI flash bank not probed yet\n");
+               command_print_sameline(cmd, "\nJTAGSPI flash bank not probed yet\n");
                return ERROR_OK;
        }
 
-       snprintf(buf, buf_size, "\nSPIFI flash information:\n"
+       command_print_sameline(cmd, "\nSPIFI flash information:\n"
                "  Device \'%s\' (ID 0x%08" PRIx32 ")\n",
                info->dev->name, info->dev->device_id);
 

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)