• AVR Freaks

Hot!Can't get bootloader to jump to app

Page: < 123 > Showing page 2 of 3
Author
newfound
Super Member
  • Total Posts : 1849
  • Reward points : 0
  • Joined: 2003/11/07 12:35:49
  • Status: offline
Re: Can't get bootloader to jump to app 2019/07/12 16:54:06 (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?




Agree that this is getting to the heart of the problem. However, what I would suggest is the most obvious or equally obvious thing is that the duplicate reset code in the non-boot section branches to the start-up code in the boot section. This is where being able to read the disassembly is a useful skill. 
 
It seems to me that you need to concentrate on the start-up code in the boot section to ensure an ordered and orderly transfer to the start-up code in the main app. The linker may relocate the start-up library code for the app but it is up to you - in your boot code - to ensure that execution gets there. 
#21
aschen0866
Super Member
  • Total Posts : 4510
  • 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 17:37:26 (permalink)
0
_fragment_
 
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.


Dave, the C startup code used to have section name .startup in the C32 and it is now called .reset.startup in the XC32. So, yes, you can eliminate the .reset section and jump directly to where .reset.startup is. This also means you can place .reset and .reset.startup in two different regions as long as the jump is reachable.
 
I am still inclined to think the problem is in your bootloader. Can you program your application code directly into the chip and then read it back? If so, see if you can export the program memory between 1D00_5000 to 1D08_0000 to a hex file. Go through the bootload process, then export the same region to another hex file. These two files must be identical if the bootloader does its job right.
 
#22
maxruben
Super Member
  • Total Posts : 3371
  • Reward points : 0
  • Joined: 2011/02/22 03:35:11
  • Location: Sweden
  • Status: offline
Re: Can't get bootloader to jump to app 2019/07/13 06:08:57 (permalink)
0
Do you have the same config register settings in your bootloader as in your app?
 
/Ruben
#23
_fragment_
Super Member
  • Total Posts : 406
  • Reward points : 0
  • Joined: 2008/10/08 09:17:55
  • Location: Idaho
  • Status: online
Re: Can't get bootloader to jump to app 2019/07/15 09:58:14 (permalink)
0
maxruben
Do you have the same config register settings in your bootloader as in your app?
 
/Ruben


Yes, these settings are the same.
#24
_fragment_
Super Member
  • Total Posts : 406
  • Reward points : 0
  • Joined: 2008/10/08 09:17:55
  • Location: Idaho
  • Status: online
Re: Can't get bootloader to jump to app 2019/07/15 10:14:44 (permalink)
0
aschen0866
 
Dave, the C startup code used to have section name .startup in the C32 and it is now called .reset.startup in the XC32. So, yes, you can eliminate the .reset section and jump directly to where .reset.startup is. This also means you can place .reset and .reset.startup in two different regions as long as the jump is reachable.
 
I am still inclined to think the problem is in your bootloader. Can you program your application code directly into the chip and then read it back? If so, see if you can export the program memory between 1D00_5000 to 1D08_0000 to a hex file. Go through the bootload process, then export the same region to another hex file. These two files must be identical if the bootloader does its job right.
 


Let me explain how my bootloader works. On entry, it reads the first 2 bytes at the start of the external serial flash to see if there is already a new app ready for processing. If not, it then reads the first 4 bytes at 9D00 4800 to see if there is already an app installed (I use a pattern that is the last thing written during app installation to indicate this). If there is no valid app, it reverts to a utility mode that waits for data on UART1 to program into the external flash. At present, I have disabled the writing of the pattern to indicate presence of the app and added commands that I can type via UART1 that will process the data in the external flash. I then have a separate command that I can type to attempt to jump to the app at 9D00 5000. I have also added a command that will read contents of the program flash starting at 9D00 5000 and increment forward from there each time I hit "+". I have checked the first dozen instructions and they all match what is in the .hex file produced from the XC32 compiler. This whole process worked flawlessly with the C32 tools. Everything appears to be working as planned, except for the jump to app. Maybe I need to try programming the application as a standalone program and see if any problems shake out that way.
#25
_fragment_
Super Member
  • Total Posts : 406
  • Reward points : 0
  • Joined: 2008/10/08 09:17:55
  • Location: Idaho
  • Status: online
Re: Can't get bootloader to jump to app 2019/07/15 10:24:13 (permalink)
0
newfound
 
 
Agree that this is getting to the heart of the problem. However, what I would suggest is the most obvious or equally obvious thing is that the duplicate reset code in the non-boot section branches to the start-up code in the boot section. This is where being able to read the disassembly is a useful skill. 
 
It seems to me that you need to concentrate on the start-up code in the boot section to ensure an ordered and orderly transfer to the start-up code in the main app. The linker may relocate the start-up library code for the app but it is up to you - in your boot code - to ensure that execution gets there. 


I don't have a problem if the reset goes back to the boot code, in fact that's what I want. The boot code then decides if it needs to process data from external flash and install a new app, jump to the existing app, or wait for serial data to load into external flash in the absence of an installed app. The linker is placing the app startup code at 9D00 5000 (I checked the map file, plus the hex file has a jump to 9D00 5008 there, which is where the map says the .reset.startup is located). So the boot code attempts to jump there this way:
 
 
#define IX_APP_RESET_ADDRESS 0x9D005000

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

 
How else do I ensure the boot code jumps correctly?
 
Dave
#26
_fragment_
Super Member
  • Total Posts : 406
  • Reward points : 0
  • Joined: 2008/10/08 09:17:55
  • Location: Idaho
  • Status: online
Re: Can't get bootloader to jump to app 2019/07/15 13:17:41 (permalink)
4 (1)
Something seems to be causing a problem in the app, not the boot code. I put the watchdog reset at the start of the app inside a while(1) and now I don't get reset and sent back to the boot code, but stuck in the app as you would expect. Now I can move the while(1) down the start of main() and find out what is making it unhappy.
 
Dave
#27
ric
Super Member
  • Total Posts : 24544
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Can't get bootloader to jump to app 2019/07/15 13:45:54 (permalink)
0
Is the boot code using interrupts?
Does it leave any enabled that the app is not expecting?
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#28
_fragment_
Super Member
  • Total Posts : 406
  • Reward points : 0
  • Joined: 2008/10/08 09:17:55
  • Location: Idaho
  • Status: online
Re: Can't get bootloader to jump to app 2019/07/15 14:15:07 (permalink)
0
ric
Is the boot code using interrupts?
Does it leave any enabled that the app is not expecting?
 


No interrupts in use in the boot code.
 
Dave
#29
_fragment_
Super Member
  • Total Posts : 406
  • Reward points : 0
  • Joined: 2008/10/08 09:17:55
  • Location: Idaho
  • Status: online
Re: Can't get bootloader to jump to app 2019/07/15 14:37:56 (permalink)
0
OK, it bounces back to boot code precisely when I enabled interrupts in the app, like this:
 
    __builtin_enable_interrupts();

The boot code does not use interrupts. At the point in the app where interrupts are enabled, the only interrupts active are Timer1 and UART1.
 
Dave 
#30
ric
Super Member
  • Total Posts : 24544
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Can't get bootloader to jump to app 2019/07/15 15:41:22 (permalink)
0
Can't you single step the code from that point and see what is happening?
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#31
NKurzman
A Guy on the Net
  • Total Posts : 18030
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: Can't get bootloader to jump to app 2019/07/15 15:55:19 (permalink)
0
Are you sure all the Interrupt enable flags are disabled.  The Harmony Bootloaders are Notorious for that.
#32
_fragment_
Super Member
  • Total Posts : 406
  • Reward points : 0
  • Joined: 2008/10/08 09:17:55
  • Location: Idaho
  • Status: online
Re: Can't get bootloader to jump to app 2019/07/15 16:22:28 (permalink)
0
ric
Can't you single step the code from that point and see what is happening?
 


Haven't compiled this for debug, standalone or loadable. Just debugging through serial data. I have trust issues with debuggers, which is why I don't use them much. If it comes down to it, I will explore what the debugger might offer.
 
Dave
#33
_fragment_
Super Member
  • Total Posts : 406
  • Reward points : 0
  • Joined: 2008/10/08 09:17:55
  • Location: Idaho
  • Status: online
Re: Can't get bootloader to jump to app 2019/07/15 16:24:33 (permalink)
0
NKurzman
Are you sure all the Interrupt enable flags are disabled.  The Harmony Bootloaders are Notorious for that.


This is not a Harmony bootloader, but one I wrote myself. That's how I am sure there are no interrupts in use in the bootloader.
 
Dave
#34
NKurzman
A Guy on the Net
  • Total Posts : 18030
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: Can't get bootloader to jump to app 2019/07/15 16:55:30 (permalink)
0
_fragment_
NKurzman
Are you sure all the Interrupt enable flags are disabled.  The Harmony Bootloaders are Notorious for that.


This is not a Harmony bootloader, but one I wrote myself. That's how I am sure there are no interrupts in use in the bootloader.
 
Dave


Check the all the IEx registers to insure they are all zero.  Or set them to all zero before jumping to the Main Program. 
Also insure that you have correct handlers for Timer1 and UART1 in you main program.
And insure the IVT is not overlapped with anything else.
#35
maxruben
Super Member
  • Total Posts : 3371
  • Reward points : 0
  • Joined: 2011/02/22 03:35:11
  • Location: Sweden
  • Status: offline
Re: Can't get bootloader to jump to app 2019/07/16 04:35:27 (permalink)
5 (1)
_fragment_
ric
Can't you single step the code from that point and see what is happening?
 


Haven't compiled this for debug, standalone or loadable. Just debugging through serial data. I have trust issues with debuggers, which is why I don't use them much. If it comes down to it, I will explore what the debugger might offer.
 
Dave


But in this case, the debugger together with the loadables function would help you a lot. You probably would have fixed it by now using a debugger...
 
/Ruben
#36
cvm
Super Member
  • Total Posts : 293
  • Reward points : 0
  • Joined: 2011/09/16 05:16:15
  • Location: 0
  • Status: offline
Re: Can't get bootloader to jump to app 2019/07/16 05:09:55 (permalink)
0
>I still get bounced back to the bootloader, which currently prints out RCON at startup and it shows 00 40, indicating a software reset. 
 
I do not know the MX series very well, but how do you get a SWR flag set unless a software reset was done, and how do you get a software reset to work without jumping through hoops (system unlock sequence). It seems there is a software reset somewhere in the loaded app, so start from there and work backwards (like what code path leads to a software reset, etc.).
#37
aschen0866
Super Member
  • Total Posts : 4510
  • 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/16 07:14:15 (permalink)
0
cvm
... It seems there is a software reset somewhere in the loaded app, so start from there and work backwards (like what code path leads to a software reset, etc.).

Here is the general exception handler compiler provides:

/* This is a default definition of a general exception handler function.
* It does nothing and just does a software reset. If the user
* application supplies a handler function, this function will not be
* referenced and thus not pulled in from the library.
*/
extern void __attribute__((nomips16, noreturn, far, weak)) __pic32_software_reset();
void __attribute__((weak)) __exception_handler_break(void);
extern void _DEBUGGER __attribute__((weak));
void
__attribute__((weak, nomips16, noreturn)) _general_exception_handler (void)
{
if (&_DEBUGGER != 0 && __exception_handler_break)
__asm__ volatile ("sdbbp 0");

if (__pic32_software_reset)
__pic32_software_reset();

while(1);
}

#38
Jim Nickerson
User 452
  • Total Posts : 6359
  • 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/16 08:02:58 (permalink)
0
maxruben
But in this case, the debugger together with the loadables function would help you a lot. You probably would have fixed it by now using a debugger...
 
/Ruben

Like mentioned in post 2 4 days ago ?
#39
cvm
Super Member
  • Total Posts : 293
  • Reward points : 0
  • Joined: 2011/09/16 05:16:15
  • Location: 0
  • Status: offline
Re: Can't get bootloader to jump to app 2019/07/16 11:08:25 (permalink)
0
I may have previously stated something quite obvious/unhelpful about the software reset (I didn't realize how many opportunities there were to get there). I created an empty main in a new project for a mx570-whatever, created some post-build commands for the project to see what symbols are defined, the asm listing, etc.-
 
${MP_CC_DIR}/xc32-readelf -aW ${ImageDir}/${PROJECTNAME}.${IMAGE_TYPE}.elf > elf.txt; ${MP_CC_DIR}/xc32-objdump -d ${ImageDir}/${PROJECTNAME}.${IMAGE_TYPE}.elf > list.txt;
 
then tried to figure out what paths end up in a software reset. The obvious places, it seems- in the handlers for general,default interrupt,debug,and bootstrap exceptions. That hardly narrows it down.
 
A quick and dirty way to locate the 'path', would be to override the weak functions one at a time, so if you do not get the software reset then that is where the software reset originates (if watchdog on, reset in the loop so you simply get 'stuck' in the while loop)-
 
void _DefaultInterrupt (void){ while(1); }
//if no longer get swr (but 'hangs' in the while loop), then is coming from an interrupt
//can then create some code inside to debug the source of irq
 
void _general_exception_handler(unsigned int cause, unsigned int status){ while(1); }
//if no longer get swr, then is an exception and can debug further
//more info to decode exception-
https://microchipdeveloper.com/faq:82
#40
Page: < 123 > Showing page 2 of 3
Jump to:
© 2019 APG vNext Commercial Version 4.5