This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Loading Bootloader from Flash to RAM

Hi,

i am using an STM32F103RB Controller and the KEIL uVision 5 IDE (5.17) and STM32CubeMX.

My bootloader resides in the first 16kB of the Flash 0x08000000 to 0x08003FFF, The data Data RAM-Region is shiftet to 0x20004000.

I wanted to copy the Bootloader to RAM before jumping to SystemInit function.

The Plan was to copy the whole Bootloader to RAM and afterwards change the Interrupt-Vectors in RAM from 0x08xxxxx to 0x20xxxxxx, then Jump to the SystemInitFunction in RAM. 

The Assembled Code uses PC - relative Adressing, so i thought it should be possible.

As a first test, i compiled the Bootloader once for Flash and afterwards for RAM and compared the HEX-Files.

I noticed that there are a few places in the File which seems to use absolute Adresses, not only in the Vector-Table where i expected it, but only a few places.

Does anybody know if there is a possibility to make the whole compile relative, or is there a better way to transfer the Loader to RAM?

I use interrupts in the bootloader for UART, CAN and a timer.

Thank you for helping me!

Chris

Parents
  • Hi Chris,

    I come up with an idea, but didn't use yet. Maybe I will try it later.

    Do you mind using the keil internal function __main in the startup code to move your code to the sram? If not, you can have a look at the "scatter file", whose file name suffix is .sct.

    Usually, the bin file containing the RO code, RO data, RW data is downloaded into the mcu flash. Then one task of function "__main" is to move the RW data from flash to sram. So usually, when main function is executing, the real location of RW data is in sram. 

    And this is indicated in the scatter file as below:

    LR_IROM1 0x08000000 0x00010000 { ; load region size_region
     ER_IROM1 0x08000000 0x00010000 { ; load address = execution address
      *.o (RESET, +First)
      *(InRoot$$Sections)
      .ANY (+RO)
      .ANY (+XO)
     }
     RW_IRAM1 0x20000000 0x00002000 { ; RW data
      .ANY (+RW +ZI)
     }

    The scatter file tells the __main function to move each section to the right place. Meanwhile tells the compiler to allocate the code or data a right address.

    So I think your problem may be solved by scatter file, and you may learn the format of scatter file so you can make your own arrangement.

    Best regards,

    Wenchuan 

Reply
  • Hi Chris,

    I come up with an idea, but didn't use yet. Maybe I will try it later.

    Do you mind using the keil internal function __main in the startup code to move your code to the sram? If not, you can have a look at the "scatter file", whose file name suffix is .sct.

    Usually, the bin file containing the RO code, RO data, RW data is downloaded into the mcu flash. Then one task of function "__main" is to move the RW data from flash to sram. So usually, when main function is executing, the real location of RW data is in sram. 

    And this is indicated in the scatter file as below:

    LR_IROM1 0x08000000 0x00010000 { ; load region size_region
     ER_IROM1 0x08000000 0x00010000 { ; load address = execution address
      *.o (RESET, +First)
      *(InRoot$$Sections)
      .ANY (+RO)
      .ANY (+XO)
     }
     RW_IRAM1 0x20000000 0x00002000 { ; RW data
      .ANY (+RW +ZI)
     }

    The scatter file tells the __main function to move each section to the right place. Meanwhile tells the compiler to allocate the code or data a right address.

    So I think your problem may be solved by scatter file, and you may learn the format of scatter file so you can make your own arrangement.

    Best regards,

    Wenchuan 

Children