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

use emu arm from github #253

Merged
merged 14 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .github/workflows/build-tenv-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/Dockerfile
file: ./docker/Dockerfile-debian
platforms: linux/amd64,linux/arm64
push: true
tags: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ __pycache__
src/binaries/firmware/bin/*
!src/binaries/firmware/bin/download.sh
!src/binaries/firmware/bin/download_latest_gh.py
!src/binaries/firmware/bin/patch-bin.sh
!src/binaries/firmware/bin/arm
!src/binaries/trezord-go/bin/download.sh
emulator.img
Expand Down
54 changes: 54 additions & 0 deletions docker/Dockerfile-debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Start with a base Debian image
FROM debian:bookworm-slim

# Set environment variables
ENV TERM=xterm \
XDG_RUNTIME_DIR="/var/tmp" \
LC_ALL=C.UTF-8 \
LANG=C.UTF-8 \
GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt \
NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt

# Install required packages
RUN curl -sL https://deb.nodesource.com/setup_22.x | bash -
RUN apt-get update && apt-get install -y --no-install-recommends \
openssl \
bash \
git \
nodejs \
python3 \
python3-dev \
python3-pip \
python3-venv \
python3-poetry \
libsdl2-2.0-0 \
libsdl2-image-2.0-0 \
x11-xserver-utils \
wget \
unzip \
curl \
procps \
build-essential \
g++ \
libc6 \
libc6-dev \
patchelf \
&& apt-get clean && rm -rf /var/lib/apt/lists/*


# Add basic trezor-user-env files
COPY ./ /trezor-user-env
WORKDIR /trezor-user-env

# Install Python dependencies using poetry
RUN poetry cache clear --all pypi
RUN poetry install --no-dev --no-root

# Execute scripts and clean up
RUN ./src/binaries/firmware/bin/download.sh
RUN ./src/binaries/trezord-go/bin/download.sh
# Patch emulator binaries
RUN cd src/binaries/firmware/bin && ./patch-bin.sh

# Command to run on container start
CMD poetry run python src/main.py
1 change: 0 additions & 1 deletion docker/compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:
trezor-user-env-unix:
container_name: trezor-user-env.unix
Expand Down
2 changes: 1 addition & 1 deletion patch_emulators.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ DIR_TO_PATCH="${1:-src/binaries/firmware/bin}"

echo "Patching ${DIR_TO_PATCH}"

nix-shell --run "autoPatchelf ${DIR_TO_PATCH}"
patchelf ${DIR_TO_PATCH}
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["SatoshiLabs <[email protected]>"]
[tool.poetry.dependencies]
python = "^3.11"
termcolor = "^1.1.0"
trezor = { git = "https://github.com/trezor/trezor-firmware.git", branch = "main", subdirectory = "python" }
trezor = "^0.13.9"
websockets = "^10.1"
psutil = "^5.8.0"
Pillow = "^9.1.0"
Expand Down
1 change: 0 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ stdenv.mkDerivation {
xorg.xhost
wget
git
unzip
curl
procps
];
Expand Down
26 changes: 10 additions & 16 deletions src/binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
USER_DOWNLOADED_DIR = FIRMWARE_BIN_DIR / "user_downloaded"
USER_DOWNLOADED_DIR.mkdir(exist_ok=True)

Model = Literal["1", "2", "R", "T3T1"]
Model = Literal["T1B1", "T2T1", "T2B1", "T3T1"]
FIRMWARES: Dict[Model, Dict[str, str]] = {
"1": OrderedDict(),
"2": OrderedDict(),
"R": OrderedDict(),
"T1B1": OrderedDict(),
"T2T1": OrderedDict(),
"T2B1": OrderedDict(),
"T3T1": OrderedDict(),
}

Expand All @@ -24,9 +24,9 @@
IS_ARM = os.uname().machine.startswith(("aarch64", "arm"))
ARM_IDENTIFIER = "-arm"

IDENTIFIER_T1 = "trezor-emu-legacy-v"
IDENTIFIER_TT = "trezor-emu-core-v"
IDENTIFIER_TR = "trezor-emu-core-R-v"
IDENTIFIER_T1B1 = "trezor-emu-legacy-v"
IDENTIFIER_T2T1 = "trezor-emu-core-v"
IDENTIFIER_T2B1 = "trezor-emu-core-R-v"
IDENTIFIER_T3T1 = "trezor-emu-core-T3T1-v"


Expand Down Expand Up @@ -84,9 +84,9 @@ def explore_firmwares(args: Any) -> None:
continue

models: List[Tuple[str, Model]] = [
(IDENTIFIER_T1, "1"),
(IDENTIFIER_TT, "2"),
(IDENTIFIER_TR, "R"),
(IDENTIFIER_T1B1, "T1B1"),
(IDENTIFIER_T2T1, "T2T1"),
(IDENTIFIER_T2B1, "T2B1"),
(IDENTIFIER_T3T1, "T3T1"),
]

Expand Down Expand Up @@ -140,15 +140,9 @@ def explore_bridges() -> None:
if IS_ARM:
BRIDGES.append(f"2.0.33{ARM_IDENTIFIER}")
BRIDGES.append(f"2.0.32{ARM_IDENTIFIER}")
BRIDGES.append(f"2.0.31{ARM_IDENTIFIER}")
BRIDGES.append(f"2.0.30{ARM_IDENTIFIER}")
else:
BRIDGES.append("2.0.33")
BRIDGES.append("2.0.32")
BRIDGES.append("2.0.31")
BRIDGES.append("2.0.27")
BRIDGES.append("2.0.26")
BRIDGES.append("2.0.19")


def patch_emulators_for_nix(dir_to_patch: str = "") -> None:
Expand Down
Binary file not shown.
43 changes: 13 additions & 30 deletions src/binaries/firmware/bin/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,12 @@ SYSTEM_ARCH=$(uname -m)
cd "$(dirname "${BASH_SOURCE[0]}")"
BIN_DIR=$(pwd)

# WARNING: this will download the emulators from the latest SUCCESSFULLY run pipeline from trezor-firmware.
# If the pipeline fails, it will download from the previous successful run.
GITLAB_URL="https://gitlab.com/satoshilabs/trezor/trezor-firmware/-/jobs/artifacts/main/download"

if [[ $SYSTEM_ARCH == x86_64* ]]; then
# All core emulators are downloaded from trezor.io
SITE="https://data.trezor.io/dev/firmware/releases/emulators/"
LEGACY_LATEST_BUILD="${GITLAB_URL}?job=legacy%20emu%20regular%20debug%20build"
CUT_DIRS=4

elif [[ $SYSTEM_ARCH == aarch64* ]]; then
SITE="https://data.trezor.io/dev/firmware/releases/emulators/arm/"
CORE_LATEST_BUILD="${GITLAB_URL}?job=core%20unix%20frozen%20debug%20build%20arm"
R_LATEST_BUILD="${GITLAB_URL}?job=core%20unix%20frozen%20R%20debug%20build%20arm"
LEGACY_LATEST_BUILD="${GITLAB_URL}?job=legacy%20emu%20regular%20debug%20build%20arm"
T3T1_LATEST_BUILD="${GITLAB_URL}?job=core%20unix%20frozen%20T3T1%20debug%20build%20arm"
CUT_DIRS=5

else
Expand Down Expand Up @@ -52,38 +42,31 @@ cd "$TMP_DIR"
# otherwise extracting TR into already existing TT will ask for confirmation

if [[ $SYSTEM_ARCH == x86_64* ]]; then
wget --no-config -O trezor-emu-legacy-main.zip "$LEGACY_LATEST_BUILD"
unzip -o -q trezor-emu-legacy-main.zip
mv legacy/firmware/trezor.elf ../trezor-emu-legacy-v1-main
wget https://data.trezor.io/dev/firmware/emu-nightly/trezor-emu-legacy-T1B1-universal
mv trezor-emu-legacy-T1B1-universal ../trezor-emu-legacy-v1-main

wget https://data.trezor.io/dev/firmware/emu-nightly/trezor-emu-core-T2T1-universal
mv trezor-emu-core-T2T1-universal ../trezor-emu-core-v2-main

wget https://data.trezor.io/dev/firmware/emu-nightly/trezor-emu-core-T3T1-universal
mv trezor-emu-core-T3T1-universal ../trezor-emu-core-T3T1-v2-main

wget https://data.trezor.io/dev/firmware/emu-nightly/trezor-emu-core-T2B1-universal
mv trezor-emu-core-T2B1-universal ../trezor-emu-core-R-v2-main

wget https://data.trezor.io/dev/firmware/emu-nightly/trezor-emu-core-T3T1-universal
mv trezor-emu-core-T3T1-universal ../trezor-emu-core-T3T1-v2-main

elif [[ $SYSTEM_ARCH == aarch64* ]]; then
wget --no-config -O trezor-emu-core-arm-main.zip "$CORE_LATEST_BUILD"
unzip -o -q trezor-emu-core-arm-main.zip -d arm/
mv arm/core/build/unix/trezor-emu-core-arm ../trezor-emu-core-v2-main-arm

wget --no-config -O trezor-emu-core-R-arm-main.zip "$R_LATEST_BUILD"
unzip -o -q trezor-emu-core-R-arm-main.zip -d arm/
mv arm/core/build/unix/trezor-emu-core-arm ../trezor-emu-core-R-v2-main-arm
wget https://data.trezor.io/dev/firmware/emu-nightly/trezor-emu-arm-legacy-T1B1-universal
mv trezor-emu-arm-legacy-T1B1-universal ../trezor-emu-legacy-v1-main-arm

# TEMPORARILY replaced by baking the emulators into the image
wget --no-config -O trezor-emu-core-T3T1-arm-main.zip "$T3T1_LATEST_BUILD"
unzip -o -q trezor-emu-core-T3T1-arm-main.zip -d arm/
mv arm/core/build/unix/trezor-emu-core-arm ../trezor-emu-core-T3T1-v2-main-arm
mv ../arm/trezor-emu-core-T3T1-v2-main-arm ../trezor-emu-core-T3T1-v2-main-static-arm
wget https://data.trezor.io/dev/firmware/emu-nightly/trezor-emu-arm-core-T2T1-universal
mv trezor-emu-arm-core-T2T1-universal ../trezor-emu-core-v2-main-arm

wget --no-config -O trezor-emu-legacy-arm-main.zip "$LEGACY_LATEST_BUILD"
unzip -o -q trezor-emu-legacy-arm-main.zip -d arm/
mv arm/legacy/firmware/trezor-arm.elf ../trezor-emu-legacy-v1-main-arm
wget https://data.trezor.io/dev/firmware/emu-nightly/trezor-emu-arm-core-T2B1-universal
mv trezor-emu-arm-core-T2B1-universal ../trezor-emu-core-R-v2-main-arm

wget https://data.trezor.io/dev/firmware/emu-nightly/trezor-emu-arm-core-T3T1-universal
mv trezor-emu-arm-core-T3T1-universal ../trezor-emu-core-T3T1-v2-main-arm
fi

cd "$BIN_DIR"
Expand Down
100 changes: 0 additions & 100 deletions src/binaries/firmware/bin/download_latest_gh.py

This file was deleted.

Loading
Loading