Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build and docs #13

Draft
wants to merge 4 commits into
base: s-x-compat
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bin
debug
dep
obj
src/glyphs.c
src/glyphs.h
# Compilation files of the application
build/

# Legacy compilation output
bin/
debug/
57 changes: 0 additions & 57 deletions Dockerfile.build

This file was deleted.

53 changes: 0 additions & 53 deletions Dockerfile.build-all

This file was deleted.

134 changes: 134 additions & 0 deletions Dockerfile.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Adapted from LedgerHQ/ledger-app-builder (lite)
# https://github.com/LedgerHQ/ledger-app-builder/blob/a5e4a50c400d169149cacfdf49fa92f3ef954862/lite/Dockerfile

# Usage:
# $ docker build -f Dockerfile.builder -t ledger-hns-builder .

# Build for Nano X (default):
# $ docker run --rm -ti -v "$(realpath .):/app" --user $(id -u):$(id -g) \
# ledger-hns-builder:latest

# Build for Nano S+:
# $ docker run --rm -ti -v "$(realpath .):/app" --user $(id -u):$(id -g) \
# -e MODEL=NANOSP ledger-hns-builder:latest

# Build for Nano S with debug set:
# $ docker run --rm -ti -v "$(realpath .):/app" --user $(id -u):$(id -g) \
# -e MODEL=NANOSP ledger-hns-builder:latest -- DEBUG=1


FROM alpine:3.15
ENV LANG C.UTF-8

# Install dependencies
# --------------------

RUN apk update
RUN apk upgrade

# Adding LLVM-15 APT repository and installing it
# LLVM-15 is only present starting from the v3.17 Alpine version
RUN apk add --repository=http://dl-cdn.alpinelinux.org/alpine/v3.17/main llvm15
RUN ln -s /usr/lib/llvm15/bin/llvm-objcopy /usr/bin/llvm-objcopy-15 && ln -s /usr/lib/llvm15/bin/llvm-nm /usr/bin/llvm-nm-15

RUN apk add \
bash \
clang \
clang-analyzer \
clang-extra-tools \
cmake \
cmocka-dev \
doxygen \
gcc-arm-none-eabi \
git \
jq \
lld \
make \
musl-dev \
newlib-arm-none-eabi \
protoc \
python3

# Install pip and wheel
RUN python3 -m ensurepip --upgrade \
&& pip3 install --upgrade pip \
&& pip3 install wheel

# These packages contain shared libraries which will be needed at runtime
RUN apk add \
eudev \
libjpeg \
libusb \
zlib

# Python packages building dependencies, can be removed afterwards
RUN apk add -t python_build_deps eudev-dev \
jpeg-dev \
libusb-dev \
linux-headers \
python3-dev \
zlib-dev

# temporary, until a fixed version of hidapi is released
# (with https://github.com/trezor/cython-hidapi/commit/749da69)
RUN pip3 install 'Cython<3'

# Python package to load app onto device
RUN pip3 install ledgerblue tomli-w

# Cleanup, remove packages that aren't needed anymore
RUN apk del python_build_deps


# Download SDKs for all models
# ----------------------------

ARG NANOS_SDK_TAG=v2.1.0-14
ARG NANOX_SDK_TAG=v5.8.0
ARG NANOSP_SDK_TAG=v1.10.1

# Work around the git security to be able to get informations from repositories
# even if the container is not run with root UID/GID
RUN git config --system --add safe.directory "*"
ENV GIT_SERVER=https://github.com/LedgerHQ

# Latest Nano S SDK
# Will switch to the unified SDK for next OS release.
ENV NANOS_SDK=/opt/nanos-secure-sdk
RUN git clone --branch "$NANOS_SDK_TAG" --depth 1 "$GIT_SERVER/nanos-secure-sdk.git" "$NANOS_SDK"

# Unified SDK
ENV LEDGER_SECURE_SDK=/opt/ledger-secure-sdk
RUN git clone "$GIT_SERVER/ledger-secure-sdk.git" "$LEDGER_SECURE_SDK"

# Nano X
ENV NANOX_SDK=/opt/nanox-secure-sdk
RUN git -C "$LEDGER_SECURE_SDK" worktree add "$NANOX_SDK" "$NANOX_SDK_TAG"
RUN echo nanox > $NANOX_SDK/.target

# Nano S+
ENV NANOSP_SDK=/opt/nanosplus-secure-sdk
RUN git -C "$LEDGER_SECURE_SDK" worktree add "$NANOSP_SDK" "$NANOSP_SDK_TAG"
RUN echo nanos2 > $NANOSP_SDK/.target

# Stax
# Not supported.

# Old Nano X SDK, use for <= 2.0.2-2
# ENV NANOX_SDK=/opt/nanox-secure-sdk
# RUN git clone --branch 2.0.2-2 --depth 1 "$GIT_SERVER/nanox-secure-sdk.git" "$NANOX_SDK"

# Old Nano S+ SDK, use for <= 1.0.4
# ENV NANOSP_SDK=/opt/nanosplus-secure-sdk
# RUN git clone --branch 1.0.4 --depth 1 "$GIT_SERVER/nanosplus-secure-sdk.git" "$NANOSP_SDK"


# Build the app
# -------------

WORKDIR /app

# can be: NANOS, NANOX (default), NANOSP
ENV MODEL=NANOX

ENTRYPOINT ["/bin/sh", "-c", "eval \"export BOLOS_SDK=\\${${MODEL}_SDK}\" && make $@"]
49 changes: 3 additions & 46 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ all: default
include $(BOLOS_SDK)/Makefile.glyphs

load: all
python -m ledgerblue.loadApp $(APP_LOAD_PARAMS)
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS)

delete:
python -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)
python3 -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)

include $(BOLOS_SDK)/Makefile.rules

Expand All @@ -140,47 +140,4 @@ dep/%.d: %.c Makefile
listvariants:
@echo VARIANTS COIN hns

#
# Docker Rules
#

ifeq ($(GIT_NAME),)
GIT_NAME := nanos-secure-sdk
endif

ifeq ($(GIT_REF),)
GIT_REF := nanos-1612
endif

DOCKER_ARGS = --build-arg GIT_NAME='$(GIT_NAME)' \
--build-arg GIT_REF='$(GIT_REF)' \
--build-arg CACHE_BUST='$(shell date)'

docker:
docker build $(DOCKER_ARGS) -f Dockerfile.build -t ledger-app-hns-build .
docker run --name ledger-app-hns-build ledger-app-hns-build
docker cp ledger-app-hns-build:/ledger-app-hns/bin/app.elf ./bin
docker cp ledger-app-hns-build:/ledger-app-hns/bin/app.hex ./bin
docker cp ledger-app-hns-build:/ledger-app-hns/debug/app.map ./debug
docker cp ledger-app-hns-build:/ledger-app-hns/debug/app.asm ./debug
docker rm ledger-app-hns-build

docker-load: docker
python -m ledgerblue.loadApp $(APP_LOAD_PARAMS)

docker-build-all:
docker build -f Dockerfile.build-all -t ledger-app-hns-build-all . --progress=plain
docker run --name ledger-app-hns-build-all ledger-app-hns-build-all
docker cp ledger-app-hns-build-all:/nanos/bin/app.elf ./bin/hns-nanos.elf
docker cp ledger-app-hns-build-all:/nanos/bin/app.hex ./bin/hns-nanos.hex
docker cp ledger-app-hns-build-all:/nanos/debug/app.map ./debug/hns-nanos.map
docker cp ledger-app-hns-build-all:/nanos/debug/app.asm ./debug/hns-nanos.asm
docker cp ledger-app-hns-build-all:/nanox/bin/app.elf ./bin/hns-nanox.elf
docker cp ledger-app-hns-build-all:/nanox/bin/app.hex ./bin/hns-nanox.hex
docker cp ledger-app-hns-build-all:/nanox/debug/app.map ./debug/hns-nanox.map
docker cp ledger-app-hns-build-all:/nanox/debug/app.asm ./debug/hns-nanox.asm
docker rm ledger-app-hns-build-all

MAKECMDGOALS := docker docker-load

.PHONY: all load delete listvariants docker docker-load
.PHONY: all load delete listvariants
Loading