Skip to content

cli: reject missing -kernel up front instead of hanging in SBI [#50]#148

Merged
zevorn merged 1 commit into
gevico:mainfrom
Lfan-ke:feat/50-missing-kernel-error
May 23, 2026
Merged

cli: reject missing -kernel up front instead of hanging in SBI [#50]#148
zevorn merged 1 commit into
gevico:mainfrom
Lfan-ke:feat/50-missing-kernel-error

Conversation

@Lfan-ke
Copy link
Copy Markdown
Collaborator

@Lfan-ke Lfan-ke commented May 10, 2026

Resolves #50.

What

Implement the issue author's preferred fix (Alternative): detect
`no -kernel and no external firmware` during CLI validation
and exit 1 with a clear diagnostic, instead of silently sitting
inside RustSBI with nothing to run.

Behaviour table

Invocation Before After
`machina -nographic` (default = bundled RustSBI) hangs exit 1 with message
`machina -nographic -bios none` hangs exit 1 with message
`machina -nographic -bios builtin` hangs exit 1 with message
`machina -nographic -kernel X` unchanged unchanged
`machina -nographic -bios ` unchanged unchanged (firmware may be self-contained)
`machina -M ?` lists machines unchanged

The check is placed in `main()` after machine-name and
per-machine option validation so existing rejections (unknown
machine, LoongArch `-S`/`-gdb`/`-monitor` rejections) still
surface first when both apply.

Diagnostic

```
machina: no kernel specified.
Please use -kernel <path/to/kernel.elf> to provide a guest payload.
Without -kernel, machina would sit inside SBI firmware with nothing
to run.
```

Tests

`tests/src/cli_kernel.rs`:

  • `missing_kernel_with_default_bios_errors_with_diagnostic`
  • `missing_kernel_with_bios_none_errors`
  • `missing_kernel_with_bios_builtin_errors`

All existing cli_kernel, tools and machine-help tests continue
to pass.

Test plan

  • `cargo test -p machina-tests cli_kernel` — 5/5 pass.
  • `cargo test -p machina-tests tools::` — 10/10 pass (no regressions).
  • `make fmt-check` clean.
  • `make clippy` clean.

@Lfan-ke
Copy link
Copy Markdown
Collaborator Author

Lfan-ke commented May 10, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c9ee169fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main.rs Outdated
@Lfan-ke
Copy link
Copy Markdown
Collaborator Author

Lfan-ke commented May 10, 2026

@codex please review again!

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c9ee169fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main.rs Outdated
@Lfan-ke Lfan-ke changed the title cli: reject missing -kernel up front instead of hanging in SBI (#50) cli: reject missing -kernel up front instead of hanging in SBI [#50] May 10, 2026
@Lfan-ke Lfan-ke force-pushed the feat/50-missing-kernel-error branch 2 times, most recently from 77497ef to 9366625 Compare May 11, 2026 11:17
@zevorn
Copy link
Copy Markdown
Member

zevorn commented May 20, 2026

@codex review this pr thoroughly again.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…o#50)

Running \`machina -nographic\` (or any invocation that lands in the
bundled RustSBI without a guest payload) silently sat inside the
firmware forever. To a first-time user this looks like a freeze:
the README documents Ctrl-A, X to escape, but a contributor who
just typed \`cargo run\` to verify the build had no way to know.

Implement the issue's preferred host-side check: after the CLI is
fully validated (machine name, per-machine option rejections),
detect "no -kernel and no external firmware" and exit 1 with a
clear message:

    machina: no kernel specified.
    Please use -kernel <path/to/kernel.elf> to provide a guest payload.
    Without -kernel, machina would sit inside SBI firmware with
    nothing to run.

The check intentionally allows -bios <ext-firmware> without -kernel
because a self-contained firmware (U-Boot, custom OpenSBI) can
drive its own boot. -bios none and -bios builtin still require
-kernel.

Tests in tests/src/cli_kernel.rs:
- missing_kernel_with_default_bios_errors_with_diagnostic
- missing_kernel_with_bios_none_errors
- missing_kernel_with_bios_builtin_errors

Existing cli_kernel, tools and machine-help tests still pass.

Signed-off-by: Leo Cheng <chengkelfan@qq.com>
@Lfan-ke Lfan-ke force-pushed the feat/50-missing-kernel-error branch from 9366625 to 6381cdb Compare May 22, 2026 14:57
@zevorn zevorn merged commit cc75fe8 into gevico:main May 23, 2026
9 checks passed
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.

feat: improve first-time user experience when no -kernel is specified

2 participants