Commit Graph

567 Commits

Author SHA1 Message Date
Daniel Jobson
c7e44d3575
Update tk1/README and fpga README regarding system mode
Updates Readme with:
- Dynamic execution mode control in hardware
- ROM execution
- Syscall API
- Sensitive assets only read-/writable before first switch to app mode
- SPI master only accessible in firmware mode
2024-12-09 13:26:42 +01:00
Mikael Ågren
04eefe01fa
Fix tb_tk1.v tests broken when implementing hw controlled system mode 2024-12-09 13:26:42 +01:00
Daniel Jobson
2abe93cf06
Make sensitive assets only readable/writable before system_mode is set
After the first time system_mode is set to one, the assets will no
longer be read- or writeable, even if system_mode is set to zero at a
later syscall. This is to make sure syscalls does not have the same
privilege as the firmware has at first boot.

We need to monitor when system_mode is set to one, otherwise we might
accedentially lock the assets before actually leaving firmware, for
example if firmware would use a function set in any of the registers
used in system_mode_ctrl.

Co-authored-by: Mikael Ågren <mikael@tillitis.se>
2024-12-09 13:26:42 +01:00
Daniel Jobson
690bb53267
Introduce new bit to mark ROM as non-executable
This is dynamically set by hw in system_mode_ctrl. ROM will reset to
executable, but will be marked as non-executable as soon as we are no
longer executing in ROM, like system_mode.

ROM will be marked as executable again, if function calls are made to
either `syscall_addr_reg` or `blake2s_addr_reg`. Set reset value of
`blake2s_addr_reg` to an illegal address, halting the CPU if it is
called unset.

The blake2s function is 4-byte aligned, to ensure the cpu_addr is is
aligned with the address in the register.

Co-authored-by: Mikael Ågren <mikael@tillitis.se>
2024-12-09 09:36:57 +01:00
Daniel Jobson
9062b49804
Deny access to the SPI master in app mode
Co-authored-by: Mikael Ågren <mikael@tillitis.se>
2024-12-09 09:33:03 +01:00
Daniel Jobson
8c6ab6902d
Automatically control system_mode in hardware
Raise privilege (go to firmware mode) when a function call occurs
to the function set in syscall_addr_reg. Automatically revoke privilege
when executing above ROM (go to app mode).

Remove the option of writing to system_mode through the API.

Co-authored-by: Mikael Ågren <mikael@tillitis.se>
2024-12-09 09:33:02 +01:00
Daniel Jobson
31708a39d3
Add API for syscall
Add a register to store an address to a syscall function defined in
firmware. Set the reset value to an illegal address, to make sure a call
to an unset address will halt the CPU.

Co-authored-by: Mikael Ågren <mikael@tillitis.se>
2024-12-09 09:33:02 +01:00
Jonas Thörnblad
07dec8b8dc
Add make target for testbench simulation and simulation firmware.
Create separate sources for FPGA specific code, testbench simulation
specific code, verilator simulation specific code.
2024-11-28 16:10:01 +01:00
Jonas Thörnblad
ede92af2c1
Updated application_fpga_verilator.cc to match module application_fpga_sim.
- include printout of used clock and baud rate speed
- Use the the same clock frequency as target
2024-11-28 16:10:01 +01:00
Jonas Thörnblad
48c9709164
Set APP_SIZE if not defined. 2024-11-28 16:10:01 +01:00
Jonas Thörnblad
a99e69f33e
Remove non-working make targets for "post-synthesis functional simulation"
and "post-place and route functional simulation".
2024-11-28 16:10:00 +01:00
Jonas Thörnblad
15ce2c438b
Add needed changes to firmware for simulation. 2024-11-28 16:10:00 +01:00
Jonas Thörnblad
fe9055ea23
Add script to split app into simulation ram
Co-authored-by: Mikael Ågren <mikael@tillitis.se>
2024-11-28 16:10:00 +01:00
Jonas Thörnblad
3cd902f792
Add top level testbench for application_fpga_sim.v 2024-11-28 16:10:00 +01:00
Jonas Thörnblad
4260e1d5ac
Update application_fpga_sim.v to match application_fpga.v 2024-11-28 16:10:00 +01:00
Jonas Thörnblad
a330aa15ec
Add verilog file for TRNG simulation 2024-11-28 16:10:00 +01:00
Jonas Thörnblad
d3b9660180
Align module name with its file name. 2024-11-28 16:09:59 +01:00
Jonas Thörnblad
e54045a4dd
Add APP_SIZE parameter to tk1 block to set size of application when simulating. 2024-11-28 16:09:59 +01:00
Daniel Jobson
5b49d80891
tb: make timer core testbench selftesting
- Compare against an expected result and count errors
- Exit with the right error code
- Clean up the output
2024-11-27 08:10:15 +01:00
Daniel Jobson
c735c6fdde
tb: make tb_timer.v selftesting
- Compare against an expected result and count errors
- Exit with the right error code
- Lower write_word() to 1 clk cycle instead of two. It only requires one
  clock cycle to write, otherwise if it is two one have to compensate for it
  in the tests since we are counting cycles.
2024-11-27 08:10:15 +01:00
Daniel Jobson
6bdedf4f86
Fix bug in timer core, where it misses clock cycles
Remove redundant timer state. This fixes a bug where the timer misses a
clock cycle every time the prescaler counter reaches 1. This means if
one uses a large prescaler, like 18E6, it is barely noticeable, but if
one have a low prescaler and a high timer value it becomes significant.
This also yields the running_* registers redundant, which are removed.

Add clarity to the readme.

Update the timer to default to values of one, for prescaler and timer
count.
2024-11-27 08:10:15 +01:00
Daniel Jobson
3d7a97ecbc
fpga: remove the API for configuring the UART core
This removes the possibility to configure the bit rate, data bits and
stop bits at runtime from the API. This reduces the
usage of LCs with ~4%.

It is still possible to configure the core before building.

Update digest of application_fpga.bin.sha256
2024-11-26 15:24:12 +01:00
Jonas Thörnblad
0445c8f993
Add nextpnr flag '--exit-on-failed-target-frequency' 2024-11-22 15:47:42 +01:00
Jonas Thörnblad
08a204dfa6
Minimize number of Dockerfile RUN commands to lower number of
used layers in the image. Too many layers will give an error.
2024-11-22 15:47:41 +01:00
Daniel Jobson
1941a22007
Doc: move implementation details of RAM scrambling to RAM core 2024-11-20 15:48:49 +01:00
Michael Cardell Widerkrantz
de8fcb8768
Remove DCO document 2024-11-20 15:48:49 +01:00
Michael Cardell Widerkrantz
ebd6b17966
Revise top-level README
- Simplify.
- Update links.
- Remove DCO link
2024-11-20 15:48:49 +01:00
Michael Cardell Widerkrantz
86aedcce69
Revise top-level README for the hardware design
Merged information from fpga.md, and hence fpga.md is removed.
2024-11-20 15:48:49 +01:00
Michael Cardell Widerkrantz
9f975bb66f
Add clangd target
Create a compile_commands.json to help clangd for LSP.
2024-11-15 15:01:31 +01:00
Michael Cardell Widerkrantz
fe8f0b1aa9
doc: Harmonize preformatted in tk1 core
- No unnecessary indentation
- Mark API constants as preformatted
2024-11-15 15:01:31 +01:00
Michael Cardell Widerkrantz
7043521ba9
Move high level system description to README in application_fpga 2024-11-15 15:01:31 +01:00
Michael Cardell Widerkrantz
6e2a77f885
Remove quickstart for the old OSFC dev kit 2024-11-15 15:01:31 +01:00
Jonas Thörnblad
7dc72ade04
Updated application_fpga.bin.sha256 with new hash 2024-11-14 16:35:51 +01:00
Jonas Thörnblad
1b3bae334a
Change "rosc" references to "trng" 2024-11-14 16:35:51 +01:00
Jonas Thörnblad
2364466a9e
Rename rosc.v to trng.v 2024-11-14 16:35:51 +01:00
Jonas Thörnblad
49189a3ba7
Fix typo 2024-11-14 16:35:50 +01:00
Jonas Thörnblad
1ea5db1179
Renamed sb_rgba_drv.v to sb_rgba_drv_sim.v 2024-11-14 16:35:29 +01:00
Jonas Thörnblad
2b89b28b82
Fix small TRNG testbench issues 2024-11-14 11:09:33 +01:00
Daniel Jobson
c4e8f6b6fb
Doc: fix typo of system mode in readme 2024-11-13 14:13:02 +01:00
Daniel Jobson
b90bbea1f6
Remove duplicate entries in default values assignment of tk1 api
cpu_mon_en_we and cdi_mem_we was set twice
2024-11-13 11:16:05 +01:00
Jonas Thörnblad
330146ba3a
Rename top level simulation files
* Rename application_fpga_vsim.v and reset_gen_vsim.v to
  application_fpga_sim.v and reset_gen_sim.v
* Update Makefile
* Fix a typo
2024-11-12 15:33:33 +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
Daniel Jobson
69ef6dde8b
Remove production_test files
production_test related files are moved out of this repository, since it
relates to production of the hardware and not the fpga construction or
firmware.
2024-10-25 13:20:50 +02:00
Mikael Ågren
a32ecade54
Fix flash target in contrib/Makefile
Setting the working directory to a directory that exist.

Previously the working directory was set to /build/hw/application_fpga.
But that path does not exist since hw/application_fpga was mounted to
/build. Thus resulting in an error:
'Error: workdir "/build/hw/application_fpga" does not exist on
container'
2024-10-25 12:55:27 +02:00
Jonas Thörnblad
c6e8b6930c
Add place and route script
Run multiple threads of nextpnr-ice40 to find a seed that gives a
layout that meets timing.
2024-10-22 15:20:39 +02:00
Jonas Thörnblad
8af048fb9a
Add yosys flags to optimize synthesis
* -abc2, run two passes of 'abc' for slightly improved logic density
  * -device u, optimize timing for up5k device
  * -dff, run 'abc'/'abc9' with -dff (D flip flop) option

  Update digest of application_fpga.bin
2024-10-22 12:46:12 +02:00
Jonas Thörnblad
3514d7ef3c
FPGA: Format verilog code 2024-10-22 12:04:19 +02:00
Jonas Thörnblad
e04aacda48
Add make target to format verilog code using verible-verilog-format
Flags:
        --indentation_spaces=2
        --wrap_end_else_clauses=true

Verify flag, used in checkfmt, only returns error if the last file is
not formatted, temporary fix implemented with grep.
2024-10-22 12:04:19 +02:00
Daniel Jobson
70986a1840
Doc: fix broken links, update system_description regarding data and
address randomization and fix typos
2024-10-17 16:21:32 +02:00
Daniel Jobson
1d6830adf7
Swap to a newer picture of the TKey for the readme 2024-10-17 16:21:32 +02:00