Add separate executable build target


I come from a world of Cmake and wanted to give PlatformIO a try, so please bare with me. I want to port over my current build setup and am pretty much stuck as neither SCons nor the PlatformIO magic is familiar to me.

My Cmake build currently does something like this:

  • Build bootloader binary from source using bootloader linker-file
  • Generate a source file which embeds the bootloader binary into a dedicated memory region and add it to the application target sources
  • Build application binary from source using application linker-file

This setup should be as reusable as possible, so I was hoping to somehow get it working as a library. I figured out how to build the application using my own linker file, but I’m stuck at adding a custom build target for the bootloader executable. I’m pretty sure the advanced scripting feature can be used for that, but I don’t know how.

How would you setup a build like this?

I figured something out, I hope this makes sense :sweat_smile:

I created a project for the application which depends on a library with library.json:

    "name": "bootloader",
    "build": {
        "extraScript": ""

The extraScript changes the linker script for the application:

global_env = DefaultEnvironment()

I don’t know if changing the “DefaultEnvironment” has other consequences, but this seems to work.

Now for building the actual bootloader I tried:

bootloader_elf = env.Program(join("$BUILD_DIR", "bootloader.elf"), Glob("src/*.c"))
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", bootloader_elf)

Now the bootloader starts building but the linker script (bootloader.ld) is not applied.

I don’t know why LDSCRIPT_PATH is not working here, but this fixed it:


Last missing part is to somehow embed the bootloader binary into the application.