Pass source path to bootloader

Hello...

I have some special bootloader in nano every. As uploader (python script, not avrdude) does some data crunching one of them is program CRC calculation I wish to output that modified hex into arduino project folder. But didn't manage how to find path to sources.

I'm pretty sure that I need to modify one line in platform.txt
I already done some mod to execute my uploader and now looks like this:


tools.caa_boot.upload.pattern="/home/eslavko/Mega4809/do_upload" "{build.path}/{build.project_name}.hex" "{serial.port}"

That start my do_upload script with two parameters, the 1st one is hex file and the other is serial port name. Here I want the third parameter with path to source files.
I did try to append "{sketch_path}" but got "{sketch_path}" as result.

I moved your topic to an appropriate forum category @eslavko.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Hi @eslavko

Are you using Arduino IDE 2.x? There is currently a bug that causes the sketch_path platform property to be unavailable when using Arduino IDE:

That bug has already been fixed in Arduino CLI, but the fix was made after the last release of Arduino IDE 2.x, so the bug is still present in Arduino IDE 2.x. The Arduino IDE developer Akos Kitta is currently in the process of pulling that fix into Arduino IDE 2.x:

There is a beta tester build of that version of Arduino IDE 2.x in case you would like to give it a try. Instructions for getting the beta tester build are available here:

https://github.com/arduino/arduino-ide/blob/main/docs/contributor-guide/beta-testing.md#testing-pull-requests

Please let me know if you have any questions or problems while following them.


There is an alternative build.source.path property:

https://arduino.github.io/arduino-cli/dev/platform-specification/#recipes-to-export-compiled-binary:~:text=OPTION_ID[%2CMENU2_ID%3DOPTION_ID%20...]]-,{build.source.path},-%3A%20Path%20to%20the

Keep in mind this caveat though:

Path to the sketch being compiled. If the sketch is in an unsaved state, it will be the path of its temporary folder.

Using Arduino 1.8.13 on linux.
and even {build.source.path} doesn't work

I see the problem. If you check the documentation for the sketch_path platform property:

https://arduino.github.io/arduino-cli/latest/platform-specification/#recipes-to-export-compiled-binary

The recipe.hooks.savehex.presavehex.NUMBER.pattern and recipe.hooks.savehex.postsavehex.NUMBER.pattern hooks (but not recipe.output.tmp_file and recipe.output.save_file) can be built concatenating the following automatically generated properties:

  • {sketch_path}: the absolute path of the sketch folder

But you are attempting to use the property in the tools.TOOL_NAME.upload.pattern command pattern property, where it is not available.

And it's probably very rare needed in tools. So I need to find some workaround.

I don't have a good understanding of your use case, but I can try to make a suggestion based on my flawed understanding.

You should consider whether you can accomplish what appear to be two distinct requirements separately:

  • The hex file must be saved in the sketch folder
  • The path to the hex file must be available for use in the upload command

Since the sketch path is not available in the upload command, it seems that these two things are contradictory. However, it is not actually so because you can generate multiple copies of the file. So if you can use one of the commands that are invoked during the compilation process to generate the hex files in the locations where they are accessible to the user and to the upload command pattern (e.g., in build.path).

You will find the "build hooks" feature useful for that purpose:

There are a couple of possible approaches:

Use the "savehex" command

You can use a recipe.hooks.savehex.presavehex.NUMBER.pattern or recipe.hooks.savehex.postsavehex.NUMBER.pattern build hook to put the hex file into the sketch folder (using the sketch_path property).

With this approach, the user would need to do a Sketch > Export Compiled Binary in order to get the hex file in the sketch folder.

Use the build.source.path property

This property is available for use in build hooks other than the "savehex" ones, meaning you can generate the hex file in this location during the normal compilation process.

The behavior that the file will be written to the temporary folder where the sketch is staged in the case where the sketch is in an unsaved state is potentially problematic. It is more common for Arduino IDE 2.x users to always have their sketch in a saved state because the Arduino IDE 2.x auto save feature (which is enabled by default) saves the sketch after every change (rather than only on compilation or upload as is the behavior of the equivalent feature in Arduino IDE 1.x).

ptillisch thanks for that info.

As I'm not able to pass *.ino path to my uploader I do some workaround that's works for me.

From information I have available there is project name. So I implemented in uploader script a search to get complete path to "/ProjectName/ProjectName.ino" as this is same even in temp path available.

and I solved all my trouble in that way. As search is pretty slow I create a little json config in uploader to keep already known path, so only 1st time the search is slow.

You are welcome. I'm glad you were able to find a solution. Thanks for taking the time to post an update!

If you ever publish your custom Arduino boards platform online, please let us know. I make an effort to be aware of all the wonderful platforms this community has created so I'm always interested to learn of new ones.

Regards,
Per

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.