This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28375S: Can I clear RAM at the end of a bootloader, running from RAM

Part Number: TMS320F28375S

Tool/software:

I have a bootloader running from Flash. At the end, this Bl chooses one of the two possible applications (A or B) in flash and jumps to it. The application should run from RAM.

Before the jump, these things are done in a sequence (last things done in the BL):
wd_disable > init_ram (clearing whole RAM) > copy the selected application from Flash to RAM (A or B) > branch to the BEGIN address in Flash for the selected application (A or B)

this way, the selected application will start running (From RAM)


When first implemented this, I decided to run the BL itself from Flash instead of RAM, because I thought if running from RAM, the BL itself would crash when I clear the whole RAM at the end, before it could successfully jump to the selected application A or B. I have had very strange problems when the BL runs from Flash (explained here and here). Sometimes it works fine, sometimes I get strange behavior which happens randomly.

I tried running the BL from RAM instead, and saw that unlike what I expected, it works fine. 

Now my question is this: Can this be safe to have this structure, and run the BL from RAM, and not from Flash? If yes, that could be a solution for me. But if you say it might not always work properly, I know that I have to discard this case (BL running from RAM) and focus on running the BL from Flash and solving the issues that I got in that case.

I should add that the sequence done at the end of BL (right before jump) mentioned above (clear RAM + copy selected application to RAM + branch into it's beginning address in Flash) are done in some assembly files that are linked to Flash (in the flash area dedicated for BL), and even when I tried running BL from RAM, I still kept those linked to Flash. 


  • Hi Saeed, 

    Yes, that is possible, although the available RAM space will be a tight constraint. What is the size of your bootloader? 

    Best,

    Matt

  • Hi Matt

    I don't think that RAM space is an issue. The BL code in Flash takes first two sectors. Besides, it has been used in another design where it was running from RAM without any problem. In this project I decided to run it from Flash, because I have to clear the whole RAM at the end of it, while we are still inside the BL code (right before jump). 

    For running BL from RAM I tried this case, which worked fine:

    In the BL:
    Whole code runs from RAM (Load from Flash, Run from RAM), except the assembly instructions at the end of BL, which do the sequence [clear whole RAM + copy next stage app to RAM + jump to the start address of next app in flash], are linked only to flash. So it seems like when we are still in BL and the RAM is cleared, everything else in BL after that point runs from flash. Therefore, BL can continue finishing those instructions and not crash even though the RAM is cleared at that time.

    That is my understanding, but I had to ask you to be sure that everything here is normal and could be explained. 

    The problems that I had in the other case (BL running from Flash) were happening quite randomly. I would see the issue, try something, it was fixed, but then some days later it would happen again accidentally when I did an irrelevant change somewhere else in the code, which couldn't possibly be the origin of the issue! So you can understand that even when I have a running version without any issue, I can't trust that it's really all good.

    That's why also in this case (Running BL from RAM), even though it's working now, I still have doubts and posted this question to confirm my understanding.


    Regards,
    Saeed

  • Hi Saeed,

    If RAM space is not an issue and your memory management is clean, then running the bootloader from RAM is a valid approach. 

    Best,

    Matt