Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objcopy elf to bin file

I have STM32F404 board and I am trying to flash it. I am following this tutorial.

In the project Makefile

$(PROJ_NAME).elf: $(SRCS)
    $(CC) $(CFLAGS) $^ -o $@ 
    $(OBJCOPY) -O ihex $(PROJ_NAME).elf $(PROJ_NAME).hex
    $(OBJCOPY) -O binary $(PROJ_NAME).elf $(PROJ_NAME).bin

burn: proj
    $(STLINK)/st-flash write $(PROJ_NAME).bin 0x8000000

The bin file is generated using OBJCOPYand then flashed using the Make target burn

My questions :

Question 1: What does OBJCOPY=arm-none-eabi-objcopy in this case. I opened the man but I didn't fully undrestand can anyone explain it simply ?

Question 2: Flashing the bin file gives the expected result (Leds blinking) However the leds are not blinking by flashing the elf file $(STLINK)/st-flash write $(PROJ_NAME).elf 0x8000000 so why ?

like image 655
Mouin Avatar asked Apr 05 '18 19:04

Mouin


People also ask

What is the difference between ELF and BIN file?

bin is the final way that the memory looks before the CPU starts executing it. ELF is a cut-up/compressed version of that, which the CPU/MCU thus can't run directly. The (dynamic) linker first has to sufficiently reverse that (and thus modify offsets back to the correct positions).


1 Answers

Question 1: What does OBJCOPY=arm-none-eabi-objcopy in this case. I opened the man but I didn't fully undrestand can anyone explain it simply ?

It assigns value arm-none-eabi-objcopy to make variable OBJCOPY.

When make executes this command:

$(OBJCOPY) -O binary $(PROJ_NAME).elf $(PROJ_NAME).bin

the actual command that runs is

arm-none-eabi-objcopy -O binary tim_time_base.elf tim_time_base.bin

Question 2: Flashing the bin file gives the expected result (Leds blinking) However the leds are not blinking by flashing the elf file $(STLINK)/st-flash write $(PROJ_NAME).elf 0x8000000 so why?

The tim_time_base.elf is an ELF file -- it has metadata associated with it. Run arm-none-eabi-readelf -h tim_time_base.elf to see what some of this metadata are.

But when you processor jumps to location 0x8000000 after reset, it is expecting to find executable instructions, not metadata. When it finds "garbage" it doesn't understand, it probably just halts. It certainly doesn't find instructions to blink the lights.

like image 51
Employed Russian Avatar answered Oct 17 '22 23:10

Employed Russian