blob: 72506cd3cce59a19a59149be1981e2f72e4a7b9a [file] [log] [blame] [view]
Woytenfbf1ffc2018-03-19 23:10:33 +01001[![Build Status](https://travis-ci.org/tock/libtock-rs.svg?branch=master)](https://travis-ci.org/tock/libtock-rs)
torfmaster92f81312019-12-30 00:09:03 +01002
Amit Levybf8fec82017-05-10 14:43:48 -04003# libtock-rs
torfmaster92f81312019-12-30 00:09:03 +01004
Amit Levybf8fec82017-05-10 14:43:48 -04005Rust userland library for Tock (WIP)
Pat Pannuto287a8ae2017-05-10 18:19:21 -04006
Alistair Francis073efcc2020-06-08 09:30:21 -07007Generally this library was tested with tock [Release 1.5](https://github.com/tock/tock/releases/tag/release-1.5).
8Since then changes have been made that might not work with the Tock
9release 1.5, but instead target Tock master. For example this library
10might support newer boards (Apollo3), changed boards (HiFive1 revB) or
11new drivers (HMAC).
Florian Hars5cf866b2019-10-14 02:32:51 +020012
Florian Hars70791a32019-10-14 18:32:56 +020013The library works in principle on most boards, but there is currently the [showstopper
Florian Hars5cf866b2019-10-14 02:32:51 +020014bug #28](https://github.com/tock/libtock-rs/issues/28) that prevents
15the generation of relocatable code. This means that all applications
16must be installed at the flash address they are compiled with, which
Florian Hars70791a32019-10-14 18:32:56 +020017usually means that they must be compiled especially for your board
18and that there can only be one application written in rust at a time
Florian Hars5cf866b2019-10-14 02:32:51 +020019and it must be installed as the first application on the board, unless
20you want to play games with linker scripts.
Alistair Francisb3e3a9a2020-03-09 16:36:44 -070021There are some `boards/layout_*.ld` files provided that allow to run the
Florian Hars7d9d8562019-10-16 11:56:54 +020022examples on common boards.
23Due to MPU region alignment issues they may not work for applications
24that use a lot of RAM, in that case you may have to change the SRAM
25start address to fit your application.
Philipp Vollmer090398c2018-06-29 15:14:54 +020026
Pat Pannuto287a8ae2017-05-10 18:19:21 -040027## Getting Started
28
29This project is nascent and still under heavy development, but first steps:
30
torfmaster92f81312019-12-30 00:09:03 +0100311. Ensure you have [rustup](https://www.rustup.rs/) installed.
Pat Pannuto00bb1982017-08-17 00:02:37 -070032
JOE1994ddacb122020-04-27 17:31:43 -0400331. Clone the repository:
Teddy Katzbc376852018-04-02 16:39:46 -040034
Alistair Francis0c1cb582020-03-10 13:49:40 -070035 ```shell
Johnathan Van Why8580c472020-06-17 09:03:06 -070036 git clone --recursive https://github.com/tock/libtock-rs
Woyten97b27b02018-06-19 20:44:59 +020037 cd libtock-rs
38 ```
39
JOE1994ddacb122020-04-27 17:31:43 -0400401. Install the dependencies:
Woyten97b27b02018-06-19 20:44:59 +020041
Alistair Francis0c1cb582020-03-10 13:49:40 -070042 ```shell
43 make setup
Teddy Katzbc376852018-04-02 16:39:46 -040044 ```
45
JOE1994ddacb122020-04-27 17:31:43 -0400461. Use `make` to build examples
Teddy Katzbc376852018-04-02 16:39:46 -040047
Alistair Francis0c1cb582020-03-10 13:49:40 -070048 ```shell
49 make nrf52 # Builds all examples for the nrf52 platform
Teddy Katzbc376852018-04-02 16:39:46 -040050 ```
51
torfmaster02f000a2020-01-05 02:16:00 +010052 ```bash
Alistair Francis0c1cb582020-03-10 13:49:40 -070053 make opentitan # Builds all examples for the OpenTitan platform
Woyten860e0bc2020-01-29 21:17:14 +010054 ```
torfmastercf1018c2019-02-11 19:35:24 +010055
Alistair Francis55e3d6b2020-03-10 14:04:22 -070056 ```bash
57 make opentitan FEATURES=alloc # Builds all examples for the OpenTitan platform, with alloc feature enabled
58 ```
59
JOE199451168c92020-04-27 17:05:34 -040060 ```bash
61 make flash-hail EXAMPLE=blink # Flash the example 'blink' program to the hail platform
62 ```
63
Alistair Franciscb3d5b82020-03-10 13:43:48 -070064 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 Hars5dbdd502019-10-15 20:10:56 +020065
Philipp Vollmer209e3182018-03-27 09:05:49 +020066## Using libtock-rs
67
68The easiest way to start using libtock-rs is adding an example to the examples folder.
69The boiler plate code you would write is
torfmaster92f81312019-12-30 00:09:03 +010070
Philipp Vollmer209e3182018-03-27 09:05:49 +020071```rust
72#![no_std]
73
Woyten82633c12019-11-27 18:29:17 +010074use libtock::result::TockResult;
75
torfmasterac39e922019-12-17 09:37:38 +010076#[libtock::main]
Woyten82633c12019-11-27 18:29:17 +010077async fn main() -> TockResult<()> {
Philipp Vollmer209e3182018-03-27 09:05:49 +020078 // Your code
79}
80```
torfmaster92f81312019-12-30 00:09:03 +010081
Philipp Vollmer209e3182018-03-27 09:05:49 +020082If you want to use heap based allocation you will have to add
torfmaster92f81312019-12-30 00:09:03 +010083
Philipp Vollmer209e3182018-03-27 09:05:49 +020084```rust
torfmaster9ca48f02019-11-15 08:49:36 +010085extern crate alloc;
Philipp Vollmer209e3182018-03-27 09:05:49 +020086```
torfmaster92f81312019-12-30 00:09:03 +010087
Woytenf0b3e082020-02-18 23:11:19 +010088to the preamble and store your example in the `examples-alloc` folder.
Philipp Vollmer209e3182018-03-27 09:05:49 +020089
JOE199451168c92020-04-27 17:05:34 -040090To build the examples for your board you can use
torfmaster92f81312019-12-30 00:09:03 +010091
Alistair Francis0c1cb582020-03-10 13:49:40 -070092```shell
93make <platform> [FEATURES=alloc]
94```
95
JOE1994a31b9752020-04-27 18:12:28 -040096An example can be flashed to your board after the build process by running:
Alistair Francis0c1cb582020-03-10 13:49:40 -070097
98```shell
99make flash-<platform> EXAMPLE=<example>
Philipp Vollmer209e3182018-03-27 09:05:49 +0200100```
torfmaster92f81312019-12-30 00:09:03 +0100101
Philipp Vollmer209e3182018-03-27 09:05:49 +0200102This script does the following steps for you:
torfmaster92f81312019-12-30 00:09:03 +0100103
104- cross-compile your program
105- create a TAB (tock application bundle)
Woyten860e0bc2020-01-29 21:17:14 +0100106- if you have a J-Link compatible board connected: flash this TAB to your board (using tockloader)
107
Philipp Vollmer209e3182018-03-27 09:05:49 +0200108
Pat Pannuto0dc3e132017-05-11 16:22:12 -0400109## License
110
Johnathan Van Why5a9606e2020-06-11 15:41:07 -0700111libtock-rs is licensed under either of
Pat Pannuto0dc3e132017-05-11 16:22:12 -0400112
torfmaster92f81312019-12-30 00:09:03 +0100113- 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 Pannuto0dc3e132017-05-11 16:22:12 -0400117
118at your option.
119
Johnathan Van Why5a9606e2020-06-11 15:41:07 -0700120Submodules have their own licenses.
121
Pat Pannuto0dc3e132017-05-11 16:22:12 -0400122### Contribution
123
124Unless you explicitly state otherwise, any contribution intentionally submitted
125for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
126dual licensed as above, without any additional terms or conditions.
torfmasterf310ac02019-12-30 00:12:17 +0100127
128The contribution guidelines can be found here: [contribution guidelines](CONTRIBUTING.md)