Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
NickeZ committed Oct 15, 2024
0 parents commit 695d3d2
Show file tree
Hide file tree
Showing 38 changed files with 2,553 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .ci/ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -xe

cd bitbox02-bt

cargo check

cargo clippy

# There will be a warning about "unused patch". It does work as expected. See
# https://github.com/rust-lang/cargo/issues/14003
make build

make build-release
1 change: 1 addition & 0 deletions .containerversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
latest
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*

!rust-toolchain.toml
!SDK*.zip
!da14531-sdk/patches/*
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI
on: [push, pull_request]

env:
CARGO_TERM_COLOR: always
# We cannot deny warnings because setting this environment variable overrides
# the other custom rust flags that are defined in `.cargo/config.toml`.
# RUSTFLAGS: -Dwarnings

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- run: podman pull shiftcrypto/da14531

- run: >
podman run
--volume ${{github.workspace}}:/checkout
--workdir /checkout
--env CARGO_TERM_COLOR
shiftcrypto/da14531
.ci/ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SDK*.zip
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "da14531-hal"]
path = da14531-hal
url = http://github.com/BitBoxSwiss/da14531-hal
[submodule "da14531-sdk"]
path = da14531-sdk
url = http://github.com/BitBoxSwiss/da14531-sdk
[submodule "da14531-sdk-macros"]
path = da14531-sdk-macros
url = http://github.com/BitBoxSwiss/da14531-sdk-macros
[submodule "da14531"]
path = da14531
url = http://github.com/BitBoxSwiss/da14531
71 changes: 71 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2024 Shift Crypto AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM ubuntu:22.04

# arm-none-eabi-gdb depends on libncurses5, libncursesw5 and libtinfo5
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
curl \
make \
gcc \
xz-utils \
unzip \
patch \
gnupg2 \
libncurses5 \
libncursesw5 \
libtinfo5 \
&& rm -rf /var/lib/apt/lists/*

# for llvm-18, see https://apt.llvm.org/
RUN echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list && \
echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list && \
curl -L https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
clang-18 \
&& rm -rf /var/lib/apt/lists/*

# Install ARM GNU Toolchain
ARG TARGETPLATFORM
RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
GNU_TOOLCHAIN=https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-aarch64-arm-none-eabi.tar.xz \
GNU_TOOLCHAIN_HASH=c8824bffd057afce2259f7618254e840715f33523a3d4e4294f471208f976764; \
else \
GNU_TOOLCHAIN=https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi.tar.xz \
GNU_TOOLCHAIN_HASH=95c011cee430e64dd6087c75c800f04b9c49832cc1000127a92a97f9c8d83af4; \
fi; \
curl -sSLo gcc.tar.xz ${GNU_TOOLCHAIN} && \
echo "$GNU_TOOLCHAIN_HASH gcc.tar.xz" | sha256sum -c && \
tar -xf gcc.tar.xz -C /usr/local --strip-components=1 && \
rm -f gcc.tar.xz

# The da14531 SDK is not publicly available. So there needds to be a copy of it
# in the same folder where the Dockerfile is.
ENV SDK_PATH=/opt/DA145xx_SDK/6.0.22.1401
RUN --mount=source=.,target=/mnt \
cd /opt && \
unzip /mnt/SDK_6.0.22.1401.zip && \
cd /opt/DA145xx_SDK/6.0.22.1401 && \
for patch in `ls /mnt/da14531-sdk/patches`; do patch -p1 < /mnt/da14531-sdk/patches/$patch; done

# Install rust compiler
ENV PATH=/opt/cargo/bin:$PATH RUSTUP_HOME=/opt/rustup
RUN --mount=source=rust-toolchain.toml,target=/mnt/rust-toolchain.toml \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | CARGO_HOME=/opt/cargo sh -s -- --default-toolchain $(grep -oP '(?<=channel = ")[^"]+' /mnt/rust-toolchain.toml) -y && \
rustup target add thumbv6m-none-eabi && \
rustup component add \
rustfmt \
clippy \
rust-src
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# To replace docker with podman set `DOCKER=podman` in your environment
DOCKER ?= docker

.PHONY: dockerdev
dockerdev:
@./scripts/dockerenv.sh

.PHONY: dockerinit
dockerinit:
${DOCKER} build -t shiftcrypto/da14531 .

.PHONY: dockerpull
dockerpull:
${DOCKER} pull shiftcrypto/da14531

.PHONY: dockerpush
dockerpush:
${DOCKER} build --push --platform linux/amd64,linux/arm64 -t shiftcrypto/da14531 .

.PHONY: dockerstop
dockerstop:
@./scripts/dockerenv.sh stop

.PHONY: gdb-server
gdb-server:
JLinkGDBServer -device da14531 -if SWD -ir

.PHONY: rtt-client
rtt-client:
telnet localhost 19021

.PHONY: build
build:
${MAKE} -C bitbox02-bt build

.PHONY: run
run:
${MAKE} -C bitbox02-bt run

.PHONY: clean
clean:
${MAKE} -C bitbox02-bt clean

.PHONY: test
test:
(cd u2fframing; cargo test test)
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# bitbox02 bluetooth firmware

## Dependencies

See Dockerfile for details

* ARM GCC Toolchain
* da14531 SDK

## Develop using a dev container

Run

```
docker pull shiftcrypto/da14531
```

or fetch the SDK from renasys website and run

```
make dockerinit
```

To run the container you can run

```
make dockerdev
```

## Connect to device

Run Jlink gdb server

```
make gdb-server
```

Run telnet to see rtt output

```
make rtt-client
```

Run gdb, which will load firmware into RAM and start execution. The gdbinit
script assumes that you run from inside a container. If you run it on your host
machine you will need to change the address gdb should connect to.

```
cd bitbox02-bt
make run
```
31 changes: 31 additions & 0 deletions bitbox02-bt/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[build]
target = "thumbv6m-none-eabi"

[patch.crates-io]
da14531-sdk-macros = {path="../da14531-sdk-macros"}

[target.thumbv6m-none-eabi]
rustflags = [
"-C", "linker=arm-none-eabi-gcc",
"-C", "link-arg=-march=armv6s-m",
# Generate output map
"-C", "link-arg=-Wl,-Map=output.map",
"-C", "link-arg=-specs=nano.specs",
"-C", "link-arg=-specs=nosys.specs",
# By default cargo doesn't link witih libc. We need to link with libc since we use nano libc
'-C', "default-linker-libraries",
"-C", "link-arg=-Wl,-Tldscript_DA14531.lds",
]

[profile.release]
opt-level = "z"
lto = true
debug = true # does not impact final binary
codegen-units = 1

[profile.dev]
opt-level = "z"
lto = true

[env]
DA14531_NON_RET_HEAP_SZ="2048"
2 changes: 2 additions & 0 deletions bitbox02-bt/.cargo/runner-debug.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.thumbv6m-none-eabi]
runner = "arm-none-eabi-gdb -x jlink-debug.gdb"
2 changes: 2 additions & 0 deletions bitbox02-bt/.cargo/runner-release.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.thumbv6m-none-eabi]
runner = "arm-none-eabi-gdb -x jlink-release.gdb"
2 changes: 2 additions & 0 deletions bitbox02-bt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
output.map
Loading

0 comments on commit 695d3d2

Please sign in to comment.