feat(cli): Add support to NVRAM - #519
Draft
brunomenezes wants to merge 21 commits into
Draft
brunomenezes wants to merge 21 commits into
brunomenezes wants to merge 21 commits into
Conversation
…-emulator dependency lua-lpeg
🦋 Changeset detectedLatest commit: 2d4fe71 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Coverage Report
📁 File Coverage (20 files)
|
brunomenezes
force-pushed
the
feat/cli-add-nvram-support
branch
from
August 18, 2026 18:29
391697a to
9a7432d
Compare
tuler
force-pushed
the
refactor/sdk-update-anvil-state-source
branch
from
September 2, 2026 20:57
edd91c9 to
0a66b6f
Compare
brunomenezes
force-pushed
the
feat/cli-add-nvram-support
branch
from
October 3, 2026 09:18
9a7432d to
2d4fe71
Compare
Base automatically changed from
refactor/sdk-update-anvil-state-source
to
prerelease/v2-alpha
October 3, 2026 12:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds NVRAM support to the CLI. Stacked on
refactor/sdk-update-anvil-state-source, which supplies emulator 0.21.0 and rollups-node 2.0.0-alpha.13.An NVRAM is a raw range of bytes exposed to the guest as a
/dev/uio*device. Unlike a flash drive it has no filesystem, no mount point and no page cache between the guest and the memory range, so writes are visible to the emulator immediately, with no flush before snapshotting.New
cartesi.tomlsection[nvrams]is optional — a config without it behaves exactly as before, emits no new flags and runs no new build steps.Each table needs
sizeorfilename(both is allowed, and they must agree exactly). Sizes must be a multiple of 4Ki, at most 8 nvrams, and labels cannot collide with drive labels — all validated at parse time.size = "4Ki"--nvram=label:input,length:4096size,shared,user--nvram=label:output,length:4096,data_filename:output.raw,user:dapp,sharedfilename = "./seed.raw"--nvram=label:seed,data_filename:seed.rawOnly nvrams needing a backing image get a build step:
sharedis allocated zero-filled in.cartesi/,filenameis copied there (the source is never written). A pristine nvram produces no artifact.Documented in
apps/cli/tests/unit/config/fixtures/full.toml.Behaviour change: cartesi-machine 0.21.0 required
--nvramdoes not exist before 0.21.0, sorequiredVersionmoves from^0.20.0to^0.21.0.That constant was previously declarative only — nothing read it at runtime. It is now enforced:
buildandshellcheck before booting, anddoctorreports it alongside the Docker checks. Without this, a user on 0.20.0 got a rawunrecognized option --nvram=...lua traceback instead of:The check does not block when the version cannot be determined at all, since that also happens with Docker down or the binary missing.
Note
user = "dapp"is a Unix permission on the device node, not a read-only range —--user=rootwrites a root-owned nvram fine. The emulator's realread_onlymemory-range flag is not exposed here.Also included
fix(cli)— the version check ignored itsforceDockeroption, reading the host binary instead of the SDK image.test(cli)—CARTESI_TEST_SDKoverrides the image the integration suite runs against.test(cli)—cartesi-machine-stored-hashno longer prefixes the output with0x, which 0.21.0 already includes.refactor(cli)— argument assembly split out ofbootMachineinto a purebuildMachineArgs, so the flags can be unit tested without spawning a machine.Testing
tests/unit/config.test.ts[nvrams]parsing, IEC sizes, validation errorstests/unit/machine.test.ts--nvram=strings and their ordertests/unit/exec/cartesi-machine.test.tstests/integration/builder/nvram.test.tstests/integration/machine/nvram.test.tsThe boot test builds a throwaway app declaring a pristine
inputand a sharedoutput, then asserts: only the nvrams needing an image get one; one/dev/uio*per nvram; labels resolve incartesi.tomlorder; andwritemmap/readmmapround-trips and reaches the host'soutput.raw— the assertion that provessharedworks.It is gated on the emulator supporting
--nvram, not onCARTESI_TEST_SDK, so it skips cleanly on an older image and starts running by itself onceDEFAULT_SDK_VERSIONis bumped.Against an SDK image with emulator 0.21.0: 202 pass, 1 skip, 0 fail.
bun run build --filter @cartesi/cli CARTESI_TEST_SDK=cartesi/sdk:devel bun test apps/cli/Merge blocker
DEFAULT_SDK_VERSIONis still0.12.0-alpha.41, whose published image ships emulator 0.20.0. Until an SDK release carrying 0.21.0 exists and the default is bumped to it, anyone on the default image hits the new version error. Do not merge before that bump.The tip commit,
wip(cli): Point CI integration tests at the PR's SDK image., touches one file and must be dropped before merge.It adds three things to
.github/workflows/cli.yaml:packages/sdk/**in thepathsfilter,CARTESI_TEST_SDK: ghcr.io/cartesi/sdk:pr-${{ github.event.number }}, and a ghcr.io login step so that image can be pulled. This makes CI run the integration suite against an emulator that supports--nvram, which the releasedcartesi/sdkdoes not yet.Known fragility: that image is built by
sdk.yaml, a separate workflow with no ordering againstcli.yaml. A first run can fail on a missing image and pass on re-run.wip(cli): Point CI integration tests at the PR's SDK image.DEFAULT_SDK_VERSIONto the SDK release shipping emulator 0.21.0