Menu

#448 Flashing S32K with FlexNVM partitioned as EEPROM crashes OpenOCD & puts chip in secure state

0.10.0
new
nobody
None
2025-01-20
2025-01-17
No

I'm working with an S32K116. When I

  1. Mass-erase it with kinetis mdm mass_erase
  2. Partition the FlexNVM as EEPROM (using the attached Python script)
  3. Try to flash the MCU (by attaching with GDB and running load)

OpenOCD crashes with an assertion failure in src/flash/nor/kinetis.c:1492. If I restart OpenOCD and try to flash the chip again, I get the message that the MCU is in secured state.

As far as I understand, this happens because kinetis_probe() detects the EEPROM partitioning and thus does not allocate sectors or prot_blocks (kinetis.c:3022).

If I add a check for num_prot_blocks == 0 before the assert (see the attached patch), OpenOCD no longer crashes and the MCU does not go into secured state.

I'm not sure if this is the correct place to fix it --- the assertion is kind of obvious, but I don't understand why the MCU goes into secured state, or why not failing the assertion prevents going into secured state.

2 Attachments

Discussion

  • Tomas Vanek

    Tomas Vanek - 2025-01-17

    Thanks for reporting!

    I was able to reproduce the problem on the older K66FX1M0
    Your solution is correct, but...

    Please be aware that OpenOCD project requires submitting patches to the Gerrit review system, we are not able to accept patches from mails and tickets. See https://openocd.org/doc/doxygen/html/patchguide.html

    In this case I made an exception as I want to remove the assert() to prevent the MCU locking effect (and I'm the author of this bug ;-)

    Please test
    8719: flash/nor/kinetis: fix assertion during flash write | https://review.openocd.org/c/openocd/+/8719

    I added your mail to Suggested-by clause of the commit message. I hope it's enough to express your credit.

    BTW Don't you want to contribute a S32K1xx part of kinetis_nvm_partition handler?
    You already managed it in python, so it should be easy to rewrite to C...

     
  • Jasper v. Blanckenburg

    Thanks for the swift response and submitting the patch, I'll test it on Monday. No worries about credit, I'm just happy if we don't have to maintain a patched version ;)

    I'll look into writing the partition handler.

     
  • Jasper v. Blanckenburg

    Just tested the patch, it works fine :)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.