cancel
Showing results for 
Search instead for 
Did you mean: 

Question about linker script

Ming Wong
Associate
Posted on May 06, 2018 at 06:03

Hello,

I am trying to write a firmware upgrade and bootloader module for a hobby project of mine. I am using a STM32L4 chip.

The bootloader is a customer bootloader residing in the first bank taking about 10 pages of flash.

Then the first of the flash is split evenly, first half for Application #1 and second half is Application #2.

The idea was to re-flash the other half whenever I have a new firmware to update, and then reboot the device and execute the new firmware. The file format is .bin file generated using -objcopy.

So for example, if I am originally running at application #1, I would flash the new firmware to application #2 space. Reboot the device, and the bootloader would jump to application #2 space.

As a test, I flashed the same application 1 binary to application 2 space, and performed CRC calcs (which matches), however, for some reason, code executing at application 2 would crash. I am not too sure why as the binary data was exactly the same.

I rebuilt the application, but this time changed the linker script to have flash start at the address of application #2 space. I then flashed this binary file and to my relievement, application 2 runs fine!

I am still new to the coding world and my understanding of linkers and what not has not yet fully matured, but why would changing the linker's flash starting address affect my result?

3 REPLIES 3
Posted on May 06, 2018 at 18:59

The processor has expectations about where code is placed. The Vector Table contains absolute addresses, so the linker needs to build a binary with all those expectations met.

You might want to review books on the Cortex-M4 micro-controller, both the ARM Technical Reference Manual and Joseph Yiu's Essential series are recommended. Standard texts on micro-controllers, and assemblers, linkers and loaders are also good foundation.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 06, 2018 at 20:32

Thanks for the response.

The processor has expectations about where code is placed. The Vector Table contains absolute addresses, so the linker needs to build a binary with all those expectations met.

If I were to place the vector table at the beginning of RAM, would I need to recompile the binary to reflect different start of FLASH addresses?

Posted on May 06, 2018 at 23:20

The binary code is located at absolute address and will fail if run at a different address.

Probably you have not compiled the program in position-independent mode. 

Also there's a issue with vectors table, mentioned by Clive One.

This idea to switch two halves of the flash looks attractive, but in reality hard to implement.

-- pa