From 4bc68409f8c2e84c3a523384e8d76860b55eb7b0 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Tue, 28 Jun 2022 23:30:19 -0400 Subject: [PATCH] kinetis: Clean up how kl_gen_flash_done builds the command buffers to send to ensure the security byte is OK --- src/target/kinetis.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/target/kinetis.c b/src/target/kinetis.c index 53f4eb0..3ab08c3 100644 --- a/src/target/kinetis.c +++ b/src/target/kinetis.c @@ -493,16 +493,16 @@ static int kinetis_flash_done(struct target_flash *const f) * vs 4 byte phrases). */ if (kf->write_len == K64_WRITE_LEN) { - uint32_t vals[2]; - vals[0] = target_mem_read32(f->t, FLASH_SECURITY_BYTE_ADDRESS - 4); - vals[1] = target_mem_read32(f->t, FLASH_SECURITY_BYTE_ADDRESS); - vals[1] = (vals[1] & 0xffffff00) | FLASH_SECURITY_BYTE_UNSECURED; + uint32_t vals[2] = { + target_mem_read32(f->t, FLASH_SECURITY_BYTE_ADDRESS - 4), + target_mem_read32(f->t, FLASH_SECURITY_BYTE_ADDRESS) + }; + vals[1] = (vals[1] & 0xffffff00U) | FLASH_SECURITY_BYTE_UNSECURED; kinetis_fccob_cmd(f->t, FTFx_CMD_PROGRAM_PHRASE, FLASH_SECURITY_BYTE_ADDRESS - 4, vals, 2); } else { - uint32_t vals[1]; - vals[0] = target_mem_read32(f->t, FLASH_SECURITY_BYTE_ADDRESS); - vals[0] = (vals[0] & 0xffffff00) | FLASH_SECURITY_BYTE_UNSECURED; - kinetis_fccob_cmd(f->t, FTFx_CMD_PROGRAM_LONGWORD, FLASH_SECURITY_BYTE_ADDRESS, vals, 1); + uint32_t val = target_mem_read32(f->t, FLASH_SECURITY_BYTE_ADDRESS); + val = (val & 0xffffff00U) | FLASH_SECURITY_BYTE_UNSECURED; + kinetis_fccob_cmd(f->t, FTFx_CMD_PROGRAM_LONGWORD, FLASH_SECURITY_BYTE_ADDRESS, &val, 1); } return 0;