stm32: return early upon block write failure
[openocd.git] / src / flash / nor / stm32x.c
index ae4f02b55c7dbab61fab1168a9b17202b6ea191e..6b46afc8d543bdfefe10b9365d12b441a1cba343 100644 (file)
@@ -115,7 +115,9 @@ static int stm32x_read_options(struct flash_bank *bank)
        stm32x_info = bank->driver_priv;
 
        /* read current option bytes */
-       target_read_u32(target, STM32_FLASH_OBR, &optiondata);
+       int retval = target_read_u32(target, STM32_FLASH_OBR, &optiondata);
+       if (retval != ERROR_OK)
+               return retval;
 
        stm32x_info->option_bytes.user_options = (uint16_t)0xFFF8 | ((optiondata >> 2) & 0x07);
        stm32x_info->option_bytes.RDP = (optiondata & (1 << OPT_READOUT)) ? 0xFFFF : 0x5AA5;
@@ -124,7 +126,9 @@ static int stm32x_read_options(struct flash_bank *bank)
                LOG_INFO("Device Security Bit Set");
 
        /* each bit refers to a 4bank protection */
-       target_read_u32(target, STM32_FLASH_WRPR, &optiondata);
+       retval = target_read_u32(target, STM32_FLASH_WRPR, &optiondata);
+       if (retval != ERROR_OK)
+               return retval;
 
        stm32x_info->option_bytes.protection[0] = (uint16_t)optiondata;
        stm32x_info->option_bytes.protection[1] = (uint16_t)(optiondata >> 8);
@@ -287,7 +291,9 @@ static int stm32x_protect_check(struct flash_bank *bank)
 
        /* medium density - each bit refers to a 4bank protection
         * high density - each bit refers to a 2bank protection */
-       target_read_u32(target, STM32_FLASH_WRPR, &protection);
+       int retval = target_read_u32(target, STM32_FLASH_WRPR, &protection);
+       if (retval != ERROR_OK)
+               return retval;
 
        /* medium density - each protection bit is for 4 * 1K pages
         * high density - each protection bit is for 2 * 2K pages */
@@ -418,7 +424,9 @@ static int stm32x_protect(struct flash_bank *bank, int set, int first, int last)
 
        /* medium density - each bit refers to a 4bank protection
         * high density - each bit refers to a 2bank protection */
-       target_read_u32(target, STM32_FLASH_WRPR, &protection);
+       int retval = target_read_u32(target, STM32_FLASH_WRPR, &protection);
+       if (retval != ERROR_OK)
+               return retval;
 
        prot_reg[0] = (uint16_t)protection;
        prot_reg[1] = (uint16_t)(protection >> 8);
@@ -660,6 +668,9 @@ static int stm32x_write(struct flash_bank *bank, uint8_t *buffer,
                }
        }
 
+       if ((retval != ERROR_OK) && (retval != ERROR_TARGET_RESOURCE_NOT_AVAILABLE))
+               return retval;
+
        while (words_remaining > 0)
        {
                uint16_t value;
@@ -713,12 +724,16 @@ static int stm32x_probe(struct flash_bank *bank)
        stm32x_info->probed = 0;
 
        /* read stm32 device id register */
-       target_read_u32(target, 0xE0042000, &device_id);
+       int retval = target_read_u32(target, 0xE0042000, &device_id);
+       if (retval != ERROR_OK)
+               return retval;
        LOG_INFO("device id = 0x%08" PRIx32 "", device_id);
 
-       /* get flash size from target */
-       if (target_read_u16(target, 0x1FFFF7E0, &num_pages) != ERROR_OK)
+       /* get flash size from target. */
+       retval = target_read_u16(target, 0x1FFFF7E0, &num_pages);
+       if (retval != ERROR_OK)
        {
+               LOG_WARNING("failed reading flash size, default to max target family");
                /* failed reading flash size, default to max target family */
                num_pages = 0xffff;
        }
@@ -855,7 +870,9 @@ static int get_stm32x_info(struct flash_bank *bank, char *buf, int buf_size)
        int printed;
 
        /* read stm32 device id register */
-       target_read_u32(target, 0xE0042000, &device_id);
+       int retval = target_read_u32(target, 0xE0042000, &device_id);
+       if (retval != ERROR_OK)
+               return retval;
 
        if ((device_id & 0x7ff) == 0x410)
        {
@@ -1093,7 +1110,9 @@ COMMAND_HANDLER(stm32x_handle_options_read_command)
                return ERROR_TARGET_NOT_HALTED;
        }
 
-       target_read_u32(target, STM32_FLASH_OBR, &optionbyte);
+       retval = target_read_u32(target, STM32_FLASH_OBR, &optionbyte);
+       if (retval != ERROR_OK)
+               return retval;
        command_print(CMD_CTX, "Option Byte: 0x%" PRIx32 "", optionbyte);
 
        if (buf_get_u32((uint8_t*)&optionbyte, OPT_ERROR, 1))

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)