Tobias Wölfel | 03d1cf3 | 2020-02-26 12:47:07 +0100 | [diff] [blame] | 1 | --- |
| 2 | title: "OpenTitan Software" |
| 3 | --- |
| 4 | |
| 5 | This is the landing spot for software documentation within the OpenTitan project. |
Tobias Wölfel | 03d1cf3 | 2020-02-26 12:47:07 +0100 | [diff] [blame] | 6 | More description and information can be found within the [Reference Manual]({{< relref "doc/rm" >}}) and [User Guide]({{< relref "doc/ug" >}}) areas. |
| 7 | |
Sam Elliott | ed5086c | 2020-11-24 19:12:09 +0000 | [diff] [blame] | 8 | There are three major parts to the OpenTitan software stack: |
Sam Elliott | b6745d3 | 2020-04-08 21:46:28 +0100 | [diff] [blame] | 9 | |
Sam Elliott | ed5086c | 2020-11-24 19:12:09 +0000 | [diff] [blame] | 10 | * The _device_ software, which runs on the primary core within the OpenTitan platform chip. |
| 11 | * The _otbn_ software, which runs on the OTBN cryptographic co-processor within the OpenTitan platform chip. |
| 12 | * The _host_ software, which is run on a host device and interacts with an OpenTitan device. |
Sam Elliott | b6745d3 | 2020-04-08 21:46:28 +0100 | [diff] [blame] | 13 | |
Sam Elliott | ed5086c | 2020-11-24 19:12:09 +0000 | [diff] [blame] | 14 | We use the term "image" to denote a complete, standalone executable which has been prepared for the OpenTitan platform chip. |
| 15 | This is to differentiate from a "library", which is a collection of functions that are not complete enough to run on their own. |
| 16 | |
| 17 | # Device Software |
| 18 | |
| 19 | This software runs on the primary core within the OpenTitian platform chip itself. |
| 20 | You can find all the device software in the `sw/device` directory of the repository. |
| 21 | |
| 22 | The device software is split into two parts: |
| 23 | * The reference firmware images, which is the project's reference implementation of the Secure Boot system. |
| 24 | Not all OpenTitan chips will use exactly the same firmware images. |
| 25 | * The firmware libraries, which can be used by any software built for the device. |
| 26 | |
| 27 | Device software must be written in C, Assembly, or Rust. |
| 28 | |
| 29 | ## Reference Firmware Images |
| 30 | |
| 31 | The OpenTitan Reference Firmware Images together make up the Opentitan Reference Firmware Stack. |
| 32 | Different images are used for different boot stages. |
| 33 | |
| 34 | The Reference Firmware Images are, in boot order: |
| 35 | 1. The [Mask ROM]({{< relref "sw/device/mask_rom/docs" >}}) (in `sw/device/mask_rom`), executed at chip reset; |
| 36 | 2. The ROM_EXT (in `sw/device/rom_exts`), the second stage Silicon Creator code, executed from flash; and |
| 37 | 3. The [Tock Image]({{< relref "sw/device/tock/README.md" >}}) (in `sw/device/tock`), the Silicon Owner code, also executed from flash. |
| 38 | |
| 39 | ### Testing-only Images |
| 40 | |
| 41 | There are also some other standalone firmware images in the repository, which are only used for testing. |
| 42 | |
| 43 | * [`sw/device/tests`]({{< relref "sw/device/tests/README.md" >}}) contains many standalone smoke test images. |
| 44 | This directory also contains unit tests for software modules, which are executed on host (not device) systems using [GoogleTest](https://github.com/google/googletest). |
| 45 | |
| 46 | * [`sw/device/benchmarks/coremark`]({{< relref "sw/device/benchmarks/coremark/README.md" >}}) contains infrastructure for running the [CoreMark](https://github.com/eembc/coremark) benchmark suite on the OpenTitan device. |
| 47 | * `sw/device/riscv_compliance_support` contains infrastructure so we can run the [RISC-V Compliance](https://github.com/riscv/riscv-compliance) tests on the OpenTitan core. |
| 48 | * `sw/device/sca` contains on-device software used for Side-Channel Analysis. |
| 49 | * `sw/device/prebuilt` contains pre-built Tock images, which may not be up-to-date. |
| 50 | * `sw/device/examples` contains example images, including a simple [Hello World]({{< relref "sw/device/examples/hello_world/README.md" >}}). |
| 51 | |
| 52 | There are also prototype versions of some of the boot stages, now only used for testing: |
| 53 | * [`sw/device/boot_rom`]({{< relref "sw/device/boot_rom/README.md" >}}) is a previous, testing-only version of the Mask ROM. |
| 54 | * `sw/device/exts` contains software for our prototype second boot stage images. |
| 55 | |
| 56 | ## Firmware Libraries |
| 57 | |
| 58 | |
| 59 | The OpenTitan repository also contains device libraries which are used within our Reference Firmware Images, and can (and should) be used by other OpenTitan device software. |
| 60 | |
| 61 | These are organised into the `sw/device/lib` directory. |
| 62 | |
| 63 | * [`sw/device/lib/base`]({{< relref "sw/device/lib/base/README.md" >}}) contains the Base Libraries, including [freestanding C library headers]({{< relref "sw/device/lib/base/freestanding/README.md" >}}). |
| 64 | The Base Libraries are simple libraries that can be used by any other OpenTitan device software libraries. |
| 65 | * [`sw/device/lib/dif`]({{< relref "sw/device/lib/dif/README.md" >}}) contains the [Device Interface Functions]({{< relref "doc/rm/device_interface_functions.md" >}}). |
| 66 | * [`sw/device/lib/arch`]({{< relref "sw/device/lib/arch/README.md" >}}) contains the libraries to be used on specific device configurations (for instance FPGA, Simulation, etc.). |
| 67 | * [`sw/device/lib/runtime`]({{< relref "sw/device/lib/runtime/README.md" >}}) contains general libraries for more advanced on-device functionality (including logging, printing, and interacting with the RISC-V core). |
| 68 | |
| 69 | # OTBN Software |
| 70 | |
| 71 | This software runs on the OTBN cryptographic co-processor within the OpenTitan platform chip. |
| 72 | You can find all the OTBN software in the `sw/otbn` directory of the repository. |
| 73 | |
| 74 | This software consists of a number of hand-written assembly routines which can be run on the OTBN co-processor. |
| 75 | |
| 76 | Normally, this software can not be run on its own, and the main processor has to set up the data and instructions for the OTBN co-processor before it triggers the start of execution. |
| 77 | |
| 78 | OTBN Software must only be written in Assembly. |
| 79 | |
| 80 | # Host Software |
| 81 | |
| 82 | This software is for host-side use, either in preparing images or interacting with a running OpenTitan platform chip. |
| 83 | You can find all the device software in the `sw/host` directory of the repository. |
| 84 | |
| 85 | Host software must be written in C++ or Rust. |
| 86 | |
| 87 | ## Testing-only Utilities |
| 88 | |
| 89 | There are some host-side utilities, which are only used for testing. |
| 90 | * `sw/host/spiflash` is a tool that can flash a testing image over SPI onto a chip that uses `sw/device/boot_rom` for its reset boot stage. |
| 91 | |
| 92 | # Other Documentation |
| 93 | |
| 94 | ## OpenTitan Software API Documentation {#sw-api-docs} |
Sam Elliott | b6745d3 | 2020-04-08 21:46:28 +0100 | [diff] [blame] | 95 | |
| 96 | The [OpenTitan Software API Documentation](/sw/apis/) contains automatically generated documentation for the public software APIs. |
| 97 | This includes the Device Interface Functions (DIFs). |
| 98 | |
| 99 | All DIFs are also documented on their respective [Hardware IP Specification]({{< relref "hw" >}}) |
| 100 | |
Sam Elliott | ed5086c | 2020-11-24 19:12:09 +0000 | [diff] [blame] | 101 | ## Vendored in Code see [Vendor Tool User Guide]({{< relref "doc/ug/vendor_hw.md" >}}) |
Tobias Wölfel | a47a415 | 2020-06-02 20:35:28 +0200 | [diff] [blame] | 102 | |
| 103 | * [CoreMark](https://github.com/eembc/coremark) |
| 104 | * [RISC-V Compliance](https://github.com/riscv/riscv-compliance) |
Sam Elliott | ed5086c | 2020-11-24 19:12:09 +0000 | [diff] [blame] | 105 | * [GoogleTest](https://github.com/google/googletest) |
Tobias Wölfel | a47a415 | 2020-06-02 20:35:28 +0200 | [diff] [blame] | 106 | * [Cryptoc](https://chromium.googlesource.com/chromiumos/third_party/cryptoc/) |
Sam Elliott | ed5086c | 2020-11-24 19:12:09 +0000 | [diff] [blame] | 107 | * [MPSSE from Chromium](https://chromium.googlesource.com/chromiumos/platform2/+/master/trunks/ftdi) |
| 108 | * [LLVM's Compiler-RT Coverage Profiling Library](https://github.com/llvm/llvm-project/tree/master/compiler-rt) |