Woyten | fbf1ffc | 2018-03-19 23:10:33 +0100 | [diff] [blame] | 1 | [](https://travis-ci.org/tock/libtock-rs) |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 2 | |
Amit Levy | bf8fec8 | 2017-05-10 14:43:48 -0400 | [diff] [blame] | 3 | # libtock-rs |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 4 | |
Amit Levy | bf8fec8 | 2017-05-10 14:43:48 -0400 | [diff] [blame] | 5 | Rust userland library for Tock (WIP) |
Pat Pannuto | 287a8ae | 2017-05-10 18:19:21 -0400 | [diff] [blame] | 6 | |
Alistair Francis | 073efcc | 2020-06-08 09:30:21 -0700 | [diff] [blame] | 7 | Generally this library was tested with tock [Release 1.5](https://github.com/tock/tock/releases/tag/release-1.5). |
| 8 | Since then changes have been made that might not work with the Tock |
| 9 | release 1.5, but instead target Tock master. For example this library |
| 10 | might support newer boards (Apollo3), changed boards (HiFive1 revB) or |
| 11 | new drivers (HMAC). |
Florian Hars | 5cf866b | 2019-10-14 02:32:51 +0200 | [diff] [blame] | 12 | |
Florian Hars | 70791a3 | 2019-10-14 18:32:56 +0200 | [diff] [blame] | 13 | The library works in principle on most boards, but there is currently the [showstopper |
Florian Hars | 5cf866b | 2019-10-14 02:32:51 +0200 | [diff] [blame] | 14 | bug #28](https://github.com/tock/libtock-rs/issues/28) that prevents |
| 15 | the generation of relocatable code. This means that all applications |
| 16 | must be installed at the flash address they are compiled with, which |
Florian Hars | 70791a3 | 2019-10-14 18:32:56 +0200 | [diff] [blame] | 17 | usually means that they must be compiled especially for your board |
| 18 | and that there can only be one application written in rust at a time |
Florian Hars | 5cf866b | 2019-10-14 02:32:51 +0200 | [diff] [blame] | 19 | and it must be installed as the first application on the board, unless |
| 20 | you want to play games with linker scripts. |
Alistair Francis | b3e3a9a | 2020-03-09 16:36:44 -0700 | [diff] [blame] | 21 | There are some `boards/layout_*.ld` files provided that allow to run the |
Florian Hars | 7d9d856 | 2019-10-16 11:56:54 +0200 | [diff] [blame] | 22 | examples on common boards. |
| 23 | Due to MPU region alignment issues they may not work for applications |
| 24 | that use a lot of RAM, in that case you may have to change the SRAM |
| 25 | start address to fit your application. |
Philipp Vollmer | 090398c | 2018-06-29 15:14:54 +0200 | [diff] [blame] | 26 | |
Pat Pannuto | 287a8ae | 2017-05-10 18:19:21 -0400 | [diff] [blame] | 27 | ## Getting Started |
| 28 | |
| 29 | This project is nascent and still under heavy development, but first steps: |
| 30 | |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 31 | 1. Ensure you have [rustup](https://www.rustup.rs/) installed. |
Pat Pannuto | 00bb198 | 2017-08-17 00:02:37 -0700 | [diff] [blame] | 32 | |
JOE1994 | ddacb12 | 2020-04-27 17:31:43 -0400 | [diff] [blame] | 33 | 1. Clone the repository: |
Teddy Katz | bc37685 | 2018-04-02 16:39:46 -0400 | [diff] [blame] | 34 | |
Alistair Francis | 0c1cb58 | 2020-03-10 13:49:40 -0700 | [diff] [blame] | 35 | ```shell |
Johnathan Van Why | 8580c47 | 2020-06-17 09:03:06 -0700 | [diff] [blame] | 36 | git clone --recursive https://github.com/tock/libtock-rs |
Woyten | 97b27b0 | 2018-06-19 20:44:59 +0200 | [diff] [blame] | 37 | cd libtock-rs |
| 38 | ``` |
| 39 | |
JOE1994 | ddacb12 | 2020-04-27 17:31:43 -0400 | [diff] [blame] | 40 | 1. Install the dependencies: |
Woyten | 97b27b0 | 2018-06-19 20:44:59 +0200 | [diff] [blame] | 41 | |
Alistair Francis | 0c1cb58 | 2020-03-10 13:49:40 -0700 | [diff] [blame] | 42 | ```shell |
| 43 | make setup |
Teddy Katz | bc37685 | 2018-04-02 16:39:46 -0400 | [diff] [blame] | 44 | ``` |
| 45 | |
JOE1994 | ddacb12 | 2020-04-27 17:31:43 -0400 | [diff] [blame] | 46 | 1. Use `make` to build examples |
Teddy Katz | bc37685 | 2018-04-02 16:39:46 -0400 | [diff] [blame] | 47 | |
Alistair Francis | 0c1cb58 | 2020-03-10 13:49:40 -0700 | [diff] [blame] | 48 | ```shell |
| 49 | make nrf52 # Builds all examples for the nrf52 platform |
Teddy Katz | bc37685 | 2018-04-02 16:39:46 -0400 | [diff] [blame] | 50 | ``` |
| 51 | |
torfmaster | 02f000a | 2020-01-05 02:16:00 +0100 | [diff] [blame] | 52 | ```bash |
Alistair Francis | 0c1cb58 | 2020-03-10 13:49:40 -0700 | [diff] [blame] | 53 | make opentitan # Builds all examples for the OpenTitan platform |
Woyten | 860e0bc | 2020-01-29 21:17:14 +0100 | [diff] [blame] | 54 | ``` |
torfmaster | cf1018c | 2019-02-11 19:35:24 +0100 | [diff] [blame] | 55 | |
Alistair Francis | 55e3d6b | 2020-03-10 14:04:22 -0700 | [diff] [blame] | 56 | ```bash |
| 57 | make opentitan FEATURES=alloc # Builds all examples for the OpenTitan platform, with alloc feature enabled |
| 58 | ``` |
| 59 | |
JOE1994 | 51168c9 | 2020-04-27 17:05:34 -0400 | [diff] [blame] | 60 | ```bash |
| 61 | make flash-hail EXAMPLE=blink # Flash the example 'blink' program to the hail platform |
| 62 | ``` |
| 63 | |
Alistair Francis | cb3d5b8 | 2020-03-10 13:43:48 -0700 | [diff] [blame] | 64 | For an unknown platform, you may have to create your own memory layout definition. Place the layout definition file at `boards/layout_<platform>.ld` and do not forget to enhance the `tockloader_flags` dispatching section in `tools/flash.sh`. You are welcome to create a PR, s.t. the number of supported platforms grows. |
Florian Hars | 5dbdd50 | 2019-10-15 20:10:56 +0200 | [diff] [blame] | 65 | |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 66 | ## Using libtock-rs |
| 67 | |
| 68 | The easiest way to start using libtock-rs is adding an example to the examples folder. |
| 69 | The boiler plate code you would write is |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 70 | |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 71 | ```rust |
| 72 | #![no_std] |
| 73 | |
Woyten | 82633c1 | 2019-11-27 18:29:17 +0100 | [diff] [blame] | 74 | use libtock::result::TockResult; |
| 75 | |
torfmaster | ac39e92 | 2019-12-17 09:37:38 +0100 | [diff] [blame] | 76 | #[libtock::main] |
Woyten | 82633c1 | 2019-11-27 18:29:17 +0100 | [diff] [blame] | 77 | async fn main() -> TockResult<()> { |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 78 | // Your code |
| 79 | } |
| 80 | ``` |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 81 | |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 82 | If you want to use heap based allocation you will have to add |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 83 | |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 84 | ```rust |
torfmaster | 9ca48f0 | 2019-11-15 08:49:36 +0100 | [diff] [blame] | 85 | extern crate alloc; |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 86 | ``` |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 87 | |
Woyten | f0b3e08 | 2020-02-18 23:11:19 +0100 | [diff] [blame] | 88 | to the preamble and store your example in the `examples-alloc` folder. |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 89 | |
JOE1994 | 51168c9 | 2020-04-27 17:05:34 -0400 | [diff] [blame] | 90 | To build the examples for your board you can use |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 91 | |
Alistair Francis | 0c1cb58 | 2020-03-10 13:49:40 -0700 | [diff] [blame] | 92 | ```shell |
| 93 | make <platform> [FEATURES=alloc] |
| 94 | ``` |
| 95 | |
JOE1994 | a31b975 | 2020-04-27 18:12:28 -0400 | [diff] [blame] | 96 | An example can be flashed to your board after the build process by running: |
Alistair Francis | 0c1cb58 | 2020-03-10 13:49:40 -0700 | [diff] [blame] | 97 | |
| 98 | ```shell |
| 99 | make flash-<platform> EXAMPLE=<example> |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 100 | ``` |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 101 | |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 102 | This script does the following steps for you: |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 103 | |
| 104 | - cross-compile your program |
| 105 | - create a TAB (tock application bundle) |
Woyten | 860e0bc | 2020-01-29 21:17:14 +0100 | [diff] [blame] | 106 | - if you have a J-Link compatible board connected: flash this TAB to your board (using tockloader) |
| 107 | |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 108 | |
Pat Pannuto | 0dc3e13 | 2017-05-11 16:22:12 -0400 | [diff] [blame] | 109 | ## License |
| 110 | |
Johnathan Van Why | 5a9606e | 2020-06-11 15:41:07 -0700 | [diff] [blame] | 111 | libtock-rs is licensed under either of |
Pat Pannuto | 0dc3e13 | 2017-05-11 16:22:12 -0400 | [diff] [blame] | 112 | |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 113 | - Apache License, Version 2.0 |
| 114 | ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) |
| 115 | - MIT license |
| 116 | ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
Pat Pannuto | 0dc3e13 | 2017-05-11 16:22:12 -0400 | [diff] [blame] | 117 | |
| 118 | at your option. |
| 119 | |
Johnathan Van Why | 5a9606e | 2020-06-11 15:41:07 -0700 | [diff] [blame] | 120 | Submodules have their own licenses. |
| 121 | |
Pat Pannuto | 0dc3e13 | 2017-05-11 16:22:12 -0400 | [diff] [blame] | 122 | ### Contribution |
| 123 | |
| 124 | Unless you explicitly state otherwise, any contribution intentionally submitted |
| 125 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be |
| 126 | dual licensed as above, without any additional terms or conditions. |
torfmaster | f310ac0 | 2019-12-30 00:12:17 +0100 | [diff] [blame] | 127 | |
| 128 | The contribution guidelines can be found here: [contribution guidelines](CONTRIBUTING.md) |