Skip to content

feat: add --reset flag to tkey-runapp - #31

Open
jthornblad wants to merge 2 commits into
mainfrom
reset
Open

feat: add --reset flag to tkey-runapp#31
jthornblad wants to merge 2 commits into
mainfrom
reset

Conversation

@jthornblad

@jthornblad jthornblad commented Jun 18, 2026

Copy link
Copy Markdown

Description

Add support for sending a reset command to a running TKey application before loading a new app, without requiring a manual replug.

  • --reset TYPE: specifies the firmware reset type (default, flash1, client)
  • --bv ACTION: optionally specifies the boot verifier action after reset (app1, cmdmode); defaults to app1 if not specified

When --reset is given without a file argument, the tool exits after sending the reset. When combined with a file argument, it waits 3 seconds for the device to re-enumerate before loading the app.

Firmware version and UDI are only queried when not sending a reset, since the device may be running an app rather than firmware in that case.

Type of change

Please tick any that are relevant to this PR and remove any that aren't.

  • Bugfix (non breaking change which resolve an issue)
  • Feature (non breaking change which adds functionality)
  • Breaking Change (a change which would cause existing functionality to not work as expected)
  • Documentation (a change to documentation)

Submission checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my changes
  • I have tested and verified my changes on target
  • My changes are well written and CI is passing
  • I have squashed my work to relevant commits and rebased on main for linear history
  • I have added a "Co-authored-by: x" if several people contributed, either pair programming or by squashing commits from different authors.
  • I have updated the documentation where relevant (readme, dev.tillitis.se etc.)
  • QEMU is updated to reflect changes

@jthornblad
jthornblad marked this pull request as draft June 18, 2026 14:23
@jthornblad
jthornblad marked this pull request as ready for review June 18, 2026 14:43
@jthornblad
jthornblad force-pushed the reset branch 3 times, most recently from 1451cc9 to 6429af0 Compare June 22, 2026 08:35
…ands

Add support for sending a reset command to a running TKey application
before loading a new app, without requiring a manual replug.

- --reset TYPE: specifies the firmware reset type (default, flash1, client)
- --bv ACTION: optionally specifies the boot verifier action after reset
  (app1, cmdmode); defaults to app1 if not specified

When --reset is given without a file argument, the tool exits after
sending the reset. When combined with a file argument, it waits 3
seconds for the device to re-enumerate before loading the app.

Firmware version and UDI are only queried when not sending a reset,
since the device may be running an app rather than firmware in that
case.

@dehanj dehanj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall it looks OK and supports what I expect, and in line with what soon will be available in tkeyclient (and which tkey-runapp should start using in the future).

I have a few comments:

  1. CI is failing. Do you want to fix it or should assist?
  2. It is possible to use the flags with invalid combinations, such as using --reset default/flash1 and specifying an app to load. It is only when specifying --reset client that loading an app makes sense. I would say it shouldn't be allowed.
  3. I think it should describe in the usage what it supports regarding reset, and maybe clarify it a bit. For example if one uses default we assume it is out boot verifier.
  4. In usage, maybe include that --bv is only relevant if one specify --reset default

Comment thread cmd/tkey-runapp/main.go
if fileName == "" {
exit(0)
}
le.Printf("Waiting for CH552 to re-enumerate\n")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we shouldn't mention the CH552.
At a later stage we say "Loading app from ../tkey-device-signer/signer/app.bin onto device"
So changing it to "device" will keep it consistent, or maybe "TKey".

Comment thread cmd/tkey-runapp/main.go
if pflag.NArg() > 1 {
le.Printf("Unexpected argument: %s\n\n", strings.Join(pflag.Args()[1:], " "))
pflag.Usage()
os.Exit(2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why changing the exit code for some of the input error handling?

My interpretation is that if input flags to tkey-runapp cannot be satisfied, like wrong combination, it exited with 2 - other errors like not opening files, TKey communication was exit code 1.

Comment thread cmd/tkey-runapp/main.go
le.Printf("Firmware name0:'%s' name1:'%s' version:%d\n",
nameVer.Name0, nameVer.Name1, nameVer.Version)
if fwResetStr == "" {
nameVer, err := tk.GetNameVersion()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the user should have to think less about what state the TKey is in, and let tkey-runapp try to figure it out by itself. It has all the means to it.

So I purpose that we simplify the input a user has to give.

If I use (as before) tkey-runapp app.bin I think it should figure out if it is firmware or not, if it is not firmware it should try a reset, and then load the app.
Potentially that the reset request is guarded by the version in the UDI (we know bellatrix cannot perform a reset), or an opt-out flag --no-reset to make it both backwards compatible and possible to have the old behavior.

Then we can of course extend this to only send a reset command, but only then I think the --reset flag should be used - and that is targeting to communicate with apps, not firmware.

I see it that it handles to purposes:

  • Load an app
  • Just do a reset

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.

3 participants