# Firmware for Signet Devices

## Prerequisites

#### Cloning Directions

This project uses git submodules, you will either need to use `git clone
--recursive <repourl>` or after cloning use `git submodule update --init`.

#### Dependencies

The following packages must be installed:
`build-essential autoconf automake gawk gperf texinfo help2man ncurses-dev bison flex libtool-bin libjson-c-dev libiberty-dev dfu-util unzip wget zlib1g-dev`

This has been tested in various GNU/Linux machines, in other platforms you
might need more, and possibly differently named, packages.


## Building the Signet Legacy Firmware

#### Prepare the Toolchain, Dependencies and Tools

This will build the toolchain and dependencies:
```
cd firmware
./build-deps.sh
```

To package the firmware for the Signet client GUI we need the firmware encoder:
`make signet-firmware-encoder`.

#### Build the Firmware

`make` builds the Signet firmware.

Package it with: `./signet-firmware-encoder signet-fw signet-fw-$(cat firmware-version).sfw`

#### Flashing the firmware

1. Get `dfu-util` (e.g. `apt install -y dfu-util`).
2. Set boot switch to the "bootsw" side
3. sudo dfu-util -a 0 -s 0x8000000 -D signet-$(cat firmware-version).dfu

Note: if you have a locked CPU that can not be flashed, use the following command to unlock it.

`sudo dfu-util -a 0 -s 0x8000000:unprotect:force -D signet-fw-$(cat firmware-version).dfu`

## Building the Signet HC Firmware

#### Prepare the Toolchain, Dependencies and Tools

This will build the toolchain and dependencies:
```
cd firmware-hc
./signet-hc-build-deps.sh
```

To build the Signet High-capacity firmware encoder: `make hc-firmware-encoder`

#### Build the Firmware

Signet HC firmware has too parts, they need to be built separately:
`make BT_MODE=A` and `make BT_MODE=B`.

To package Signet HC firmware, we need to specify the version number too:
`./hc-firmware-encoder signet-fw-a.bin signet-fw-b.bin signet-fw-0.2.3.sfwhc 0 2 3`

### Reproducible Builds

Both Signet and Signet High-capacity firmware uses locally compiled toolchains
(via crosstool-ng) to increase the chance of reproducible builds.

# Release process

After all the patches are merged into the default branch and we are ready to
cut a firmware release, follow the instructions below.

1. Bump the firmware version in `firmware/firmware-version`,
   `firmware/main_l443xc.c`, and `signetdev/common/signetdev_common.h`
2. Collect the release notes and put them in the `release-notes` directory
3. Commit the above changes and create a tag for this release
4. Sign the firmware image which was built from the CI/CD system
5. Copy the firmware image and signature file to the web server
6. Update the website to indicate the new latest version
7. Update the firmware version in signet-client (client/signetapplication.cpp)
   and cut a new release of signet-client so it's clear the client will work
   with the new firmware.
8. Post on Matrix and social media that there have been updates
