2023-05-06 07:10 AM - edited 2023-11-20 06:16 AM
Hi, I have an ELF file modified to write to the main memory address 0x08004000 instead of 0x08000000. Please find the screenshot below and the ELF file in the attachment.
But instead of writing to 0x08004000 it constantly writes to 0x08000000. Why is this happening?
Solved! Go to Solution.
2023-05-09 11:38 AM
2023-05-07 09:02 AM
> Hi, I have an ELF file modified to write to the main memory address 0x08004000 instead of 0x08000000
No, you haven't. Your screenshot shows the old address, as well as
$ arm-none-eabi-readelf -l blink_50ms.elf
Elf file type is EXEC (Executable file)
Entry point 0x800435d
There are 3 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x000000 0x08000000 0x08000000 0x04e7c 0x04e7c RWE 0x10000
LOAD 0x010000 0x20000000 0x08004e7c 0x0000c 0x0002c RW 0x10000
LOAD 0x00002c 0x2000002c 0x08004e88 0x00000 0x00604 RW 0x10000
Section to Segment mapping:
Segment Sections...
00 .isr_vector .text .rodata .init_array .fini_array
01 .data .bss
02 ._user_heap_stack
hth
KnarfB
2023-05-07 09:21 AM
What created the .ELF file? Show the linker script (.LD) or relatedGUI settings
The program header is unhelpful
========================================================================
** Program header #0 (PT_LOAD) [PF_X + PF_W + PF_R]
Size : 20092 bytes
Virtual address: 0x08000000 (Alignment 65536)
====================================
** Program header #1 (PT_LOAD) [PF_W + PF_R]
Size : 44 bytes (12 bytes in file)
Virtual address: 0x20000000 (Alignment 65536)
====================================
** Program header #2 (PT_LOAD) [PF_W + PF_R]
Size : 1540 bytes (0 bytes in file)
Virtual address: 0x2000002c (Alignment 65536)
========================================================================
** Section #1 '.isr_vector' (***_PROGBITS) [SHF_ALLOC]
Size : 472 bytes
Address: 0x08004000
0x8004000: 00 c0 01 20 5d 43 00 08 2d 43 00 08 2f 43 00 08 ... ]C..-C../C..
0x8004010: 31 43 00 08 33 43 00 08 35 43 00 08 00 00 00 00 1C..3C..5C......
0x8004020: 00 00 00 00 00 00 00 00 00 00 00 00 37 43 00 08 ............7C..
..
2023-05-07 10:31 AM
Hi, @KnarfB @Community member .ELF file is created using STM32CubeIDE please find the linker file in the attachment.
File Name: STM32G491RETX_FLASH.ld
/*
******************************************************************************
**
** @file : LinkerScript.ld
**
** @author : Auto-generated by STM32CubeIDE
**
** @brief : Linker script for STM32G491RETx Device from STM32G4 series
** 512Kbytes FLASH
** 112Kbytes RAM
**
** Set heap size, stack size and stack location according
** to application requirements.
**
** Set memory bank area and size if external memory is used
**
** Target : STMicroelectronics STM32
**
** Distribution: The file is distributed as is, without any warranty
** of any kind.
**
******************************************************************************
** @attention
**
** Copyright (c) 2023 STMicroelectronics.
** All rights reserved.
**
** This software is licensed under terms that can be found in the LICENSE file
** in the root directory of this software component.
** If no LICENSE file comes with this software, it is provided AS-IS.
**
******************************************************************************
*/
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 112K
FLASH (rx) : ORIGIN = 0x8004000, LENGTH = 496K
}
/* Sections */
SECTIONS
{
/* The startup code into "FLASH" Rom type memory */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data into "FLASH" Rom type memory */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data into "FLASH" Rom type memory */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : {
. = ALIGN(4);
*(.ARM.extab* .gnu.linkonce.armextab.*)
. = ALIGN(4);
} >FLASH
.ARM : {
. = ALIGN(4);
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
. = ALIGN(4);
} >FLASH
.preinit_array :
{
. = ALIGN(4);
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
} >FLASH
.init_array :
{
. = ALIGN(4);
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(4);
} >FLASH
.fini_array :
{
. = ALIGN(4);
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
. = ALIGN(4);
} >FLASH
/* Used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections into "RAM" Ram type memory */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
*(.RamFunc) /* .RamFunc sections */
*(.RamFunc*) /* .RamFunc* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH
/* Uninitialized data section into "RAM" Ram type memory */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss section */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM
/* Remove information from the compiler libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}
2023-05-07 11:05 AM
Suspect it's not using that, or something is broken in the chain of custody.
I'd rename the ,isr_vector section name, and confirm it propagates.
2023-05-07 11:10 AM
Sure @Community member. And I have changed system_stm32g4xx.c file as below to jump to 0x08004000 after reset.
/************************* Miscellaneous Configuration ************************/
/* Note: Following vector table addresses must be defined in line with linker
configuration. */
/*!< Uncomment the following line if you need to relocate the vector table
anywhere in Flash or Sram, else the vector table is kept at the automatic
remap of boot address selected */
#define USER_VECT_TAB_ADDRESS
#if defined(USER_VECT_TAB_ADDRESS)
/*!< Uncomment the following line if you need to relocate your vector Table
in Sram else user remap will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x4000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
/******************************************************************************/
2023-05-08 05:41 AM
Hi @Community member any updates on this for me :)
2023-05-08 05:55 AM
Not from my end.
Did you change the naming in the .LD and confirmed you can see that in OBJCOPY?
@Sara BEN HADJ YAHYA any know issues with which .LD is being used or why linker would generate and odd .ELF ??
..
/* Sections */
SECTIONS
{
/* The startup code into "FLASH" Rom type memory */
.isr_something_unique_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
..
2023-05-08 06:24 AM
2023-05-08 11:50 AM
> I don't have enough knowledge on these
Then it is time to learn. @Community member gave you something to try. Surely you can edit the linker file? Then search for how to use OBJCOPY, or maybe easier, look at the MAP file and see if that new name appears or if the old "isr_vector" name appears. If your build doesn't generate a map file, the update your CubeIDE project (project properties, C/C++Build, Settings, Tool Settings, Linker, general).