• AVR Freaks

Hot!PIC32MZ jumping from custom bootloader to app causes reset

Author
lot080420
New Member
  • Total Posts : 21
  • Reward points : 0
  • Joined: 2020/08/04 14:02:03
  • Location: 0
  • Status: offline
2020/08/04 15:00:12 (permalink)
0

PIC32MZ jumping from custom bootloader to app causes reset

Using Harmony on a PIC32MZ2064DAG169.
I have 2 projects, 1 for bootloader and 1 for application. They have same device configuration bits set.
Having issues creating an application hex file that a custom bootloader can run. Probably linker issue as I am new to how the PIC32 linker files are used.
I wrote a bootloader that will either program memory if needed (ie bootload over serial port)  or jump to a hard coded address (if there is code there) .. specifically jumps to 0x9D00C000.
I have confirmed that this works ie I can program memory and jump to 0x9D00C000 as and when needed.
Problem is if the I copy the contents of the app hex file (or rather if I copy kseg0_prog_mem 0x9D00C000 part of hex file) into the jump location, then once bootloader jumps to that location a reset occurs.
I build the app project using linker script of which snippet provided below, I want to put the bootloader at 0x9D000000  (not sure what I do with  kseg0_boot_mem in this case ) and the  application at 0x9D00C000.
My bootloader jumps to 0x9D00C000 and then resets ..if I have my bootloader jump instead to the address of the main() function of my application, it works, but not if I jump to the start of my app prog mem ie 0x9D00C000.
 
Application Linker Snippet
PROVIDE(_vector_spacing = 0x0001);
PROVIDE(_ebase_address = 0x9D00C000);
_RESET_ADDR                    = 0xBFC00000;
_BEV_EXCPT_ADDR                = 0xBFC00380;
_DBG_EXCPT_ADDR                = 0xBFC00480;
_SIMPLE_TLB_REFILL_EXCPT_ADDR  = _ebase_address + 0;
_CACHE_ERR_EXCPT_ADDR          = _ebase_address + 0x100;
_GEN_EXCPT_ADDR                = _ebase_address + 0x180;
MEMORY
{
   kseg0_program_mem     (rx)  : ORIGIN = 0x9D00C000, LENGTH = (0x200000 / 2)-0xC000
  kseg0_boot_mem              : ORIGIN = 0x9FC004B0, LENGTH = 0x0
  kseg1_boot_mem              : ORIGIN = 0xBFC00000, LENGTH = 0x480
  kseg1_boot_mem_4B0          : ORIGIN = 0xBFC004B0, LENGTH = 0xFA50
etc
}
 
Bootloader loaded to 0x9D000000
Bootloader Linker Snippet
PROVIDE(_vector_spacing = 0x0001);
PROVIDE(_ebase_address = 0x9D000000);
_RESET_ADDR                    = 0xBFC00000;
_BEV_EXCPT_ADDR                = 0xBFC00380;
_DBG_EXCPT_ADDR                = 0xBFC00480;
_SIMPLE_TLB_REFILL_EXCPT_ADDR  = _ebase_address + 0;
_CACHE_ERR_EXCPT_ADDR          = _ebase_address + 0x100;
_GEN_EXCPT_ADDR                = _ebase_address + 0x180;
MEMORY
{
  kseg0_program_mem     (rx)  : ORIGIN = 0x9D000000, LENGTH = 0x100000 /*0xC000*/
  kseg0_boot_mem              : ORIGIN = 0x9FC004B0, LENGTH = 0x0
  kseg1_boot_mem              : ORIGIN = 0xBFC00000, LENGTH = 0x480
  kseg1_boot_mem_4B0          : ORIGIN = 0xBFC004B0, LENGTH = 0xFA50
  config_BFC0FF3C             : ORIGIN = 0xBFC0FF3C, LENGTH = 0x4
etc
}
 
#1

8 Replies Related Threads

    optimus_jack
    Senior Member
    • Total Posts : 102
    • Reward points : 0
    • Joined: 2017/02/16 03:02:47
    • Location: 0
    • Status: offline
    Re: PIC32MZ jumping from custom bootloader to app causes reset 2020/08/05 09:07:21 (permalink)
    0
    lot080420
     
    Application Linker Snippet
    PROVIDE(_vector_spacing = 0x0001);
    PROVIDE(_ebase_address = 0x9D00C000);
    _RESET_ADDR                    = 0xBFC00000;
    _BEV_EXCPT_ADDR                = 0xBFC00380;
    _DBG_EXCPT_ADDR                = 0xBFC00480;
    _SIMPLE_TLB_REFILL_EXCPT_ADDR  = _ebase_address + 0;
    _CACHE_ERR_EXCPT_ADDR          = _ebase_address + 0x100;
    _GEN_EXCPT_ADDR                = _ebase_address + 0x180;
    MEMORY
    {
       kseg0_program_mem     (rx)  : ORIGIN = 0x9D00C000, LENGTH = (0x200000 / 2)-0xC000
      kseg0_boot_mem              : ORIGIN = 0x9FC004B0, LENGTH = 0x0
      kseg1_boot_mem              : ORIGIN = 0xBFC00000, LENGTH = 0x480
      kseg1_boot_mem_4B0          : ORIGIN = 0xBFC004B0, LENGTH = 0xFA50
    etc
    }
     

    HI,
    There is slight error in your application linker script. below is proper memory regions
    PROVIDE(_vector_spacing = 0x0001);
    PROVIDE(_ebase_address = 0x9D00D000);

    _RESET_ADDR                    = 0x9D00C000;
    _SIMPLE_TLB_REFILL_EXCPT_ADDR  = _ebase_address + 0;
    _CACHE_ERR_EXCPT_ADDR          = _ebase_address + 0x100;
    _GEN_EXCPT_ADDR                = _ebase_address + 0x180;
    MEMORY
    {
        /* All C files will be located here */
        kseg0_program_mem  (rx) : ORIGIN = 0x9D00D000, LENGTH = (0x200000 / 2) - 0xC000- 0x1000
        kseg1_boot_mem          : ORIGIN = 0x9D00C000, LENGTH = 0x480
        kseg1_boot_mem_4B0      : ORIGIN = 0x9D00C4B0, LENGTH = 0x1000 - 0x4B0

        kseg0_data_mem       (w!x)  : ORIGIN = 0x80000000 + 16, LENGTH = 0x80000

        sfrs                        : ORIGIN = 0xBF800000, LENGTH = 0x100000
        kseg2_ebi_data_mem          : ORIGIN = 0xC0000000, LENGTH = 0x4000000
        kseg2_sqi_data_mem          : ORIGIN = 0xD0000000, LENGTH = 0x4000000
        kseg3_ebi_data_mem          : ORIGIN = 0xE0000000, LENGTH = 0x4000000
        kseg3_sqi_data_mem          : ORIGIN = 0xF0000000, LENGTH = 0x4000000
    }
     
    You can refer to below H3 test applicarion linker script for reference
    https://github.com/Microc...c32mz_das_sk/app_mz.ld
    #2
    lot080420
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2020/08/04 14:02:03
    • Location: 0
    • Status: offline
    Re: PIC32MZ jumping from custom bootloader to app causes reset 2020/08/05 09:59:37 (permalink)
    0
    Thanks optimus_jack for your reply.  Thing is I do not want the app to reset into itself , I need app to reset into the bootloader and bootloader jump to the app, not the other way around.
    I made this change anyway to see  if the app would run by itself with these new settings, figured it  would help me understand a few things,  but it fails to run with this linker file ie  I made linker file change and used Real ICE to load it, but it does not even make it into app's main().
    #3
    optimus_jack
    Senior Member
    • Total Posts : 102
    • Reward points : 0
    • Joined: 2017/02/16 03:02:47
    • Location: 0
    • Status: offline
    Re: PIC32MZ jumping from custom bootloader to app causes reset 2020/08/05 10:09:53 (permalink)
    0
    Hi,
    The bootloader reset handler will be placed at 0xBFC00000 which means after reset bootloader is going to run, now in bootloader code if you decide to run the Application then you need to jump to application.
    Yes if you modify the linker as i mentioned and program only the application it will not run as there is nothing at 0xBFC00000
     
    1. Use the debugger to load the bootloader (Reset at 0xBFC00000 and Code at 0x9D000000)
    2. Bootloader programs the applications (0x9D00C000)
    3. resets the device
    4. Bootloader runs after reset and then checks the app start address and then jumps to the location.
     
    You can look at the existing bootloader application here and understand how they work.
    https://github.com/Microc...r/apps/uart_bootloader
    #4
    lot080420
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2020/08/04 14:02:03
    • Location: 0
    • Status: offline
    Re: PIC32MZ jumping from custom bootloader to app causes reset 2020/08/05 12:47:22 (permalink)
    0
    Wonderful. Thank you muchly.  Using the new linker as you suggested and having bootloader jump to 0x9D00C000 (not 0x9D00D000) worked.  I have one more question,  useful to test the app independent of bootloading mechanism by adding the application hex as a loadable in the bootloader project. Problem I get is that the app hex has data record for 0x1fc0xxxx  section in it, so loading the app hex "as built" causes compilation error due to conflict with that area in bootloader. I manually edited the app hex file to remove the 0x1fc0xxxx section (see below) and then used the edited hex as loadable in bootloader project and that works, bootloader jumps to 0x9D00C000 and runs code from the loadable hex. Any way via linker file to have that app hex file not include those 0x1fc0xxxx sections to begin with? They seem to be for the kseg0-boot_mem section ?? But linker has " kseg0_boot_mem : ORIGIN = 0x9FC004B0, LENGTH = 0x0"  so with 0 length why anything make it into hex file? Or are they coming from somewhere else in linker file? Thanks in advance.
    0x1fc0xxxx record in the app hex file
    :020000040000fa
    :020000041fc01b
    :04ffbc00fffffff450
    .... bunch of these 02 and 04 records and then data records
    :020000040000fa
    :020000041fc01b
    :1004800000f89b40c0000000019d1b3c60db7b2707
    :10049000020060130000000000c09b4000f81b40f9
    :0c04a000c00000001f000042000000002f
    #5
    optimus_jack
    Senior Member
    • Total Posts : 102
    • Reward points : 0
    • Joined: 2017/02/16 03:02:47
    • Location: 0
    • Status: offline
    Re: PIC32MZ jumping from custom bootloader to app causes reset 2020/08/05 20:15:09 (permalink)
    0
    Yes, the application linker script should not have regions which fall in 0x1FCxxxx section.
    #6
    lot080420
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2020/08/04 14:02:03
    • Location: 0
    • Status: offline
    Re: PIC32MZ jumping from custom bootloader to app causes reset 2020/08/19 08:42:32 (permalink)
    0
    The linker file (see attached renamed to .txt) does not put anything in that area, at least not that I can see, but looks like by default MPLAB is  "The Debug exception vector is located at 0x9FC00480" .    How do I stop it doing that?
     
    :020000040000fa
    :020000041fc01b
    :1004800000f89b40c0000000019d1b3ca8e07b27ba
    :10049000020060130000000000c09b4000f81b40f9
    :0c04a000c00000001f000042000000002f
    #7
    optimus_jack
    Senior Member
    • Total Posts : 102
    • Reward points : 0
    • Joined: 2017/02/16 03:02:47
    • Location: 0
    • Status: offline
    Re: PIC32MZ jumping from custom bootloader to app causes reset 2020/08/19 09:19:45 (permalink)
    0
    Hi,
    I see your test_app linker is having the configuration sections. application linker script should not have any device configuration bits.
     
    Refer to for example https://github.com/Microc...c32mz_das_sk/app_mz.ld
    #8
    lot080420
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2020/08/04 14:02:03
    • Location: 0
    • Status: offline
    Re: PIC32MZ jumping from custom bootloader to app causes reset 2020/08/20 10:19:14 (permalink)
    0
    Thanks.   After removing config sections from linker file I was able to see app  hex created without 0x1FC0xxxx sections, and as a result the conflict was eradicated and I was able to include my app project as a loadable to the bootloader project. I am unable to debug the app though. The app example linker files do not set any debug sections , assume it inherits from bootloader linker file? But that does not seem to be case as I am able to debug bootloader but not the app, even though app project is added to "Loadables".  The app project is being compiled though when I compile the bootloader, so that works !
     
    #9
    Jump to:
    © 2020 APG vNext Commercial Version 4.5