Bootloader Erased when Application is programmed
I can not follow what you are telling us. The elf file is an image which contains information how to load the structure of the executeable to the location from where it gets executed.
Here we have the problem, that a flash programmer, openocd in this case, programs the elf header itself to flash memory. There is nothing wrong with the generation of the elf file.
The application is already relocated above the bootloader:
from STM32F103CBTx_FLASH.ld:
MEMORY { RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K FLASH (rx) : ORIGIN = 0x8004000, LENGTH = 112K /* FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K */ }
from system_stm32f1xx.c:
#define VECT_TAB_OFFSET 0x4000 //#define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field. This value must be a multiple of 0x200. */
A look into the elf file:
objdump -x /array_data01/STM32-34/mini-sys/Debug/mini-sys.elf /array_data01/STM32-34/mini-sys/Debug/mini-sys.elf: file format elf32-littlearm /array_data01/STM32-34/mini-sys/Debug/mini-sys.elf architecture: arm, flags 0x00000112: EXEC_P, HAS_SYMS, D_PAGED start address 0x0800da45 Program Header: LOAD off 0x00000000 vaddr 0x08000000 paddr 0x08000000 align 2**16 filesz 0x00012e88 memsz 0x00012e88 flags rwx LOAD off 0x00020000 vaddr 0x20000000 paddr 0x08012e88 align 2**16 filesz 0x000003f0 memsz 0x000024dc flags rw- LOAD off 0x000224dc vaddr 0x200024dc paddr 0x08013278 align 2**16 filesz 0x00000000 memsz 0x00000604 flags rw- private flags = 5000200: [Version5 EABI] [soft-float ABI] Sections: Idx Name Size VMA LMA File off Algn 0 .isr_vector 0000010c 08004000 08004000 00004000 2**0 CONTENTS, ALLOC, LOAD, READONLY, DATA 1 .text 0000c4a4 08004110 08004110 00004110 2**3 CONTENTS, ALLOC, LOAD, READONLY, CODE 2 .rodata 000028c0 080105b8 080105b8 000105b8 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA 3 .ARM 00000008 08012e78 08012e78 00012e78 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 4 .init_array 00000004 08012e80 08012e80 00012e80 2**2 CONTENTS, ALLOC, LOAD, DATA 5 .fini_array 00000004 08012e84 08012e84 00012e84 2**2 CONTENTS, ALLOC, LOAD, DATA 6 .data 000003f0 20000000 08012e88 00020000 2**2 CONTENTS, ALLOC, LOAD, DATA 7 .bss 000020ec 200003f0 08013278 000203f0 2**3 ALLOC 8 ._user_heap_stack 00000604 200024dc 08013278 000224dc 2**0 ALLOC 9 .ARM.attributes 0000002b 00000000 00000000 000203f0 2**0 CONTENTS, READONLY 10 .debug_info 0002281d 00000000 00000000 0002041b 2**0 CONTENTS, READONLY, DEBUGGING 11 .debug_abbrev 0000654b 00000000 00000000 00042c38 2**0 CONTENTS, READONLY, DEBUGGING 12 .debug_loc 0000ff9f 00000000 00000000 00049183 2**0 CONTENTS, READONLY, DEBUGGING 13 .debug_aranges 00001670 00000000 00000000 00059128 2**3 CONTENTS, READONLY, DEBUGGING 14 .debug_ranges 00001b80 00000000 00000000 0005a798 2**3 CONTENTS, READONLY, DEBUGGING 15 .debug_macro 00022e2f 00000000 00000000 0005c318 2**0 CONTENTS, READONLY, DEBUGGING 16 .debug_line 0001e9be 00000000 00000000 0007f147 2**0 CONTENTS, READONLY, DEBUGGING 17 .debug_str 000a08d6 00000000 00000000 0009db05 2**0 CONTENTS, READONLY, DEBUGGING 18 .comment 0000006e 00000000 00000000 0013e3db 2**0 CONTENTS, READONLY 19 .debug_frame 000049a8 00000000 00000000 0013e44c 2**2 CONTENTS, READONLY, DEBUGGING SYMBOL TABLE: 08004000 l d .isr_vector 00000000 .isr_vector ...