target/efm32: bootloader lock word handling fix

Signed-off-by: Rafael Silva <perigoso@riseup.net>
This commit is contained in:
Rafael Silva 2022-07-12 23:13:18 +01:00 committed by Rachel Mant
parent c2589bc39f
commit 096927b0b8
1 changed files with 5 additions and 4 deletions

View File

@ -860,17 +860,18 @@ static bool efm32_cmd_bootloader(target *t, int argc, const char **argv)
}
uint32_t clw0 = target_mem_read32(t, EFM32_LOCK_BITS_CLW0);
bool bootloader_status = (clw0 & EFM32_CLW0_BOOTLOADER_ENABLE) ? 1 : 0;
if (argc == 1) {
const bool bootloader_status = clw0 & EFM32_CLW0_BOOTLOADER_ENABLE;
tc_printf(t, "Bootloader %s\n", bootloader_status ? "enabled" : "disabled");
return true;
} else {
bootloader_status = (argv[1][0] == 'e');
}
/* Modify bootloader enable bit */
clw0 &= bootloader_status ? ~0 : ~EFM32_CLW0_BOOTLOADER_ENABLE;
if (argv[1][0] == 'e')
clw0 |= EFM32_CLW0_BOOTLOADER_ENABLE;
else
clw0 &= ~EFM32_CLW0_BOOTLOADER_ENABLE;
/* Unlock */
target_mem_write32(t, EFM32_MSC_LOCK(msc), EFM32_MSC_LOCK_LOCKKEY);