From f85fe5e6b0edf457a2cbfdaa2d3fd3e3c37bdb35 Mon Sep 17 00:00:00 2001 From: tadeubas Date: Mon, 29 Dec 2025 16:33:42 -0300 Subject: [PATCH 1/6] chore: Simulator Docker instructions --- .gitignore | 1 + Dockerfile | 32 ++++++++++++++++++++++++++++++++ README.md | 25 +++++++++++++++++++++++++ unix/simulator.py | 8 +++++++- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/.gitignore b/.gitignore index ed8510c11..0623e03b7 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ __pycache__/ pp .idea/ +firmware \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..35ffc5aa1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM gcc:11.5.0-bullseye + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y \ + git \ + make \ + python3 python3-venv python3-pip \ + swig \ + libpcsclite-dev pcscd \ + pkg-config \ + libffi-dev \ + xterm \ + autoconf automake libtool m4 + +WORKDIR /build + +RUN git clone --depth 1 --recursive \ + https://github.com/Coldcard/firmware.git + +WORKDIR /build/firmware/unix + +# Build mpy-cross +RUN make -C ../external/micropython/mpy-cross + +# Build simulator & tools +RUN make setup +RUN make ngu-setup +RUN make + +# remove unnecessary git files +RUN find /build/firmware -name ".git" -type d -prune -exec rm -rf '{}' + \ No newline at end of file diff --git a/README.md b/README.md index e0cbbb7d4..1e5a9e044 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,25 @@ so at the top level, do this command: pip install -r requirements.txt ``` +### Using Docker to build simulator +Install [Docker Desktop or Docker Engine](https://docs.docker.com/desktop/) (don't forget to add your user to the docker group `sudo usermod -aG docker $USER` than logout and login again) + +``` +# Build simulator +docker build -t coldcard-simulator . +docker create --name cc coldcard-simulator +docker cp cc:/build/firmware ./firmware +docker rm cc + +# Install specific libffi7 (as new Ubuntu versions ship with libffi8 only) +wget http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi7_3.3-4_amd64.deb +sudo dpkg -i libffi7_3.3-4_amd64.deb + +# Run simulator (remember to follow the OS specific instructions detailed below to install python and its dependencies) +cd firmware/unix +./simulator.py +``` + ### macOS [Python 3.5 or higher](https://www.python.org) and [Homebrew](https://brew.sh) is required. @@ -179,7 +198,13 @@ All steps you need to install and run the Coldcard simulator on Ubuntu 20.04: apt install build-essential git python3 python3-pip libudev-dev gcc-arm-none-eabi libffi-dev xterm swig libpcsclite-dev python-is-python3 autoconf libtool python3-venv # Get sources, this takes a long time (because of external libraries), then open + +# Recommended (fast, minimal download; sufficient for building and running the simulator): +git clone --depth 1 --recursive https://github.com/Coldcard/firmware.git + +# Full clone (developers only; required for history, bisecting, or contributing): git clone --recursive https://github.com/Coldcard/firmware.git + cd firmware # Apply address patch diff --git a/unix/simulator.py b/unix/simulator.py index af7e94fa0..9840eb11d 100755 --- a/unix/simulator.py +++ b/unix/simulator.py @@ -903,8 +903,14 @@ def sock_cleanup(): child.kill() return + logfile = '/tmp/cc_simulator.log' + + # truncate logfile and set correct permissions before starting xterm + open(logfile, 'w').close() + os.chmod(logfile, 0o644) + xterm = subprocess.Popen(['xterm', '-title', 'Coldcard Simulator REPL', - '-geom', '132x40+650+40', '-e'] + cc_cmd, + '-geom', '132x40+650+40', '-l', '-lf', logfile, '-e'] + cc_cmd, env=env, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, pass_fds=pass_fds, shell=False) From 279a30f31aceb6ac9cf186ea2e03dc3d9e641d29 Mon Sep 17 00:00:00 2001 From: tadeubas Date: Tue, 30 Dec 2025 18:08:46 -0300 Subject: [PATCH 2/6] chore: removed Docker --- Dockerfile | 32 -------------------------------- README.md | 21 +-------------------- 2 files changed, 1 insertion(+), 52 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 35ffc5aa1..000000000 --- a/Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -FROM gcc:11.5.0-bullseye - -ENV DEBIAN_FRONTEND=noninteractive - -RUN apt-get update && apt-get install -y \ - git \ - make \ - python3 python3-venv python3-pip \ - swig \ - libpcsclite-dev pcscd \ - pkg-config \ - libffi-dev \ - xterm \ - autoconf automake libtool m4 - -WORKDIR /build - -RUN git clone --depth 1 --recursive \ - https://github.com/Coldcard/firmware.git - -WORKDIR /build/firmware/unix - -# Build mpy-cross -RUN make -C ../external/micropython/mpy-cross - -# Build simulator & tools -RUN make setup -RUN make ngu-setup -RUN make - -# remove unnecessary git files -RUN find /build/firmware -name ".git" -type d -prune -exec rm -rf '{}' + \ No newline at end of file diff --git a/README.md b/README.md index 1e5a9e044..3aae27cef 100644 --- a/README.md +++ b/README.md @@ -91,25 +91,6 @@ so at the top level, do this command: pip install -r requirements.txt ``` -### Using Docker to build simulator -Install [Docker Desktop or Docker Engine](https://docs.docker.com/desktop/) (don't forget to add your user to the docker group `sudo usermod -aG docker $USER` than logout and login again) - -``` -# Build simulator -docker build -t coldcard-simulator . -docker create --name cc coldcard-simulator -docker cp cc:/build/firmware ./firmware -docker rm cc - -# Install specific libffi7 (as new Ubuntu versions ship with libffi8 only) -wget http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi7_3.3-4_amd64.deb -sudo dpkg -i libffi7_3.3-4_amd64.deb - -# Run simulator (remember to follow the OS specific instructions detailed below to install python and its dependencies) -cd firmware/unix -./simulator.py -``` - ### macOS [Python 3.5 or higher](https://www.python.org) and [Homebrew](https://brew.sh) is required. @@ -200,7 +181,7 @@ apt install build-essential git python3 python3-pip libudev-dev gcc-arm-none-eab # Get sources, this takes a long time (because of external libraries), then open # Recommended (fast, minimal download; sufficient for building and running the simulator): -git clone --depth 1 --recursive https://github.com/Coldcard/firmware.git +git clone --depth 1 --shallow-submodules --recursive https://github.com/Coldcard/firmware.git # Full clone (developers only; required for history, bisecting, or contributing): git clone --recursive https://github.com/Coldcard/firmware.git From ac0453dcfdf3b3d4c9f53da4e5e206622e7defa4 Mon Sep 17 00:00:00 2001 From: tadeubas Date: Tue, 30 Dec 2025 20:38:50 -0300 Subject: [PATCH 3/6] feat: add --log flag to enable simulator logging --- unix/README.md | 1 + unix/simulator.py | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/unix/README.md b/unix/README.md index 27e2575db..c44b244f6 100644 --- a/unix/README.md +++ b/unix/README.md @@ -63,6 +63,7 @@ wallet (on testnet, always with the same seed). But there are other options: - `--segregate` => scroll down to `Running simulators in parallel` section - `--bricked` => simulate a system w/ bricked SE1: no more pin tries, etc. - `--fails N` => simulate N wrong PIN attempts before login, where (1 <= N <= 13) +- `--log` => enable logging to `/tmp/cc-simulators//cc_simulator.log` See `variant/sim_settings.py` for the details of settings-related options. diff --git a/unix/simulator.py b/unix/simulator.py index 9840eb11d..e0e82198e 100755 --- a/unix/simulator.py +++ b/unix/simulator.py @@ -903,14 +903,24 @@ def sock_cleanup(): child.kill() return - logfile = '/tmp/cc_simulator.log' + xterm_args = ['xterm', '-title', 'Coldcard Simulator REPL', '-geom', '132x40+650+40'] - # truncate logfile and set correct permissions before starting xterm - open(logfile, 'w').close() - os.chmod(logfile, 0o644) + log = ("--log" in sys.argv) + if log: + logfile = '/tmp/cc-simulators/%d/cc_simulator.log' % pid - xterm = subprocess.Popen(['xterm', '-title', 'Coldcard Simulator REPL', - '-geom', '132x40+650+40', '-l', '-lf', logfile, '-e'] + cc_cmd, + # create dir for the file in /tmp + os.makedirs(os.path.dirname(logfile), exist_ok=True) + + # create or truncate logfile and set correct permissions before starting xterm + file_desc = os.open(logfile, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o644) + os.close(file_desc) + + xterm_args.extend(['-l', '-lf', logfile, '-e']) + else: + xterm_args.extend(['-e']) + + xterm = subprocess.Popen(xterm_args + cc_cmd, env=env, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, pass_fds=pass_fds, shell=False) From 0223c318d73fa2bb3e9200c0ac91806ab6ffd327 Mon Sep 17 00:00:00 2001 From: tadeubas Date: Wed, 31 Dec 2025 12:54:56 -0300 Subject: [PATCH 4/6] refactor(simulator): --log output path respects --segregate --- unix/README.md | 2 +- unix/simulator.py | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/unix/README.md b/unix/README.md index c44b244f6..03e79d718 100644 --- a/unix/README.md +++ b/unix/README.md @@ -63,7 +63,7 @@ wallet (on testnet, always with the same seed). But there are other options: - `--segregate` => scroll down to `Running simulators in parallel` section - `--bricked` => simulate a system w/ bricked SE1: no more pin tries, etc. - `--fails N` => simulate N wrong PIN attempts before login, where (1 <= N <= 13) -- `--log` => enable logging to `/tmp/cc-simulators//cc_simulator.log` +- `--log` => enable logging to `/tmp/cc_simulator.log`, or to `/tmp/cc-simulators//cc_simulator.log` when used with `--segregate` See `variant/sim_settings.py` for the details of settings-related options. diff --git a/unix/simulator.py b/unix/simulator.py index e0e82198e..624d1e1a9 100755 --- a/unix/simulator.py +++ b/unix/simulator.py @@ -863,12 +863,15 @@ def sock_cleanup(): cc_mpy = os.path.join(cwd, "coldcard-mpy") sim_boot = os.path.join(cwd, "sim_boot.py") + log_base_dir = "/tmp" + if segregate: os.makedirs("/tmp/cc-simulators", exist_ok=True) os.chdir("/tmp/cc-simulators") # our new work /tmp/cc-simulators/ os.mkdir(str(pid)) os.chdir(str(pid)) + log_base_dir = os.getcwd() os.mkdir("MicroSD") os.mkdir("settings") os.mkdir("VirtDisk") @@ -907,11 +910,7 @@ def sock_cleanup(): log = ("--log" in sys.argv) if log: - logfile = '/tmp/cc-simulators/%d/cc_simulator.log' % pid - - # create dir for the file in /tmp - os.makedirs(os.path.dirname(logfile), exist_ok=True) - + logfile = os.path.join(log_base_dir, 'cc_simulator.log') # create or truncate logfile and set correct permissions before starting xterm file_desc = os.open(logfile, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o644) os.close(file_desc) From 68c746bc9b32d241cee233333ba75d521cf9c23a Mon Sep 17 00:00:00 2001 From: tadeubas Date: Wed, 31 Dec 2025 13:21:58 -0300 Subject: [PATCH 5/6] refactor: drop --shallow-submodules since lwIP submodule does not support shallow clone --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index 3aae27cef..e0cbbb7d4 100644 --- a/README.md +++ b/README.md @@ -179,13 +179,7 @@ All steps you need to install and run the Coldcard simulator on Ubuntu 20.04: apt install build-essential git python3 python3-pip libudev-dev gcc-arm-none-eabi libffi-dev xterm swig libpcsclite-dev python-is-python3 autoconf libtool python3-venv # Get sources, this takes a long time (because of external libraries), then open - -# Recommended (fast, minimal download; sufficient for building and running the simulator): -git clone --depth 1 --shallow-submodules --recursive https://github.com/Coldcard/firmware.git - -# Full clone (developers only; required for history, bisecting, or contributing): git clone --recursive https://github.com/Coldcard/firmware.git - cd firmware # Apply address patch From a316117ae3a566cc283f6b176f68fd10c2003edf Mon Sep 17 00:00:00 2001 From: tadeubas Date: Fri, 2 Jan 2026 16:27:17 -0300 Subject: [PATCH 6/6] chore: revert .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0623e03b7..ed8510c11 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,3 @@ __pycache__/ pp .idea/ -firmware \ No newline at end of file