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
tommelou
Associate II
Posted on April 07, 2014 at 16:39

Thank you Clive1 and Sung,

I have search a little more but without success, I have no time for searching more now. I will use the simple solution to temporary flash the second part with my new binary then copying it on the first, because of the entry point. So no recovery.

If somebody have an answer later about the multiboot? It could be nice to understand what was the solution.

Posted on April 08, 2014 at 00:57

Updating STM32 devices with some level of integrity requires that you stage a firmware update somewhere prior to committing it as an active image. This could be on an SD card, or external memory, or an unused region of the STM32 memory.

Most all scenarios you want a solid boot-loader which is not erased, and can validate application image(s) before calling. It would also provide a method to recover a device when no valid application image is detected. And update the application image via the staged download described earlier.

Dual booting with an execute-in-place really needs the multi-bank flash devices (F1 @ 1MB, of F4 @ 2MB). If you can fashion an image as position-independent code, the cortex-mx devices break this with their vector table. If all other absolute addresses issues have been resolved, you could carve out an area at the front of RAM (mapping, or just via SCB->VTOR), and copy a fixed-up version where the vector entries could point to a secondary region of FLASH
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 10, 2014 at 14:39

Hi,

I have finally solved my problem, how to make ''like'' a bootloader.

I mean like because I have a first execution code that check if my temp binary file has been well coying in the first flash part, else it try to recopy. It is not a multiboolader.

I have remmapped my system like this :

; *************************************************************

; *** Scatter-Loading Description File generated by uVision ***

; *************************************************************

LR_IROM1 0x08000000 0x1000  {    ; load region size_region

  ER_IROM1 +0 FIXED 0x1000  {  ; load address = execution address for bootloader

    *.o (BOOT,+First)                         ;area booloader in new startup_stm32f10x_hd_boot.s

    flash_handle.o (+RO)                    ;all files needed to check my copy and reflash

    flash_eeprom_emulator.o (+RO)

    stm32f10x_flash.o (+RO)

    flash_bootloader.o (+RO)

    stm32f10x_misc.o (+RO)    

  }

  RW_IRAM1 0x20000000 0x00001000  {  ; RW data

   .ANY (+RW +ZI)

   }

}

LR_IROM2 0x08001000 0x5F000  {    ; programm region for FlashPart1and Part2

  ;define only the Part1

  ER_IROM2 +0 FIXED 0x2F000 { ; main programme executed after the bootloader

  *.o (RESET,+First)                          ;startup_stm32f10x_hd.s

   *(InRoot$$Sections)

   .ANY (+RO)

  }    

  RW_IRAM2 0x20001000 0x0000F000  {  ; RW data

   .ANY (+RW +ZI)

   }

}

Don't forget in Keil to uncheck box ''Use Memory Layout ...'' to use this scatter file.

So I have recopy the startup file

''startup_stm32f10x_hd.s'' and rename it

''startup_stm32f10x_hd_boot.s''

In this new file rename all section, add ''_boot'' for HEAP and STACK

Then suppress RESET AREA and all his functions.

Create new AREA BOOT that will be linked by the scatter file.

Like This:

                AREA    BOOT, DATA, READONLY

                EXPORT  __BootLoader_Start

                EXPORT  __BootLoader_End

                    

__BootLoader_Start    DCD     __initial_sp               ; Top of Stack

                      DCD     Boot_Handler       

__BootLoader_End                  

                AREA    |.text|, CODE, READONLY

                

; Reset handler

Boot_Handler   PROC

                EXPORT  Boot_Handler             [WEAK]

                IMPORT  FLASH_Bootloader

                LDR     R0, =FLASH_Bootloader

                BLX     R0   

                ;BX     R0                   

                ENDP

With this the file is doing his function then jump to the application.

void FLASH_Bootloader(void)

{

 

   pFunction Jump_To_Application;

 __IO uint32_t JumpAddress;

  FLASH_Function();

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

  Jump_To_Application = (pFunction) JumpAddress;

  /* Initialize user application's Stack Pointer */

  __set_MSP(*(__IO uint32_t*) 0x08001000);

  Jump_To_Application();

}

Then it will go in the ''startup_stm32f10x_hd.s'' of the main execution code, in the file

''system_stm32f10x.c'' change the offset of the vector.

#define VECT_TAB_OFFSET  0x1000 /*!< Vector Table base offset field.

                                  This value must be a multiple of 0x200. */

Then just change the compilation option to separate the bootloader code and the main programm.

In the ''User'' paste this after build

C:\Keil\ARM\ARMCC\bin\fromelf.exe --bin --output=..\Output\bin ..\Output\mysoft.axf --continue_on_error

You will have two files with the region name of scatter file, just rename them with extention .bin to use them. Personaly I will use only the main programm.

All this worked! Just be carefull to make your test when you jump in the main soft after a recopy of the temp binary, that this one have the same scatter file, else the main will still at 0x8000004.

I hope this will help some people! ENJOY