Objcopy elf to bin file
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.
Mouin
Updated on July 11, 2022Comments
-
Mouin almost 2 years
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
OBJCOPY
and then flashed using the Make targetburn
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 ? -
Mouin about 6 yearsThank you @Employed Russian, for the Question 1, the purpose of the question is to explain more how objcopy works
-
Mouin about 6 yearsHow does objcopy translates this metadata in the bin ?
-
Lennon McLean about 3 years@Mouin generally it doesn't. it isn't nessesary for program execution, so it just discards it
-
Spencer McDonough over 2 yearsThis worked great for me! Here is the link to download objcopy if you are using Windows: pemicro.com/blog/index.cfm?post_id=35