cancel
Showing results for 
Search instead for 
Did you mean: 

Jump address to choose one of 2 binary in flash

tommelou
Associate II
Posted on April 03, 2014 at 17:49

Hello,

I'm trying to create a bootloader into the component STM32f106RDT with 384KO of Flash.

I have mapped the memory like this:

0x08000000 - 0x0802DFFF for main software (first binary)

0x0802F000 - 0x08030FFF reserved

0x08031000 - 0x0805FFFF for the temp binary (second binary)

My function of bootloader() to jump at selected main address is in flash.

When I debug with keil the pc is in the file startup_stm32f10x_hd.s, then i want to go into my function bootloader so IMPORT the function like this :

; Reset handler

Reset_Handler   PROC

                EXPORT  Reset_Handler             [WEAK]

                IMPORT  __main

                IMPORT  SystemInit

                IMPORT  FLASH_Bootloader       /*my add*/

                LDR     R0, =SystemInit

                BLX     R0              

                LDR     R0, =FLASH_Bootloader  /*my add*/

                BLX     R0                                       /*my add*/

                ;LDR     R0, =__main

                ;BX      R0

                ENDP

The problem is that i want to jump on one of the two binary file. How do i get the flash address of the main() function? If i jump on 0x08000000+4 the beginning of the first binary mapping it does nothing.

Somebody have an idea to select one of my 2 apps and run it?

Thank you.

#stm32 #bootloader
22 REPLIES 22
Posted on April 04, 2014 at 13:36

Look, you're not trying to jump to 0x08000004 but the content pointed TOO by it, indirectly.

You also don't want to be jumping to the main() function because it would ignore all the C runtime startup code which copies your statics, and clears your initial variables.

Observe the ODD address of the code that is supposed to get jumped too.

0690X000006056rQAA.png
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 04, 2014 at 13:45

My next function is going in hardfault handler, why?

Poor cut-n-paste job? Tried stepping through it with a debugger?

void FLASH_Bootloader(void) 
{
JumpAddress = *( (uint32_t *)0x08000004); // Load the ACTUAL content for initial PC
Jump_To_Application = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) 0x08000000);
Jump_To_Application();
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tommelou
Associate II
Posted on April 04, 2014 at 15:28

Thank you for replying and the screenshot,

this function is now working, but i'm reseting in loop.

And when i'm pointing to the second binary at 0x8031000, with the same software than binary1 I have the same address pointing to 0x80000145

0690X00000602s5QAA.jpg

and

0690X00000602rqQAA.jpg

So it point to the same point at first binary.

chen
Associate II
Posted on April 04, 2014 at 15:37

Hi

''And when i'm pointing to the second binary at 0x8031000, with the same software than binary1 I have the same address pointing to 0x80000145''

The second version of the application need to be located differently.

tommelou
Associate II
Posted on April 04, 2014 at 15:49

I agree,

how can I get the address of the function currently used?

void FLASH_Bootloader(uint32_t* register_args)

{

 pFunction Jump_To_Application;

 __IO uint32_t JumpAddress;

 uint32_t* CurrentStack;

  uint32_t BinToGo=2;

 

  CurrentStack=&FLASH_Bootloader(uint32_t*); /*not working, i'm trying to get the flash address of the current function*/

  if(((uint32_t)CurrentStack>=(uint32_t)0x31000) && BinToGo==1)/*change to Binary1*/

  {

  JumpAddress =   *(__IO uint32_t*)  (ADDRESS_BIN1+4); /*offset tab vector*/

  Jump_To_Application = (pFunction) JumpAddress;

  /* Initialize user application's Stack Pointer */

  __set_MSP(*(__IO uint32_t*) ADDRESS_BIN1);

  Jump_To_Application();

  }

  else if(((uint32_t)CurrentStack<(uint32_t)0x2F000) && BinToGo==2)/*change to Binary2*/

  {

    JumpAddress = *(((__IO uint32_t*)(ADDRESS_BIN2+4))+0x31000); /*offset of main function*/

    Jump_To_Application = (pFunction) JumpAddress;

    /* Initialize user application's Stack Pointer */

    __set_MSP(ADDRESS_BIN2);

    Jump_To_Application();

  }

  else

  {

    /*don't change binary file*/

  }

}

chen
Associate II
Posted on April 04, 2014 at 15:58

Hi

How does the bootloader decide which binary to use?

tommelou
Associate II
Posted on April 04, 2014 at 16:05

When you don't change the binary, you continu to the __main.

The ''BinToGo'' will be dynamical, reading from an emulated EEPROM in the Flash. Like a flag to select with binary file to boot on.

; Reset handler

Reset_Handler   PROC

                EXPORT  Reset_Handler             [WEAK]

                IMPORT  __main

                IMPORT  SystemInit

                IMPORT  FLASH_Bootloader       /*my add*/

                LDR     R0, =SystemInit

                BLX     R0              

                LDR     R0, =FLASH_Bootloader  /*my add*/

                BLX     R0                                       /*my add*/

                LDR     R0, =__main /*continue if no binary change*/

                BX      R0

                ENDP

Posted on April 04, 2014 at 16:14

You have to build two different binaries, as the Vector Table contains fixed/absolute addresses. To do this in Keil you have to modify the IROM(1) range in the Target dialog pane.

For examples to Boot Loader + App, review the IAP USART example code, and search also the forum where I covered this all before.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chen
Associate II
Posted on April 04, 2014 at 16:14

Hi

I am confused about the current problem.

Can you say again what the current problem is please?

tommelou
Associate II
Posted on April 07, 2014 at 09:25

I think Clive1 you are right, may be I have to change the mapping in the scatter file to make my new binary. My problem Sung is that I have the two same binary file in two different part of flash, I can boot on these two binary BUT the address of the first pointing function is fixed, so my main() address will be always the same, pointing to the main of the first binary. I was meaning that there was an offset made but it don't look like so.

But with this method I need always to know where the new binary will be flashed, and this is a problem for me, because it should be random in function of my cards.