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.