Skip to content

Phase 3: Mono runtime glue, Kconfig and SDRAM placement - #696

Merged
NevynUK merged 7 commits into
MergeManagedCodefrom
Phase3
Oct 14, 2026
Merged

NevynUK merged 7 commits into
MergeManagedCodefrom
Phase3

Conversation

@NevynUK

@NevynUK NevynUK commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Phase 3 of the managed runtime work: the Mono glue, its Kconfig and build wiring, and placement of the runtime in the SDRAM image.

Changes

  • apps/system/mono (new, CONFIG_SYSTEM_MONO). This is the glue ported from Legacy meadow-3.0:
    • the monovm host (mono_main.c)
    • the P/Invoke tables, with an added mbedtls library and cell stubs
    • the TLS shim against mbedTLS 3.6.2, with psa_crypto_init and threading enabled
    • the support functions a protected NuttX 12 build lacks: I-cache maintenance through up_coherent_dcache, an atomic __sync_val_compare_and_swap_8 (NuttX's weak version masks interrupts, which does nothing in unprivileged mode), readlink, mprotect and posix_madvise.
  • Placement: the runtime archives, libSystem.Native.a and the TLS shim go in the SDRAM runtime image; mbedTLS and SQLite stay in user flash. SDRAM image: 1568 of 3072 KiB. User flash: about 835 of 1024 KiB.
  • hcom starts meadow_mono_main again. The required files are now System.Private.CoreLib.dll and Meadow.dll.
  • build.sh runs build-mono.sh when CONFIG_SYSTEM_MONO=y. The defconfig enables SYSTEM_MONO, LIBC_LOCALE, FS_RAMMAP and mbedTLS threading.
  • Syscalls: meadow_client_cert_retrieve_credentials and meadow_client_cert_release_credentials.
  • elf_globals: entries are now weak and the table is in .rodata. The test-only symbols no longer break the link, and the move saves 62 KB of user SRAM.
  • Bug fix: the packed Mono version test misread build numbers above 255, so the board reported "Mono version: (null)" and disabled Mono.
  • CI: fetches the pinned runtime into runtime-src/; the Docker image installs CMake and Ninja.
  • Version: bumped to 1.99.1.

Runtime

MONO_RUNTIME_COMMIT now pins runtime MergeManagedCode 520e78f6c99 (WildernessLabs/runtime#3). That PR drops the sdram_cache_track_fd hook, calls nxsock_close_notify in SystemNative_Close, and avoids _Thread_local in minipal_get_current_thread_id. CI run 38608329148 passes against the pinned runtime. The earlier failed run built against the previous pin.

Testing (CCM, built with the runtime Phase3 changes)

  • OS flashed and verified over SWD; runtime written with meadow firmware write runtime.
  • meadow device info: OS 1.99.1.0, Runtime 1.99.1.0.
  • Boot log: "Mono version: 1.99.1.0" and user heap 30507004 total. Mono stays disabled. Starting it is phase 4.

🤖 Generated with Claude Code

NevynUK and others added 6 commits October 14, 2026 17:26
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The configuration manager treated a runtime version as packed when any of
bits 8-23 of the build field were set, so a build number above 255 (for
example 1.99.0.19735) was misdecoded, the board reported "Mono version:
(null)" and hcom disabled Mono.  Test only the top byte instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Configuration-dependent test symbols (hello_world_results,
meadow_kt_dispatcher, tensorflow_tests_hello_world) broke the user-space
link when the tests were not built.  Make each entry .weak, and move the
table from .data to .rodata, which saves 62 KB of user SRAM; the loader only
searches it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Mono TLS shim runs in user space and needs
meadow_client_cert_retrieve_credentials and
meadow_client_cert_release_credentials, which are implemented in the kernel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Phase 3 of the managed runtime plan.  apps/system/mono holds the glue ported
from Legacy meadow-3.0: the monovm host (mono_main.c), the P/Invoke tables,
the mbedTLS 3.6.2 TLS shim and root CA table, and support functions the
runtime needs in a protected NuttX 12 build (I-cache maintenance through
up_coherent_dcache, an atomic 64-bit compare-and-swap, readlink, mprotect).

The runtime archives, libSystem.Native.a and the TLS shim are placed in the
SDRAM runtime image; mbedTLS and SQLite stay in user flash.  hcom starts
meadow_mono_main again.  build.sh runs build-mono.sh when CONFIG_SYSTEM_MONO
is set.  The defconfig enables SYSTEM_MONO, LIBC_LOCALE, FS_RAMMAP (file
mmap for assemblies) and mbedTLS threading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fetch the runtime commit recorded in MONO_RUNTIME_COMMIT into runtime-src/,
pass it to the build container as MEADOW_RUNTIME_DIR, and install CMake and
Ninja in the build image for the runtime build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WildernessLabs/runtime#3 adds the NuttX 12 fixes the phase 3 glue needs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NevynUK
NevynUK marked this pull request as ready for review October 14, 2026 17:42
@NevynUK
NevynUK merged commit 8ebcc0b into MergeManagedCode Oct 14, 2026
2 checks passed
@NevynUK
NevynUK deleted the Phase3 branch October 14, 2026 17:44
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