Commit fb700f7
zephyr-cp: freeze .mpy modules named in circuitpython.toml
The port had no frozen-module support: its Python-driven build never runs
make, and the freeze pipeline lives in py/circuitpy_mpconfig.mk. Reimplement
the pipeline in cptools/build_circuitpython.py behind a per-board opt-in,
FROZEN_MPY_DIRS = ["frozen/<lib>", ...] in circuitpython.toml (paths relative
to the repository root, as $(TOP)/... is in mpconfigboard.mk):
- tools/preprocess_frozen_modules.py stages the trees into
<build>/frozen_mpy (repo directory dropped, __version__ filled in, examples
and tests left out), before the qstr pass;
- MICROPY_QSTR_EXTRA_POOL / MICROPY_MODULE_FROZEN_MPY are added to the flags
for the qstr pass as well as the compile -- Q(.frozen) and the sys.path
entry that uses it are behind MICROPY_MODULE_FROZEN;
- after genhdr/qstrdefs.generated.h and root_pointers.h exist, mpy-cross
compiles each module (-s with the module path, so mpy-tool derives the
frozen name from it) and tools/mpy-tool.py -f -q emits frozen_content.c,
fed the same collected qstr list that produced the generated header so the
frozen pool numbers from MP_QSTRnumber_of correctly. tools/makemanifest.py
is bypassed: it insists on genhdr/qstrdefs.preprocessed.h, which this
builder never produces. Only MPY freezing: MICROPY_MODULE_FROZEN_STR would
reference the mp_frozen_str_* tables makemanifest emits.
- frozen_content.c is compiled with the no-qstr sources (it defines its own
MP_QSTR_* enum values and must never go through extraction).
pre_zephyr_build_prep.py builds mpy-cross first when a board freezes modules
(honouring MICROPY_MPYCROSS), and tools/ci_fetch_deps.py learns the toml key
so CI initialises the right frozen/ submodules (it had a TODO for this).
The Pico W opts in with adafruit_ble: it has ~42 KB of heap and a BLE node
cannot otherwise load the library. Measured on a Pico 2 W (same core, same
flags): importing adafruit_ble plus its advertising.standard and
services.nordic modules costs 10,384 B of heap frozen vs 21,792 B from .mpy
files on CIRCUITPY (gc.mem_alloc() delta after gc.collect(); gc.mem_free()
is not usable here, the split heap grows on demand), 0.055 s vs 0.132 s.
Freezing the 20 modules adds 28,336 B of flash and no static RAM on the
Pico W (1,208,636 -> 1,236,972 B with the rest of this series). The Pico 2 W
is not opted in: it has the heap, and a frozen copy would pin the library
version for everyone.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent 8ea8f3f commit fb700f7
4 files changed
Lines changed: 120 additions & 2 deletions
File tree
- ports/zephyr-cp
- boards/raspberrypi/rpi_pico_w_zephyr
- cptools
- tools
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
6 | 9 | | |
7 | 10 | | |
| |||
356 | 359 | | |
357 | 360 | | |
358 | 361 | | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
359 | 433 | | |
360 | 434 | | |
361 | 435 | | |
| |||
404 | 478 | | |
405 | 479 | | |
406 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
407 | 497 | | |
408 | 498 | | |
409 | 499 | | |
| |||
736 | 826 | | |
737 | 827 | | |
738 | 828 | | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
739 | 837 | | |
740 | 838 | | |
741 | 839 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
23 | 32 | | |
24 | 33 | | |
25 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
254 | 255 | | |
255 | 256 | | |
256 | 257 | | |
257 | | - | |
258 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
259 | 265 | | |
260 | 266 | | |
261 | 267 | | |
| |||
0 commit comments