This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
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

Bootloader with GCC problems

Hi all,

I am using gcc for my Nordic project and I wanted to add the bootloader. After some reading and experimenting the bootloader worked. Now I thought of making a release build using -Os for optimization. The bootloader stopped working sadly. After some debugging I traced it down to StartApplication in bootloader_util_gcc.c This function calls the application in Flash using inline assembly. Looking at this function it was not that strange it dit not work. The parameter start_addr was not used and thus optimized out. So r0 has a undefined value. I personally don't understand how and why it can work by other people who are using this code. I fixed this problem by using the parameters the function is giving me.

static inline void StartApplication(uint32_t start_addr)
{
    asm volatile(
			"LDR   R2, [%0]\t\n"
			"MSR   MSP, R2\t\n"
			"LDR   R3, [%0, #0x00000004]\t\n"
			"BX    R3\t\n"
			:
			: "l" (start_addr)
			: "r3", "r2"
    );
}

Now everything it working perfectly :-)

Another thing I am very surprised of is the use of m_uicr_bootloader_start_address. Because this constant is nowhere used and it is also optimized out and thus the hex file does not contain the bootloader start address for the UICR register (0x10001014). To solve this problem I use now:

volatile const uint32_t m_uicr_bootloader_start_address __attribute__ ((section(".uicrBootStartAddress"))) = BOOTLOADER_REGION_START;

Hope this helps other people and I hope Nordic will fix this in their new SDK.

Regards, Marcel

Parents
  • Where did you find a bintuils linker script to set the addresses of uicrbootstartaddress and the bootloader settings?

    Also, the version of the gcc_util file that I have already includes the following. Did this not work for you?

    attribute ((section(".uicrBootStartAddress"))) uint32_t m_uicr_bootloader_start_address = BOOTLOADER_REGION_START;

Reply
  • Where did you find a bintuils linker script to set the addresses of uicrbootstartaddress and the bootloader settings?

    Also, the version of the gcc_util file that I have already includes the following. Did this not work for you?

    attribute ((section(".uicrBootStartAddress"))) uint32_t m_uicr_bootloader_start_address = BOOTLOADER_REGION_START;

Children
No Data
Related