[SOLVED] Creating relocatable image file

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] Creating relocatable image file

    Hello-
    We have a project using a bootloader on the STM32F411. Splitting the flash memory section into sections 'A' and 'B' and keeping the bootloader and application as separate projects (yes, there are ways to combine it, but we're not doing that for now) the bootloader running in flash section 'A' correctly receives, writes, and branches to the application in flash section 'B'. As a side note, the application project is compiling with the __VTOR_CONFIG option.

    As an additional level of safety we'd like to have two sections of application flash, 'B' and 'C', so that if the write to one section fails then the application can still be executed from the last successfully loaded memory section. It's not clear what the exact terminology is to be used but we would like to get some kind of relocatable image built so that after compiling the application only one time the bootload process can successfully place and execute the application in either flash section 'B' or 'C'. From reviewing the SES link options it seems like to get this to work the application would have to be compiled twice, once under each different memory map, and the host and device ends of the bootloader would have to decide which image is the one to upload. Is this assessment correct or is there a way to have a single HEX file that will run properly regardless of where in flash you place it?
  • Hello,

    Thank you for your inquiry.

    I am not completely sure whether I understand you correctly. Could you please elaborate what you are trying to do?

    Are the applications in B and C simply mirrored or do they differ in some way?
    Should both applications be flashed at the same time or should only one be updated at a time?
    Is the increased safety related to the boot or the update process?


    In case both applications should be flashed at the same time you may set "Debug > Loader > Additional Load File[..]" to the image of the other application.
    Please note that the project needs to be setup so both applications are built at the same time, so either as build dependency for another project or using a batch build for multiple configurations.

    Best regards,
    SebastianB
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello- please forgive the lateness of this reply, I'm on vacation at the time of writing.

    There is only one application image that we hope to be able to run from either flash section B or C. If for example the image was last successfully uploaded to region B, the bootloader will attempt the next upload to region C. If this process fails then there is still a valid image in region B the bootloader can branch to. The goal is to try and minimize the chances an end-user will render our device unusable when they perform a firmware update with the file we provide. And to hopefully be clear, we're talking about an end-user connecting to our bootloader as a USB device and uploading the application image over USB so our bootloader handles the flash writing. Segger Embedded Studio is only responsible for compiling the application image in a manner that supports this behavior.
  • Hello,

    Thank you for the explanation!

    This would require the application to be built position-independent. This is rather unusual on embedded devices and does come with many limitation which have to be noted.
    The Project may be configured regarding this using the "Code > Code Generation > Relocation Model [segger-cc]" setting.
    For further information please take a look at the clang documentation.

    Alternatively we would recommend to instead always prepare and ship two images, both using static addresses but prepared for different positions.
    The bootloader would then select the appropriate image to flash and boot to.
    This removes the limitations regarding the position-independent code and simplifies the setup.

    Best regards,
    SebastianB
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • SEGGER - SebastianB wrote:

    Alternatively we would recommend to instead always prepare and ship two images, both using static addresses but prepared for different positions.
    The bootloader would then select the appropriate image to flash and boot to.
    This removes the limitations regarding the position-independent code and simplifies the setup.
    Thank you, seems about as I thought then. This can get marked as "solved"...