Skip to content

Conversation

lzrd
Copy link
Contributor

@lzrd lzrd commented Mar 21, 2025

Rhai scripting is added to facilitate developer testing and potential CI use cases.

This scripting feature is much nicer to use than the bash scripts in the sprot-e2e repo. It was the threat of having to update those that motivated this PR.

See the README.md file in scripts/README.md.

This PR has the rhaiscript feature on by default.

Thanks to John for some help about a year ago to help me with async recursion.

@lzrd lzrd force-pushed the rhai branch 3 times, most recently from 9aedb56 to 370c141 Compare March 21, 2025 06:16
@labbott
Copy link
Contributor

labbott commented Mar 21, 2025

I like the idea of a rhai scripting interface over writing a bunch of shell. I also think there's multiple parts to this: there's the actual rhai interface for faux-mgs and then there's making that interface usable for test scripts. racktest uses rhai but it's slightly different because both the interface and the test scripts are within the same package which is not the case with faux-mgs.

I think the verify_rot_image function is a good example of something practical we do want but I don't think faux-mgs should be growing that much knowledge of hubris specific functions. We should figure out what's a better approach for features/functions like that.

Another separate thought: Is this is a sign that we're doing too much with the faux-mgs binary and maybe we need faux-mgs-lib? This would let us write something a little bit closer to what racktest does in a separate repository.

@lzrd
Copy link
Contributor Author

lzrd commented Mar 25, 2025

I added Hubtools issue #51. Knowledge about Hubris archives should migrate there. Existing Hubtools functions, like verify(), should be used here.

lzrd added 12 commits July 21, 2025 12:15
This message can be used in favor of resetting the RoT when recovering
from a failed or abandoned update.

A RoT transient or persistent Hubris activation has a pending phase
that is resolved on next boot.

Clearing the pending activation allows a new update flow to proceed
without resetting the RoT, or with a reset, allows the update flow to
proceed without switching to a different image (assuming a properly
signed alternate image).
Rust code changes:
  - add Rhai scripting as a feature (--features=rhaiscript)
  - add ArchiveInspector for access to RawHubrisArchive
  - add "system(argv) -> #{exit_code, stdout, stderr}" from std::process::Command
  - export faux-mgs paramsters to Rhai main.
  - run any faux-mgs command with "let result = faux_mgs(["arg0", .. "argN"]);
      - faux-mgs results are passed back to the script as a map even if they are simpler JSON.
  - ChronoPackage for time handling.
  - FilesystemPackage for file access.
  - EnvironmentPackage for env var access.
  - export "scriptdir" so that script can get other files relative to itself.
  - "verify_rot_image()" to verify a RoT image vs CFPA, CMPA.
  - vars available to main():
      - "argv" - script main's scope passing all remaining CLI args.
      - "rbi_default" - expose faux-mgs default "rot_boot_info" version
      - "interface" - pass the "--interface INTERFACE" value.
      - "reset_watchdog_timeout_ms" - pass that value to the script.
  - Route Rhai's debug function to the faux-mgs log.
      - The `debug("message")` function is routed to the faux-mgs slog logging.
        Prefixing a message with "crit|", "trace|", "error|", "warn|", "error|", or "debug|"
        will log at that corresponding level. Leaving off the prefix or using some other
        prefix will log at the debug level.
      - Rhai's `print()` still goes to stdout.

Rhai scripts:

scripts/util.rhai contains common script and faux-mgs support.
  - getops()
  - to_hexstring()
  - cstring_to_string(a)
  - array_to_mac(a)
  - ab_to_01(v)
  - env_expand(s, override)
  - rot_boot_info()
  - state()
  - caboose_value(component, slot, key)
  - get_device_cabooses()
  - rkth_to_key_name(rkth)
  - array_to_blob(a)
  - get_cmpa()
  - get_cfpa()
  - get_rot_keyset()

scripts/update-rollback.rhai
  - Only use MGS messages for testing, no humility or other APIs
  - perform happy path update and rollback from baseline to under-test images.

scripts/targets.json
  - an example configuration script for scripts/update-rollback.rhai
Fix `json_to_map()` so that JSON errors are reported properly.
Some calls to `print()` change to logging to debug or info.
Add configuration for `faux-ipcc`.
  - since system() needs to be used to run faux-ipcc, should there
    be a regex to parse or are Rhai's existing string functions
    sufficient to pull out certs and measurements? Since faux-ipcc
    doesn't handle attestations yet, we'll wait a bit.
Move RawHubrisArchive knowledge to a separate source file.
Also work around baseline not implementing transient boot preference
Also error handling in to_hexstring.
Positional baseline and UT args become options.
Remove dead code.
Add docs and tests for getopts
Power control is needed to test recovery from failed RoT updates when
using transient boot preference and fault insertion.
lzrd added 6 commits July 21, 2025 12:49
Checkin TEST_PLAN.md for upgrade-rollback tests
Update TODO.md for upgrade-rollback tests
The FMR script helps when running single commands from the repo that use rhai scripts.
  - Fix `faux_mgs` rhai function to return full error text.
  - Changed `util::set_rot_boot_preference()` to `util::rot_boot_preference(...,
    action, ...)`
  - Test recovery flows for dealing with previous failed or abandoned updates that
    set RoT image preferences.
Also: Update scripts test plan, scripts todo list, and remove Hubris issue #2093 workaround.
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.

2 participants