Objcopy elf to bin file

28,164

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.

Share:
28,164
Mouin
Author by

Mouin

Updated on July 11, 2022

Comments

  • Mouin
    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 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 ?

  • Mouin
    Mouin about 6 years
    Thank you @Employed Russian, for the Question 1, the purpose of the question is to explain more how objcopy works
  • Mouin
    Mouin about 6 years
    How does objcopy translates this metadata in the bin ?
  • Lennon McLean
    Lennon McLean about 3 years
    @Mouin generally it doesn't. it isn't nessesary for program execution, so it just discards it
  • Spencer McDonough
    Spencer McDonough over 2 years
    This worked great for me! Here is the link to download objcopy if you are using Windows: pemicro.com/blog/index.cfm?post_id=35