Make framework patching easier

Hello everyone,

Sometimes I need to patch the framework I’m working with (Arduino, Mbed, etc.). For example, I’m using it with my custom board which uses different external oscillator frequency. I thought it would be a good feature to enable file tree overlay for a framework.

I.e. add a new setting to platformio.ini build environment section, for example, framework_overlay_dir = patches.
This is the path to a subdirectory in the project tree. It can contain files and directories, replicating the structure of the used framework. Whenever a file from the framework is built (or a header file included), if similar file is found in patches subdirectory of the project, it will be used instead of the file shipped with the framework.

Pros: makes framework patching easier, the patches will survive framework version update.
Cons: can lead to errors if you forget about file substitution (it is readily detected by seeing additional setting in platformio.ini, though).

1 Like

For that, board_build.f_cpu = 168000000L in the platformio.ini should solve your problem (example).

What else did you need to tweak?

I had to patch system_clock.c file of Mbed framework (in target subdirectory for blue pill board) because it sets PLL multiplier to 9 which is fine for 8 MHz external crystal, but my customized board has 12 MHz external crystal.

board_build.f_cpu did not work for me because the frequency is the same (72 MHz), only PLL multiplier is different (72 = 9*8 = 12*6).

Ah right, in that case you’d need a framework modification. In mbed-os speak, that would even be a new target variant.

It should very difficult to do this from our perspective. Indeed, you can run your own Pre script and “patching” before building. See Redirecting...

You can even control build process per files … env.AddPostAction("$BUILD_DIR/src/main.cpp.o", callback...)

I thought about patching the framework files. There are currently two ideas in my mind:

  1. Freeze the version of framework. Then I can patch needed files once and for all.

or, 2. Keep patched files inside separate subdirectory of my project, then copy them to framework folder when building, using env.AddPreAction.

Is 1. possible with PlatformIO?

You mean as in specifying a specific framework version in your platformio.ini? You can specifiy a specific platform version… does that do what you want?

No, I’d like to freeze framework version specifically. Or load framework from local folder instead of Internet. Platform version does not prohibit framework version updates, and if framework is updated, all my local patches would be gone.

I think it’s okay if it’s not possible, I’ll have to copy patched files over original ones before each build then.

Or I can simply set the filesystem permissions so that framework is read only. Then it won’t be updated ever.

1 Like

Framework depends to dev/platform and it is declared in platform.json.

In any case, will this help?

Yeah, I think it would help (override framework package with local folder or git repo).

I think it would be useful if framework script and package can be specified in platformio.ini.

It’s possible now in Platformio 4.0, isn’t it?

1 Like

As @azarubkin suggested, it’s already possible as of PIO v4 to do platforms… i.e. you can specify a git repo like github as the platform source… I think a URL can be specified also for frameworks… but if not, the new platform_packages override will do the job, especially if you just want to tweak a framework package for a standard platform…

Here is good example Redirecting...

1 Like