README.md 2.54 KB
Newer Older
rnd's avatar
rnd committed
1
# Rust support for the card10 CCCamp19 badge
Astro's avatar
Astro committed
2

Danilo's avatar
Danilo committed
3
4
## Prerequisites

rnd's avatar
rnd committed
5
6
You need rust nightly and a working setup to compile the card10
firmware including the matching libc.
Danilo's avatar
Danilo committed
7

8
1) For instructions how to setup rust please see https://rustup.rs.
Danilo's avatar
Danilo committed
9

rnd's avatar
rnd committed
10
11
   Please ensure that you installed the latest rust nightly toolchain
   and add the `thumbv7em-none-eabi` target.
Danilo's avatar
Danilo committed
12

rnd's avatar
rnd committed
13
14
15
16
17
   ```shell
   rustup toolchain install nightly
   rustup update
   rustup target add thumbv7em-none-eabi --toolchain nightly
   ```
Astro's avatar
Astro committed
18

rnd's avatar
rnd committed
19
2) For instructions how to setup the card10 firmware check the dependency
20
   chapter in https://firmware.card10.badge.events.ccc.de/how-to-build.html.
Astro's avatar
Astro committed
21

rnd's avatar
rnd committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
3) Additionally you may need the packages for the llvm and libc i386
   dev headers.

4) Clone this repository with `--recursive` to get the submodules,
   otherwise update them afterwards:

   ```shell
   git submodule update --init --recursive
   ```

## Setup a Rust enabled firmware

To allow rust based apps on card10 you need a firmware which allows
to run custom elf binaries on the core. This requires a custom build
with `-Djailbreak_card10=true` as bootstrapping flag.

Assuming that you installed all required dependencies mentioned in
39
https://firmware.card10.badge.events.ccc.de/how-to-build.html this
rnd's avatar
rnd committed
40
should work as following:
41
42

```shell
rnd's avatar
rnd committed
43
44
45
cd c/
./bootstrap -Djailbreak_card10=true
ninja -C build/
46
```
Astro's avatar
Astro committed
47

rnd's avatar
rnd committed
48
49
50
51
And then copy `build/pycardium/pycardium_epicardium.bin` as
`card10.bin` onto your badge.

## Build and run Rust loadables
Astro's avatar
Astro committed
52
53

```shell
rnd's avatar
rnd committed
54
cargo +nightly build --release --target thumbv7-none-eabi
Astro's avatar
Astro committed
55
56
```

rnd's avatar
rnd committed
57
Then copy the resulting executable from the target directory 
Astro's avatar
Astro committed
58
`target/thumbv7em-none-eabi/release/example` into the
rnd's avatar
rnd committed
59
60
`apps` directory of your badge.

Astro's avatar
Astro committed
61
62
**Attention**: Its necessary to rename the executable to add the `elf`
extension (e.g `example` must be renamed as `example.elf`).
Astro's avatar
Astro committed
63

Astro's avatar
Astro committed
64
65
66
67
## Crates

| Crate    | Description                                               |
| ----     | ---                                                       |
Astro's avatar
Astro committed
68
| l0dable  | Helper crate for building l0dables                        |
Astro's avatar
Astro committed
69
| example  | l0dable example                                           |
Astro's avatar
Astro committed
70
| rkanoid  | Arkanoid clone                                            |
Astro's avatar
Astro committed
71

rnd's avatar
rnd committed
72
73
74

## Misc

Astro's avatar
Astro committed
75
### How to update the firmware bindings
rnd's avatar
rnd committed
76
77
78
79
80
81
82
83
84
85
86
87
88

1) Update the `c/` submodule to the latest firmware state.

2) Rebuild the firmware as described above.

3) Run the following script from the project root directory

   ```shell
   python c/epicardium/api/genapi.py -H c/epicardium/epicardium.h -c l0dable/src/client.c -s l0dable/src/server.c
   ```

4) Rebuild your app :)

Astro's avatar
Astro committed
89
90
91
## TODO

- [ ] alloc