From fee6f28915fadcf5c208dd8b67eab5fd7b135769 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Wed, 22 Jun 2022 00:22:14 -0400 Subject: [PATCH] kinetis: General formatting and readability cleanup --- src/target/kinetis.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/target/kinetis.c b/src/target/kinetis.c index 5e44bfe..bcce410 100644 --- a/src/target/kinetis.c +++ b/src/target/kinetis.c @@ -436,19 +436,18 @@ static int kl_gen_flash_write(struct target_flash *f, /* Ensure we don't write something horrible over the security byte */ if (!f->t->unsafe_enabled && - (dest <= FLASH_SECURITY_BYTE_ADDRESS) && - ((dest + len) > FLASH_SECURITY_BYTE_ADDRESS)) { + dest <= FLASH_SECURITY_BYTE_ADDRESS && + dest + len > FLASH_SECURITY_BYTE_ADDRESS) { ((uint8_t*)src)[FLASH_SECURITY_BYTE_ADDRESS - dest] = FLASH_SECURITY_BYTE_UNSECURED; } /* Determine write command based on the alignment. */ uint8_t write_cmd; - if (kf->write_len == K64_WRITE_LEN) { + if (kf->write_len == K64_WRITE_LEN) write_cmd = FTFE_CMD_PROGRAM_PHRASE; - } else { + else write_cmd = FTFA_CMD_PROGRAM_LONGWORD; - } while (len) { if (kl_gen_command(f->t, write_cmd, dest, src, 1)) { @@ -458,9 +457,8 @@ static int kl_gen_flash_write(struct target_flash *f, len = 0; dest += kf->write_len; src += kf->write_len; - } else { + } else return 1; - } } return 0; } @@ -472,14 +470,13 @@ static int kl_gen_flash_done(struct target_flash *f) if (f->t->unsafe_enabled) return 0; - if (target_mem_read8(f->t, FLASH_SECURITY_BYTE_ADDRESS) == - FLASH_SECURITY_BYTE_UNSECURED) + if (target_mem_read8(f->t, FLASH_SECURITY_BYTE_ADDRESS) == FLASH_SECURITY_BYTE_UNSECURED) return 0; /* Load the security byte based on the alignment (determine 8 byte phrases * vs 4 byte phrases). */ - if (kf->write_len == 8) { + 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);