This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Creation of the position-independent firmware.

Hello!

I am implementing a custom OTA procedure for the NRF52840 development board and I need to be able to load the firmware from several predefined positions in the flash. I've already implemented the bootloader that is able to load firmwares from any position (patching the IVT in the process). Currently I am able to get a litlle bit further than the main function, but after that I am getting hardfaults.

If I compile the firmware without -fPIC option, the linker puts a lot of data and code to hardcoded positions, so the firmware cannot be loaded. If I use the option then linker adds PC-relative offset not only to the code, but also to global and static variables thus leading to busfaults.

Is there any way to create relocatable firmwares?

I am using the NRF5SDK 15.2 and s140_nrf52_6.1.0 softdevice.

Thanks.

UPDATE:

If I am using the following set of flags:

-fPIC
-msingle-pic-base

-mno-pic-data-is-text-relative

-mpic-register=r9

I am getting hardfault at

#if (defined(__ARM_ARCH_FPV4_SP_D16__) || defined(__ARM_ARCH_FPV5_D16__)) && !defined(NO_FPU_ENABLE)
  /* Enable FPU */
  ldr r0, =FPU_CPACR_REG 
  ldr r1, [r0]  /*** SEGFAULT IS HERE ***/
  orr r1, r1, #(0xF << 20)
  str r1, [r0]
  dsb
  isb
#endif

of ses_startup_nrf_common.s. 

Parents
  • Hi,

    This question is very similar to a question I recently got via a different channel, so I believe I am already discussing this topic with one of your colleagues.

    Generally, we do not recommend position independent firmware, nor do we have any instructions or guidance. There are several issues with it and in most cases little benefit in small embedded systems.

    Regarding the specific question about the hardfault when enabling the FPU this seems strange to me as well. We do not have an explanation for it at this point.

Reply
  • Hi,

    This question is very similar to a question I recently got via a different channel, so I believe I am already discussing this topic with one of your colleagues.

    Generally, we do not recommend position independent firmware, nor do we have any instructions or guidance. There are several issues with it and in most cases little benefit in small embedded systems.

    Regarding the specific question about the hardfault when enabling the FPU this seems strange to me as well. We do not have an explanation for it at this point.

Children
No Data
Related