cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to reallocate Application at other than base address

Ashvin Ramani
Associate III

I aim to load my application at 0x08002000 instead of 0x08000000(base address) and secure the first two sections which will be used to store CRC and other firmware update information.

I use a post-build script to calculate the CRC using srecord utility on application firmware and embed it into the executable at the base address.

I also change the vector table offset to #define VECT_TAB_OFFSET     0x00002000U.

but don't know why it was not working, following is my observation:

1)When I just build & load the application firmware at the address of 0x08002000 without embedding CRC it was working.

2)But when I embed CRC into the executable it was not working, I also verify flash contained and that it was loaded properly. (After loading cube-programmer gives a warning: The core is locked up)

Am I missing any steps? Please help me here to resolve my issue.

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

> If I just change the linker script to start flash at 0x08002000 and change #define VECT_TAB_OFFSET     0x00002000U and without embedding CRC then my application is working fine. 

Probably it works because of the debugger. The debugger is smart and [often] can run a program, even loaded at custom address. But to start it without a debugger you need a bootloader.

Some STM32 models can also specify the vector address in option bytes.

View solution in original post

5 REPLIES 5
gbm
Lead III

The STM32 MCU always fetches two words from memory location 0 and 4 (mapped to 0x8000000 and 0x8000004) to start the program - you cannot change this behavior on most of STM32 MCUs. You must have the bootloader or application code at 0 (0x8000000). You may use page 1 of Flash for yoyur data storage but not page 0. Look at the the threads on bootloaders in this forum.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

Not clear how you're embedding CRC

How does code execution make it to the new base address?

The MCU has fixed expectations about where it is starting.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Ashvin Ramani
Associate III

@gbm​ & @Community member​ ,

Thanks for your input on this and FYI:I am using STM32l4R9AI CPU

@gbm​ , If I just change the linker script to start flash at 0x08002000 and change  #define VECT_TAB_OFFSET     0x00002000U and without embedding CRC then my application is working fine. So, this says that because of this offset value, it was able to find out the vector table.

but when I embed CRC on page 0 my application gets stuck.

@Community member​ , the following are the way I am calculating and embedding CRC into the executable:

1)Convert .elf to .hex using objcopy.exe,

2)Find out size of application.hex and it should be multiplied by 16. If not then do the conversion so it will be multiplied by 16,

3)Calculate and embed CRC at page 0

srec_cat.exe "application.hex" -Intel -fill 0xFF 0x8002000 0xsizeofW(from step-3) -STM32 0x8000000 -Output_Block_Size=16 -o "final_application.hex" -Intel

4)embed 0xsizeofW(from step-3) to final executable at address 0x8000004: while executation application will read this, and it knows the range of the firmware on which it has to calculate CRC:

srec_cat.exe "final_application.hex" -I -E 0x8000004 0x8000008 -GEN 0x8000004 0x8000008 -CONSTant_Little_Endian 0xsizeofW(from step-3) 4 -Output_Block_Size=16 -O "final_application.hex" -I

Let me know if you need more information to understand the scenarios

You need the Initial SP, PC ​at 0x08000000, copy that word pair from 0x08002000 table.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

> If I just change the linker script to start flash at 0x08002000 and change #define VECT_TAB_OFFSET     0x00002000U and without embedding CRC then my application is working fine. 

Probably it works because of the debugger. The debugger is smart and [often] can run a program, even loaded at custom address. But to start it without a debugger you need a bootloader.

Some STM32 models can also specify the vector address in option bytes.