0

I have a code for an embedded microncontroller in an FPGA that contains variables stored in the stack and I would like to seperate the code from those variables and put those into 2 ELF files. The goal in the end is to convert the ELF files into intel hex format and initialize 2 distinct RAM with them.

The goal in the end is to have an Harvard architecture (i.e an architecture with a memory for the data and a memory for the program itself)

Right now I have a makefile with this rule:

%.hex: %.elf
    $(OBJCOPY) -j .data -O ihex $^ [email protected]
    $(OBJCOPY) --remove-section .data $^
    $(OBJCOPY) -O ihex $^ $@

Here I create a single ELF and then extract the .data section into a seperate intel hex file. Then I remove the .data section from the original ELF and convert it to intel hex format. My problem is that this doesn't seem to be right as removing the section from the original elf relocate the next section in the file to a new position, which I guess is not something I want.

1
  • Are these variables or constants? Do you have some sample code to illustrate? Commented May 22, 2023 at 22:53

2 Answers 2

1

I have a code for an embedded microncontroller in an FPGA that contains variables stored in the stack and I would like to seperate the code from those variables and put those into 2 ELF files.

Variables placed on the stack are allocated runtime and you can't separate them in an elf file.

Also .data might not be physically present (only information about the position and the size) in the elf file. If the code is run from the non-volatile storage like FLASH the dada is copied from the FLASH to the place where .data segment is located by the startup code.

It looks to me like a X-Y problem.

Sign up to request clarification or add additional context in comments.

5 Comments

But what if there are constants in the code, are they not in the data section ?
No, read about VMA & LMA addresses
@cfl no, usually const data is in a section .const (in some platforms) or .text. .data is storage allocated for non-zero "permanent" variables at boot time (the linker may populate it directly, or the boot code copies from ROM to the variable at init--depending on your architecture), .bss is for storage for "permanent" variables allocated at boot time, but initialized to zero. The stack and heap GENERALLY sit in the "empty" space between the end of .data/.bss and the end of available memory. Stack grows downward and heap grows upward.
@RussSchultz no, the section containing const data is called .rodata on most implementations
@0___________ you're right. my bad. too early and not enough coffee.
0

What you need to use is a linker script (better, modify the one you are using), that allows you to indicate in the ELF binary, where to put the different sections. Don't do things that the linker is designed to do.

Read the ld(1) command info documentation (in case you are using GNU binutils) to get an idea on how to do this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.