-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
126 lines (92 loc) · 3.64 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
RUSTARGS=--release
VERSION=$(shell git describe --dirty=+)
NANOSP_ARGS=
NANOX_ARGS=
SPECULOS_ARGS=--zoom=4
ifdef MNEMONIC
SPECULOS_ARGS+=--seed "$(MNEMONIC)"
endif
all: fw lib
# Build all firmware
fw: nanosplus nanox
# Build lib / CLI
lib:
cd lib && cargo build
# Run tests
test: core-test nanosplus-test nanox-test
core-test:
cargo nextest run --package ledger-mob-core
nanosplus-test: nanosplus
MODEL=nanosplus cargo nextest run --package ledger-mob $(NANOSP_ARGS)
nanox-test: nanox
MODEL=nanox cargo nextest run --package ledger-mob
# Build docs
docs:
cargo doc --no-deps --workspace
# Build nanosplus firmware
nanosplus:
cd fw && cargo build --target nanosplus $(NANOSP_ARGS) $(RUSTARGS)
# Build nanox firmware
nanox:
cd fw && cargo build --target ./nanox.json $(NANOX_ARGS) $(RUSTARGS)
# Run nanosplus firmware under speculos without debug
nanosplus-run:
cd fw && cargo run --target nanosplus $(NANOSP_ARGS) $(RUSTARGS) -- $(SPECULOS_ARGS)
# Run nanox firmware under speculos without debug
nanox-run:
cd fw && cargo run --target ./nanox.json $(NANOX_ARGS) $(RUSTARGS) -- $(SPECULOS_ARGS)
# Load firmware onto device
nanosplus-load: nanosplus
cd fw && cargo ledger --use-prebuilt target/nanosplus/release/ledger-mob-fw build nanosplus --load
# Convert ELF to HEX for loading
fw/target/%/release/ledger-mob-fw.hex: %
arm-none-eabi-objcopy fw/target/$</release/ledger-mob-fw -O ihex $@
# Package nanoapp to archive
package-%: % fw/target/%/release/ledger-mob-fw.hex
mkdir -p target/ledger-mob-fw-$<
cp fw/target/$</release/ledger-mob-fw.hex target/ledger-mob-fw-$<
cp fw/target/$</release/app_$<.json target/ledger-mob-fw-$<
cp fw/target/$</release/mob14x14i.gif target/ledger-mob-fw-$<
tar cvf ledger-mob-fw-$<.tgz \
-C target \
ledger-mob-fw-$<
# Run firmware under speculos with QEMU debug connection
nanosplus-debug:
cd fw && speculos --model nanosp --display qt --apdu-port 1237 $(SPECULOS_ARGS) -d target/nanosplus/release/ledger-mob-fw
# Launch GDB connecting to speculos QEMU
nanosplus-gdb:
cd fw && rust-gdb target/nanosplus/release/ledger-mob-fw
# Objdump to show disassembly of sample_main (see `sp` for stack allocation)
objdump:
arm-none-eabi-objdump fw/target/nanosplus/release/ledger-mob-fw --disassemble=sample_main -S | head -n 20
wts-nanosplus:
wts fw/target/nanosplus/release/ledger-mob-fw -n 20
wts-nanox:
wts fw/target/nanox/release/ledger-mob-fw -n 20
# Run linters
lint: fmt clippy
fmt:
cargo fmt --check -p ledger-mob -p ledger-mob-apdu ledger-mob-core -p ledger-mob-tests
cargo fmt --check --manifest-path=fw/Cargo.toml
clippy:
cargo clippy -p ledger-mob -p ledger-mob-apdu -p ledger-mob-core -p ledger-mob-tests --no-deps -- -D warnings
# TODO: fix... something to do with target / build-std
# cd fw && cargo clippy -p ledger-mob-fw --no-deps -- -D warnings
# Apply linters
fix: fmt-fix clippy-fix
fmt-fix:
cargo fmt -p ledger-mob -p ledger-mob-apdu -p ledger-mob-core -p ledger-mob-tests
cargo fmt --manifest-path=fw/Cargo.toml
clippy-fix:
cargo clippy --fix --allow-dirty -p ledger-mob -p ledger-mob-apdu -p ledger-mob-core -p ledger-mob-tests --no-deps -- -D warnings
cd fw && cargo clippy --fix --target nanosplus --allow-dirty -p ledger-mob-fw --no-deps -- -D warnings
# Run MIRI checks
# Notes:
# - this requires a patched `mc-crypto-hashes` to disable `simd`
# - `cargo clean` must be run to clear non-miri objects
# - only specific tests with miri support are enabled
miri:
cd core && cargo miri nextest run --no-default-features --features alloc,mlsag,ident,memo,summary -j4 -- miri_function tx_summary ring_sign test_sign
clean:
rm -rf target fw/target
.PHONY: fw lib core nanosplus nanox fmt clippy clean docs