Jlink flash programming interface does not take memory changes from CPU/code into account

  • When Jlink performs flash updates, it looks that its cache is not up-to-date if the memory content has been modified by code execution. It results in having wrong memory content at the end.

    My use is case is the following : My application is initializing 16 bytes at defined address of the Flash memory at startup, assuming the first byte is FFh.

    - 1. Flash code -> memory is virgin -> All bytes are FFh
    - 2. Using memory viewer, I modified some bytes (lets say 8th and 12th to CCh) into the buffer. The flasher runs and modifies the memory. Memory viewer shows the right data.
    - 3. I run code and stop it just after my code performs memory initialization. Memory viewer shows the expected data : All the bytes are written with new value including 8th and 12th bytes
    - 4. I use the memory viewer to modify first byte to 33h. The flasher runs but the result is not the good one. First byte is ok but 8th and 12th get the value written in dot 2 !!!!

    @0x5000 (Flash Memory)
    1. -> FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
    2. -> FF FF FF FF FF FF FF CC FF FF FF CC FF FF FF FF FF FF
    3. -> 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    4. -> 33 FF FF FF FF FF FF CC FF FF FF CC FF FF FF FF FF FF (expected value with Read-Modify-Feature: 33 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 )

    If I perform exactly the same but replacing the code operation with direct modification in Memory viewer , everything is ok

    Looking at jlinklog, the CPU mem read and cache update are ok. See log attached (line 1383). But it looks the Flasher has its own cache that it is not up-to-date as it restores the former data.


    Context :
    - Embedded Studio 8.16
    - Jlink software 7.98d
    - Jlink base compact with last firmware.

    Note: All the Flash memory has been excluded from Flash caching in jlink script file using JLINK_ExecCommand("ExcludeFlashCacheRange 0x00000000-0x0007FFFF"); as required.

  • More information about the issue:
    When using the memory viewer of embedded studio to modify some bytes of the memory, only modified characters are updated into the cache used for flashing. That is visible in the jlink control panel and llink log file.

    However the first modification MUST trig a refresh of the cache by reading the full content of the concerned memory sector.
    This seems not to be done.
    As a result, the jlink flash driver does not know the current memory content of the sector and so performs inconsistent write operations.

    Regards
    Fred

  • Hi,

    We can confirm that the problem is reproducible on our side.
    We already have an internal solution for it but need to perform another round of iterations to check against unwanted side effects.


    BR
    Alex

    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: https://www.segger.com/ticket/

    Or you can contact us via e-mail.

  • Hello,

    The fix for this issue will be included in the next version, scheduled for later today.

    Stay up-to-date regarding J-Link:
    https://www.segger.com/notification/s…php?prodid=7,94

    Best regards,
    Simon

    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: https://www.segger.com/ticket/

    Or you can contact us via e-mail.

  • Hello Simon,
    I've just tried the new version.
    It does not work on my side. When using the memory viewer to modify the memory, it looks the flash loader is not loaded into RAM memory before calling it, resulting in having an illegal instruction error with address in loader.

    [Update]
    The exception does not occurs when doing a "step into" after the modification. Doing a "step over" or a run after cause the illegal exception occurs. And for step over I get the error message "Failed to set stepover breakpoint".

    For both I can also see in console: PC of target system has unexpected value after erasing sectors. (PC = 0x000001C4)! for all cases (including step into)

    Any idea ?

    Regards
    Frederic

    Edited once, last by fjouen: More information (September 6, 2024 at 4:11 PM).

  • Additionnal information :

    The exception occurs for all exit conditions so for "step into" too.

    Exceptions occurs when attempting to execute flash loader code that should be loaded into RAM memory.
    mcause register indicates an illegal instruction at start address of SEGGER_FL_Erase.

    The exception results in having PC into the security exception handler. That's why I get the following message after modifying the memory:

    PC of target system has unexpected value after erasing sectors. (PC = 0x000001C4)!
    Failed to erase sectors.

    So now, I have 2 issues:
    1 - Memory update from memory viewer cause a security exception due to an illegal instruction (loader not loaded ?). Please note that everything is working well when loading the code.
    2 - When using "step into" mode the debbuger seems ignoring PC modification from flash loader and restore the PC value to the nex expected one.


    Here are the log trace:

    Regarding the trace, I note something strange in the log (lines 19 and 21). 7.98f release is intended to update cache reading the full memory sector. We can see 2 CPU_ReadMem in the trace :
    - Read 384 bytes from 0x5000
    - Read 64 bytes from 0x51C0
    So 64 bytes are still missing from 0x5180 to 0x51C0.


    Regards
    Fred

    Edited once, last by fjouen (September 6, 2024 at 5:04 PM).

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!