Skip to content

builder(zephyr): register XIAO modules via ZEPHYR_EXTRA_MODULES, drop platformio-build.py patch - #97

Open
cumin777 wants to merge 1 commit into
Seeed-Studio:mainfrom
cumin777:refactor/retire-a6-module-patch
Open

cumin777 wants to merge 1 commit into
Seeed-Studio:mainfrom
cumin777:refactor/retire-a6-module-patch

Conversation

@cumin777

Copy link
Copy Markdown
Contributor

Summary

Retire the _patch_platformio_extra_modules monkey-patch (inventory item A6) and replace it with Zephyr's own out-of-tree module mechanism.

Why: the patch edited the framework package's scripts/platformio/platformio-build.py (needle-based) to append platform-provisioned modules to ZEPHYR_MODULES. It was not reliably idempotent — a stale floating-URL platform install re-inserted its block on every build (14 duplicate copies found on a real machine), and marker drift on a framework package update would silently drop the module, surfacing as "1200-bps DFU touch stopped working".

What:

  • New _register_xiao_modules_via_env(): collects _pio/modules cache modules (xiao_dfu_reset, sdk-edge-ai, edge-impulse-sdk-zephyr) plus XIAO_EDGE_AI_DIR / XIAO_EDGE_IMPULSE_DIR developer overrides, and registers them via the ZEPHYR_EXTRA_MODULES env var — which Zephyr's CMake reads through zephyr_get()'s ENV scope (cmake/modules/extensions.cmake). Called after all provisioning.
  • The stm32c5 path already used this env mechanism; the 20B path now matches it.
  • Dead PIO_NCS_MODULES SCons variable removed.
  • Net −44 lines; no more mutation of platformio-build.py for module discovery.

Existing installs keep previously injected blocks in their cached platformio-build.py — harmless (dedup-guarded), simply no longer maintained.

Validation (local platform tree, framework-zephyr 4.4.0)

Sample Result
20B zephyr-blink CONFIG_XIAO_DFU_RESET=y; xiao_dfu_reset symbols in firmware.elf incl. __init_xiao_dfu_init
20B edgeai-classification CONFIG_NRF_EDGEAI=y; 118 Axon/EdgeAI symbols in firmware.elf — sdk-edge-ai registered through the env var only
seeed-xiao-stm32c5 zephyr-blink cannectivity / uf2_dfu_reset / xiao_dfu_reset all present in build.ninja via the env mechanisms
regression installed platformio-build.py stayed unpatched across all three builds

nRF54L15 has no example set and uses no XIAO modules (its Kconfig gates on the 20B board symbol), so it is unaffected by construction.

🤖 Generated with Claude Code

@cumin777
cumin777 force-pushed the refactor/retire-a6-module-patch branch from 1686607 to 21a84d3 Compare September 20, 2026 09:10
@cumin777

Copy link
Copy Markdown
Contributor Author

This PR has been verified. It is recommended to wait for the version management to be implemented before merging.

… platformio-build.py patch

_patch_platformio_extra_modules monkey-patched the framework package's
scripts/platformio/platformio-build.py to append platform-provisioned
modules (_pio/modules) to the ZEPHYR_MODULES CMake variable. The patch
was needle-based and not reliably idempotent: a stale floating-URL
platform install re-inserted its block on every build (14 duplicate
copies found on a real machine), and marker drift on a framework
package update would silently drop the module instead -- showing up as
'1200-bps DFU touch stopped working'.

Replace it with Zephyr's own out-of-tree module mechanism: set the
ZEPHYR_EXTRA_MODULES environment variable, which Zephyr's CMake reads
through zephyr_get()'s ENV scope (cmake/modules/extensions.cmake).
_register_xiao_modules_via_env() collects the framework-cache modules
(xiao_dfu_reset, sdk-edge-ai, edge-impulse-sdk-zephyr) plus the
XIAO_EDGE_AI_DIR / XIAO_EDGE_IMPULSE_DIR developer overrides and
registers them after all provisioning. The dead PIO_NCS_MODULES SCons
variable is removed with it.

Existing installs keep previously injected blocks in their cached
platformio-build.py; those are harmless (dedup-guarded) and simply no
longer maintained.

Known limitation (accepted): ZEPHYR_EXTRA_MODULES is transient. Zephyr's
MERGE-mode zephyr_get() never writes the ENV value into CMakeCache.txt,
so a cmake/ninja reconfigure started outside a PlatformIO-driven process
(fresh shell, IDE CMake integration) silently drops these modules, where
the retired -DZEPHYR_MODULES= injection persisted in the cache. Builds
driven by 'pio run' always inherit the variable and are unaffected;
after editing CMake files, re-run 'pio run'. Documented in
_register_xiao_modules_via_env()'s docstring.

Also add docs/zephyr-patch-inventory.md (was untracked): A6 marked
retired with no upstream destination, zephyr.py line references
re-anchored after the deletion, totals adjusted (A 6->5, total 17->16,
upstreamable ~11->~10).

Validation (local platform tree, framework-zephyr 4.4.0):
- 20B zephyr-blink: CONFIG_XIAO_DFU_RESET=y, xiao_dfu_reset symbols in
  firmware.elf (incl. __init_xiao_dfu_init)
- 20B edgeai-classification: CONFIG_NRF_EDGEAI=y, Axon/EdgeAI symbols
  in firmware.elf -- sdk-edge-ai registered through the env var only
- stm32c5 zephyr-blink: cannectivity/uf2_dfu_reset/xiao_dfu_reset all
  present in build.ninja via the env mechanisms
- installed platformio-build.py stayed unpatched across all builds

Co-Authored-By: Claude <noreply@anthropic.com>
@cumin777
cumin777 force-pushed the refactor/retire-a6-module-patch branch from 21a84d3 to 5f11a38 Compare September 21, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant