91 Commits

Author SHA1 Message Date
Mikael Ågren
7755716b1e
Format c code 2025-04-11 11:55:04 +02:00
Michael Cardell Widerkrantz
a3bdc73efa
fw: Simplify starting management app
- In state INITIAL: Register allowed app digest early for the default
  case where we start from flash slot 0. Transition to LOAD_FLASH_MGMT.

- Introduce new state FW_STATE_LOAD_FLASH_MGMT which loads an app from
  flash slot 0 and registers app as a prospective management app.

- Rely on ordinary verification in state START to actually do the
  verification of the prospective management app.
2025-04-11 09:38:04 +02:00
Michael Cardell Widerkrantz
767be4fd43
fw: Change flash 1 and flash 2 to flash 0 and 1 2025-04-11 09:38:04 +02:00
Michael Cardell Widerkrantz
3edc0001e6
fw: Fix splint complaints
- Make splint work on current code.
- Check error return values.
- Cast to void when not caring about result.
- Declare internal functions to be static.
2025-04-11 09:38:03 +02:00
Mikael Ågren
8562f08e2c
fw: Check for NULL pointer in copy_name 2025-04-11 09:38:03 +02:00
Mikael Ågren
65e67b604d
fw: Check NULL pointer in main.c 2025-04-11 09:38:02 +02:00
Mikael Ågren
abc1fc8280
fw: Remove leftover debug usage of puts/readselect/read 2025-04-11 09:38:00 +02:00
Mikael Ågren
c14f8d634a
check fix: Mark argument to debug function as unused
The md argument will only be used when compiling with debug_ functions
enabled
2025-04-11 09:37:59 +02:00
Michael Cardell Widerkrantz
3d4f177359
fw: Remove define about size of app in app slot 0 2025-04-11 09:37:57 +02:00
Michael Cardell Widerkrantz
dd641118b8
fw: Use BLAKE2s functions from tkey-libs
Instead of using the firmware's own copy of BLAKE2s functions, use the
functions from tkey-libs.
2025-04-11 09:37:57 +02:00
Mikael Ågren
16e478a993
fw: Use existing compute_app_digest function when loading from client 2025-04-11 09:37:56 +02:00
Michael Cardell Widerkrantz
dc9f2c6750
fw: Simplify state machine
- Remove state FW_STATE_CDI.
- Add CDI calculation to FW_STATE_START.
- Go directly to FW_STATE_START from both _LOAD_FLASH and _LOADING.
2025-04-11 09:37:55 +02:00
Mikael Ågren
6d76bdeafd
fw: Read pre loaded app 0 size from flash 2025-04-11 09:37:54 +02:00
Michael Cardell Widerkrantz
4c29de23dc
Update length and digest of testloadapp 2025-04-11 09:37:52 +02:00
Mikael Ågren
f24c7ea515
fw: Add checksum to partition table
Refuse to boot if blake2s digest over the partition table does not match
digest stored on flash
2025-04-11 09:37:51 +02:00
Mikael Ågren
b837eec9e6
fw: Remove TK1_SYSCALL_REG_MGMT
Validate preload API access using the fixed, pre-calculated app digest
instead of letting an app register itself as a management app.
2025-04-11 09:37:49 +02:00
Mikael Ågren
715d792d86
fw: Remove pre loaded app auth and status from partition table 2025-04-11 09:37:49 +02:00
Michael Cardell Widerkrantz
29638a99a0
fw: Only allow a specific app to start from first flash
Store size and app digest in ROM and compare to what we are booting.
2025-04-11 09:37:48 +02:00
Mikael Ågren
12916f9736
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-04-11 09:37:47 +02:00
Mikael Ågren
9018ae5b33
Store app digest and signature for each app slot 2025-04-11 09:37:45 +02:00
Mikael Ågren
ac5c2aef86
fw: Add second pre-loaded app slot in flash 2025-04-11 09:37:44 +02:00
Mikael Ågren
1c4d11f49e
fw: When requested, verify app digest before running 2025-04-11 09:37:44 +02:00
Mikael Ågren
e4028d9a86
Handle reset info in reset syscall
Disabling debug printouts to get firmware to fit in ROM
2025-04-11 09:37:44 +02:00
Michael Cardell Widerkrantz
ba9e08fcdb
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-04-11 08:43:41 +02:00
Michael Cardell Widerkrantz
ab12c201c4
Experiment with new state machine 2025-04-11 08:43:41 +02:00
Michael Cardell Widerkrantz
6ef1b1c659
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-04-11 08:43:40 +02:00
Michael Cardell Widerkrantz
9316886c88
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-04-11 08:43:40 +02:00
Michael Cardell Widerkrantz
a20bcdab29
Make run_flash() and run() both call jump_to_app() 2025-04-11 08:43:40 +02:00
Michael Cardell Widerkrantz
820c273e7f
Add hardcoded preloaded app size
- Enable TKEY_DEBUG
- Wait for something on CDC before continuing
2025-04-11 08:43:39 +02:00
Michael Cardell Widerkrantz
f2b78be4cb
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-04-08 11:00:59 +02:00
Michael Cardell Widerkrantz
20b008d20e
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-04-08 11:00:59 +02: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
Mikael Ågren
9e317666d3
fpga/fw: Remove SYSTEM_MODE_CTRL register 2025-02-27 14:29:07 +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
Michael Cardell Widerkrantz
5eb020275b
fpga/fw/testfw: Remove Blake2s register
Since the introduction of the syscall mechanism we don't allow
execution in ROM anymore so it's impossible to call the firmware's
blake2s() function.

Co-authored-by: Mikael Ågren <mikael@tillitis.se>
2025-02-27 14:20:38 +01:00
Mikael Ågren
97de5e68fd
fpga/fw: Rename system_mode to app_mode
Rename `system_mode` to `app_mode` as to not confuse it with syscall or
firmware mode. When `app_mode` is `1`/`true` we are in app mode.
2025-02-27 14:20:37 +01:00
Jonas Thörnblad
8f2f312531
fpga/fw: Resize ROM and FW_RAM, add RESETINFO partition
In order to be able to leave data for firmware signalling the
intention with a reset or to leave data for the next app in a chain of
apps, we introduce a part of FW_RAM that can be used to store this
data. In order to do this, we:

- Change size of ROM from 6 KB to 8 KB.
- Change size of FW_RAM, from 2 KB to 4 KB.
- Add RESETINFO memory partition inside FW_RAM.
- Add generation of map file.
- Change CFLAGS from using -O2 to using -Os.
- Update address ranges for valid access to ROM and FW_RAM.
- Move stack to be located before data+bss and the RESETINFO data
  above them. This also means we introduce hardware stack overflow
  protection through the Security Monitor.
- Revise firmware README to the new use of FW_RAM.
2025-02-21 11:15:34 +01:00
Mikael Ågren
a0c031eb25
fw: Minimal CDC implementation of new framing protocol
Throwing away mode and length from incoming data. Adding mode and
length to outgoing data.

Splitting responses into frames small enough for the USB<->UART
transceiver to handle.
2025-02-11 13:50:03 +01:00
Jonas Thörnblad
15ce2c438b
Add needed changes to firmware for simulation. 2024-11-28 16:10:00 +01:00
Jonas Thörnblad
aea2e319eb
Harmonize the naming of firmware and app mode.
- The API changes name from `_SWITCH_APP` to `_SYSTEM_MODE_CTRL`.
- The registers and wires changes name to `system_mode_*`, instead of a
  mix of `switch_app_*` and `fw_app_mode`.
2024-11-12 15:13:59 +01:00
Joachim Strömbergson
53c5e70795
FPGA: Update names for RAM randomization API
Update:
- README
- testbench
- Symbolic names and variables in fw
- registers
- port name and wires
- Update fpga and fw digests

Signed-off-by: Joachim Strömbergson <joachim@assured.se>
2024-07-10 13:45:26 +02:00
dehanj
b4c525695a
Remove redundant RAM address and data scrambling
The RAM address and data scrambling API was called twice, once before filling
RAM with random values, and once after. Since moving to a significantly
better PRNG (xorwow) this is now deemed unnecessary. See issue #225.

This changes both FPGA and firmware hashes.
2024-06-13 12:54:47 +02:00
Joachim Strömbergson
eade3e11c5
Fill RAM with random data using xorwow.
xorwow provides significantly better random data, compared to previously
used function. Making it harder to predict what data RAM is filled with.
It adds a startup time of approx 80 ms, but can be compensated with
optimising other parts of the startup routine.

This changes both firmware and fpga hashes.

Signed-off-by: Joachim Strömbergson <joachim@assured.se>
2024-06-11 11:15:00 +02:00
dehanj
4bd249816a
fw: Remove unused header includes 2024-03-26 13:09:06 +01:00
dehanj
3a6a60ff26
fw: Protect zeroisation against compiler optimisation.
The memset() responsible for the zeroisation of the secure_ctx under
the compute_cdi() function in FW's main.c, was optimised away by the
compiler. Instead of using memset(), secure_wipe() is introduced
which uses a volatile keyword to prevent the compiler to try to
optimise it. Secure_wipe() is now used on all locations handling
removal of sensitive data.
2024-03-26 13:09:01 +01:00
Michael Cardell Widerkrantz
09c1f3f549
Silence splint somewhat
The only real changes are some unitialized variables and that we now
make explicit that we don't care about the return value from memset().
2024-03-22 11:03:13 +01:00
Michael Cardell Widerkrantz
4d4db70590
fw: Change ASLR name in MMIO
Use _RAM_ADDR_RAND instead of _RAM_ASLR since this is not OS-level
ASLR we're talking about. It's address randomization as seen from
outside of the CPU, not from the process running inside it. Ordinary
ASLR is visible from the CPU.
2024-03-19 14:36:31 +01:00
Michael Cardell Widerkrantz
e085d0ebd0
Add void to function signatures meant to be used without args 2024-03-19 08:41:39 +01:00
dehanj
9d36acde08
FW: Force the CPU to hang on errors 2024-03-14 15:48:10 +01:00