Skip to main content

nros_platform/board/
runtime.rs

1//! [`RuntimeCtx`].
2//!
3//! Per-invocation runtime context handed to `BoardEntry::run`'s
4//! `setup` callback. Carries the overlay knobs the codegen
5//! `run_plan(runtime)` body reads:
6//!
7//! - **params** — `(key, value)` pairs from launch XML
8//!   `<param name="…" value="…"/>`, projected here by `nros sync` at BUILD
9//!   time. NOT from `--ros-args -p k:=v`: a generated entry reads no argv,
10//!   and the hosted `nros::init_with_args` parse refuses `-p` rather than
11//!   pretending to honour it (a parameter changes at run time through the
12//!   ROS 2 parameter services).
13//! - **remaps** — `(from, to)` topic/service renames, from launch
14//!   `<remap from= to=/>` by the same build-time projection.
15//! - **env** — environment-style key/value pairs (POSIX `getenv`
16//!   shape) accessible from no_std boards via this struct rather
17//!   than a `libc::getenv` call.
18//! - **runtime** — `&mut dyn NodeDispatchRuntime` sink the
19//!   codegen-emitted `run_plan(runtime)` body forwards each Node
20//!   pkg's `register(runtime)` call into.
21//!   Populated by each `BoardEntry::run` impl after opening its
22//!   executor; defaults to a no-op sink when constructed via
23//!   [`RuntimeCtx::with_runtime`].
24//!
25//! ## no_std-safe shape
26//!
27//! Slice-of-tuples kept on the boot stack. No allocation, no
28//! `core::collections`. Codegen owns the storage and passes a
29//! `&mut RuntimeCtx<'_>` whose backing slices live in `static`s.
30//!
31//! Hosted boards (POSIX) may instead build a longer-lived owned
32//! variant on the heap; the trait surface is slice-based so
33//! both shapes work.
34
35use super::dispatch::DispatchStrategy;
36
37/// Layer-clean substitute for `nros::node_metadata::CallbackId` +
38/// `nros::node::CallbackCtx` at the [`NodeDispatchRuntime`] boundary.
39/// `nros-platform` sits below `nros` in the dep
40/// graph, so the trait surface cannot reference those types
41/// directly. The `nros`-side runtime impl wraps a real
42/// `(CallbackId, &mut CallbackCtx)` pair into this opaque shape
43/// before invoking [`NodeDispatchRuntime::signal_callback`]; the
44/// concrete dispatcher casts `ctx_ptr` back to
45/// `&mut nros::CallbackCtx<'_>` at the call site.
46///
47/// `#[repr(C)]` keeps the layout stable across the (same-language
48/// today, FFI-shaped tomorrow) `nros-platform` ↔ `nros` boundary.
49#[repr(C)]
50pub struct SignaledCallback<'a> {
51    /// Stable identifier string carried by `nros::CallbackId(&'a str)`.
52    pub cb_id: &'a str,
53
54    /// Erased pointer to the `nros::CallbackCtx<'_>` the dispatcher
55    /// will drive. The `nros`-side `NodeDispatchRuntime` impl casts
56    /// back to `&mut nros::CallbackCtx<'_>` before invoking the
57    /// component body.
58    pub ctx_ptr: *mut core::ffi::c_void,
59}
60
61// Phase 258 (Track 2, w5) — the opaque per-Node `extern "Rust" fn()` aliases
62// (~~`NodeRegisterFn`~~ / ~~`NodeInitFn`~~ / ~~`NodeDispatchFn`~~ / ~~`NodeTickFn`~~) are gone.
63// They anchored the retired ~~`register_dispatch_slot_dyn`~~ four-fn-ptr bridge
64// (owned-spin declarative register), which the install seam replaced — Rust
65// owned-spin now registers via `RuntimeCtx::runtime.executor_handle()` +
66// `nros::__macro::install_node_typed` like the C/C++ typed entries.
67
68/// Node runtime sink the codegen-emitted `run_plan(runtime)`
69/// body talks to.
70///
71/// Object-safe + `no_std`. The concrete impl
72/// (`ExecutorNodeRuntime` in `nros`) owns the live executor;
73/// `BoardEntry::run` installs it on the per-boot
74/// [`RuntimeCtx::runtime`] slot before invoking the user `setup`
75/// closure.
76///
77/// Renamed from `NodeRuntime` to disambiguate from
78/// the user-facing `nros::NodeRuntime` metadata-sink trait in
79/// `packages/api/nros/src/node.rs:112`. The two traits live at
80/// different layers (board-side dispatch sink vs user-side metadata
81/// declaration sink) and the previous shared name forced explicit
82/// `nros_platform::` / `nros::` qualification at every use site +
83/// produced confusing `impl NodeRuntime for X` ambiguity. The
84/// `NodeRuntime` deprecation alias has been removed; use
85/// `NodeDispatchRuntime` directly.
86pub trait NodeDispatchRuntime {
87    /// Drive the underlying executor for at most `timeout_ms`
88    /// milliseconds. `Ok(())` on a clean spin (including timeout);
89    /// `Err(())` if the executor surfaces a spin error.
90    ///
91    /// `Result<_, ()>` is deliberate: the board entry-point callers
92    /// (`nros-board-{freertos,nuttx,threadx}` spin loops) only
93    /// `{:?}`-print the error and `B::exit_failure()` — a typed enum
94    /// would carry no extra info across the trait boundary, since the
95    /// underlying `ExecutorError` from `nros::node_runtime` is mapped
96    /// to `()` at the impl site (`impl NodeDispatchRuntime for
97    /// ExecutorNodeRuntime`). `#[allow]` keeps the surface narrow.
98    #[allow(clippy::result_unit_err)]
99    fn spin_once(&mut self, timeout_ms: u32) -> Result<(), ()>;
100
101    /// phase-521 W6 (RFC-0113 D2) — the budget an entry loop passes to
102    /// [`spin_once`](Self::spin_once). The executor-backed runtime answers
103    /// with how long its park can safely run (until its next deadline when
104    /// every source of work can end it, else a 10 ms slice). The default is
105    /// that slice, for a runtime that cannot say.
106    fn entry_spin_budget_ms(&self) -> u32 {
107        10
108    }
109
110    /// Start the runtime's timing now, as if its executor had just opened, so
111    /// a wait between registration and the first spin (the boot-time
112    /// wall-clock resolution) is owed to no timer. The executor-backed runtime
113    /// forwards to `Executor::restart_timing`; the default is a no-op, for a
114    /// runtime with no timers of its own.
115    fn restart_timing(&mut self) {}
116
117    /// RFC-0128 D2 (phase-554 W2) — make one MANAGED node of this image a
118    /// lifecycle node: register the five REP-2002 services under the node's
119    /// own name (`namespace` + `name`, the node `nros::main!` created for that
120    /// launch entry) and drive its boot `autostart` (0 none, 1 configure,
121    /// 2 configure + activate). `nros::main!` calls this (via
122    /// [`RuntimeCtx::apply_lifecycle_node`]) once per node the resolved model
123    /// marks managed, right after that node's `register` call. No machine is
124    /// ever registered on the executor's own identity.
125    ///
126    /// Default no-op (non-executor runtimes, or `nros` built without
127    /// `lifecycle-services`); the `ExecutorNodeRuntime` impl in `nros` does
128    /// the real work behind that feature. issue 0460 — the `Err` carries a
129    /// STATIC REASON, not `()`: a capability that fails to register is
130    /// reported by the caller as `RuntimeError::Capability`, and without the
131    /// reason that said which capability and nothing about why. `&'static str`
132    /// rather than a typed error because this trait lives below `nros-node`
133    /// and cannot name `NodeError`.
134    fn apply_lifecycle_node(
135        &mut self,
136        namespace: &'static str,
137        name: &'static str,
138        autostart: u8,
139    ) -> Result<(), &'static str> {
140        let _ = (namespace, name, autostart);
141        Ok(())
142    }
143
144    /// RFC-0128 D2 (phase-554 W2) — the self-bringup form of
145    /// [`apply_lifecycle_node`](Self::apply_lifecycle_node). A single-package
146    /// self-bringup has no launch file to mark a node managed, so the managed
147    /// nodes are those whose own code registered a lifecycle machine (RFC-0128
148    /// D2, ruled 2026-11-13: the code decides, as in ROS 2); each is driven to
149    /// `autostart`. A plain node is left alone. Default no-op, as above.
150    fn apply_lifecycle_self_bringup(&mut self, autostart: u8) -> Result<(), &'static str> {
151        let _ = autostart;
152        Ok(())
153    }
154
155    /// Phase 264 W4b -- register the 6 ROS 2 parameter services on the underlying
156    /// executor and create its volatile RAM param store. Launch `<param>`
157    /// initials are NOT passed here (issue 1272): each node's are seeded on that
158    /// node as it is built, from the `params` slice `nros::main!` sets before
159    /// the node's `register` call. After this,
160    /// `ros2 param list/get/set` works against the running node; reconfigured values
161    /// live in RAM until the next boot (RFC-0004 §10; persistence is out of scope,
162    /// issue 0080). Default no-op (non-executor runtimes, or `nros` built without
163    /// `param-services`); the `ExecutorNodeRuntime` impl in `nros` does the real work
164    /// behind that feature. `nros::main!` calls this (via
165    /// [`RuntimeCtx::apply_param_services`]) when `system.toml` declares
166    /// `[param_services]`, mirroring the bake's `generate.rs::render_param_persistence_fn`.
167    /// issue 0460 — the `Err` carries a STATIC REASON, not `()`.
168    ///
169    /// A capability that fails to register is reported by the caller as
170    /// `RuntimeError::NodeRegister("lifecycle")`, which names WHICH capability
171    /// and nothing about WHY. On Zephyr that opaque string was the entire
172    /// diagnostic for three dead entries: the image printed nothing after
173    /// "Network ready" and the cause could only be guessed at. `&'static str`
174    /// rather than a typed error because this trait lives below `nros-node` and
175    /// cannot name `NodeError`.
176    fn apply_param_services(&mut self) -> Result<(), &'static str> {
177        Ok(())
178    }
179
180    /// phase-461 W6 -- build the parameter STORE and register no service: the
181    /// `params` capability axis. `nros::main!` calls this (via
182    /// [`RuntimeCtx::apply_param_store`]) before the per-node `register` calls
183    /// when the system declares `params` and not `param_services`. Default
184    /// no-op (non-executor runtimes, or `nros` built without `param-store`,
185    /// which the entry const-asserts against).
186    fn apply_param_store(&mut self) -> Result<(), &'static str> {
187        Ok(())
188    }
189
190    /// Phase 258 (Track 2, 2a) — raw `*mut Executor` (as `void*`) for the
191    /// owned-spin entry, so a Node pkg's `register(runtime)` wrapper can call
192    /// the uniform `__nros_component_<pkg>_install(.., executor, ..)` seam
193    /// (`nros::__macro::install_node_typed`) instead of the retired opaque-fn-ptr
194    /// ~~`register_dispatch_slot_dyn`~~ bridge. A pointer crosses the
195    /// `nros-platform` → `nros` layering wall cleanly (the concrete
196    /// `ExecutorNodeRuntime` lives in `nros`; this trait can't name it).
197    ///
198    /// Default `null` — sinks without a live executor (e.g.
199    /// [`NullNodeRuntime`], framework-dispatch-only runtimes) report no
200    /// handle; the install path treats null as a registration error.
201    fn executor_handle(&mut self) -> *mut core::ffi::c_void {
202        core::ptr::null_mut()
203    }
204
205    /// phase-446 W6 -- hand the executor the parameters each node's contract
206    /// DECLARES, so a node whose code declares a parameter its contract does
207    /// not (or with another type) refuses the boot naming the node, the
208    /// parameter and the contract.
209    ///
210    /// `nodes` is `(node FQN, contract)`; `params` is `(node FQN, name,
211    /// rcl_interfaces type code)`. Plain tuples because this trait lives below
212    /// `nros-params` and cannot name its types. `nros::main!` calls this before
213    /// any node registers. Default no-op: a runtime with no parameter store
214    /// has nothing to check.
215    fn apply_declared_params(
216        &mut self,
217        nodes: &'static [(&'static str, &'static str)],
218        params: &'static [(&'static str, &'static str, u8)],
219    ) -> Result<(), &'static str> {
220        let _ = (nodes, params);
221        Ok(())
222    }
223
224    /// Observability counters from hosted/runtime tests.
225    ///
226    /// Returns `(all_callbacks, message_callbacks)`. Implementations
227    /// that cannot observe callback dispatch keep the default zeros.
228    fn observed_callback_counts(&self) -> (usize, usize) {
229        (0, 0)
230    }
231
232    /// Hand a signaled callback to the framework-side dispatcher
233    /// (Phase 216.A.2). Only meaningful for `DispatchStrategy::Deferred`
234    /// (RTIC) runtimes — `Inline` runtimes drive callbacks
235    /// directly from `spin_once` and never call this. The default panic
236    /// surfaces the mis-wire loudly rather than silently dropping the
237    /// callback signal.
238    fn signal_callback(&mut self, _cb: SignaledCallback<'_>) {
239        panic!("signal_callback not implemented for Inline runtime");
240    }
241
242    /// Declare how this runtime delivers callbacks (Phase 216.A.2).
243    /// `nros check` (Phase 216.D.1) cross-validates each Node pkg's
244    /// `Node::DISPATCH` against this value. Defaults to `Inline` so
245    /// every existing impl reports the historical behavior unchanged.
246    fn dispatch_strategy(&self) -> DispatchStrategy {
247        DispatchStrategy::Inline
248    }
249}
250
251/// No-op [`NodeDispatchRuntime`] for tests / placeholders. Every call
252/// returns `Err(())` so callers that depend on a populated runtime
253/// fail loud rather than silently no-op.
254///
255/// `BoardEntry::run` impls replace this with a real
256/// `ExecutorNodeRuntime`-backed sink before invoking the user
257/// `setup` closure.
258#[derive(Debug, Default)]
259pub struct NullNodeRuntime;
260
261impl NodeDispatchRuntime for NullNodeRuntime {
262    fn spin_once(&mut self, _timeout_ms: u32) -> Result<(), ()> {
263        Err(())
264    }
265}
266
267/// Runtime context handed to `BoardEntry::run(setup)`.
268///
269/// All three overlay slices may be empty. A board's launch overlay
270/// typically populates `params` + `remaps`; `env` is rarely set on
271/// embedded.
272pub struct RuntimeCtx<'a> {
273    /// `<param name=… value=…/>` from launch XML, baked here by
274    /// `nros::main!` from the resolved model at BUILD time.
275    ///
276    /// NOT `-p name:=value` CLI overrides: a generated entry reads no argv,
277    /// and the hosted `nros::init_with_args` parse refuses `-p` loudly, so
278    /// launch is the only producer of these.
279    pub params: &'a [(&'a str, &'a str)],
280
281    /// Topic / service / action remaps: `(from, to)`, set per component by
282    /// `nros::main!` from the model's launch `<remap>` rules.
283    /// `nros::node!`'s `register` forwards them into
284    /// `install_node_typed_with_launch`, where entity creation expands
285    /// `~`/relative names and substitutes matching rules (exact-FQN match,
286    /// first rule wins).
287    ///
288    /// These are AUTHORITATIVE rules: `ExecutorSink::create_entity` passes
289    /// them as `nros_node::names::resolve_name_layered`'s authoritative tier,
290    /// beneath which the executor's `--ros-args` rules (installed by a hosted
291    /// `nros::Context`) can only apply to a name the launch projected no rule
292    /// for.
293    pub remaps: &'a [(&'a str, &'a str)],
294
295    /// Environment-style key/value pairs (mostly POSIX). Empty on
296    /// embedded boards.
297    pub env: &'a [(&'a str, &'a str)],
298
299    /// Launch-injected node identity `(name, namespace)` for
300    /// the NEXT `register()` call, set by `nros::main!` per component before
301    /// each `<pkg>::register(runtime)?` call. `None` → the node's own
302    /// `create_node(NodeOptions::new("…"))` default stands (backward-compatible).
303    /// Reset to `None` after every register in the self-bringup arm so a prior
304    /// component's identity never leaks into the next.
305    pub node_identity: Option<(&'static str, &'static str)>,
306
307    /// Per-node QoS overrides for the NEXT `register()` call, baked
308    /// by `nros::main!` from the model's
309    /// `qos_overrides.<topic>.<role>.<policy>` params. Same reset discipline as
310    /// `params`/`remaps`: `&[]` when the node has none, so a prior component's
311    /// table never leaks into the next.
312    ///
313    /// Primitive `(topic, role, policy, value)` codes — the SAME wire form the
314    /// C and C++ ABIs use — because `nros-platform` sits below `nros-rmw` in the
315    /// layer graph and a typed `QoSOverride` field here would invert it. The
316    /// register seam installs them via `Executor::set_node_qos_overrides`, which
317    /// decodes at entity-create time.
318    pub qos_overrides: &'static [(&'static str, u8, u8, u32)],
319
320    /// Node runtime sink. `BoardEntry::run` populates this with
321    /// the live `ExecutorNodeRuntime`-backed impl before invoking
322    /// the user `setup` closure. The codegen-emitted
323    /// `run_plan(runtime)` body calls `<pkg>::register(runtime)` once per Node
324    /// pkg, which installs through `runtime.executor_handle()` +
325    /// `nros::__macro::install_node_typed`.
326    ///
327    /// Defaults to a [`NullNodeRuntime`] when the context is
328    /// built via [`RuntimeCtx::with_runtime`]. That sink errors
329    /// every call so test fixtures that forget to wire a real runtime
330    /// fail loud.
331    pub runtime: &'a mut dyn NodeDispatchRuntime,
332}
333
334impl core::fmt::Debug for RuntimeCtx<'_> {
335    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
336        f.debug_struct("RuntimeCtx")
337            .field("params", &self.params)
338            .field("remaps", &self.remaps)
339            .field("qos_overrides", &self.qos_overrides)
340            .field("env", &self.env)
341            .field("node_identity", &self.node_identity)
342            .field("runtime", &"<dyn NodeDispatchRuntime>")
343            .finish()
344    }
345}
346
347impl<'a> RuntimeCtx<'a> {
348    /// Build a [`RuntimeCtx`] with no params / remaps / env and the
349    /// given runtime sink. The common shape `BoardEntry::run`
350    /// constructs after opening its executor.
351    ///
352    /// For test fixtures that don't need a populated runtime, pass a
353    /// `&mut NullNodeRuntime` — every call against the sink
354    /// returns `Err(())`, surfacing the missing wiring.
355    pub fn with_runtime(runtime: &'a mut dyn NodeDispatchRuntime) -> Self {
356        Self {
357            params: &[],
358            remaps: &[],
359            env: &[],
360            node_identity: None,
361            qos_overrides: &[],
362            runtime,
363        }
364    }
365
366    /// Build a [`RuntimeCtx`] with explicit overlay slices + runtime
367    /// sink.
368    pub fn new(
369        runtime: &'a mut dyn NodeDispatchRuntime,
370        params: &'a [(&'a str, &'a str)],
371        remaps: &'a [(&'a str, &'a str)],
372        env: &'a [(&'a str, &'a str)],
373    ) -> Self {
374        Self {
375            params,
376            remaps,
377            env,
378            node_identity: None,
379            qos_overrides: &[],
380            runtime,
381        }
382    }
383
384    /// Make one managed node a lifecycle node (forwards to
385    /// [`NodeDispatchRuntime::apply_lifecycle_node`]). `nros::main!` emits this
386    /// after the `register` call of each node the model marks managed. No-op
387    /// unless `nros` is built with `lifecycle-services`.
388    pub fn apply_lifecycle_node(
389        &mut self,
390        namespace: &'static str,
391        name: &'static str,
392        autostart: u8,
393    ) -> Result<(), &'static str> {
394        self.runtime
395            .apply_lifecycle_node(namespace, name, autostart)
396    }
397
398    /// The self-bringup form (forwards to
399    /// [`NodeDispatchRuntime::apply_lifecycle_self_bringup`]).
400    pub fn apply_lifecycle_self_bringup(&mut self, autostart: u8) -> Result<(), &'static str> {
401        self.runtime.apply_lifecycle_self_bringup(autostart)
402    }
403
404    /// Register the ROS 2 parameter services and create the
405    /// volatile param store (forwards to
406    /// [`NodeDispatchRuntime::apply_param_services`]). `nros::main!` emits this
407    /// BEFORE the per-node `register` calls when `system.toml` declares
408    /// `[param_services]`, so the store exists when each node is built and that
409    /// node's launch `<param>` initials ([`RuntimeCtx::params`]) are seeded on it.
410    /// No-op unless `nros` is built with `param-services`.
411    pub fn apply_param_services(&mut self) -> Result<(), &'static str> {
412        self.runtime.apply_param_services()
413    }
414
415    /// Build the parameter store without its services
416    /// (forwards to [`NodeDispatchRuntime::apply_param_store`]). Emitted where
417    /// [`Self::apply_param_services`] would be, for a system declaring
418    /// `params` alone. No-op unless `nros` is built with `param-store`.
419    pub fn apply_param_store(&mut self) -> Result<(), &'static str> {
420        self.runtime.apply_param_store()
421    }
422
423    /// Lookup a param by name; first match wins. Linear scan
424    /// because the slice is typically small (≤ a dozen entries).
425    pub fn param(&self, name: &str) -> Option<&'a str> {
426        self.params
427            .iter()
428            .find(|(k, _)| *k == name)
429            .map(|(_, v)| *v)
430    }
431
432    /// Lookup a remap by the original (`from`) name; returns the
433    /// rewritten name when remapped, else `None`.
434    pub fn remap(&self, from: &str) -> Option<&'a str> {
435        self.remaps
436            .iter()
437            .find(|(k, _)| *k == from)
438            .map(|(_, v)| *v)
439    }
440
441    /// Lookup an env entry by name.
442    pub fn env_var(&self, name: &str) -> Option<&'a str> {
443        self.env.iter().find(|(k, _)| *k == name).map(|(_, v)| *v)
444    }
445
446    /// The contract's declared parameters (forwards to
447    /// [`NodeDispatchRuntime::apply_declared_params`]). `nros::main!` emits
448    /// this before the per-node `register` calls.
449    pub fn apply_declared_params(
450        &mut self,
451        nodes: &'static [(&'static str, &'static str)],
452        params: &'static [(&'static str, &'static str, u8)],
453    ) -> Result<(), &'static str> {
454        self.runtime.apply_declared_params(nodes, params)
455    }
456}
457
458/// Error returned by the codegen-emitted `run_plan(runtime)` body
459/// and by Node pkg `register(runtime)` wrappers.
460///
461/// `no_std`-safe — variants are string-typed so embedded Entry pkgs
462/// don't need to pull `thiserror`/`anyhow` to print. The
463/// out-of-tree `nros-build` codegen library re-exports this type so
464/// emitted code references `::nros_platform::RuntimeError`, NOT
465/// `::nros_build::RuntimeError` — the embedded Entry pkg's runtime
466/// path then doesn't need `nros-build` as a runtime dep (build-dep
467/// only).
468#[derive(Debug)]
469#[non_exhaustive]
470pub enum RuntimeError {
471    /// A node's `register(runtime)` call failed. The string carries the
472    /// node pkg name.
473    ///
474    /// Phase 212.N.12 hard-renamed the legacy `ComponentRegister` variant
475    /// to `NodeRegister` to match the rclcpp_components / ROS 2 launch.xml
476    /// `<node pkg=…>` convention.
477    NodeRegister(&'static str),
478
479    /// issue 0460 — a CAPABILITY (`[lifecycle]`, `[param_services]`) failed to
480    /// register, with the reason.
481    ///
482    /// Distinct from [`NodeRegister`](Self::NodeRegister) because reusing it
483    /// forced the capability name to be the whole message: three Zephyr entries
484    /// died reporting `NodeRegister("lifecycle")`, which says WHICH capability
485    /// and nothing about WHY, and the image printed nothing else. Two static
486    /// strings rather than a log call, because not every entry crate depends on
487    /// `log` — the first attempt emitted `::log::error!` from the macro and
488    /// broke `linux_rust_qos_entry` with `cannot find 'log' in the crate root`.
489    Capability {
490        /// `"lifecycle"` / `"param_services"`.
491        name: &'static str,
492        /// Why registration failed, from the runtime that attempted it.
493        reason: &'static str,
494    },
495
496    /// Issue 0095 — a node's `register` failed specifically because the
497    /// executor's fixed callback-entry table (`NROS_EXECUTOR_MAX_CBS`) is full.
498    /// Distinct from the opaque [`NodeRegister`](Self::NodeRegister) so the user
499    /// sees the actionable knob. The string carries the node pkg name.
500    ExecutorFull(&'static str),
501
502    /// The hosted Entry spin loop failed or did not observe the
503    /// requested runtime condition before its bounded test deadline.
504    Spin,
505
506    /// RFC-0065 D5 amendment — the image's `before_boot` step returned an
507    /// error, with its reason. Nothing else has run yet.
508    BeforeBoot(&'static str),
509}
510
511impl core::fmt::Display for RuntimeError {
512    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
513        match self {
514            Self::NodeRegister(msg) => write!(f, "node register failed: {msg}"),
515            Self::ExecutorFull(msg) => write!(
516                f,
517                "node '{msg}' register failed: executor callback table full — \
518                 raise NROS_EXECUTOR_MAX_CBS (build-time env, default 4)"
519            ),
520            Self::Capability { name, reason } => write!(
521                f,
522                "capability '[{name}]' failed to register: {reason} — the system \
523                 declares it, so the entry cannot run without it"
524            ),
525            Self::Spin => write!(f, "entry spin failed"),
526            Self::BeforeBoot(reason) => write!(f, "before_boot failed: {reason}"),
527        }
528    }
529}