flash/stm32h7x: use alignment infrastructure 88/5388/5
authorChristopher Head <chead@zaber.com>
Fri, 3 Jan 2020 22:49:16 +0000 (14:49 -0800)
committerTomas Vanek <vanekt@fbl.cz>
Sun, 23 Feb 2020 12:38:38 +0000 (12:38 +0000)
Report the 32-byte alignemnt requirement via the bank structure rather
than enforcing it ad-hoc in the write routine. This allows people to do
non-32-byte-aligned writes if they want, with the infrastructure fixing
up the addresses passed to the low-level driver.

Change-Id: I2c4f532f2000435954a900224dbc9f2c30d1cc94
Signed-off-by: Christopher Head <chead@zaber.com>
Reviewed-on: http://openocd.zylin.com/5388
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
src/flash/nor/stm32h7x.c

index 152a154bd08c5c70fb0342164df1b2d1bd3bf0a2..bf003684cb259830ce1915863e7163374090926e 100644 (file)
@@ -170,6 +170,9 @@ FLASH_BANK_COMMAND_HANDLER(stm32x_flash_bank_command)
        stm32x_info->probed = 0;
        stm32x_info->user_bank_size = bank->size;
 
+       bank->write_start_alignment = FLASH_BLOCK_SIZE;
+       bank->write_end_alignment = FLASH_BLOCK_SIZE;
+
        return ERROR_OK;
 }
 
@@ -610,17 +613,17 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer,
                return ERROR_TARGET_NOT_HALTED;
        }
 
-       if (offset % FLASH_BLOCK_SIZE) {
-               LOG_WARNING("offset 0x%" PRIx32 " breaks required 32-byte alignment", offset);
-               return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
-       }
+       /* should be enforced via bank->write_start_alignment */
+       assert(!(offset % FLASH_BLOCK_SIZE));
+
+       /* should be enforced via bank->write_end_alignment */
+       assert(!(count % FLASH_BLOCK_SIZE));
 
        retval = stm32x_unlock_reg(bank);
        if (retval != ERROR_OK)
                goto flash_lock;
 
        uint32_t blocks_remaining = count / FLASH_BLOCK_SIZE;
-       uint32_t bytes_remaining = count % FLASH_BLOCK_SIZE;
 
        /* multiple words (32-bytes) to be programmed in block */
        if (blocks_remaining) {
@@ -667,25 +670,6 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer,
                blocks_remaining--;
        }
 
-       if (bytes_remaining) {
-               retval = stm32x_write_flash_reg(bank, FLASH_CR, FLASH_PG | FLASH_PSIZE_64);
-               if (retval != ERROR_OK)
-                       goto flash_lock;
-
-               retval = target_write_buffer(target, address, bytes_remaining, buffer);
-               if (retval != ERROR_OK)
-                       goto flash_lock;
-
-               /* Force Write buffer of FLASH_BLOCK_SIZE = 32 bytes */
-               retval = stm32x_write_flash_reg(bank, FLASH_CR, FLASH_PG | FLASH_PSIZE_64 | FLASH_FW);
-               if (retval != ERROR_OK)
-                       goto flash_lock;
-
-               retval = stm32x_wait_flash_op_queue(bank, FLASH_WRITE_TIMEOUT);
-               if (retval != ERROR_OK)
-                       goto flash_lock;
-       }
-
 flash_lock:
        retval2 = stm32x_lock_reg(bank);
        if (retval2 != ERROR_OK)

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)