Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge lpc55 into embedded runner #97

Merged
merged 11 commits into from
Nov 17, 2022
Merged

Merge lpc55 into embedded runner #97

merged 11 commits into from
Nov 17, 2022

Conversation

robin-nitrokey
Copy link
Member

@robin-nitrokey robin-nitrokey commented Oct 22, 2022

This PR merges the lpc55 runner into the embedded runner (currently only used for nrf52). This makes the firmware very much hardware agnostic, reduces the code duplication between the lpc55 and nrf52 targets and makes maintenance easier.

Fixes #79

(The old lpc55 runner is not yet deleted in this PR so that it still can be used for reference.)

For comparison, the numbers of lines of Rust code in the runners (calculated with cloc) are:

Runner loc
lpc55 (legacy) 3,073
embedded (nrf52-only) 2,634
embedded (nrf52 + lpc55) 4,304

Build instructions

To build the firmware, you need a recent Rust version with the thumbv8m.main-none-eabi target, e. g. installed with rustup:

$ rustup update stable
$ rustup target add thumbv8m.main-none-eabi

There are also some required libraries and tools, e. g. for Debian:

$ sudo apt-get install llvm clang libclang-dev gcc-arm-none-eabi libc6-dev-i386 python3-toml

Now you can build the lpc55 and nrf52 runners:

$ cd runners/embedded
$ make build-nk3am  # nrf52
$ make build-nk3xn  # lpc55

Execution logs (lpc55)

$ make run-nk3xn FEATURES=develop,log-semihosting
# ...
making flash
making fs
mount start 64 ms
inside IDLE, initial SP = 20030248
Embedded Runner (LPC55:nk3xn) using librunner 1.2.2
do not need to update cfpa version 4194434
bootrom request start 0
EEPROM already initialized.
EFS Mount Error, Reformat Ok(())
mount end 96 ms
init took 96 ms

Test of USB communication, touch button, LED, admin and FIDO2 applications:

$ nitropy nk3 test --all
Command line tool to interact with Nitrokey devices 0.4.29
Found 1 Nitrokey 3 device(s):
- Nitrokey 3 at /dev/hidraw0

Running tests for Nitrokey 3 at /dev/hidraw0

[1/5]   uuid            UUID query                      SUCCESS         223FE5E2AE287150AD9DAD9E34B7F989
[2/5]   version         Firmware version query          SUCCESS         v1.2.2
[3/5]   bootloader      Bootloader configuration        FAILURE         bootloader not locked
[4/5]   provisioner     Firmware mode                   SUCCESS  
Please press the touch button on the device ...
[5/5]   fido2           FIDO2                           FAILURE         Unexpected FIDO2 cert hash for version v1.2.2: c7d87cac86b69059bbff5c43872a20892267518614dfc9822c7ee55ad89f0022

5 tests, 3 successful, 0 skipped, 2 failed

Summary: 1 device(s) tested, 0 successful, 1 failed

(The test failures are caused by the device being a development device. The tests still show that the communication works correctly though.)

@daringer
Copy link
Collaborator

Ran some tests on NK3AM - Athene (development device):

  • nitropy nk3 test (ok)
  • change pin (ok)
  • webauthn.bin reg/auth (ok)
  • sign-in data (chromium) (ok)
  • webauthn.bin.coffee (ok)
  • gitlab reg/login (ok)
  • ssh-keygen ed25519-sk (ok)
  • reset (ok)

Execution logs (nrf52)

Embedded Runner (NRF52840:NK3AM) using librunner 1.2.2
RESET Reason: 4
FICR DeviceID 5F 74 E7 94 XX XX XX XX
FICR IdtRoot  426432f1 cafecafe cafecafe cafecafe
FICR EncRoot  4af82017 cafecafe cafecafe cafecafe
FICR DevAddr  F3 64 EA XX XX XX
UICR REGOUT0 fffffffd NFCPINS fffffffe
UICR APPROTECT is DISABLED!
qspi jedec: C8 40 15
...

@robin-nitrokey
Copy link
Member Author

robin-nitrokey commented Nov 9, 2022

To do:

  • manage no-encrypted-storage feature
  • investigate flashing with lpc55
  • monotonic

@robin-nitrokey robin-nitrokey force-pushed the embedded-runner-lpc55 branch 3 times, most recently from ca0120e to afecbdf Compare November 15, 2022 16:09
The semihosting log target requires the cortex-m-semihosting dependency.
We only need the rtt-target dependency if the log-rtt feature is
enabled.
This allows the user to select either log-rtt or log-semihosting.
The usbfs-peripheral feature is not used and does not cause any changes,
so we can safely remove it.
This patch merges the old lpc55 runner into the embedded runner.  It
also removes dead code and features that are no longer used.

Fixes #79
@robin-nitrokey
Copy link
Member Author

robin-nitrokey commented Nov 15, 2022

This commit causes an error message during the build (though it still succeeds):

Traceback (most recent call last):                                                                       
  File "<string>", line 1, in <module> 
  File "/home/robin/venv/nk3am/lib/python3.9/site-packages/toml/decoder.py", line 133, in load
    with io.open(_getpath(f), encoding='utf-8') as ffile:
FileNotFoundError: [Errno 2] No such file or directory: 'profiles/.toml' 

Does this make sense to you @daringer? Otherwise this should be ready to merge.

Edit: Should be fixed now.

For the nrf52, no-encrypted-storage does not have any effects.  For the
lpc55, we only want to enable it in development builds as the release
firmware is expected to be run with PRINCE enabled.
This patch renames the existing bin artifact to elf and then adds a real
bin artifact generated by objcopy with `-O binary`.
This patch adds a builder Makefile for building and running the firmware
for the lpc55.
@daringer
Copy link
Collaborator

lgtm, some random tests on NK3mini also show no issues

@daringer daringer merged commit 06238fd into main Nov 17, 2022
@daringer daringer deleted the embedded-runner-lpc55 branch November 17, 2022 11:08
@szszszsz szszszsz mentioned this pull request Nov 18, 2022
4 tasks
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.

Merge lpc55 runner into embedded runner
2 participants