658 Commits

Author SHA1 Message Date
Mikael Ågren
5cba9b3f7e
testloadapp: Delete any existing preloaded app before installing 2025-03-24 13:54:19 +01:00
Mikael Ågren
2caaf2a453
WIP: verify pre loaded app 2 2025-03-24 11:36:11 +01:00
Mikael Ågren
543c5a8968
testloadapp: Use blake2s from tkey-libs 2025-03-24 11:36:10 +01:00
Mikael Ågren
478212f72f
Add tool to create a flash image containing a preloaded app at slot 0 2025-03-24 11:36:10 +01:00
Mikael Ågren
a8f2a8c30e
Do not hardcode preloaded app 1 size
Hardcoding it causes preload_check_valid_app and therefore preload_store
to assume there already is an app installed. Causing the
TK1_SYSCALL_PRELOAD_STORE syscall to fail.
2025-03-24 11:36:10 +01:00
Mikael Ågren
15bf72bc37
Add QEMU_SYSCALL to enable Qemu syscalls
Enable Qemu syscall handling by defining QEMU_SYSCALL instead of
QEMU_DEBUG. That way we can select either or.
2025-03-24 11:36:09 +01:00
Michael Cardell Widerkrantz
97582da977
Add start of test app for installing and verifying flash app
Currently needs LIBDIR set to tkey-libs with blake2s().
2025-03-24 11:36:09 +01:00
Mikael Ågren
feca8f19f4
Do note delete or corrupt preloaded app 0 when storing preloaded app 1 2025-03-20 16:22:47 +01:00
Mikael Ågren
a86cd4a618
Delete app digest and signature when preloaded app is deleted 2025-03-20 16:07:21 +01:00
Mikael Ågren
6dcb5018d1
Store app digest and signature for each app slot 2025-03-20 16:07:21 +01:00
Michael Cardell Widerkrantz
dd147657a4
Introduce syscalls to change preloaded app
Introduce syscalls:

- TK1_SYSCALL_PRELOAD_STORE
- TK1_SYSCALL_PRELOAD_STORE_FIN
- TK1_SYSCALL_PRELOAD_DELETE
- TK1_SYSCALL_REG_MGMT = 11

Change preload_store_finalize() not to take USS arg. Unused for
preloaded apps.
2025-03-20 16:07:21 +01:00
Mikael Ågren
970668a47b
Add second pre-loaded app slot in flash 2025-03-20 16:07:20 +01:00
Mikael Ågren
6ad32f7317
When requested, verify app digest before running 2025-03-18 17:40:12 +01:00
Mikael Ågren
6067d130a2
Handle reset info in reset syscall
Disabling debug printouts to get firmware to fit in ROM
2025-03-18 17:40:12 +01:00
Jonas Thörnblad
7a59d778f2
Add resetinfo testapp
Co-authored-by: Mikael Ågren <mikael@tillitis.se>
Co-authored-by: Michael Cardell Widerkrantz <mc@tillitis.se>
2025-03-18 17:40:11 +01:00
Michael Cardell Widerkrantz
1f81c9bdb6
Add resetinfo handling
Decide where to start from with data from resetinfo part of FW_RAM.

Co-authored-by: Jonas Thörnblad <jonas@tillitis.se>
Co-authored-by: Mikael Ågren <mikael@tillitis.se>
2025-03-18 17:40:11 +01:00
Michael Cardell Widerkrantz
101c6fe1a2
Document state machine
Golden path not updated
2025-03-18 17:40:11 +01:00
Michael Cardell Widerkrantz
15036c4d0c
Experiment with new state machine 2025-03-18 17:40:11 +01:00
Michael Cardell Widerkrantz
1ab6dc12bf
Experiment with state machine when starting from flash
- Move around code to start an app from flash.
- Mark experimental stuff and debug stuff more clearly.
2025-03-18 17:40:11 +01:00
Michael Cardell Widerkrantz
c359a52905
Introduce symbolic names for present and present & authenticated
A preloaded app can be:

- present and not yet authenticated (0x01)
- present and authenticated (0x02)

Let's use symbolic names for these.
2025-03-18 17:40:11 +01:00
Michael Cardell Widerkrantz
980a3c84a1
Make run_flash() and run() both call jump_to_app() 2025-03-18 17:40:11 +01:00
Michael Cardell Widerkrantz
955c7e4736
Add hardcoded preloaded app size
- Enable TKEY_DEBUG
- Wait for something on CDC before continuing
2025-03-18 17:40:11 +01:00
Mikael Ågren
9e878c3288
Add script to load pre-loaded app into flash 2025-03-18 17:40:10 +01:00
Mikael Ågren
d239b952b0
fw: Replace custom picorv32 instructions in qemu target 2025-03-18 17:40:10 +01:00
Michael Cardell Widerkrantz
2cb5f2eca6
Add start of pre-loaded app from flash
Based on earlier code by Daniel Jobson <jobson@tillitis.se> now
integrated into the new world order.

Co-authored-by: Mikael Ågren <mikael@tillitis.se>
Co-authored-by: Daniel Jobson <jobson@tillitis.se>
2025-03-18 17:40:10 +01:00
Michael Cardell Widerkrantz
6ef6c36f6f
Add filesystem code and storage syscalls
Adds syscalls:

- ALLOCATE_AREA
- DEALLOCATE_AREA
- WRITE_DATA
- READ_DATA

and code to access the filesystem and the flash over SPI.

Based on original work by Daniel Jobson <jobson@tillitis.see> for
these files:

- auth_app.[ch]
- flash.[ch]
- spi.[ch]
- partition_table.[ch]
- rng.[ch]
- storage.[ch]

which are used with small changes to integrate with the new syscall
method.

Co-authored-by: Daniel Jobson <jobson@tillitis.se>
Co-authored-by: Mikael Ågren <mikael@tillitis.se>
2025-03-18 17:40:10 +01:00
Michael Cardell Widerkrantz
e86e60fcfe
Update firmware state machine
Include flash apps and states in firmware state machine description
and diagram.
2025-03-18 17:40:10 +01:00
Michael Cardell Widerkrantz
3195f2f21b
Clarify golden path
- Clarify what the default behaviour is.
- Clarify when we should halt CPU.
- Move common things when booting from flash and UART to its own
  section.
2025-03-18 17:40:10 +01:00
Michael Cardell Widerkrantz
bfda615f8c
doc: Add description on how firmware starts app from flash
A first attempt at describing how to start an app from flash and how
to handle information left in resetinfo from the previous app in the
chain.
2025-03-18 17:40:02 +01:00
Jonas Thörnblad
8d8f4c7faf
ch552: Misc. cleanup
- Merge Makefile and Makefile.include into Makefile
  - Format structure
  - Remove unused variables, targets etc.

- Add missing check if it is ok to send data to the FPGA.

- Remove 'baud rate calculator.ods'

- Update encode_usb_strings.py to generate strings for
  CdcCtrlInterfaceDesc, CdcDataInterfaceDesc,
  FidoHidInterfaceDesc, TkeyCtrlInterfaceDesc.
  Also store generated strings in UTF-16 instead of hex.

- Update usb_strings.h to match new encode_usb_strings.py
  output.

- Remove unused struct SetupReqBuf.
2025-03-14 09:49:26 +01:00
Michael Cardell Widerkrantz
33f14122ad
doc: Add note about building 2025-03-13 11:07:47 +01:00
Michael Cardell Widerkrantz
435b1f9d29
build: Update binary digests 2025-03-13 11:07:47 +01:00
Michael Cardell Widerkrantz
16a9e8c367
fw: Import tkey-libs fw-2
This is an import of the fw-2 tag of tkey-libs.

We import the entire tkey-libs repo minus dot files into the
tillitis-key1 repo to make it very simple not to make mistakes
regarding which firmware tag depends on which tkey-libs tag,
especially considering locking down with NVCM.

Please see README for information about developing with another
tkey-libs or how to import future tkey-libs.

Since tkey-libs is now a part of the repo we also add tkey-libs to the
clean_fw target.
2025-03-13 11:07:47 +01:00
Michael Cardell Widerkrantz
3dbc31f54c
fw: Move tk1_mem.h to tkey-libs
From now on the canonical home of the tk1_mem.h header file describing
the memory map of the TKey lives in tkey-libs:

https://github.com/tillitis/tkey-libs
2025-03-13 11:07:47 +01:00
Michael Cardell Widerkrantz
cd1a089763
fw: Build with tkey-libs
Build firmware, testfw and testapp using tkey-libs:

  https://github.com/tillitis/tkey-libs

In an effort not to have more or less identical code maintained in two
places, use tkey-libs when developing firmware, testfw and the
firmware testapp, too.

You can place the Git directory directly under hw/application_fpga
and then an ordinary make should work.

Or build with:

  make LIBDIR=/path/to/tkey-libs

Co-authored-by: Mikael Ågren <mikael@tillitis.se>
2025-03-13 11:07:36 +01:00
Sasko Simonovski
1d5d721f1e
README: Added section about work in progress. 2025-03-07 15:24:27 +01:00
Mikael Ågren
a41360917a
build: Update digests of firmware and bitstream 2025-02-27 14:35:23 +01:00
Mikael Ågren
b524cd0d6e
fpga: Update next-pnr seed to reach 24 MHz 2025-02-27 14:35:23 +01:00
Michael Cardell Widerkrantz
ad62f6e48f
doc: Update release notes about syscall mechanism 2025-02-27 14:35:22 +01:00
Mikael Ågren
c52442b54c
doc: Update documentation about syscalls
- Revise firmware implementation notes
- Document how to do fw syscalls
  - Document how to trigger a syscall function in the firmware, how to
    pass arguments, what the caller is responsible for and what is
    returned.
- Describe hardware syscall implementation
  - how the syscall interrupts are triggered,
  - the hardware privilege escalation,
  - the UDS protection.

Co-authored-by: Daniel Jobson <jobson@tillitis.se>
Co-authored-by: Michael Cardell Widerkrantz <mc@tillitis.se>
2025-02-27 14:35:22 +01:00
Mikael Ågren
7554787678
fpga: Add extra access control on UDS
Restrict access to UDS when we have exited firmware the first time.

Co-authored-by: Michael Cardell Widerkrantz <mc@tillitis.se>
2025-02-27 14:35:22 +01:00
Mikael Ågren
77fc5cf578
fpga: Only allow system reset in firmware mode and syscalls 2025-02-27 14:29:07 +01:00
Mikael Ågren
9e317666d3
fpga/fw: Remove SYSTEM_MODE_CTRL register 2025-02-27 14:29:07 +01:00
Michael Cardell Widerkrantz
df04fd56dd
fpga/fw: Introduce syscall TK1_SYSCALL_GET_VIDPID
Introduce new syscall TK1_SYSCALL_GET_VIDPID to get Vendor ID and
Product ID from the protected Unique Device Identification number.

UDI is protected from device apps to protect the serial number, so
apps won't know the exact TKey they are running on other than the CDI.
It may, however, be important to know what *kind* of TKey they are
running on, so we want to expose the Vendor ID and Product ID.

- fpga: Allow UDI to be read when doing syscalls.
- Add the new syscall to firmware.
- Add test to testapp directly after negative test of reading UDI to
  read out VID/PID through a syscall.
2025-02-27 14:29:07 +01:00
Mikael Ågren
13f40561ab
testapp: Call reset syscall 2025-02-27 14:29:06 +01:00
Mikael Ågren
4ba164732d
testapp: Add syscalls 2025-02-27 14:29:06 +01:00
Mikael Ågren
fed9354fe9
testfw/testapp: Break out tests running in app mode into separate app
App mode can no longer be controlled from software. So the tests have to
run from firmware RAM.
2025-02-27 14:27:12 +01:00
Mikael Ågren
d82c3a706e
fw: Add syscalls
Adds:
- SYSCALL_RESET
- SYSCALL_SET_LED

Co-authored-by: Michael Cardell Widerkrantz <mc@tillitis.se>
2025-02-27 14:27:05 +01:00
Mikael Ågren
969df46315
tb: Test ROM execution protection 2025-02-27 14:20:40 +01:00
Mikael Ågren
0ee971e38c
tb: Expand existing tests with access checks in app mode and syscalls
Checks availability of:
- CDI
- UDI
- RAM
- SPI
2025-02-27 14:20:39 +01:00