Skip to content

Commit ce35419

Browse files
k9ertubbabeck
andauthored
chore: Get build back to work and some CI (#307)
* fix: pin dependencies via on nix and create flake * ci: try build * Update flake.nix Co-authored-by: Ruben <[email protected]> * Update shell.nix Co-authored-by: Ruben <[email protected]> * fix: as suggested by mike * a bit more concrete prerequisites * nix prefixes --------- Co-authored-by: Ruben <[email protected]>
1 parent 24d1137 commit ce35419

File tree

8 files changed

+224
-19
lines changed

8 files changed

+224
-19
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.github/workflows/build.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
branches: [main, master]
6+
push:
7+
branches: [main, master]
8+
9+
jobs:
10+
build:
11+
name: Build Firmware
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
submodules: recursive
17+
18+
- name: Install Nix
19+
uses: DeterminateSystems/nix-installer-action@v14
20+
21+
- name: Cache Nix store
22+
uses: actions/cache@v3
23+
with:
24+
path: |
25+
~/.cache/nix
26+
/nix/store
27+
key: nix-${{ runner.os }}-${{ hashFiles('flake.lock') }}
28+
restore-keys: |
29+
nix-${{ runner.os }}-
30+
31+
- name: Build Unix simulator
32+
run: nix develop -c make unix
33+
34+
- name: Build STM32F469 Discovery firmware
35+
run: nix develop -c make disco
36+
37+
- name: Upload firmware artifacts
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: firmware-binaries
41+
path: |
42+
bin/specter-diy.bin
43+
bin/specter-diy.hex

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ release
88
.idea
99
.vscode
1010
.DS_Store
11+
.direnv

docs/build.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,35 @@ Clone the repository recursively `git clone https://github.com/cryptoadvance/spe
66

77
## Prerequisities
88

9+
There are multiple ways to get all necessary tools. The recommended way is to use the Nix flake with direnv.
10+
If that's too complicated for you, you can use the traditional `nix-shell` or install the tools manually (which mighty be tricky to get the dependencies right).
11+
12+
### Nix flake (Recommended)
13+
14+
The easiest way to get all necessary tools is to use the Nix flake from the root of the repository. You need to have [Nix](https://nixos.org/) (on Mac use [determinate](https://github.com/DeterminateSystems/nix-installer)) with flakes enabled. This only works with Nix >2.7 (check with `nix --version`).
15+
Install direnv with `brew install direnv` (on Mac) or `sudo apt install direnv` (on Linux).
16+
17+
Make sure that [flakes are enabled](https://nixos.wiki/wiki/Flakes) in your Nix config. On Linux systems, your user might need to be added to the nix-users group.
18+
19+
```sh
20+
# Enter development shell
21+
nix develop
22+
23+
# Or use with direnv for automatic activation
24+
direnv allow
25+
```
26+
27+
928
### Nix shell
1029

11-
The easiest way to get all necessary tools is to run `nix-shell` from the root of the repository. You need to have [Nix](https://nixos.org/) installed.
30+
Alternatively, you can use the traditional `shell.nix`:
31+
32+
```sh
33+
nix-shell
34+
```
35+
You'll need to have [Nix](https://nixos.org/) installed as well.
1236

13-
### Prerequisities: Board
37+
### Prerequisities (Manually): Board
1438

1539
To compile the firmware for the board you will need `arm-none-eabi-gcc` compiler.
1640

@@ -34,7 +58,7 @@ brew install arm-none-eabi-gcc
3458

3559
On **Windows**: Install linux subsystem and follow Linux instructions.
3660

37-
### Prerequisities: Simulator
61+
### Prerequisities (Manually): Simulator
3862

3963
You may need to install SDL2 library to simulate the screen of the device.
4064

@@ -55,6 +79,8 @@ brew install sdl2
5579

5680
## Build
5781

82+
All build commands might need a prefix like `nix develop -c` or need to be run from `nix develop` shell. If you use direnv, you don't need to do anything, apart from an initial `direnv allow`.
83+
5884
To build custom bootloader and firmware that you will be able to sign check out the bootloader doc on [self-signed firmware](https://github.com/cryptoadvance/specter-bootloader/blob/master/doc/selfsigned.md). To wipe flash and remove protections on the device with the secure bootloader check out [this doc](https://github.com/cryptoadvance/specter-bootloader/blob/master/doc/remove_protection.md).
5985

6086
To build an open firmware (no bootloader and signature verifications) run `make disco`. The result is the `bin/specter-diy.bin` file that you can copy-paste to the board over miniUSB.

docs/development.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,36 @@
22

33
## Compiling the code yourself
44

5-
We use this build as a platform for Specter: https://github.com/diybitcoinhardware/f469-disco
5+
See the [build documentation](build.md) for instructions on how to compile the code.
66

7-
To compile the firmware you will need `arm-none-eabi-gcc` compiler.
8-
9-
On MacOS install it using brew: `brew install arm-none-eabi-gcc`
10-
11-
On Debian: `sudo apt install gcc-arm-none-eabi binutils-arm-none-eabi gdb-arm-none-eabi openocd`
12-
13-
On Arch Linux: `sudo pacman -S arm-none-eabi-gcc arm-none-eabi-binutils arm-none-eabi-gdb arm-none-eabi-newlib openocd`
7+
## Enabling developer mode
148

15-
Run `make disco` to get the binary or `make unix` to compile the simulator. They will be in the `bin` folder.
9+
By default developer mode and USB communication are turned off. This means that when you connect the board to the computer it will NOT mount the `PYBFLASH` anymore and there will be no way to connect to debug shell.
1610

17-
`specter-diy.bin` file is the firmware that you need to copy to the device.
1811

19-
The easiest way to start developing is to use a [simulator](./simulator.md), and when you are done - try it on a real hardware.
12+
~~To turn on the developer mode get to the main screen (enter PIN code, generate recovery phrase, enter password), and then go to **Settings - Security - turn on Developer mode - Save**.~~
13+
(Currently deactivated for securtiy reasons)
2014

21-
## Enabling developer mode
15+
~~Now the board will restart and get mounted to the computer as before. You can also connect to the board over miniUSB and get to interactive console (baudrate 115200). You can use `screen` or `putty` or `minicom` for that, i.e. `screen /dev/tty.usbmodem14403 115200`.~~
2216

23-
By default developer mode and USB communication are turned off. This means that when you connect the board to the computer it will NOT mount the `PYBFLASH` anymore and there will be no way to connect to debug shell.
17+
In order to connect to the board, modify those lines in [boot.py](https://github.com/cryptoadvance/specter-diy/blob/2f51e152bcdb184cf719792e6c5f972214e3dd36/boot/main/boot.py#L33-L40) like this:
18+
```python
19+
# configure usb from start if you want,
20+
# otherwise will be configured after PIN
21+
pyb.usb_mode("VCP+MSC") # debug mode with USB and mounted storages from start
22+
#pyb.usb_mode("VCP") # debug mode with USB from start
23+
# disable at start
24+
# pyb.usb_mode(None)
25+
```
2426

25-
To turn on the developer mode get to the main screen (enter PIN code, generate recovery phrase, enter password), and then go to **Settings - Security - turn on Developer mode - Save**.
27+
and after flashing, you can connect with something like:
28+
```
29+
# Linux
30+
screen /dev/ttyACM0 115200 # or maybe ttyACM1 or ttyACM2
31+
# Mac
32+
screen /dev/tty.usbmodem14403 115200`.
33+
```
2634

27-
Now the board will restart and get mounted to the computer as before. You can also connect to the board over miniUSB and get to interactive console (baudrate 115200). You can use `screen` or `putty` or `minicom` for that, i.e. `screen /dev/tty.usbmodem14403 115200`.
2835

2936
## Writing a simple app
3037

flake.lock

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
description = "Specter DIY development environment";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
flake-compat = {
8+
url = "github:edolstra/flake-compat";
9+
flake = false;
10+
};
11+
};
12+
13+
outputs = { self, nixpkgs, flake-utils, ... }:
14+
flake-utils.lib.eachDefaultSystem (system:
15+
let
16+
pkgs = nixpkgs.legacyPackages.${system};
17+
in
18+
{
19+
devShells.default = pkgs.mkShell {
20+
nativeBuildInputs = [
21+
pkgs.buildPackages.gcc-arm-embedded-9
22+
pkgs.buildPackages.python39
23+
pkgs.openocd
24+
pkgs.stlink
25+
pkgs.SDL2
26+
];
27+
hardeningDisable = ["all"];
28+
};
29+
});
30+
}

shell.nix

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
{ pkgs ? import <nixpkgs> {} }:
1+
(import
2+
(
3+
let
4+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
5+
in
6+
fetchTarball {
7+
url =
8+
lock.nodes.flake-compat.locked.url
9+
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
10+
sha256 = lock.nodes.flake-compat.locked.narHash;
11+
}
12+
)
13+
{
14+
src = ./.;
15+
}
16+
).shellNix
17+
url = "https://github.com/NixOS/nixpkgs/archive/nixos-22.05.tar.gz";
18+
sha256 = "154x9swf494mqwi4z8nbq2f0sp8pwp4fvx51lqzindjfbb9yxxv5";
19+
}) {}
20+
}:
221
pkgs.mkShell {
322
nativeBuildInputs = [
423
pkgs.buildPackages.gcc-arm-embedded-9

0 commit comments

Comments
 (0)