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.

Run external code (bootloader like)

Hi everyone,

I was doing some tests to develop a bootloader like application.
Of course I've been reading on the available TM4C bootloader. Unfortunately it doesn't fit the requirements. Further ahead (maybe already time to), I will try to adapt some parts into what I need.

In this test I had 2 projects. Let's call the first one the bootloader project and the second the application code.
The bootloader project had in the linker .cmd a section defined at 0x4000 and a empty function was create there in the main.

The app code would start at 0x4000 by changing the APP_BASE value in the .cmd.
I got the binary and converted it to a 32bit array.

Again in the bootloader project, I added the 32bit array in RAM and then copied into Flash starting at 0x4000 - this using FlashProgram and erasing that block first.

Running the code I can see the whole array was copied to flash. I also checked to see if the original code and the array matched. But still it goes into a fault ISR.
FAULT_STAT shows that the flag bus fault address register valid and precise data bus error are set. I will have to check better on what that means precisely.

If anyone has suggestions in what the problem is it would be appreciated. I will be trying to read more on the bootloader app notes


  • Hello Luis

    A precise bus fault will capture the bus fault address in FAULTADDR register

    Regards
    Amit
  • Luis Afonso said:
    The app code would start at 0x4000 by changing the APP_BASE value in the .cmd.
    I got the binary and converted it to a 32bit array.

    I'm no expert w/this vendor's boot-loaders - yet that, "Binary to array conversion" may complicate - is not that true?   Anything which deviates from "normal/customary" - when performing such an analysis - usually is best avoided.   (and can be added later - after the "basic method" is demonstrated to work)

    I'd suggest an elementary "blinky" program - minus any conversions - as a more suitable (and safer) "App Code."

  • Luis, besides cb1's good suggestion to make sure your initial test application is as simple as possible have you tried doing this w/o the 'bootloader'.

    I.E. load both the boot code and application code using JTAG. That will narrow the problem to either your loading to RAM and then flash or your basic location and build process.

    Robert
  • The thing is, the objective is to just store a code either in RAM or in another place in flash and when needed, move it to the main code to be executed.
    I checked and the copy was successful, exactly the same as the original one.
    The conversion was just a way to store the binary code without having to send it, by already have it programmed in a array ready to go.
    I believe the problem is due to the startup of the application code, something with the vector table or something.

    Note - I am not using the bootloader! As I said, it did not meet requirements. I am testing if this approach will be easier than adapting the bootloader example. The array was a way to eliminate the communication errors that could possibly arise.


    Got a bit of an issue with my CCS when checking the address, I will try to check the problem and come back.


    How do you suggest I do that Robert? Upload the boot code and then the app code with LM flash programmer? (programming the app code only at 0x4000 and erasing only the needed pages?)
  • Essentially yes, Luis

    With my adapter I'd either (erase everything, program 'boot', program 'app') or (merge 'boot' and 'app' in programing adapter software, erase and program). Remove your array conversion and flash programming from the equation.

    Robert
  • Didn't quite work :/

    I think there is also (and can be this problem) with the main. Both have a main. I tried to change the name on the bootloader project but I was not successful, getting the error:
    Description Resource Path Location Type
    unresolved symbol main, first referenced in C:\ti\ccsv6\tools\compiler\ti-cgt-arm_5.2.5\lib\rtsv7M4_T_le_v4SPD16_eabi.lib<args_main.obj>

    Not sure how to solve it. The boot example doesn't have int main but I did not find how it was done.

    The address at FAULT_ADDRESS was way way way off somewhere in the RAM.
  • Unless you have done something unusual then there is no problem with main in both. No symbols are maintained in the binary.

    There's a good chance you need a different startup though, those are often absolutely located (at 0 on a cortex core).

    Robert
  • I edited the linker so the app code only starts at 0x4000 so that should not be a problem.

    I notice that in the dissassembly the copied code is always in thumb instead of mixed. Don't know if this is just the dissassembly acting up but in this situation, the second assembly line is actually a branch to address 0! Weird. I am trying to compile the app code in 16bit instructions only to try it out
  • Editing the linker will be insufficient if the startup is absolutely located

    Robert
  • True.
    I have checked the memory with the debugger and everything just starts at 0x4000. So I think that can be ruled out.
  • Solved the problem.

    The jump was incorrect. Now to jump I do this process:

    -Update vector table offset register
    -Change SP to the APP address
    -Change PC to APP address + 4.


    I have everything working so far (let's see how it goes). Besides finding that process above, everything is actually quite simple.

    The only issues I have but have made workarounds are related to the compiler and linker. Like, how do I remove the symbol Main (wanted to test out something) and how to get a library flash footprint to be in a specific spot in flash (I was only able to get everything! Including RAM variables)