Adding custom targets to board, not the project

I checked the docs on custom build targets, and I was wondering if there’s a way to attach a custom target on a board level (not on a project level) without having the board’s user add this target via extra_scripts etc?

For example, our lilka_v2 board has an option to run firmwares from an SD card.

Currently, the user has to do the following sequence:

  • run pio run
  • copy .pio/build/default/firmware.bin into a different folder and rename it to my_app.bin (not even sure where would Windows users have to search for this file)
  • copy my_app.bin to an SD card.

I’m wondering if there’s a way for the user to have a new target (out of the box) when they set board to lilka_v2. Then, they could run something like:

pio run -t buildimage -a my_app.bin
… and then have the firmware image appear in their project folder.

Additionally, if the target would show up in the PlatformIO IDE extension, that would be totally great for VS Code users, since they wouldn’t need to browse through build files to fetch the newly-built firmware image.

If adding code / references to a project is forbidden, you can only solve it on the platform level. There, you can easily realize a Post-Action for the firmware.bin to also be copied somewhere else. Users would need to remember to use your custom platform = .. in their platformio.ini though

This makes sense, though I’ll probably stick to official platform - forking and maintaining a custom platform just for having few additional convenience scripts would be an overkill in my case.

I wish there was something like “custom scripts” on a board level - this way setting board = ... would allow pio run to invoke the board-specific targets without any changes to platformio.ini.

Still, thanks for you input!