Change name of firmware file

Hi, I would like to have custom firmware name, instead of firmware.bin i would like IotSwitch.bin file to be generated. Is it possible to configure?

http://docs.platformio.org/en/latest/projectconf/advanced_scripting.html#custom-firmware-program-name

Hi there. Thank you for this info, but where in Platform.ini do I put this code?
Do I just copy and paste it just like it is:

[env:featheresp32]
platform = espressif32
board = featheresp32
framework = arduino
lib_deps =
PubSubClient
EspSoftwareSerial
build_flags = -D VERSION=1.1.3
extra_scripts = pre:extra_script.py
monitor_speed = 115200

Or what part of this code do I use in my specific board’s env section:

[env:LPC1769]
platform = ${common_LPC.platform}
extends = common_LPC
board = nxp_lpc1769

The critical part is the definition of the verseion via build_flags and the definition of the extra_script to run. So just add the lines

build_flags = -D VERSION=13
extra_scripts = pre:extra_script.py

to the environment and make sure that the extra_script.py with the content as shown in the docs exists in the project root folder. Refer to the docs for all further documentation on platformio.ini options.

So the script must be exactly this:

And put into the root dirctory like this:

But where in platform.ini do I put what to call that script?

Well through the extra_scripts = pre:extra_script.py line… Please see docs and the therein linked docs…

You mean, like this:

Can you show the contents of your extra_script.py in VSCode? Is the first line Import("env") as it should or Import("projenv"). Not being able to reference projenv is correct for pre: scripts as per docs.

Though there might be secondary error after that: The given example doesn’t work when there defines in the build script that are not defined to some value, but just defined. Because then the CPPDEFINES will e.g. be

['BEARSSL_SSL_BASIC', ['VERSION', '13']

and viewing them as (key, value) pairs as the code

defines = {k: v for (k, v) in my_flags.get("CPPDEFINES")}

does fails since the first item cannot be written in such a way.

But let’s see your file content first. The directives in the platformio.ini are correct.

1 Like

A better, more general script for converting the -D VERSION=14 into the firmware name would be

Import("env")

version_from_buildflags = "not_found"
my_flags = env.ParseFlags(env['BUILD_FLAGS'])
#print(my_flags.get("CPPDEFINES"))
# some flags are just defines without value
# some are key, value pairs
for x in my_flags.get("CPPDEFINES"):
    #print(x)
    if isinstance(x, list):
        # grab as key, value
        k, v = x
        if k == "VERSION":
            version_from_buildflags = v
            # no need to iterate further
            break

env.Replace(PROGNAME="firmware_%s" % str(version_from_buildflags))
1 Like

Thank you.
I’ll try that today.
But how do I call this script and where in platformio.ini file?
Currently I have this:

[env:Replace]
build_flags = -D VERSION=1.1
extra_scripts = pre:extra_script.py

I had somebody else’ script with that projenv name thingi…

So I changed to another script without that.
This example shows that I need to define the platform, board and framework etc to call this script?

[env:env_custom_prog_name]
platform = espressif8266
board = nodemcuv2
framework = arduino
build_flags = -D VERSION=13
extra_scripts = pre:extra_script.py

I am currently running the BTT SKR1.4 turbo board with tmc2209 drivers…

And with this setup, I still only get the firmware.bin file instead of the firmware version number…