• AVR Freaks

Hot!bootloader crash when jumping to app

Author
Thorben.Z
Starting Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2017/06/03 06:33:33
  • Location: 0
  • Status: offline
2019/05/10 03:58:51 (permalink)
0

bootloader crash when jumping to app

I just started playing with a project of mine, trying to make a bootloader that loads the new code from an external SPI flash.But I am already failing in getting it to jump to my app.
As a test, to see if my concept works, it reads a memory location, to see if the app loaded correctly, if it did it jump back to it and otherwise just flash a LED. It worked when the app was just another program flashing another other LED, but when i used it with a more complex app, it just resets after executing the first few lines of code.
 
The bootloader is in the boot flash (just after the startup code), with the app starting (as i think it normally would) at the beginning of the program flash. To jump there i have tried both 'jr' (as the startup code does i think) and just 'j 0x9D000000' (program flash), and also put a "j main" command at 0x9D000000 in the app, in case 'main' was located elsewhere.
I have also tried to make the compiler link the startup code for the app to program memory start, but once i include the bootloader as a loadable it complains about overlapping memory locations (multiple ones, including the debug exception vector code, which i don't think i can move).
 
BTW i have not really got any clue about what i am doing here, I'm just trying to learn it, so excuse any wrong assumptions or conclusions about what goes where, or what the compiler does/needs to do before app startup.
I have also been on google for three hours now and haven't found any possible cause of this (probably because i don't really now what to search for :P)
 
EDIT: i found a solution. look down below
post edited by Thorben.Z - 2019/05/13 08:40:05
#1

10 Replies Related Threads

    qhb
    Superb Member
    • Total Posts : 9999
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: bootloader chrash when jumping to app 2019/05/10 04:13:26 (permalink)
    3.67 (3)
    Why does everyone try to implement a bootloader as their first project, when that is one of the most advanced topics on a microcontroller?
    Learn how to program it first, WITHOUT a bootloader, and your experience will be much more enjoyable.
     

    Nearly there...
    #2
    Thorben.Z
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2017/06/03 06:33:33
    • Location: 0
    • Status: offline
    Re: bootloader chrash when jumping to app 2019/05/10 04:19:03 (permalink)
    0
    qhb
    Why does everyone try to implement a bootloader as their first project, when that is one of the most advanced topics on a microcontroller?
    Learn how to program it first, WITHOUT a bootloader, and your experience will be much more enjoyable.
     




    i've been programming things in C, java and a bit of assembler for only around 9 years now and earning money with it ;)
    i just do not know exactly where the compiler links what, as until now somebody else did all the bootloader stuff. Now i just want to learn about those. programming isn't the issue here
    post edited by Thorben.Z - 2019/05/10 04:21:15
    #3
    Jim Nickerson
    User 452
    • Total Posts : 6797
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: bootloader chrash when jumping to app 2019/05/10 07:18:03 (permalink)
    4 (1)
    Did you base your bootloader on an app note example ?
    #4
    Thorben.Z
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2017/06/03 06:33:33
    • Location: 0
    • Status: offline
    Re: bootloader chrash when jumping to app 2019/05/10 08:55:56 (permalink)
    0
    JANickerson
    Did you base your bootloader on an app note example ?


    I started with the example one from AN1388, but since it placed the code into program memory, and even the UART version was too large to fit into the boot section, I started over and wanted to write my own.
     
    And it isn't a bootloader yet, at the moment it is just a piece of code, jumping to the app as a test.
    I also didn't use the Harmony one because i do want to learn how it works and not just click a button to include it.
    #5
    NKurzman
    A Guy on the Net
    • Total Posts : 19031
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: bootloader chrash when jumping to app 2019/05/10 09:08:11 (permalink)
    0
    The bootloader and the main application are two separate projects. Each needs its own linker script too locate the two programs in non overlapping and correct memory.
    You are using an appnote for a pic32mx.
    Is that what you are using.
    #6
    Thorben.Z
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2017/06/03 06:33:33
    • Location: 0
    • Status: offline
    Re: bootloader chrash when jumping to app 2019/05/10 09:30:24 (permalink)
    0
    Yes. I have added my bootloader project to the app as a loadable. But i can only manage to upload if i exclude the startup code from the app (i guessed, that would be the same as the startup code for the bootloader). But no matter which address I put it I get "(944) data conflict at address 1FC00488h" (1FC00488h is the debug exception vector according to the linker).
     
     
    #7
    NKurzman
    A Guy on the Net
    • Total Posts : 19031
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: bootloader chrash when jumping to app 2019/05/10 09:47:11 (permalink)
    0
    loadable is an optional method.
    Does it work that way?
    Which PIC do you have.
    What did you do for linker scripts?
    You can’t exclude start up code from the app, it needs it. The fact that you have to says you linker scripts are wrong.
    You can look up my old bootloader posts.
    The linker scripts are key, and are not simple.
    Things must be in the correct place. The PIC32 has 3 address for each memory location. The linker does always spot overlaps, or give warnings for incorrect addresses.

    You could try the Harmony Bootloader. It works for many PICs, but it is not of good quality.
    #8
    Thorben.Z
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2017/06/03 06:33:33
    • Location: 0
    • Status: offline
    Re: bootloader chrash when jumping to app 2019/05/10 10:26:39 (permalink)
    0
    It does work with another app that just blinks an LED.
    I'm using a pic32mx170f256b.
    In the linker scrips, I changed the defined memory sections:
     
    for the App (this was after i tried to move the startup code to program memory):
      kseg0_program_mem (rx) : ORIGIN = 0x9D00F000, LENGTH = 0x30000
      exception_mem : ORIGIN = 0x9D03F000, LENGTH = 0x1000
      debug_exec_mem : ORIGIN = 0x9D000490, LENGTH = 0x760
      kseg0_boot_mem : ORIGIN = 0x9D000490, LENGTH = 0x0
      kseg1_boot_mem : ORIGIN = 0xBD000000, LENGTH = 0x490
     
    and for the "bootloader":
      kseg0_program_mem (rx) : ORIGIN = 0x9FC004B0, LENGTH = 0x650
      exception_mem : ORIGIN = 0x9D03F000, LENGTH = 0x1000
    /* I wasn't sure where to put exception_mem. I tried both boot mem after the bootloader and program mem*/
      debug_exec_mem : ORIGIN = 0x9FC00AF0, LENGTH = 0x100
      kseg0_boot_mem : ORIGIN = 0x9FC00AF0, LENGTH = 0x0
      kseg1_boot_mem : ORIGIN = 0xBFC00000, LENGTH = 0x490
     
    other than that i didn't change anything about the files, and my bootloader doesn't contain any config words (but i did leave them defined in the linker)
    #9
    Thorben.Z
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2017/06/03 06:33:33
    • Location: 0
    • Status: offline
    Re: bootloader chrash when jumping to app 2019/05/13 08:44:23 (permalink)
    0
    just as an update, in case somebody else has the same issue:
     
    i have managed to get it working by putting all of the bootloader code (exceptions, debug and code) into the boot memory and including the app startup code in the program memory before the app. The bootloader then jumps to the the second startup code.
     
    Not sure if that's how it should be done but it works for me ;)
    #10
    toms
    Junior Member
    • Total Posts : 96
    • Reward points : 0
    • Joined: 2006/03/07 18:06:24
    • Location: London, UK
    • Status: offline
    Re: bootloader crash when jumping to app 2020/11/21 07:16:17 (permalink)
    0
    Thorben.Z
    To jump there i have tried both 'jr' (as the startup code does i think) and just 'j 0x9D000000' (program flash), and also put a "j main" command at 0x9D000000 in the app, in case 'main' was located elsewhere.



    Might be a bit late for this now, but may help others in the future...
     
    I am also starting my PIC32 journey, and have just had this same problem while working on my bootloader, and I think it might be a trap for young MIPS assembly players.
     
    The key is in the MIPS instruction set reference, e.g.: https://www.cs.cornell.edu/courses/cs3410/2008fa/MIPS_Vol2.pdf
     
    Page 115 for example is for the J instruction. There is a particular note:
     

    Restrictions:
     
    Processor operation is UNPREDICTABLE if a branch, jump, ERET, DERET, or WAIT instruction is placed in the delay slot of a branch or jump.

     
    And in conjunction with the sentence above that one:
     

    Jump to the effective target address. Execute the instruction that follows the jump, in the branch delay slot, before executing the jump itself.

     
    In my case the jump just didnt seem to be executing, and was simply "passing by" to the following instruction which was a branch causing a (deliberate) infinite loop.
     
    So it could depend on what the very next instruction was in your source code, but you may have needed to add a NOP after the jump instruction.
    #11
    Jump to:
    © 2020 APG vNext Commercial Version 4.5