Nitrokey / nitrokey-3-firmware

Nitrokey 3 firmware
Apache License 2.0
249 stars 26 forks source link

Flash nitrokey3 on LPCXpresso55S69 #275

Closed tarun14110 closed 6 months ago

tarun14110 commented 1 year ago

I am planning to utilize the LPCXpresso55S69 board for development purposes and I am currently attempting to flash the Nitrokey3. However, I encountered an issue while following the instruction lpc55 ls command, no output was displayed. I can see the NXP board listed in the dmesg output. Based on this observation, I suspect the board might not be in bootloader mode. I followed the steps outlined in the following link (https://os.mbed.com/teams/NXP/wiki/Updating-LPCXpresso-firmware), but unfortunately, it did not resolve the problem. I would greatly appreciate any suggestions or alternative instructions to properly set up the LPCXpresso55S69 board for development and successfully flash the Nitrokey3.

szszszsz commented 1 year ago

Hey!

  1. Did you see this one already?
  2. Make sure you have the Udev rules set up
tarun14110 commented 1 year ago

Yes! I am following these instructions. After I connect the board, I see the following through lsusb command Bus 002 Device 003: ID 1fc9:0090 NXP Semiconductors LPC-LINK2 CMSIS-DAP v 5.361. According to the documentation above, this is not what I am supposed to see. Also, I also do not see anything on running lpc55 ls.

Based on the product id I see in the above documentation, I assume it is because I am using the built-in LPC-LINK2 debug probe in LPCXpresso55S69 board instead of an external MCU-LINK debug probe. Any suggestions on how can I get it to work?

szszszsz commented 1 year ago

I think you need to move one of the switches, like JP2. See the mentioned doc for the details.

tarun14110 commented 1 year ago

Thank @szszszsz! I installed the J-link firmware based on the instructions in the documentation. I then run command make -C utils/lpc55-builder jlink on terminal 1 and make -C utils/lpc55-builder run on terminal 2. I think, I was successfully able to enter in gdb mode. However, I still cannot get it to work with https://webauthn.io/ or fido2-token-i /dev/cu.usmodem00072.... I do not see LEDs blinking or color change on starting FIDO2 registration. How can I use the LPCXpresso55S69 board as a nitrokey3 to register and authenticate? Also, what would be the button press equivalent on this board?

Thanks for helping out with this. I am just getting started with the hardware, so let me know if I am missing something obvious.

For reference, this is what I get in terminal 1 and terminal 2. Terminal 1: make -C utils/lpc55-builder jlink

JLinkGDBServer -strict -device LPC55S69 -if SWD -vd
SEGGER J-Link GDB Server V7.88d Command Line Version

JLinkARM.dll V7.88d (DLL compiled May 24 2023 15:19:06)

Command line: -strict -device LPC55S69 -if SWD -vd
-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     2331
SWO raw output listening port: 2332
Terminal I/O port:             2333
Accept remote connection:      yes
Generate logfile:              off
Verify download:               on
Init regs on start:            off
Silent mode:                   off
Single run mode:               off
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 LPC55S69
Target device parameters:      none
Target interface:              SWD
Target interface speed:        4000kHz
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link LPCXpresso V2 compiled Apr  4 2019 16:54:03
Hardware: V1.00
S/N: 729479000
Checking target voltage...
Target voltage: 3.30 V
Listening on TCP/IP port 2331
Connecting to target...
Halting core...
Core security extensions: Implemented
Connected to target
Waiting for GDB connection...Connected to 0000:0000:0000:0000:0000:0000:0000:0001
GDB client (conn. 11) requested target.xml from GDB Server
Reading common registers: Read register 'r0' (4 bytes) from hardware: 0x00000800
Read register 'r1' (4 bytes) from hardware: 0x04E20840
Read register 'r2' (4 bytes) from hardware: 0x01000000
Read register 'r3' (4 bytes) from hardware: 0x00000000
Read register 'r4' (4 bytes) from hardware: 0x00014000
Read register 'r5' (4 bytes) from hardware: 0xA8F00020
Read register 'r6' (4 bytes) from hardware: 0xE4890020
Read register 'r7' (4 bytes) from hardware: 0x50870020
Read register 'r8' (4 bytes) from hardware: 0x00000000
Read register 'r9' (4 bytes) from hardware: 0x9C370120
Read register 'r10' (4 bytes) from hardware: 0x01000000
Read register 'r11' (4 bytes) from hardware: 0x01000000
Read register 'r12' (4 bytes) from hardware: 0xF8060800
Read register 'sp' (4 bytes) from hardware: 0x50870020
Read register 'lr' (4 bytes) from hardware: 0x255E0400
Read register 'pc' (4 bytes) from hardware: 0xFC640400
Read register 'xpsr' (4 bytes) from hardware: 0x00000029
Read 4 bytes @ address 0x000464FC (Data = 0xD4D4E7FE)
Reading 64 bytes @ address 0x20008740
Read 4 bytes @ address 0x0000386C (Data = 0xB580DEFE)
Downloading 304 bytes @ address 0x00000000 - Verified OK
Downloading 16256 bytes @ address 0x00000130 - Verified OK
Downloading 16144 bytes @ address 0x000040B0 - Verified OK
Downloading 16240 bytes @ address 0x00007FC0 - Verified OK
Downloading 16112 bytes @ address 0x0000BF30 - Verified OK
Downloading 16160 bytes @ address 0x0000FE20 - Verified OK
Downloading 16160 bytes @ address 0x00013D40 - Verified OK
Downloading 16176 bytes @ address 0x00017C60 - Verified OK
Downloading 16144 bytes @ address 0x0001BB90 - Verified OK
Downloading 16048 bytes @ address 0x0001FAA0 - Verified OK
Downloading 16064 bytes @ address 0x00023950 - Verified OK
Downloading 16160 bytes @ address 0x00027810 - Verified OK
Downloading 16176 bytes @ address 0x0002B730 - Verified OK
Downloading 16256 bytes @ address 0x0002F660 - Verified OK
Downloading 16224 bytes @ address 0x000335E0 - Verified OK
Downloading 16208 bytes @ address 0x00037540 - Verified OK
Downloading 16160 bytes @ address 0x0003B490 - Verified OK
Downloading 16240 bytes @ address 0x0003F3B0 - Verified OK
Downloading 16240 bytes @ address 0x00043320 - Verified OK
Downloading 16176 bytes @ address 0x00047290 - Verified OK
Downloading 16160 bytes @ address 0x0004B1C0 - Verified OK
Downloading 16160 bytes @ address 0x0004F0E0 - Verified OK
Downloading 16160 bytes @ address 0x00053000 - Verified OK
Downloading 16176 bytes @ address 0x00056F20 - Verified OK
Downloading 16208 bytes @ address 0x0005AE50 - Verified OK
Downloading 16240 bytes @ address 0x0005EDA0 - Verified OK
Downloading 16128 bytes @ address 0x00062D10 - Verified OK
Downloading 16224 bytes @ address 0x00066C10 - Verified OK
Downloading 16192 bytes @ address 0x0006AB70 - Verified OK
Downloading 16160 bytes @ address 0x0006EAB0 - Verified OK
Downloading 14944 bytes @ address 0x000729D0 - Verified OK
Downloading 16304 bytes @ address 0x00076430 - Verified OK
Downloading 16336 bytes @ address 0x0007A3E0 - Verified OK
Downloading 16320 bytes @ address 0x0007E3B0 - Verified OK
Downloading 16304 bytes @ address 0x00082370 - Verified OK
Downloading 6756 bytes @ address 0x00086320 - Verified OK
Downloading 14376 bytes @ address 0x00087D88 - Verified OK
Writing register 'pc' = 0x00000000
Received monitor command: reset
Resetting target
Received monitor command: semihosting enable
Semi-hosting enabled (Handle on breakpoint instruction hit)
Received monitor command: semihosting IOClient 3
Semihosting I/O set to TELNET and GDB Client
Starting target CPU...

Terminal 2: make -C utils/lpc55-builder run

/Library/Developer/CommandLineTools/usr/bin/make -C "../../runners/embedded/" build-nk3xn
/Library/Developer/CommandLineTools/usr/bin/make build BUILD_PROFILE=lpc55 BOARD=nk3xn FEATURES=
******************************************************************************************
**** TARGET:                 build | BINARY:   artifacts/runner-lpc55-nk3xn.bin(.ihex)
**** BOARD:                  nk3xn | SOC:      lpc55
**** PROFILE:                lpc55 | BUILD_ID: lpc55-nk3xn
**** FEATURES:  board-nk3xn 
******************************************************************************************
cargo --version
cargo 1.68.0 (115f34552 2023-02-26)
cp -f profiles/lpc55.toml cfg.toml
echo '' >> cfg.toml
echo '[build]' >> cfg.toml
echo 'build_profile = "lpc55"' >> cfg.toml
echo 'board = "nk3xn"' >> cfg.toml
cargo build --release --target thumbv8m.main-none-eabi \
        --features board-nk3xn, \
        --quiet
cp ../../target/thumbv8m.main-none-eabi/release/lpc55_runner ./artifacts/runner-lpc55-nk3xn.elf
arm-none-eabi-nm ./artifacts/runner-lpc55-nk3xn.elf | grep ' [ABbDdRrTt] ' | sort | c++filt > symbols-lpc55-nk3xn.txt 
cat arm-none-eabi-arch-symbols.txt >> symbols-lpc55-nk3xn.txt
arm-none-eabi-objcopy -O binary ./artifacts/runner-lpc55-nk3xn.elf ./artifacts/runner-lpc55-nk3xn.bin
arm-none-eabi-objcopy -O ihex ./artifacts/runner-lpc55-nk3xn.elf ./artifacts/runner-lpc55-nk3xn.bin.ihex
arm-none-eabi-readelf -l ./artifacts/runner-lpc55-nk3xn.elf | grep LOAD
  LOAD           0x010000 0x00000000 0x00000000 0x00130 0x00130 R   0x10000
  LOAD           0x010130 0x00000130 0x00000130 0x76300 0x76300 R E 0x10000
  LOAD           0x086430 0x00076430 0x00076430 0x11954 0x11954 R   0x10000
  LOAD           0x09b0a8 0x2002b0a8 0x00087d88 0x03828 0x03828 RW  0x10000
  LOAD           0x09e8d0 0x2002e8d0 0x2002e8d0 0x00000 0x1572c RW  0x10000
arm-none-eabi-gdb -q -x ./jlink.gdb "../../runners/embedded//artifacts/runner-lpc55-nk3xn.elf"
Reading symbols from ../../runners/embedded//artifacts/runner-lpc55-nk3xn.elf...
embedded_runner_lib::panic (_info=<optimized out>) at runners/embedded/src/lib.rs:297
297     loop {
Loading section .vector_table, size 0x130 lma 0x0
Loading section .text, size 0x76300 lma 0x130
Loading section .rodata, size 0x11954 lma 0x76430
Loading section .data, size 0x3828 lma 0x87d88
Start address 0x00000000, load size 570796
Transfer rate: 46451 KB/sec, 15426 bytes/write.
Resetting target
Semi-hosting enabled (Handle on breakpoint instruction hit)
Semihosting I/O set to TELNET and GDB Client
robin-nitrokey commented 1 year ago

The easiest way to run the Nitrokey 3 firmware on a development device is using a Nitrokey 3 Hacker device which you can order at shop@nitrokey.com. We can give you some pointers to get it running on the LPCXpresso55 board, but you will have to make some changes yourself and it is not an officially supported configuration.

It is very likely that the Xpresso board has a different pinout than the actual Nitrokey hardware so this might cause some issues. For debugging, I recommend the following steps:

Previously, we had support for the Xpresso board in the firmware, but we dropped it because we were not actually using it and had no way to test it:

Since then, we also added checks of the SE050 and the external flash at boot. These could also fail on your board.

robin-nitrokey commented 6 months ago

Closing as there is no action required at the moment. Please open a new issue if there are specific problems.