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

Position inpdeped code for bootloader.

Hello,

I'm creating a custom OTA firmware update on cc2640 chip from TI. (Cortex M3)
For this reason two memory regions are reserved for firmware images.
The problem is, the code works only if it is stored in one of the regions. (According to the Linker File)
If the code is stored in the second region, it does not start at all.

In IAR Compiler the -ropi (the same as PIE/PIC in GCC) works correctly.

The Linker Script is the following:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* Entry Point */
ENTRY( ResetISR )
/* System memory map */
MEMORY
{
CRC (RX) : ORIGIN = 0x00001000, LENGTH = 0x00000004
OHD (RX) : ORIGIN = 0x00001004, LENGTH = 0x0000000C
INT_VEC (RX) : ORIGIN = 0x00001010, LENGTH = 0x000000C8
FWU_DESCR (RX) : ORIGIN = 0x000010D8, LENGTH = 0x00000040
APP_DESCR (RX) : ORIGIN = 0x00001118, LENGTH = 0x00000040
FLASH (RX) : ORIGIN = 0x00001158, LENGTH = 0x0000AF2F
CONFIG (RX) : ORIGIN = 0x0001E000, LENGTH = 0x00001000
SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00005000
/* Application can use GPRAM region as RAM if cache is disabled in the CCFG
(DEFAULT_CCFG_SIZE_AND_DIS_FLAGS.SET_CCFG_SIZE_AND_DIS_FLAGS_DIS_GPRAM = 0) */
GPRAM (RWX) : ORIGIN = 0x11000000, LENGTH = 0x2000
}
/*. Generate a link error if heap and stack don’t fit into RAM .*/
_Min_Heap_Size = 0x800;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


The Startup function was already updated to copy the .rodata correctly as following:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void
ResetISR(void)
{
//
// Final trim of device
//
SetupTrimDevice();
//
// Copy the data segment initializers from FLASH to SRAM.
//
__asm(
" ldr r1, =_ldata \n" // get source
" mov r2, pc\n" // get program counter
" cmp r1, r2\n" // compare as difference
" it lo\n" // if then condition. If r2 is greeter than r1
" addlo r1, r1, #45056\n" // add 0xB000
" ldr r2, =_data\n" // get start of the ram
" ldr r3, =_edata\n" // get the data length in the ram
" copy_loop:\n" // start copy loop
" ldr r4, [r1], #4\n"// load a word from the source and
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The bootloader calles the entry (ResetISR(void)) function of the valid firmware at startup.

All libraries are linked with -fPIC option.

target_link_libraries(${TARGETFILE}} ${LIB_LIST} "-fPIC")

I have used listet options:

Compiler flags :  -O2 -fdata-sections -ffunction-sections -fno-strict-aliasing -nostartfiles -fno-exceptions -mcpu=cortex-m3 -mthumb -g0 -Wall "
Linker flags: -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections  -nostartfiles -mthumb -lc -lm -lgcc -lnosys -u __vector_table"
 Effekt -> Firmware works only at first address (0x1000). Other positions does not works.


Compiler flags :  -O2 -fdata-sections -ffunction-sections -fno-strict-aliasing -nostartfiles -fno-exceptions -mcpu=cortex-m3 -mthumb -g0 -Wall -fPIE "
Linker flags: -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections  -nostartfiles -mthumb -lc -lm -lgcc -lnosys -u __vector_table"
 Effekt -> Firmware does not starts

Compiler flags :  -O2 -fdata-sections -ffunction-sections -fno-strict-aliasing -nostartfiles -fno-exceptions -mcpu=cortex-m3 -mthumb -g0 -Wall -fPIE"
Linker flags: -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections  -nostartfiles -mthumb -lc -lm -lgcc -lnosys -u __vector_table -pie "
 Effekt -> Firmware does not starts. The linker flag -pie causes the binarys to be 3 Times grater as whitout this option.


I have alredy read the "Multiple Application Code with Bootloader" question. Unfortunately, the provided solution does not work for me:

Compiler flags :  -O2 -fdata-sections -ffunction-sections -fno-strict-aliasing -nostartfiles -fno-exceptions -mcpu=cortex-m3 -mthumb -g0 -Wall -fPIC "
Linker flags: -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections  -nostartfiles -mthumb -lc -lm -lgcc -lnosys -u __vector_table -msingle-pic-base -mpic-register=r9"
Effekt -> Firmware does not starts.


Coud someone provide some assistance to correct the mistake?

0