Zephyr support for code relocation

I’m trying to build a zephyr project for teensy / IMXRT1060 and am setting CONFIG_FLASH=y for some ota dfu functionality and I’m getting an error:

*** [.pio/build/evkb/code_relocation_source_lib/zephyr/code_relocation.c.o] Source `.pio/build/evkb/zephyr/code_relocation.c' not found, needed by target `.pio/build/evkb/code_relocation_source_lib/zephyr/code_relocation.c.o'

So, I did some digging. When CONFIG_FLASH is enabled then CONFIG_CODE_DATA_RELOCATION gets enabled automatically. Once CONFIG_CODE_DATA_RELOCATION is enabled it seems like CMakeLists.txt knows to generate the code relocation source files, library, and linker scripts (target_relocation.cmake is included from root CMakeLists.txt). However the platformio toolchain is not aware of that project setting and doesn’t generate the required files.

I dug even more into framework-zephyr/scripts/platformio/platformio-build.py and noticed that the build script manually generates many of the dependencies like offsets header, isr table, and many others. It seems to me like the code relocation generation is in the same category of things but it exists in CMakeLists but not in platformio-build.py.

This is where it got a bit too deep for me and I wasn’t able to figure out how to add the right call to scripts/gen_relocate_app.py into platformio-build.py.

Can anyone more experienced with zephyr + pio integration help with this?

Thanks!!

Can you upload the minimal project in which this error occurs and post it in Issues · platformio/platform-teensy · GitHub? Seems like a clear-cut bug.

Thanks max. This happens on mxmt1060 eval board too, I think it’s a framework-zephyr bug more than a platform-teensy one. Should I create the issue on the zephyr repo instead?

The Zephyr repos don’t have the PlatformIO scripts in them (no platformio here), the PlatformIO team puts them into the packages after grabbing the Zephyr release. These is no repo for the PlatformIO-version / additions of Zephyr. So the closest thing is indeed the platform repository (platform = teensy in your case).

I needed this feature to get mcuboot working on zephyr and ended up implementing it myself: Changes for code relocation tooling · shlomozippel/zephyr@5f7cafe · GitHub