• AVR Freaks

Hot!Can't get bootloader to jump to app

Page: 123 > Showing page 1 of 3
Author
_fragment_
Super Member
  • Total Posts : 390
  • Reward points : 0
  • Joined: 2008/10/08 09:17:55
  • Location: Idaho
  • Status: offline
2019/07/11 10:37:59 (permalink)
0

Can't get bootloader to jump to app

PIC32MX570F512L
XC32 v1.42
MPLAB X 3.35
No harmony
 
Background:
I maintain code for a product that uses a PIC32MX795F512L, currently using MPLAB 8.92 (started with 8.14) and C32 1.12. It has a serial bootloader at the bottom part of program flash and jumps to the app that resides in the upper part of program flash. This system still works fantastically well in production.
 
Now, I'm working on a new system with the setup outlined at the top of this post. I have the serial bootloader of my design (like before) running in the bottom part of the program flash. The app is loaded via serial port to the PC with a Windows program of our design (same one as for the previous product) into a serial flash chip. Once loaded there it is analyzed for syntax and checked for a proper CRC. If all that looks good, it then erases the appropriate pages and programs the app. All of this is working as planned.
 
However, when I try to jump to the app, using the same technique as the previous product, the PIC resets and I'm back in the bootloader. I have verified that the first several instructions where the app starts match what and where they should be by reading the data from program flash (I wrote a utility in the bootloader to read from program flash). I just can't figure out what might have changed that's messing my system up.
 
Here's how the linker file is set up for the bootloader:
PROVIDE(_vector_spacing = 0x0001);
PROVIDE(_ebase_address = 0x9D003000);

_RESET_ADDR = 0xBFC00000;
_BEV_EXCPT_ADDR = 0xBFC00380;
_DBG_EXCPT_ADDR = 0xBFC00480;
_DBG_CODE_ADDR = 0x9FC00490;
_DBG_CODE_SIZE = 0x760;
_GEN_EXCPT_ADDR = _ebase_address + 0x180;

MEMORY
{
  kseg0_program_mem (rx) : ORIGIN = 0x9D000000, LENGTH = 0x3000
  exception_mem : ORIGIN = 0x9D003000, LENGTH = 0x1000
  debug_exec_mem : ORIGIN = 0x9FC00490, LENGTH = 0x760
  kseg0_boot_mem : ORIGIN = 0x9FC00490, LENGTH = 0x0
  kseg1_boot_mem : ORIGIN = 0xBFC00000, LENGTH = 0x490
  config3 : ORIGIN = 0xBFC00BF0, LENGTH = 0x4
  config2 : ORIGIN = 0xBFC00BF4, LENGTH = 0x4
  config1 : ORIGIN = 0xBFC00BF8, LENGTH = 0x4
  config0 : ORIGIN = 0xBFC00BFC, LENGTH = 0x4
  kseg1_data_mem (w!x) : ORIGIN = 0xA0000020, LENGTH = 0xFFE0
  sfrs : ORIGIN = 0xBF800000, LENGTH = 0x100000
  configsfrs : ORIGIN = 0xBFC00BF0, LENGTH = 0x10
}

 
Here's how the linker file is set up for the app:
PROVIDE(_vector_spacing = 0x0001);
PROVIDE(_ebase_address = 0x9D07F000);

_RESET_ADDR = 0x9D005000;
_BEV_EXCPT_ADDR = 0x9D005380;
_DBG_EXCPT_ADDR = 0x9D005480;
_DBG_CODE_ADDR = 0x9FC00490;
_DBG_CODE_SIZE = 0x760;
_GEN_EXCPT_ADDR = _ebase_address + 0x180;

MEMORY
{
  kseg0_program_mem (rx) : ORIGIN = 0x9D005490, LENGTH = 0x79B70
  exception_mem : ORIGIN = 0x9D07F000, LENGTH = 0x1000
  debug_exec_mem : ORIGIN = 0x9FC00490, LENGTH = 0x760
  kseg0_boot_mem : ORIGIN = 0x9D005000, LENGTH = 0x0
  kseg1_boot_mem : ORIGIN = 0x9D005000, LENGTH = 0x490
  config3 : ORIGIN = 0xBFC00BF0, LENGTH = 0x4
  config2 : ORIGIN = 0xBFC00BF4, LENGTH = 0x4
  config1 : ORIGIN = 0xBFC00BF8, LENGTH = 0x4
  config0 : ORIGIN = 0xBFC00BFC, LENGTH = 0x4
  kseg1_data_mem (w!x) : ORIGIN = 0xA0000020, LENGTH = 0xFFE0
  sfrs : ORIGIN = 0xBF800000, LENGTH = 0x100000
  configsfrs : ORIGIN = 0xBFC00BF0, LENGTH = 0x10

  BLreset : ORIGIN = 0x9D004800, LENGTH = 0x8
  IXhwid : ORIGIN = 0x9D004400, LENGTH = 0x400
}

 
Here's the method of jumping to the app (still the same as in AN1388 which I downloaded the latest version of yesterday):
#define IX_APP_RESET_ADDRESS 0x9D005000

void jump_to_app( void )
{
    void ( *fptr )( void );
    fptr = ( void (*)(void) )IX_APP_RESET_ADDRESS;
    fptr();
}

 
If anyone sees something amiss in this method, I would appreciate any observations or advice.
 
Dave
#1

46 Replies Related Threads

    Jim Nickerson
    User 452
    • Total Posts : 6187
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/11 11:01:41 (permalink)
    0
    You might try adding the application project as a "loadable" to the bootloader project so you could run it all in debug and watch the code as it jumps to the application.
    I presume you have handled all the exceptions in both the bootloader and the application.
    #2
    _fragment_
    Super Member
    • Total Posts : 390
    • Reward points : 0
    • Joined: 2008/10/08 09:17:55
    • Location: Idaho
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/11 11:07:53 (permalink)
    0
    I have a general exception handler in the app, but not the bootloader. I am not using any interrupts in the bootloader.
     
    Dave
    #3
    aschen0866
    Super Member
    • Total Posts : 4498
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/11 11:10:30 (permalink)
    0
    Can you upload the application linker script as a whole? 
    #4
    Jim Nickerson
    User 452
    • Total Posts : 6187
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/11 11:12:57 (permalink)
    0
    Maybe there is a difference in the way the different versions of xc32 and MpLab handle exceptions.
    When I made my app a "loadable" project I saw things I did not expect ( nor handle ).
    #5
    _fragment_
    Super Member
    • Total Posts : 390
    • Reward points : 0
    • Joined: 2008/10/08 09:17:55
    • Location: Idaho
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/11 12:10:01 (permalink)
    0
    aschen0866
    Can you upload the application linker script as a whole? 




    Here it is.
     
    Dave
    #6
    skruegel1
    Starting Member
    • Total Posts : 78
    • Reward points : 0
    • Joined: 2017/02/04 03:32:13
    • Location: 0
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/11 13:40:22 (permalink)
    0
    Why does your linker script reference a PIC32MX570F512L?  I thought you were using a PIC32MX795F512L.  
    #7
    skruegel1
    Starting Member
    • Total Posts : 78
    • Reward points : 0
    • Joined: 2017/02/04 03:32:13
    • Location: 0
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/11 13:48:53 (permalink)
    0
    Also, I don't believe you're using all of the data memory.
     
    #8
    aschen0866
    Super Member
    • Total Posts : 4498
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/11 14:20:59 (permalink)
    0
    I don't see anything obviously wrong. Can you try turning off the instruction cache before the jump?
     

    void __attribute__ ((nomips16)) CheKseg0CacheOff()
    {
    register unsigned long tmp;
    asm("mfc0 %0,$16,0" : "=r"(tmp));
    tmp = (tmp & ~7) | 2;
    asm("mtc0 %0,$16,0" :: "r" (tmp));
    }

    #9
    _fragment_
    Super Member
    • Total Posts : 390
    • Reward points : 0
    • Joined: 2008/10/08 09:17:55
    • Location: Idaho
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/11 14:22:52 (permalink)
    0
    skruegel1
    Why does your linker script reference a PIC32MX570F512L?  I thought you were using a PIC32MX795F512L.  


    Read more carefully. The 795 was the older project, not the current one.
     
    Dave
    #10
    _fragment_
    Super Member
    • Total Posts : 390
    • Reward points : 0
    • Joined: 2008/10/08 09:17:55
    • Location: Idaho
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/11 14:56:17 (permalink)
    0
    aschen0866
    I don't see anything obviously wrong. Can you try turning off the instruction cache before the jump?

     
    Just tried that. No difference. I still get bounced back to the bootloader, which currently prints out RCON at startup and it shows 00 40, indicating a software reset. This is the same behavior as I got without turning off cache.
     
    Dave
    #11
    _fragment_
    Super Member
    • Total Posts : 390
    • Reward points : 0
    • Joined: 2008/10/08 09:17:55
    • Location: Idaho
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/11 15:01:19 (permalink)
    0
    JANickerson
    Maybe there is a difference in the way the different versions of xc32 and MpLab handle exceptions.
    When I made my app a "loadable" project I saw things I did not expect ( nor handle ).


    Any other details on what you had to handle differently? Is it not possible to get this working without making the app a "loadable" with these tools?
     
    Dave
    #12
    aschen0866
    Super Member
    • Total Posts : 4498
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/12 07:49:00 (permalink)
    0
    I suppose the bootloader was ported from your old MX795 project. Did you change the Flash page size and row size accordingly? 
    #13
    Jim Nickerson
    User 452
    • Total Posts : 6187
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/12 07:53:24 (permalink)
    0
    Dave,
    I only made the app project a loadable to debug problems ( like you have ), once resolved I no longer use a loadable.
    #14
    _fragment_
    Super Member
    • Total Posts : 390
    • Reward points : 0
    • Joined: 2008/10/08 09:17:55
    • Location: Idaho
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/12 09:48:41 (permalink)
    0
    aschen0866
    I suppose the bootloader was ported from your old MX795 project. Did you change the Flash page size and row size accordingly? 


    Yes, the page size shrank from 4K to 1K and I had to change the index for my page erase array from 8 bit to 16 bit to handle 512 pages. I am not using row programming, just word programming. As far as I have been able to determine, the programming worked as planned, I just can't successfully jump to the app.
     
    So far, I have determined that the instruction at 9D005000 is a JAL to 9D005008. The instruction at 9D005008 is reading a CP0 register into GPR[1A]. Haven't found what that is doing yet, but it all looks normal, so I'm confused as to why the jump to app could be failing.
     
    Dave
    #15
    _fragment_
    Super Member
    • Total Posts : 390
    • Reward points : 0
    • Joined: 2008/10/08 09:17:55
    • Location: Idaho
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/12 09:50:30 (permalink)
    0
    JANickerson
    Dave,
    I only made the app project a loadable to debug problems ( like you have ), once resolved I no longer use a loadable.


    Do you recall what problems you found and how you fixed them?
     
    Dave
    #16
    Jim Nickerson
    User 452
    • Total Posts : 6187
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/12 11:13:09 (permalink)
    0
    Dave,
    I added handlers for all the possible exceptions.
    Once you have the application as a loadable project debugging the bootloader and watching what happens as it jumps to the application should show what your problem is.
    #17
    _fragment_
    Super Member
    • Total Posts : 390
    • Reward points : 0
    • Joined: 2008/10/08 09:17:55
    • Location: Idaho
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/12 11:44:55 (permalink)
    0
    JANickerson
    Dave,
    I added handlers for all the possible exceptions.
    Once you have the application as a loadable project debugging the bootloader and watching what happens as it jumps to the application should show what your problem is.


    I added a general exception handler to my app, same as in the old app. Shouldn't that catch everything? Unless I'm getting an exception from the bootloader as it tries to jump to app. Maybe I need a general exception handler in the boot loader, although I didn't need one on the older project.
     
    Dave
    #18
    andersm
    Super Member
    • Total Posts : 2639
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/12 12:28:47 (permalink)
    5 (1)
    Don't change these addresses. They are either defined by the hardware, or the development environment, and can't be relocated. Duplicating them into your application is just wasting memory. The debugger-related memory reservations are listed in the MPLAB X help and release notes, under "Reserved Resources".
    _RESET_ADDR                    = 0xBFC00000;
    _BEV_EXCPT_ADDR                = 0xBFC00380;
    _DBG_EXCPT_ADDR                = 0xBFC00480;
    _DBG_CODE_ADDR                 = 0xBFC02000;
    _DBG_CODE_SIZE                 = 0xFF0;

    You don't need the .reset section in the application, it's only there to transfer control from the hardware reset vector to the startup code.
     
    Edit: Also have you checked the most obvious, that there's no watchdog the application isn't servicing?
    post edited by andersm - 2019/07/12 12:45:41
    #19
    _fragment_
    Super Member
    • Total Posts : 390
    • Reward points : 0
    • Joined: 2008/10/08 09:17:55
    • Location: Idaho
    • Status: offline
    Re: Can't get bootloader to jump to app 2019/07/12 13:14:10 (permalink)
    0
    andersm
    Don't change these addresses. They are either defined by the hardware, or the development environment, and can't be relocated. Duplicating them into your application is just wasting memory. The debugger-related memory reservations are listed in the MPLAB X help and release notes, under "Reserved Resources".
    _RESET_ADDR                    = 0xBFC00000;
    _BEV_EXCPT_ADDR                = 0xBFC00380;
    _DBG_EXCPT_ADDR                = 0xBFC00480;
    _DBG_CODE_ADDR                 = 0xBFC02000;
    _DBG_CODE_SIZE                 = 0xFF0;

    You don't need the .reset section in the application, it's only there to transfer control from the hardware reset vector to the startup code.
     
    Edit: Also have you checked the most obvious, that there's no watchdog the application isn't servicing?


    Appendix C of AppNote 1388, step 6 tells you to change these addresses, plus the demo application included with the download shows these addresses changed from the default. I couldn't find an app linker script for the MX570, but there was for the MX575.
     
    With the newer compiler, they have moved the C startup code, which initializes the app globals, etc into the .reset section:
     
      /* Boot Sections */
      .reset _RESET_ADDR :
      {
        KEEP(*(.reset))
        KEEP(*(.reset.startup))
      } > kseg1_boot_mem

     
    So I don't think you can just eliminate the .reset section.
     
    First statement in main() in the app:
        WDTCONSET = 0x00000001; // Reset the watchdog

     
    Dave
    #20
    Page: 123 > Showing page 1 of 3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5