Accessing toolchain tools with Advanced Scripting

Hello there!

I’ve got the following problem:
I am trying to generate a firmware.lss file using avr-objdump.
I am able to generate the .lss file by manually executing the following command on the commandline:
avr-objdump -h -S .pio\build\uno\firmware.elf > .pio\build\uno\firmware.lss
I execute the command from the root of my platformio project.
This works because I added ${userhome}/.platformio/packages/toolchain-atmelavr/bin to my Windows path variable.

Now I want to automate this step. So I looked at Advanced Scripting and I’ve come up with this simple script:

Import("env", "projenv")

env.AddPostAction(
	"$BUILD_DIR/${PROGNAME}.elf",
	env.VerboseAction("avr-objdump -h -S $BUILD_DIR/${PROGNAME}.elf > $BUILD_DIR/${PROGNAME}.lss", 
	"Creating $BUILD_DIR/${PROGNAME}.lss")
)

This script works like a charm. But now comes the part that I am stuck on.

As I am supposed to create a template for many users, I cannot take for granted that they’ve added the toolchain folder to their path. So I was looking for a way to access the toolchain folder automatically. I searched the documentation and found the variable $PLATFORMIO_PACKAGES_DIR here.
But I don’t know how to use that variable in my script. I would use it as follows:

Import("env", "projenv")

env.AddPostAction(
	"$BUILD_DIR/${PROGNAME}.elf",
	env.VerboseAction("$PACKAGES_DIR/toolchain-atmelavr/bin/avr-objdump -h -S $BUILD_DIR/${PROGNAME}.elf > $BUILD_DIR/${PROGNAME}.lss", 
	"Creating $BUILD_DIR/${PROGNAME}.lss")
)

Note that $PACKAGES_DIR is just a placeholder. The script above does not work.

TL;DR:
How do I access the Platformio package folder? (Or avr-objdump directly for that matter)

Thank you in advance :smiley:

See platform-atmelavr/main.py at develop · platformio/platform-atmelavr · GitHub

Just use $OBJCOPY instead of avr-objdump and PlatformIO will do the rest :slight_smile:

1 Like

Thank you for your fast reply!
Thanks to the link you’ve provided I was able to learn something new today.

First of all: $OBJCOPY would not work, because it references to avr-objcopy but I need avr-objdump.
But that doesn’t even matter, because PlatformIO does find the tools even though the user’s PATH variable doesn’t point to the directory. I noticed that because of the link you provided, so thank you very much for it :smiley:

So the final solution for my problem looks like the following:

Import("env", "projenv")

env.AddPostAction(
	"$BUILD_DIR/${PROGNAME}.elf",
	env.VerboseAction("avr-objdump -h -S $BUILD_DIR/${PROGNAME}.elf > $BUILD_DIR/${PROGNAME}.lss", 
	"Creating $BUILD_DIR/${PROGNAME}.lss")
)

This successfully creates my .lss file, even though I’ve removed the ${userhome}/.platformio/packages/toolchain-atmelavr/bin folder from my path variable :smiley:

Thank you very much for your help and thank you for providing such a great product :smiley:

2 Likes