Skip to content

Commit

Permalink
flash/nor/kinetis: fix assertion during flash write
Browse files Browse the repository at this point in the history
If the device has at lest one FlexNVM bank and it is set as EE backup
only, the bank has no protection blocks.

kinetis_fill_fcf() collects protection data from all banks before
flash write of the sector containing FCF block. In case it encountered
a FlexNVM bank with no protection blocks assert failed.

Failed flash write of previously erased FCF block could cause
engaging debugging lock (if the device was run or reset).

Skip banks with zero protection blocks.
Replace assert() by LOG_ERROR() as we have to finish FCF write.

Change-Id: Ibe7e7ec6d0db4453b8a53c8256987621b809c99d
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Suggested-by: Jasper v. Blanckenburg <jazzpi@users.sourceforge.net>
Fixes: https://sourceforge.net/p/openocd/tickets/448/
Reviewed-on: https://review.openocd.org/c/openocd/+/8719
Tested-by: jenkins
Reviewed-by: Jasper v. Blanckenburg <jasper@mezzo.de>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
  • Loading branch information
tom-van authored and borneoa committed Jan 25, 2025
1 parent 3099547 commit 77f9da7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/flash/nor/kinetis.c
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,22 @@ static int kinetis_fill_fcf(struct flash_bank *bank, uint8_t *fcf)

kinetis_auto_probe(bank_iter);

assert(bank_iter->prot_blocks);
if (bank_iter->num_prot_blocks == 0) {
if (k_bank->flash_class == FC_PFLASH) {
LOG_ERROR("BUG: PFLASH bank %u has no protection blocks",
bank_idx);
} else {
LOG_DEBUG("skipping FLEX_NVM bank %u with no prot blocks (EE bkp only)",
bank_idx);
}
continue;
}

if (!bank_iter->prot_blocks) {
LOG_ERROR("BUG: bank %u has NULL protection blocks array",
bank_idx);
continue;
}

if (k_bank->flash_class == FC_PFLASH) {
for (unsigned int i = 0; i < bank_iter->num_prot_blocks; i++) {
Expand Down

0 comments on commit 77f9da7

Please # to comment.