stlink: collapse consecutive mem AP r/w in a single command
[openocd.git] / src / flash / nor / fespi.c
index 134fba6e31c871bc7d064a924c5af9e3e78b4705..150e91a1c4f0f210780f7b93d5c67bdedb592857 100644 (file)
 
 
 struct fespi_flash_bank {
-       int probed;
+       bool probed;
        target_addr_t ctrl_base;
        const struct flash_device *dev;
 };
@@ -136,9 +136,9 @@ struct fespi_target {
 /* TODO !!! What is the right naming convention here? */
 static const struct fespi_target target_devices[] = {
        /* name,   tap_idcode, ctrl_base */
-       { "Freedom E310-G000 SPI Flash",  0x10e31913 , 0x10014000 },
-       { "Freedom E310-G002 SPI Flash",  0x20000913 , 0x10014000 },
-       { NULL,    0,           0          }
+       { "Freedom E310-G000 SPI Flash", 0x10e31913, 0x10014000 },
+       { "Freedom E310-G002 SPI Flash", 0x20000913, 0x10014000 },
+       { NULL, 0, 0 }
 };
 
 FLASH_BANK_COMMAND_HANDLER(fespi_flash_bank_command)
@@ -151,13 +151,13 @@ FLASH_BANK_COMMAND_HANDLER(fespi_flash_bank_command)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        fespi_info = malloc(sizeof(struct fespi_flash_bank));
-       if (fespi_info == NULL) {
+       if (!fespi_info) {
                LOG_ERROR("not enough memory");
                return ERROR_FAIL;
        }
 
        bank->driver_priv = fespi_info;
-       fespi_info->probed = 0;
+       fespi_info->probed = false;
        fespi_info->ctrl_base = 0;
        if (CMD_ARGC >= 7) {
                COMMAND_PARSE_ADDRESS(CMD_ARGV[6], fespi_info->ctrl_base);
@@ -189,7 +189,7 @@ static int fespi_write_reg(struct flash_bank *bank, target_addr_t address, uint3
 
        int result = target_write_u32(target, fespi_info->ctrl_base + address, value);
        if (result != ERROR_OK) {
-               LOG_ERROR("fespi_write_reg() error writing 0x%x to " TARGET_ADDR_FMT,
+               LOG_ERROR("fespi_write_reg() error writing 0x%" PRIx32 " to " TARGET_ADDR_FMT,
                                value, fespi_info->ctrl_base + address);
                return result;
        }
@@ -274,7 +274,7 @@ static int fespi_rx(struct flash_bank *bank, uint8_t *out)
                        break;
                int64_t now = timeval_ms();
                if (now - start > 1000) {
-                       LOG_ERROR("rxfifo didn't go positive (value=0x%x).", value);
+                       LOG_ERROR("rxfifo didn't go positive (value=0x%" PRIx32 ").", value);
                        return ERROR_TARGET_TIMEOUT;
                }
        }
@@ -438,7 +438,7 @@ static int slow_fespi_write_buffer(struct flash_bank *bank,
        uint32_t ii;
 
        if (offset & 0xFF000000) {
-               LOG_ERROR("FESPI interface does not support greater than 3B addressing, can't write to offset 0x%x",
+               LOG_ERROR("FESPI interface does not support greater than 3B addressing, can't write to offset 0x%" PRIx32,
                                offset);
                return ERROR_FAIL;
        }
@@ -538,7 +538,7 @@ static unsigned as_compile(struct algorithm_steps *as, uint8_t *target,
                                        break;
                                }
                        case STEP_WRITE_REG:
-                               if (4 > bytes_left) {
+                               if (bytes_left < 4) {
                                        finish_early = true;
                                        break;
                                }
@@ -546,7 +546,7 @@ static unsigned as_compile(struct algorithm_steps *as, uint8_t *target,
                                offset += 3;
                                break;
                        case STEP_SET_DIR:
-                               if (3 > bytes_left) {
+                               if (bytes_left < 3) {
                                        finish_early = true;
                                        break;
                                }
@@ -555,7 +555,7 @@ static unsigned as_compile(struct algorithm_steps *as, uint8_t *target,
                                break;
                        case STEP_TXWM_WAIT:
                        case STEP_WIP_WAIT:
-                               if (2 > bytes_left) {
+                               if (bytes_left < 2) {
                                        finish_early = true;
                                        break;
                                }
@@ -651,7 +651,7 @@ static int steps_add_buffer_write(struct algorithm_steps *as,
                const uint8_t *buffer, uint32_t chip_offset, uint32_t len)
 {
        if (chip_offset & 0xFF000000) {
-               LOG_ERROR("FESPI interface does not support greater than 3B addressing, can't write to offset 0x%x",
+               LOG_ERROR("FESPI interface does not support greater than 3B addressing, can't write to offset 0x%" PRIx32,
                                chip_offset);
                return ERROR_FAIL;
        }
@@ -916,7 +916,7 @@ static int fespi_probe(struct flash_bank *bank)
 
        if (fespi_info->probed)
                free(bank->sectors);
-       fespi_info->probed = 0;
+       fespi_info->probed = false;
 
        if (fespi_info->ctrl_base == 0) {
                for (target_device = target_devices ; target_device->name ; ++target_device)
@@ -986,7 +986,7 @@ static int fespi_probe(struct flash_bank *bank)
        /* create and fill sectors array */
        bank->num_sectors = fespi_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;
        }
@@ -999,7 +999,7 @@ static int fespi_probe(struct flash_bank *bank)
        }
 
        bank->sectors = sectors;
-       fespi_info->probed = 1;
+       fespi_info->probed = true;
        return ERROR_OK;
 }
 
@@ -1017,17 +1017,16 @@ static int fespi_protect_check(struct flash_bank *bank)
        return ERROR_OK;
 }
 
-static int get_fespi_info(struct flash_bank *bank, char *buf, int buf_size)
+static int get_fespi_info(struct flash_bank *bank, struct command_invocation *cmd)
 {
        struct fespi_flash_bank *fespi_info = bank->driver_priv;
 
        if (!(fespi_info->probed)) {
-               snprintf(buf, buf_size,
-                               "\nFESPI flash bank not probed yet\n");
+               command_print_sameline(cmd, "\nFESPI flash bank not probed yet\n");
                return ERROR_OK;
        }
 
-       snprintf(buf, buf_size, "\nFESPI flash information:\n"
+       command_print_sameline(cmd, "\nFESPI flash information:\n"
                        "  Device \'%s\' (ID 0x%08" PRIx32 ")\n",
                        fespi_info->dev->name, fespi_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)