I downloaded a updated version of some firmware, and need to compile it into a firmware.bin
file, (firmware.hex
will not work). Most of the tutorials online said to use PlatformIO for this, but whenever I build the firmware, everything goes as planed, it compiles without any errors and says that it succeeded. However, on most youtube videos or online documents, the last few lines include something like
Archiving .pio\build\mega2560\libFrameworkArduino.a
Archiving .pio\build\mega2560\lib9e6\libU8glib-HAL_ID1932.a
Linking .pio\build\mega2560\firmware.elf
Building .pio\build\mega2560\firmware.hex
Checking size .pio\build\mega2560\firmware.elf
Building .pio\build\mega2560\firmware.bin
RAM: [====== ] 60.6% (used 4963 bytes from 8192 bytes)
Flash: [====== ] 63.7% (used 161682 bytes from 253952 bytes)
================================================ [SUCCESS] Took 222.23 seconds ================================================
While mine looks like this:
Archiving .pio\build\mega2560\libFrameworkArduino.a
Archiving .pio\build\mega2560\lib9e6\libU8glib-HAL_ID1932.a
Linking .pio\build\mega2560\firmware.elf
Building .pio\build\mega2560\firmware.hex
Checking size .pio\build\mega2560\firmware.elf
RAM: [====== ] 60.6% (used 4963 bytes from 8192 bytes)
Flash: [====== ] 63.7% (used 161682 bytes from 253952 bytes)
================================================ [SUCCESS] Took 222.23 seconds ================================================
And sure enough, there is a firmware.elf
and firmware.hex
, but no firmware.bin
. Many other places say that platformio creates a .bin
file by default, so I don't think it was something I forgot to do, but then what was it? Do I need to edit my Platformio.ini
file, or something else?
I had the same issue when building for an arduino. The solution I found was to add an extra_script.py
file in the workplace to compile the bin after.
Details on the post compiling: https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html#before-pre-and-after-post-actions
Details on the script https://community.platformio.org/t/add-t-none-or-t-binary/441/14
Basically you want to add the extra_scripts
line to your platformio.ini
file
; you env might be different to might platform, board and framework be
[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
extra_scripts = post:extra_script.py
The extra_script.py
file resides in the same folder as platformio.ini
and is
from os.path import join
Import("env", "projenv")
# Custom BIN from ELF
env.AddPostAction(
"$BUILD_DIR/${PROGNAME}.elf",
env.VerboseAction(" ".join([
"$OBJCOPY",
"-O",
"binary",
"$TARGET",
"$BUILD_DIR/${PROGNAME}.bin"
]), "Building $TARGET"))