blob: 0c1289c560cad51890e6a0ef85842ad5f5dd6f09 [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
torfmaster2740ae42019-11-22 16:09:16 +01007Tested with tock [Release 1.4.1](https://github.com/tock/tock/commit/7e37bf67761d83fd585cace4fb201e2864d300b1).
Florian Hars5cf866b2019-10-14 02:32:51 +02008
Florian Hars70791a32019-10-14 18:32:56 +02009The library works in principle on most boards, but there is currently the [showstopper
Florian Hars5cf866b2019-10-14 02:32:51 +020010bug #28](https://github.com/tock/libtock-rs/issues/28) that prevents
11the generation of relocatable code. This means that all applications
12must be installed at the flash address they are compiled with, which
Florian Hars70791a32019-10-14 18:32:56 +020013usually means that they must be compiled especially for your board
14and that there can only be one application written in rust at a time
Florian Hars5cf866b2019-10-14 02:32:51 +020015and it must be installed as the first application on the board, unless
16you want to play games with linker scripts.
Alistair Francisb3e3a9a2020-03-09 16:36:44 -070017There are some `boards/layout_*.ld` files provided that allow to run the
Florian Hars7d9d8562019-10-16 11:56:54 +020018examples on common boards.
19Due to MPU region alignment issues they may not work for applications
20that use a lot of RAM, in that case you may have to change the SRAM
21start address to fit your application.
Philipp Vollmer090398c2018-06-29 15:14:54 +020022
Pat Pannuto287a8ae2017-05-10 18:19:21 -040023## Getting Started
24
25This project is nascent and still under heavy development, but first steps:
26
torfmaster92f81312019-12-30 00:09:03 +0100271. Ensure you have [rustup](https://www.rustup.rs/) installed.
Pat Pannuto00bb1982017-08-17 00:02:37 -070028
JOE199451168c92020-04-27 17:05:34 -0400292. Clone the repository:
Teddy Katzbc376852018-04-02 16:39:46 -040030
Alistair Francis0c1cb582020-03-10 13:49:40 -070031 ```shell
Teddy Katzbc376852018-04-02 16:39:46 -040032 git clone https://github.com/tock/libtock-rs
Woyten97b27b02018-06-19 20:44:59 +020033 cd libtock-rs
34 ```
35
JOE199451168c92020-04-27 17:05:34 -0400363. Install the dependencies:
Woyten97b27b02018-06-19 20:44:59 +020037
Alistair Francis0c1cb582020-03-10 13:49:40 -070038 ```shell
39 make setup
Teddy Katzbc376852018-04-02 16:39:46 -040040 ```
41
JOE199451168c92020-04-27 17:05:34 -0400424. Use `make` to build examples
Teddy Katzbc376852018-04-02 16:39:46 -040043
Alistair Francis0c1cb582020-03-10 13:49:40 -070044 ```shell
45 make nrf52 # Builds all examples for the nrf52 platform
Teddy Katzbc376852018-04-02 16:39:46 -040046 ```
47
torfmaster02f000a2020-01-05 02:16:00 +010048 ```bash
Alistair Francis0c1cb582020-03-10 13:49:40 -070049 make opentitan # Builds all examples for the OpenTitan platform
Woyten860e0bc2020-01-29 21:17:14 +010050 ```
torfmastercf1018c2019-02-11 19:35:24 +010051
Alistair Francis55e3d6b2020-03-10 14:04:22 -070052 ```bash
53 make opentitan FEATURES=alloc # Builds all examples for the OpenTitan platform, with alloc feature enabled
54 ```
55
JOE199451168c92020-04-27 17:05:34 -040056 ```bash
57 make flash-hail EXAMPLE=blink # Flash the example 'blink' program to the hail platform
58 ```
59
Alistair Franciscb3d5b82020-03-10 13:43:48 -070060 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 +020061
Philipp Vollmer209e3182018-03-27 09:05:49 +020062## Using libtock-rs
63
64The easiest way to start using libtock-rs is adding an example to the examples folder.
65The boiler plate code you would write is
torfmaster92f81312019-12-30 00:09:03 +010066
Philipp Vollmer209e3182018-03-27 09:05:49 +020067```rust
68#![no_std]
69
Woyten82633c12019-11-27 18:29:17 +010070use libtock::result::TockResult;
71
torfmasterac39e922019-12-17 09:37:38 +010072#[libtock::main]
Woyten82633c12019-11-27 18:29:17 +010073async fn main() -> TockResult<()> {
Philipp Vollmer209e3182018-03-27 09:05:49 +020074 // Your code
75}
76```
torfmaster92f81312019-12-30 00:09:03 +010077
Philipp Vollmer209e3182018-03-27 09:05:49 +020078If you want to use heap based allocation you will have to add
torfmaster92f81312019-12-30 00:09:03 +010079
Philipp Vollmer209e3182018-03-27 09:05:49 +020080```rust
torfmaster9ca48f02019-11-15 08:49:36 +010081extern crate alloc;
Philipp Vollmer209e3182018-03-27 09:05:49 +020082```
torfmaster92f81312019-12-30 00:09:03 +010083
Woytenf0b3e082020-02-18 23:11:19 +010084to the preamble and store your example in the `examples-alloc` folder.
Philipp Vollmer209e3182018-03-27 09:05:49 +020085
JOE199451168c92020-04-27 17:05:34 -040086To build the examples for your board you can use
torfmaster92f81312019-12-30 00:09:03 +010087
Alistair Francis0c1cb582020-03-10 13:49:40 -070088```shell
89make <platform> [FEATURES=alloc]
90```
91
JOE199451168c92020-04-27 17:05:34 -040092A program can be flashed to your board after the build process by running:
Alistair Francis0c1cb582020-03-10 13:49:40 -070093
94```shell
95make flash-<platform> EXAMPLE=<example>
Philipp Vollmer209e3182018-03-27 09:05:49 +020096```
torfmaster92f81312019-12-30 00:09:03 +010097
Philipp Vollmer209e3182018-03-27 09:05:49 +020098This script does the following steps for you:
torfmaster92f81312019-12-30 00:09:03 +010099
100- cross-compile your program
101- create a TAB (tock application bundle)
Woyten860e0bc2020-01-29 21:17:14 +0100102- if you have a J-Link compatible board connected: flash this TAB to your board (using tockloader)
103
Philipp Vollmer209e3182018-03-27 09:05:49 +0200104
Pat Pannuto0dc3e132017-05-11 16:22:12 -0400105## License
106
107Licensed under either of
108
torfmaster92f81312019-12-30 00:09:03 +0100109- Apache License, Version 2.0
110 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
111- MIT license
112 ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
Pat Pannuto0dc3e132017-05-11 16:22:12 -0400113
114at your option.
115
116### Contribution
117
118Unless you explicitly state otherwise, any contribution intentionally submitted
119for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
120dual licensed as above, without any additional terms or conditions.
torfmasterf310ac02019-12-30 00:12:17 +0100121
122The contribution guidelines can be found here: [contribution guidelines](CONTRIBUTING.md)