2017-08-01 16:50:28 +00:00
|
|
|
# pylint: disable=E0602
|
2021-03-23 12:14:33 +00:00
|
|
|
# fmt: off
|
2017-08-01 16:50:28 +00:00
|
|
|
|
2017-08-07 10:04:23 +00:00
|
|
|
import os
|
2024-09-26 10:03:59 +00:00
|
|
|
import tools, models, ui
|
2017-08-07 10:04:23 +00:00
|
|
|
|
2019-08-22 18:15:16 +00:00
|
|
|
BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0')
|
2023-03-02 15:31:25 +00:00
|
|
|
PRODUCTION = ARGUMENTS.get('PRODUCTION', '0') == '1'
|
2022-11-23 15:02:05 +00:00
|
|
|
BOOTLOADER_QA = ARGUMENTS.get('BOOTLOADER_QA', '0') == '1'
|
2023-08-10 09:30:13 +00:00
|
|
|
BOOTLOADER_DEVEL = ARGUMENTS.get('BOOTLOADER_DEVEL', '0') == '1'
|
2019-08-22 18:15:16 +00:00
|
|
|
EVERYTHING = BITCOIN_ONLY != '1'
|
2020-08-28 12:50:38 +00:00
|
|
|
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
|
2023-01-30 14:36:22 +00:00
|
|
|
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
|
2023-11-13 15:52:37 +00:00
|
|
|
PYOPT = ARGUMENTS.get('PYOPT', '1')
|
|
|
|
DISABLE_OPTIGA = ARGUMENTS.get('DISABLE_OPTIGA', '0') == '1'
|
2024-04-14 10:28:57 +00:00
|
|
|
HW_REVISION = ARGUMENTS.get('HW_REVISION', None)
|
2024-04-02 14:51:01 +00:00
|
|
|
THP = ARGUMENTS.get('THP', '0') == '1' # Trezor-Host Protocol
|
2024-09-16 12:12:51 +00:00
|
|
|
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
|
2024-08-08 12:23:13 +00:00
|
|
|
BENCHMARK = ARGUMENTS.get('BENCHMARK', '0') == '1'
|
2022-11-23 15:02:05 +00:00
|
|
|
|
2024-10-02 16:06:32 +00:00
|
|
|
if BENCHMARK and PYOPT != '0':
|
|
|
|
print("BENCHMARK=1 works only with PYOPT=0.")
|
|
|
|
exit(1)
|
|
|
|
|
2020-11-18 13:33:06 +00:00
|
|
|
FEATURE_FLAGS = {
|
|
|
|
"RDI": True,
|
2022-02-04 12:41:56 +00:00
|
|
|
"SECP256K1_ZKP": True, # required for trezor.crypto.curve.bip340 (BIP340/Taproot)
|
2024-08-08 12:22:27 +00:00
|
|
|
"AES_GCM": BENCHMARK,
|
2020-11-18 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 09:30:29 +00:00
|
|
|
FEATURES_WANTED = ["input", "sbu", "sd_card", "rgb_led", "dma2d", "consumption_mask", "usb" ,"optiga", "haptic"]
|
2023-11-13 15:52:37 +00:00
|
|
|
if DISABLE_OPTIGA and PYOPT == '0':
|
|
|
|
FEATURES_WANTED.remove("optiga")
|
2023-02-15 12:57:54 +00:00
|
|
|
|
2017-08-01 16:50:28 +00:00
|
|
|
CCFLAGS_MOD = ''
|
|
|
|
CPPPATH_MOD = []
|
|
|
|
CPPDEFINES_MOD = []
|
|
|
|
SOURCE_MOD = []
|
2024-04-10 13:11:12 +00:00
|
|
|
SOURCE_MOD_CRYPTO = []
|
2023-06-23 14:50:13 +00:00
|
|
|
CPPDEFINES_HAL = []
|
|
|
|
SOURCE_HAL = []
|
|
|
|
PATH_HAL = []
|
2024-09-26 10:03:59 +00:00
|
|
|
RUST_UI_FEATURES = []
|
2017-08-01 16:50:28 +00:00
|
|
|
|
2019-08-21 16:04:15 +00:00
|
|
|
FROZEN = True
|
2018-02-08 17:04:10 +00:00
|
|
|
|
2017-08-01 16:50:28 +00:00
|
|
|
# modtrezorconfig
|
2019-01-24 15:17:37 +00:00
|
|
|
CPPPATH_MOD += [
|
|
|
|
'embed/extmod/modtrezorconfig',
|
|
|
|
'vendor/trezor-storage',
|
|
|
|
]
|
2017-08-01 16:50:28 +00:00
|
|
|
SOURCE_MOD += [
|
|
|
|
'embed/extmod/modtrezorconfig/modtrezorconfig.c',
|
|
|
|
]
|
|
|
|
|
|
|
|
# modtrezorcrypto
|
|
|
|
CCFLAGS_MOD += '-Wno-sequence-point '
|
|
|
|
CPPPATH_MOD += [
|
2017-12-12 19:31:03 +00:00
|
|
|
'vendor/trezor-crypto',
|
2017-08-01 16:50:28 +00:00
|
|
|
]
|
|
|
|
CPPDEFINES_MOD += [
|
|
|
|
'AES_128',
|
|
|
|
'AES_192',
|
2020-04-29 08:59:10 +00:00
|
|
|
('USE_BIP32_CACHE', '0'),
|
2017-12-23 14:12:31 +00:00
|
|
|
('USE_KECCAK', '1'),
|
2019-08-21 16:53:08 +00:00
|
|
|
('USE_ETHEREUM', '1' if EVERYTHING else '0'),
|
|
|
|
('USE_MONERO', '1' if EVERYTHING else '0'),
|
|
|
|
('USE_CARDANO', '1' if EVERYTHING else '0'),
|
2024-03-04 00:02:05 +00:00
|
|
|
('USE_NEM', '1' if (EVERYTHING and TREZOR_MODEL == "T") else '0'),
|
|
|
|
('USE_EOS', '1' if (EVERYTHING and TREZOR_MODEL == "T") else '0'),
|
2017-08-01 16:50:28 +00:00
|
|
|
]
|
|
|
|
SOURCE_MOD += [
|
2021-03-23 12:14:33 +00:00
|
|
|
'embed/extmod/trezorobj.c',
|
2017-12-19 20:54:22 +00:00
|
|
|
'embed/extmod/modtrezorcrypto/crc.c',
|
2019-09-03 16:15:47 +00:00
|
|
|
'embed/extmod/modtrezorcrypto/modtrezorcrypto.c',
|
2017-08-01 16:50:28 +00:00
|
|
|
'embed/extmod/modtrezorcrypto/rand.c',
|
2024-04-10 13:11:12 +00:00
|
|
|
]
|
|
|
|
SOURCE_MOD_CRYPTO += [
|
2017-12-12 19:31:03 +00:00
|
|
|
'vendor/trezor-crypto/address.c',
|
2019-09-03 16:15:47 +00:00
|
|
|
'vendor/trezor-crypto/aes/aes_modes.c',
|
2023-08-23 13:42:16 +00:00
|
|
|
'vendor/trezor-crypto/aes/aesccm.c',
|
2017-12-12 19:31:03 +00:00
|
|
|
'vendor/trezor-crypto/aes/aescrypt.c',
|
|
|
|
'vendor/trezor-crypto/aes/aeskey.c',
|
|
|
|
'vendor/trezor-crypto/aes/aestab.c',
|
2018-03-09 10:37:06 +00:00
|
|
|
'vendor/trezor-crypto/base32.c',
|
2019-09-03 16:15:47 +00:00
|
|
|
'vendor/trezor-crypto/base58.c',
|
2017-12-12 19:31:03 +00:00
|
|
|
'vendor/trezor-crypto/bignum.c',
|
|
|
|
'vendor/trezor-crypto/bip32.c',
|
|
|
|
'vendor/trezor-crypto/bip39.c',
|
2022-05-31 13:58:34 +00:00
|
|
|
'vendor/trezor-crypto/bip39_english.c',
|
2017-12-12 21:00:15 +00:00
|
|
|
'vendor/trezor-crypto/blake256.c',
|
2017-12-12 19:31:03 +00:00
|
|
|
'vendor/trezor-crypto/blake2b.c',
|
|
|
|
'vendor/trezor-crypto/blake2s.c',
|
2023-11-24 07:39:28 +00:00
|
|
|
'vendor/trezor-crypto/buffer.c',
|
2018-01-02 17:57:23 +00:00
|
|
|
'vendor/trezor-crypto/chacha20poly1305/chacha20poly1305.c',
|
|
|
|
'vendor/trezor-crypto/chacha20poly1305/chacha_merged.c',
|
|
|
|
'vendor/trezor-crypto/chacha20poly1305/poly1305-donna.c',
|
|
|
|
'vendor/trezor-crypto/chacha20poly1305/rfc7539.c',
|
2020-02-26 16:39:59 +00:00
|
|
|
'vendor/trezor-crypto/chacha_drbg.c',
|
2019-09-03 16:15:47 +00:00
|
|
|
'vendor/trezor-crypto/curves.c',
|
2023-11-24 07:39:28 +00:00
|
|
|
'vendor/trezor-crypto/der.c',
|
2019-09-03 16:15:47 +00:00
|
|
|
'vendor/trezor-crypto/ecdsa.c',
|
2017-12-12 21:00:15 +00:00
|
|
|
'vendor/trezor-crypto/ed25519-donna/curve25519-donna-32bit.c',
|
|
|
|
'vendor/trezor-crypto/ed25519-donna/curve25519-donna-helpers.c',
|
|
|
|
'vendor/trezor-crypto/ed25519-donna/curve25519-donna-scalarmult-base.c',
|
|
|
|
'vendor/trezor-crypto/ed25519-donna/ed25519-donna-32bit-tables.c',
|
|
|
|
'vendor/trezor-crypto/ed25519-donna/ed25519-donna-basepoint-table.c',
|
|
|
|
'vendor/trezor-crypto/ed25519-donna/ed25519-donna-impl-base.c',
|
|
|
|
'vendor/trezor-crypto/ed25519-donna/ed25519-keccak.c',
|
|
|
|
'vendor/trezor-crypto/ed25519-donna/ed25519-sha3.c',
|
2019-09-03 16:15:47 +00:00
|
|
|
'vendor/trezor-crypto/ed25519-donna/ed25519.c',
|
2017-12-12 21:00:15 +00:00
|
|
|
'vendor/trezor-crypto/ed25519-donna/modm-donna-32bit.c',
|
2018-06-15 08:31:21 +00:00
|
|
|
'vendor/trezor-crypto/groestl.c',
|
2017-12-12 21:00:15 +00:00
|
|
|
'vendor/trezor-crypto/hasher.c',
|
2017-12-12 19:31:03 +00:00
|
|
|
'vendor/trezor-crypto/hmac.c',
|
2019-06-07 10:16:24 +00:00
|
|
|
'vendor/trezor-crypto/hmac_drbg.c',
|
2018-01-18 14:26:22 +00:00
|
|
|
'vendor/trezor-crypto/memzero.c',
|
2018-03-09 10:37:06 +00:00
|
|
|
'vendor/trezor-crypto/nem.c',
|
2017-12-12 19:31:03 +00:00
|
|
|
'vendor/trezor-crypto/nist256p1.c',
|
|
|
|
'vendor/trezor-crypto/pbkdf2.c',
|
2018-01-13 14:28:35 +00:00
|
|
|
'vendor/trezor-crypto/rand.c',
|
2019-06-07 10:16:24 +00:00
|
|
|
'vendor/trezor-crypto/rfc6979.c',
|
2019-09-03 16:15:47 +00:00
|
|
|
'vendor/trezor-crypto/ripemd160.c',
|
2017-12-12 19:31:03 +00:00
|
|
|
'vendor/trezor-crypto/secp256k1.c',
|
2022-09-09 20:11:58 +00:00
|
|
|
'vendor/trezor-crypto/segwit_addr.c',
|
2017-12-12 19:31:03 +00:00
|
|
|
'vendor/trezor-crypto/sha2.c',
|
|
|
|
'vendor/trezor-crypto/sha3.c',
|
2019-04-17 09:26:16 +00:00
|
|
|
'vendor/trezor-crypto/shamir.c',
|
2019-06-23 10:18:24 +00:00
|
|
|
'vendor/trezor-crypto/slip39.c',
|
2023-05-04 12:14:58 +00:00
|
|
|
'vendor/trezor-crypto/slip39_english.c',
|
2023-08-23 13:42:16 +00:00
|
|
|
'vendor/trezor-crypto/tls_prf.c',
|
2017-08-01 16:50:28 +00:00
|
|
|
]
|
2019-08-21 16:53:08 +00:00
|
|
|
if EVERYTHING:
|
2024-04-10 13:11:12 +00:00
|
|
|
SOURCE_MOD_CRYPTO += [
|
2021-10-15 15:26:13 +00:00
|
|
|
'vendor/trezor-crypto/cardano.c',
|
2019-08-21 16:53:08 +00:00
|
|
|
'vendor/trezor-crypto/monero/base58.c',
|
|
|
|
'vendor/trezor-crypto/monero/serialize.c',
|
|
|
|
'vendor/trezor-crypto/monero/xmr.c',
|
|
|
|
]
|
2017-08-01 16:50:28 +00:00
|
|
|
|
2019-04-02 15:13:03 +00:00
|
|
|
# libsecp256k1-zkp
|
2021-03-18 13:48:10 +00:00
|
|
|
if FEATURE_FLAGS["SECP256K1_ZKP"]:
|
2019-08-21 16:53:08 +00:00
|
|
|
CPPPATH_MOD += [
|
|
|
|
'vendor/secp256k1-zkp',
|
|
|
|
'vendor/secp256k1-zkp/src',
|
|
|
|
'vendor/secp256k1-zkp/include',
|
|
|
|
]
|
|
|
|
CPPDEFINES_MOD += [
|
2021-05-12 13:50:25 +00:00
|
|
|
'USE_SECP256K1_ZKP',
|
|
|
|
'USE_SECP256K1_ZKP_ECDSA',
|
2022-05-20 14:16:25 +00:00
|
|
|
('SECP256K1_CONTEXT_SIZE', '180'),
|
2019-08-21 16:53:08 +00:00
|
|
|
'USE_ASM_ARM',
|
|
|
|
'USE_EXTERNAL_ASM',
|
|
|
|
'USE_EXTERNAL_DEFAULT_CALLBACKS',
|
2022-08-24 15:04:43 +00:00
|
|
|
('ECMULT_GEN_PREC_BITS', '2'),
|
2024-08-02 13:16:48 +00:00
|
|
|
('ECMULT_WINDOW_SIZE', '2'),
|
2019-08-21 16:53:08 +00:00
|
|
|
'ENABLE_MODULE_GENERATOR',
|
|
|
|
'ENABLE_MODULE_RECOVERY',
|
2021-05-14 15:20:32 +00:00
|
|
|
'ENABLE_MODULE_SCHNORRSIG',
|
|
|
|
'ENABLE_MODULE_EXTRAKEYS',
|
2024-08-02 14:46:43 +00:00
|
|
|
'ENABLE_MODULE_ECDH',
|
2019-08-21 16:53:08 +00:00
|
|
|
]
|
2020-11-18 13:44:17 +00:00
|
|
|
SOURCE_MOD_SECP256K1_ZKP = [
|
2019-08-21 16:53:08 +00:00
|
|
|
'vendor/secp256k1-zkp/src/secp256k1.c',
|
2022-01-26 16:49:48 +00:00
|
|
|
'vendor/secp256k1-zkp/src/precomputed_ecmult.c',
|
|
|
|
'vendor/secp256k1-zkp/src/precomputed_ecmult_gen.c',
|
2019-08-21 16:53:08 +00:00
|
|
|
'vendor/secp256k1-zkp/src/asm/field_10x26_arm.s'
|
|
|
|
]
|
2024-04-10 13:11:12 +00:00
|
|
|
SOURCE_MOD_CRYPTO += [
|
2021-05-12 13:50:25 +00:00
|
|
|
'vendor/trezor-crypto/zkp_context.c',
|
|
|
|
'vendor/trezor-crypto/zkp_ecdsa.c',
|
2021-10-19 19:09:59 +00:00
|
|
|
'vendor/trezor-crypto/zkp_bip340.c',
|
2021-05-12 13:50:25 +00:00
|
|
|
]
|
2019-04-02 15:13:03 +00:00
|
|
|
|
2024-03-19 13:37:13 +00:00
|
|
|
# AES-GCM
|
|
|
|
if FEATURE_FLAGS["AES_GCM"]:
|
|
|
|
CPPDEFINES_MOD += [
|
|
|
|
'USE_AES_GCM',
|
|
|
|
'AES_VAR',
|
|
|
|
]
|
2024-04-10 13:11:12 +00:00
|
|
|
SOURCE_MOD_CRYPTO += [
|
2024-03-19 13:37:13 +00:00
|
|
|
'vendor/trezor-crypto/aes/gf128mul.c',
|
|
|
|
'vendor/trezor-crypto/aes/aesgcm.c',
|
|
|
|
]
|
|
|
|
|
2017-08-01 16:50:28 +00:00
|
|
|
# modtrezorio
|
|
|
|
SOURCE_MOD += [
|
|
|
|
'embed/extmod/modtrezorio/modtrezorio.c',
|
|
|
|
]
|
|
|
|
|
|
|
|
# modtrezorui
|
2020-01-16 10:56:50 +00:00
|
|
|
CPPPATH_MOD += [
|
2021-09-09 18:26:10 +00:00
|
|
|
'vendor/micropython/lib/uzlib',
|
2020-01-16 10:56:50 +00:00
|
|
|
]
|
2017-08-01 16:50:28 +00:00
|
|
|
SOURCE_MOD += [
|
2024-01-17 14:29:49 +00:00
|
|
|
'embed/extmod/modtrezorui/modtrezorui.c',
|
2024-01-17 14:29:49 +00:00
|
|
|
'embed/lib/display_utils.c',
|
2024-06-10 14:57:59 +00:00
|
|
|
'embed/lib/error_handling.c',
|
2023-03-27 13:03:54 +00:00
|
|
|
'embed/lib/fonts/font_bitmap.c',
|
2024-01-17 14:29:49 +00:00
|
|
|
'embed/lib/fonts/fonts.c',
|
2024-04-16 13:52:17 +00:00
|
|
|
'embed/lib/gfx_color.c',
|
|
|
|
'embed/lib/gfx_bitblt_rgb565.c',
|
|
|
|
'embed/lib/gfx_bitblt_rgba8888.c',
|
|
|
|
'embed/lib/gfx_bitblt_mono8.c',
|
2023-06-30 10:12:55 +00:00
|
|
|
'embed/lib/image.c',
|
2024-01-17 14:29:49 +00:00
|
|
|
'embed/lib/mini_printf.c',
|
2024-09-18 07:24:59 +00:00
|
|
|
'embed/lib/rsod.c',
|
2024-01-17 14:29:49 +00:00
|
|
|
'embed/lib/terminal.c',
|
2024-02-20 10:05:58 +00:00
|
|
|
'embed/lib/translations.c',
|
2024-11-13 10:04:53 +00:00
|
|
|
'embed/lib/gfx_draw.c',
|
2021-09-09 18:26:10 +00:00
|
|
|
'vendor/micropython/lib/uzlib/adler32.c',
|
|
|
|
'vendor/micropython/lib/uzlib/crc32.c',
|
|
|
|
'vendor/micropython/lib/uzlib/tinflate.c',
|
2017-08-01 16:50:28 +00:00
|
|
|
]
|
2022-10-13 11:37:02 +00:00
|
|
|
|
2022-10-20 12:26:06 +00:00
|
|
|
CPPDEFINES_MOD += [
|
2023-08-11 15:57:32 +00:00
|
|
|
'TRANSLATIONS',
|
2024-09-25 08:33:38 +00:00
|
|
|
'FANCY_FATAL_ERROR',
|
2022-05-05 11:47:19 +00:00
|
|
|
]
|
|
|
|
|
2017-08-01 16:50:28 +00:00
|
|
|
# modtrezorutils
|
|
|
|
SOURCE_MOD += [
|
|
|
|
'embed/extmod/modtrezorutils/modtrezorutils.c',
|
|
|
|
]
|
|
|
|
|
2021-03-23 12:30:03 +00:00
|
|
|
# rust mods
|
|
|
|
SOURCE_MOD += [
|
2023-06-26 12:12:22 +00:00
|
|
|
'embed/extmod/rustmods.c',
|
2021-03-23 12:30:03 +00:00
|
|
|
]
|
|
|
|
|
2017-08-01 16:50:28 +00:00
|
|
|
# modutime
|
|
|
|
SOURCE_MOD += [
|
2021-10-26 12:52:37 +00:00
|
|
|
'embed/extmod/modutime.c',
|
2017-08-01 16:50:28 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
SOURCE_MICROPYTHON = [
|
|
|
|
'vendor/micropython/extmod/modubinascii.c',
|
|
|
|
'vendor/micropython/extmod/moductypes.c',
|
|
|
|
'vendor/micropython/extmod/moduheapq.c',
|
|
|
|
'vendor/micropython/extmod/modutimeq.c',
|
|
|
|
'vendor/micropython/extmod/utime_mphal.c',
|
2021-09-09 18:26:10 +00:00
|
|
|
'vendor/micropython/shared/libc/abort_.c',
|
|
|
|
'vendor/micropython/shared/libc/printf.c',
|
|
|
|
'vendor/micropython/shared/runtime/gchelper_m3.s',
|
|
|
|
'vendor/micropython/shared/runtime/gchelper_native.c',
|
|
|
|
'vendor/micropython/shared/runtime/interrupt_char.c',
|
|
|
|
'vendor/micropython/shared/runtime/pyexec.c',
|
|
|
|
'vendor/micropython/shared/runtime/stdout_helpers.c',
|
2021-10-26 12:52:37 +00:00
|
|
|
'vendor/micropython/shared/timeutils/timeutils.c',
|
2019-09-03 16:15:47 +00:00
|
|
|
'vendor/micropython/ports/stm32/gccollect.c',
|
2017-08-01 16:50:28 +00:00
|
|
|
'vendor/micropython/py/argcheck.c',
|
|
|
|
'vendor/micropython/py/asmarm.c',
|
|
|
|
'vendor/micropython/py/asmbase.c',
|
|
|
|
'vendor/micropython/py/asmthumb.c',
|
|
|
|
'vendor/micropython/py/asmx64.c',
|
|
|
|
'vendor/micropython/py/asmx86.c',
|
|
|
|
'vendor/micropython/py/asmxtensa.c',
|
|
|
|
'vendor/micropython/py/bc.c',
|
|
|
|
'vendor/micropython/py/binary.c',
|
|
|
|
'vendor/micropython/py/builtinevex.c',
|
|
|
|
'vendor/micropython/py/builtinhelp.c',
|
|
|
|
'vendor/micropython/py/builtinimport.c',
|
|
|
|
'vendor/micropython/py/compile.c',
|
|
|
|
'vendor/micropython/py/emitbc.c',
|
|
|
|
'vendor/micropython/py/emitcommon.c',
|
|
|
|
'vendor/micropython/py/emitglue.c',
|
|
|
|
'vendor/micropython/py/emitinlinethumb.c',
|
|
|
|
'vendor/micropython/py/emitinlinextensa.c',
|
|
|
|
'vendor/micropython/py/formatfloat.c',
|
|
|
|
'vendor/micropython/py/frozenmod.c',
|
|
|
|
'vendor/micropython/py/lexer.c',
|
|
|
|
'vendor/micropython/py/malloc.c',
|
|
|
|
'vendor/micropython/py/map.c',
|
|
|
|
'vendor/micropython/py/modarray.c',
|
|
|
|
'vendor/micropython/py/modbuiltins.c',
|
|
|
|
'vendor/micropython/py/modgc.c',
|
|
|
|
'vendor/micropython/py/modmath.c',
|
|
|
|
'vendor/micropython/py/modmicropython.c',
|
|
|
|
'vendor/micropython/py/modstruct.c',
|
|
|
|
'vendor/micropython/py/modsys.c',
|
|
|
|
'vendor/micropython/py/mpprint.c',
|
|
|
|
'vendor/micropython/py/mpstate.c',
|
|
|
|
'vendor/micropython/py/mpz.c',
|
|
|
|
'vendor/micropython/py/nativeglue.c',
|
|
|
|
'vendor/micropython/py/obj.c',
|
|
|
|
'vendor/micropython/py/objarray.c',
|
|
|
|
'vendor/micropython/py/objattrtuple.c',
|
|
|
|
'vendor/micropython/py/objbool.c',
|
|
|
|
'vendor/micropython/py/objboundmeth.c',
|
|
|
|
'vendor/micropython/py/objcell.c',
|
|
|
|
'vendor/micropython/py/objclosure.c',
|
|
|
|
'vendor/micropython/py/objcomplex.c',
|
|
|
|
'vendor/micropython/py/objdict.c',
|
|
|
|
'vendor/micropython/py/objenumerate.c',
|
|
|
|
'vendor/micropython/py/objexcept.c',
|
|
|
|
'vendor/micropython/py/objfilter.c',
|
|
|
|
'vendor/micropython/py/objfloat.c',
|
|
|
|
'vendor/micropython/py/objfun.c',
|
|
|
|
'vendor/micropython/py/objgenerator.c',
|
|
|
|
'vendor/micropython/py/objgetitemiter.c',
|
2018-10-25 23:09:02 +00:00
|
|
|
'vendor/micropython/py/objint.c',
|
2017-08-01 16:50:28 +00:00
|
|
|
'vendor/micropython/py/objint_longlong.c',
|
|
|
|
'vendor/micropython/py/objint_mpz.c',
|
|
|
|
'vendor/micropython/py/objlist.c',
|
|
|
|
'vendor/micropython/py/objmap.c',
|
|
|
|
'vendor/micropython/py/objmodule.c',
|
|
|
|
'vendor/micropython/py/objnamedtuple.c',
|
|
|
|
'vendor/micropython/py/objnone.c',
|
|
|
|
'vendor/micropython/py/objobject.c',
|
|
|
|
'vendor/micropython/py/objpolyiter.c',
|
|
|
|
'vendor/micropython/py/objproperty.c',
|
|
|
|
'vendor/micropython/py/objrange.c',
|
|
|
|
'vendor/micropython/py/objreversed.c',
|
|
|
|
'vendor/micropython/py/objset.c',
|
|
|
|
'vendor/micropython/py/objsingleton.c',
|
|
|
|
'vendor/micropython/py/objslice.c',
|
|
|
|
'vendor/micropython/py/objstr.c',
|
|
|
|
'vendor/micropython/py/objstringio.c',
|
|
|
|
'vendor/micropython/py/objstrunicode.c',
|
|
|
|
'vendor/micropython/py/objtuple.c',
|
|
|
|
'vendor/micropython/py/objtype.c',
|
|
|
|
'vendor/micropython/py/objzip.c',
|
|
|
|
'vendor/micropython/py/opmethods.c',
|
2021-09-09 18:25:30 +00:00
|
|
|
'vendor/micropython/py/pairheap.c',
|
2017-08-01 16:50:28 +00:00
|
|
|
'vendor/micropython/py/parse.c',
|
|
|
|
'vendor/micropython/py/parsenum.c',
|
|
|
|
'vendor/micropython/py/parsenumbase.c',
|
|
|
|
'vendor/micropython/py/persistentcode.c',
|
|
|
|
'vendor/micropython/py/qstr.c',
|
|
|
|
'vendor/micropython/py/reader.c',
|
|
|
|
'vendor/micropython/py/repl.c',
|
|
|
|
'vendor/micropython/py/runtime.c',
|
2018-10-25 23:09:02 +00:00
|
|
|
'vendor/micropython/py/runtime_utils.c',
|
2020-09-21 13:32:02 +00:00
|
|
|
'vendor/micropython/py/scheduler.c',
|
2017-08-01 16:50:28 +00:00
|
|
|
'vendor/micropython/py/scope.c',
|
|
|
|
'vendor/micropython/py/sequence.c',
|
|
|
|
'vendor/micropython/py/showbc.c',
|
|
|
|
'vendor/micropython/py/smallint.c',
|
|
|
|
'vendor/micropython/py/stackctrl.c',
|
|
|
|
'vendor/micropython/py/stream.c',
|
|
|
|
'vendor/micropython/py/unicode.c',
|
|
|
|
'vendor/micropython/py/vstr.c',
|
|
|
|
'vendor/micropython/py/warning.c',
|
|
|
|
]
|
|
|
|
|
2017-08-15 19:04:12 +00:00
|
|
|
SOURCE_MICROPYTHON_SPEED = [
|
|
|
|
'vendor/micropython/py/gc.c',
|
2020-06-30 12:42:29 +00:00
|
|
|
'vendor/micropython/py/pystack.c',
|
2017-08-15 19:04:12 +00:00
|
|
|
'vendor/micropython/py/vm.c',
|
|
|
|
]
|
|
|
|
|
2021-06-21 14:19:25 +00:00
|
|
|
CPPDEFINES_MOD += ['USE_SVC_SHUTDOWN']
|
|
|
|
|
2020-11-18 13:33:06 +00:00
|
|
|
if FEATURE_FLAGS["RDI"]:
|
2020-02-26 16:41:40 +00:00
|
|
|
CPPDEFINES_MOD += ['RDI']
|
|
|
|
|
2024-03-15 10:56:00 +00:00
|
|
|
TRANSLATION_DATA = [
|
|
|
|
"translations/en.json",
|
|
|
|
"translations/order.json",
|
|
|
|
]
|
|
|
|
|
2024-04-02 14:51:01 +00:00
|
|
|
if THP:
|
|
|
|
CPPDEFINES_MOD += ['USE_THP']
|
|
|
|
SOURCE_MOD += [
|
|
|
|
'vendor/trezor-crypto/elligator2.c',
|
|
|
|
]
|
2024-03-15 10:56:00 +00:00
|
|
|
|
2024-09-26 10:03:59 +00:00
|
|
|
ui.init_ui(TREZOR_MODEL, "firmware", CPPDEFINES_MOD, SOURCE_MOD, RUST_UI_FEATURES)
|
2022-08-18 13:12:02 +00:00
|
|
|
|
2017-08-15 19:04:12 +00:00
|
|
|
SOURCE_QSTR = SOURCE_MOD + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED
|
2017-08-01 16:50:28 +00:00
|
|
|
|
2023-11-23 21:24:55 +00:00
|
|
|
env = Environment(
|
|
|
|
ENV=os.environ,
|
|
|
|
CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DPYOPT={PYOPT} -DBOOTLOADER_QA={int(BOOTLOADER_QA)} -DBITCOIN_ONLY={BITCOIN_ONLY}",
|
|
|
|
CPPDEFINES_IMPLICIT=[]
|
|
|
|
)
|
2017-08-03 18:46:40 +00:00
|
|
|
|
2024-04-14 10:28:57 +00:00
|
|
|
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL)
|
2022-10-14 10:43:37 +00:00
|
|
|
|
2023-06-28 08:51:30 +00:00
|
|
|
FILE_SUFFIX= env.get('ENV')['SUFFIX']
|
|
|
|
|
|
|
|
SOURCE_FIRMWARE = [
|
|
|
|
'embed/firmware/header.S',
|
|
|
|
'embed/firmware/main.c',
|
|
|
|
'embed/firmware/mphalport.c',
|
|
|
|
'embed/firmware/nlrthumb.c',
|
2024-09-04 09:17:11 +00:00
|
|
|
f'embed/trezorhal/{FILE_SUFFIX}/startup_stage_4.s',
|
2023-06-28 08:51:30 +00:00
|
|
|
]
|
|
|
|
|
2023-08-24 10:46:10 +00:00
|
|
|
if 'sd_card' in FEATURES_AVAILABLE:
|
|
|
|
SDCARD = True
|
|
|
|
else:
|
|
|
|
SDCARD = False
|
|
|
|
|
2017-08-03 18:46:40 +00:00
|
|
|
env.Tool('micropython')
|
|
|
|
|
|
|
|
env.Replace(
|
2018-06-20 12:55:30 +00:00
|
|
|
CAT='cat',
|
2018-07-05 20:42:46 +00:00
|
|
|
DD='dd',
|
2023-01-10 21:28:57 +00:00
|
|
|
CP='cp',
|
2017-08-01 16:50:28 +00:00
|
|
|
SED='sed',
|
|
|
|
AS='arm-none-eabi-as',
|
|
|
|
AR='arm-none-eabi-ar',
|
|
|
|
CC='arm-none-eabi-gcc',
|
2018-02-17 15:19:16 +00:00
|
|
|
LINK='arm-none-eabi-gcc',
|
2017-08-01 16:50:28 +00:00
|
|
|
SIZE='arm-none-eabi-size',
|
|
|
|
STRIP='arm-none-eabi-strip',
|
2017-08-03 18:46:40 +00:00
|
|
|
OBJCOPY='arm-none-eabi-objcopy', )
|
|
|
|
|
|
|
|
env.Replace(
|
2022-10-14 10:43:37 +00:00
|
|
|
TREZOR_MODEL=TREZOR_MODEL,)
|
2018-09-30 14:39:40 +00:00
|
|
|
|
2024-04-12 20:39:30 +00:00
|
|
|
ALLPATHS = [
|
|
|
|
'.',
|
|
|
|
'embed/rust',
|
|
|
|
'embed/firmware',
|
|
|
|
'embed/lib',
|
|
|
|
'embed/models',
|
|
|
|
'embed/trezorhal',
|
|
|
|
'embed/extmod/modtrezorui',
|
|
|
|
'vendor/micropython',
|
|
|
|
] + CPPPATH_MOD + PATH_HAL
|
|
|
|
|
2018-09-30 14:39:40 +00:00
|
|
|
env.Replace(
|
2018-07-09 18:59:35 +00:00
|
|
|
COPT=env.get('ENV').get('OPTIMIZE', '-Os'),
|
2017-08-15 19:04:12 +00:00
|
|
|
CCFLAGS='$COPT '
|
2017-08-01 16:50:28 +00:00
|
|
|
'-g3 '
|
|
|
|
'-nostdlib '
|
2023-08-07 13:50:53 +00:00
|
|
|
'-std=gnu11 -Wall -Werror -Wdouble-promotion -Wpointer-arith -Wno-missing-braces -fno-common '
|
2017-10-13 21:21:09 +00:00
|
|
|
'-fsingle-precision-constant -fdata-sections -ffunction-sections '
|
2018-01-17 14:24:06 +00:00
|
|
|
'-ffreestanding '
|
2017-12-13 01:04:48 +00:00
|
|
|
'-fstack-protector-all '
|
2023-06-23 14:50:13 +00:00
|
|
|
+ env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD,
|
2017-08-03 19:22:02 +00:00
|
|
|
CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB',
|
2024-09-04 09:17:11 +00:00
|
|
|
LINKFLAGS='-T build/firmware/memory.ld -Wl,--gc-sections -Wl,--print-memory-usage -Wl,-Map=build/firmware/firmware.map -Wl,--warn-common',
|
2024-04-12 20:39:30 +00:00
|
|
|
CPPPATH=ALLPATHS,
|
2017-08-01 16:50:28 +00:00
|
|
|
CPPDEFINES=[
|
2022-05-31 07:31:32 +00:00
|
|
|
'FIRMWARE',
|
2022-04-26 11:47:40 +00:00
|
|
|
'TREZOR_MODEL_'+TREZOR_MODEL,
|
2017-11-05 15:57:31 +00:00
|
|
|
'USE_HAL_DRIVER',
|
2023-10-20 12:58:32 +00:00
|
|
|
'ARM_USER_MODE',
|
2024-09-26 10:03:59 +00:00
|
|
|
ui.get_ui_layout(TREZOR_MODEL),
|
2023-06-23 14:50:13 +00:00
|
|
|
] + CPPDEFINES_MOD + CPPDEFINES_HAL,
|
|
|
|
ASFLAGS=env.get('ENV')['CPU_ASFLAGS'],
|
|
|
|
ASPPFLAGS='$CFLAGS $CCFLAGS',
|
|
|
|
)
|
2017-08-03 18:46:40 +00:00
|
|
|
|
|
|
|
env.Replace(
|
2024-07-31 15:40:17 +00:00
|
|
|
HEADERTOOL='headertool',
|
2017-08-01 16:50:28 +00:00
|
|
|
PYTHON='python',
|
|
|
|
MAKEQSTRDATA='$PYTHON vendor/micropython/py/makeqstrdata.py',
|
|
|
|
MAKEVERSIONHDR='$PYTHON vendor/micropython/py/makeversionhdr.py',
|
2020-04-07 10:02:58 +00:00
|
|
|
MAKEMODULEDEFS='$PYTHON vendor/micropython/py/makemoduledefs.py',
|
2023-01-30 14:36:22 +00:00
|
|
|
MAKECMAKELISTS='$PYTHON tools/make_cmakelists.py',
|
2017-08-01 16:50:28 +00:00
|
|
|
MPY_TOOL='$PYTHON vendor/micropython/tools/mpy-tool.py',
|
2021-06-07 08:57:33 +00:00
|
|
|
MPY_CROSS='vendor/micropython/mpy-cross/mpy-cross -O' + PYOPT,
|
|
|
|
PB2PY='$PYTHON ../common/protob/pb2py',
|
2017-10-25 20:51:38 +00:00
|
|
|
)
|
2017-08-01 16:50:28 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Qstrings
|
|
|
|
#
|
|
|
|
|
2021-06-07 08:57:33 +00:00
|
|
|
PROTO_SOURCES_DIR = '../../../common/protob/'
|
2024-10-08 21:21:20 +00:00
|
|
|
|
|
|
|
exclude_list = [PROTO_SOURCES_DIR + 'messages-bootloader.proto']
|
|
|
|
if not THP:
|
|
|
|
exclude_list.append(PROTO_SOURCES_DIR + 'messages-thp.proto')
|
|
|
|
|
2021-06-07 08:57:33 +00:00
|
|
|
PROTO_SOURCES = Glob(PROTO_SOURCES_DIR + '*.proto',
|
2024-10-08 21:21:20 +00:00
|
|
|
exclude=exclude_list
|
2021-06-07 08:57:33 +00:00
|
|
|
)
|
2024-10-08 21:21:20 +00:00
|
|
|
|
2021-06-07 08:57:33 +00:00
|
|
|
qstr_protobuf = env.Command(
|
|
|
|
target=[
|
|
|
|
'genhdr/qstrdefs.protobuf.h',
|
|
|
|
],
|
|
|
|
source=PROTO_SOURCES,
|
|
|
|
action='$PB2PY $SOURCES --qstr-out ${TARGET} --bitcoin-only=%s' % BITCOIN_ONLY,
|
|
|
|
)
|
|
|
|
|
2017-08-02 21:42:04 +00:00
|
|
|
qstr_micropython = 'vendor/micropython/py/qstrdefs.h'
|
|
|
|
|
2023-11-03 13:19:24 +00:00
|
|
|
micropy_defines = env.MicroPyDefines(source=SOURCE_QSTR)
|
|
|
|
|
2017-08-01 16:50:28 +00:00
|
|
|
qstr_collected = env.CollectQstr(
|
2023-11-03 13:19:24 +00:00
|
|
|
target='genhdr/qstrdefs.collected.h', source=micropy_defines)
|
2017-08-01 16:50:28 +00:00
|
|
|
|
|
|
|
qstr_preprocessed = env.PreprocessQstr(
|
|
|
|
target='genhdr/qstrdefs.preprocessed.h',
|
2021-06-07 08:57:33 +00:00
|
|
|
source=[qstr_micropython, qstr_protobuf, qstr_collected])
|
2017-08-01 16:50:28 +00:00
|
|
|
|
|
|
|
qstr_generated = env.GenerateQstrDefs(
|
2017-08-03 18:46:40 +00:00
|
|
|
target='genhdr/qstrdefs.generated.h', source=qstr_preprocessed)
|
2017-08-01 16:50:28 +00:00
|
|
|
|
|
|
|
env.Ignore(qstr_collected, qstr_generated)
|
|
|
|
|
2019-12-17 18:24:08 +00:00
|
|
|
#
|
2023-01-24 20:57:27 +00:00
|
|
|
# Micropython module declarations
|
|
|
|
#
|
|
|
|
|
|
|
|
moduledefs_collected = env.CollectModules(
|
2023-11-03 13:19:24 +00:00
|
|
|
target='genhdr/moduledefs.collected.h', source=micropy_defines)
|
2023-01-24 20:57:27 +00:00
|
|
|
|
|
|
|
hdr_moduledefs = env.Command(
|
|
|
|
target='genhdr/moduledefs.h',
|
|
|
|
source=moduledefs_collected,
|
|
|
|
action='$MAKEMODULEDEFS $SOURCE > $TARGET', )
|
|
|
|
|
2023-11-03 13:19:24 +00:00
|
|
|
env.Ignore(micropy_defines, micropy_defines)
|
|
|
|
env.Ignore(micropy_defines, qstr_generated)
|
|
|
|
env.Ignore(micropy_defines, hdr_moduledefs)
|
2023-01-24 20:57:27 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Micropython version
|
2019-12-17 18:24:08 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
hdr_version = env.Command(
|
|
|
|
target='genhdr/mpversion.h',
|
|
|
|
source='',
|
|
|
|
action='$MAKEVERSIONHDR $TARGET', )
|
|
|
|
|
|
|
|
env.Ignore(hdr_moduledefs, hdr_moduledefs)
|
|
|
|
env.Ignore(hdr_moduledefs, qstr_collected)
|
|
|
|
env.Ignore(hdr_moduledefs, qstr_preprocessed)
|
|
|
|
env.Ignore(hdr_moduledefs, qstr_generated)
|
|
|
|
|
2017-08-01 16:50:28 +00:00
|
|
|
#
|
|
|
|
# Frozen modules
|
|
|
|
#
|
|
|
|
|
2019-08-21 16:04:15 +00:00
|
|
|
if FROZEN:
|
2020-08-03 13:33:45 +00:00
|
|
|
SOURCE_PY_DIR = 'src/'
|
2018-10-02 15:32:38 +00:00
|
|
|
|
2019-05-01 11:39:44 +00:00
|
|
|
SOURCE_PY = Glob(SOURCE_PY_DIR + '*.py')
|
2023-05-12 09:19:35 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/*.py',
|
|
|
|
exclude=[
|
|
|
|
SOURCE_PY_DIR + 'trezor/sdcard.py',
|
2023-08-24 10:46:10 +00:00
|
|
|
] if not SDCARD else []
|
2023-05-12 09:19:35 +00:00
|
|
|
))
|
2019-08-21 09:15:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/crypto/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/*.py'))
|
2023-05-04 12:32:35 +00:00
|
|
|
|
|
|
|
# UI layouts - common files and then model-specific. Exclude FIDO when BTC-only.
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/*.py',
|
|
|
|
exclude=[
|
|
|
|
SOURCE_PY_DIR + 'trezor/ui/layouts/fido.py',
|
|
|
|
] if not EVERYTHING else []
|
|
|
|
))
|
2024-09-26 10:03:59 +00:00
|
|
|
|
|
|
|
layout_path = ui.get_ui_layout_path(TREZOR_MODEL)
|
|
|
|
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + layout_path + '*.py',
|
|
|
|
exclude=[
|
|
|
|
SOURCE_PY_DIR + layout_path + 'fido.py',
|
|
|
|
] if not EVERYTHING else []
|
|
|
|
))
|
2020-12-11 16:51:20 +00:00
|
|
|
|
2019-08-21 09:15:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/wire/*.py'))
|
|
|
|
|
2023-05-12 09:19:35 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'storage/*.py',
|
|
|
|
exclude=[
|
|
|
|
SOURCE_PY_DIR + 'storage/sd_salt.py',
|
2023-08-24 10:46:10 +00:00
|
|
|
] if not SDCARD else []
|
2023-05-12 09:19:35 +00:00
|
|
|
))
|
2019-11-11 14:52:46 +00:00
|
|
|
|
2021-06-07 08:57:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/messages/__init__.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/*.py',
|
2019-08-21 16:45:07 +00:00
|
|
|
exclude=[
|
2021-06-07 08:57:33 +00:00
|
|
|
SOURCE_PY_DIR + 'trezor/enums/Binance*.py',
|
|
|
|
SOURCE_PY_DIR + 'trezor/enums/Cardano*.py',
|
|
|
|
SOURCE_PY_DIR + 'trezor/enums/DebugMonero*.py',
|
|
|
|
SOURCE_PY_DIR + 'trezor/enums/Eos*.py',
|
|
|
|
SOURCE_PY_DIR + 'trezor/enums/Ethereum*.py',
|
|
|
|
SOURCE_PY_DIR + 'trezor/enums/Monero*.py',
|
|
|
|
SOURCE_PY_DIR + 'trezor/enums/NEM*.py',
|
|
|
|
SOURCE_PY_DIR + 'trezor/enums/Ripple*.py',
|
2023-10-18 09:28:04 +00:00
|
|
|
SOURCE_PY_DIR + 'trezor/enums/Solana*.py',
|
2021-06-07 08:57:33 +00:00
|
|
|
SOURCE_PY_DIR + 'trezor/enums/Stellar*.py',
|
|
|
|
SOURCE_PY_DIR + 'trezor/enums/Tezos*.py',
|
2022-08-12 06:45:42 +00:00
|
|
|
SOURCE_PY_DIR + 'trezor/enums/Zcash*.py',
|
2019-08-21 16:45:07 +00:00
|
|
|
])
|
|
|
|
)
|
|
|
|
|
2020-07-28 10:12:31 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/*.py'))
|
2023-05-12 09:19:35 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/common/*.py',
|
|
|
|
exclude=[
|
|
|
|
SOURCE_PY_DIR + 'apps/common/sdcard.py',
|
2023-08-24 10:46:10 +00:00
|
|
|
] if not SDCARD else []
|
2023-05-12 09:19:35 +00:00
|
|
|
))
|
2019-08-21 09:15:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/debug/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/homescreen/*.py'))
|
2021-05-13 10:33:52 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*.py',
|
|
|
|
exclude=[
|
|
|
|
SOURCE_PY_DIR + 'apps/management/sd_protect.py',
|
2023-08-24 10:46:10 +00:00
|
|
|
] if not SDCARD else [])
|
2021-05-13 10:33:52 +00:00
|
|
|
)
|
2019-08-21 09:15:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*/*.py'))
|
2020-05-15 18:35:09 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/misc/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/*/*.py',
|
2019-08-26 11:48:41 +00:00
|
|
|
exclude=[
|
2020-05-15 18:35:09 +00:00
|
|
|
SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/decred.py',
|
|
|
|
SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/bitcoinlike.py',
|
2022-03-31 13:22:23 +00:00
|
|
|
SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/zcash_v4.py',
|
2019-08-26 11:48:41 +00:00
|
|
|
])
|
|
|
|
)
|
2019-08-21 09:15:33 +00:00
|
|
|
|
2019-08-21 16:53:08 +00:00
|
|
|
if EVERYTHING:
|
2019-08-21 09:15:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/binance/*.py'))
|
2021-06-07 08:57:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Binance*.py'))
|
2019-08-21 16:45:07 +00:00
|
|
|
|
2019-08-21 09:15:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/cardano/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/cardano/*/*.py'))
|
2021-06-07 08:57:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Cardano*.py'))
|
2019-08-21 16:45:07 +00:00
|
|
|
|
2024-03-04 00:02:05 +00:00
|
|
|
if TREZOR_MODEL == "T":
|
2023-08-28 14:46:57 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/eos/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/eos/*/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Eos*.py'))
|
2019-08-21 16:45:07 +00:00
|
|
|
|
2019-08-21 09:15:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/ethereum/*.py'))
|
2021-06-07 08:57:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Ethereum*.py'))
|
2019-08-21 16:45:07 +00:00
|
|
|
|
2019-08-21 09:15:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/monero/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/monero/*/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/monero/*/*/*.py'))
|
2021-06-07 08:57:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/DebugMonero*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Monero*.py'))
|
2019-08-21 16:45:07 +00:00
|
|
|
|
2024-03-04 00:02:05 +00:00
|
|
|
if TREZOR_MODEL == "T":
|
2023-08-28 14:46:57 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/nem/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/nem/*/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/NEM*.py'))
|
2019-08-21 16:45:07 +00:00
|
|
|
|
2019-08-21 09:15:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/ripple/*.py'))
|
2021-06-07 08:57:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Ripple*.py'))
|
2019-08-21 16:45:07 +00:00
|
|
|
|
2023-10-18 09:28:04 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/solana/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/solana/*/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Solana*.py'))
|
|
|
|
|
2019-08-21 09:15:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/stellar/*.py'))
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/stellar/*/*.py'))
|
2021-06-07 08:57:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Stellar*.py'))
|
2019-08-21 16:45:07 +00:00
|
|
|
|
2019-08-21 09:15:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/tezos/*.py'))
|
2021-06-07 08:57:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Tezos*.py'))
|
2019-08-21 16:45:07 +00:00
|
|
|
|
2024-10-08 21:21:20 +00:00
|
|
|
if THP:
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/thp/*.py'))
|
|
|
|
|
2022-03-31 13:22:23 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/zcash/*.py'))
|
|
|
|
|
2019-08-21 09:15:33 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/webauthn/*.py'))
|
2018-10-02 15:32:38 +00:00
|
|
|
|
2024-03-04 00:02:05 +00:00
|
|
|
if TREZOR_MODEL == "T":
|
2023-08-28 14:46:57 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/decred.py'))
|
2020-05-15 18:35:09 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/bitcoinlike.py'))
|
2022-03-31 13:22:23 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/zcash_v4.py'))
|
2022-08-12 06:45:42 +00:00
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Zcash*.py'))
|
2019-08-26 11:48:41 +00:00
|
|
|
|
2024-08-08 12:23:13 +00:00
|
|
|
if BENCHMARK:
|
|
|
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/benchmark/*.py'))
|
|
|
|
|
2023-06-23 10:07:18 +00:00
|
|
|
source_mpy = env.FrozenModule(
|
|
|
|
source=SOURCE_PY,
|
|
|
|
source_dir=SOURCE_PY_DIR,
|
|
|
|
bitcoin_only=BITCOIN_ONLY,
|
2023-08-23 13:42:16 +00:00
|
|
|
backlight='backlight' in FEATURES_AVAILABLE,
|
2023-08-24 10:46:10 +00:00
|
|
|
optiga='optiga' in FEATURES_AVAILABLE,
|
2023-04-25 20:44:59 +00:00
|
|
|
use_button='button' in FEATURES_AVAILABLE,
|
|
|
|
use_touch='touch' in FEATURES_AVAILABLE,
|
2024-09-26 10:03:59 +00:00
|
|
|
ui_layout=ui.get_ui_layout(TREZOR_MODEL),
|
2024-04-02 14:51:01 +00:00
|
|
|
thp=THP,
|
2023-06-23 10:07:18 +00:00
|
|
|
)
|
2017-08-01 16:50:28 +00:00
|
|
|
|
2019-05-01 11:39:44 +00:00
|
|
|
source_mpyc = env.FrozenCFile(
|
|
|
|
target='frozen_mpy.c', source=source_mpy, qstr_header=qstr_preprocessed)
|
2017-08-01 16:50:28 +00:00
|
|
|
|
2019-05-01 11:39:44 +00:00
|
|
|
env.Depends(source_mpyc, qstr_generated)
|
2017-08-01 16:50:28 +00:00
|
|
|
|
2024-04-12 20:39:30 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Program objects
|
|
|
|
#
|
|
|
|
|
2024-04-10 13:11:12 +00:00
|
|
|
source_files = SOURCE_MOD + SOURCE_MOD_CRYPTO + SOURCE_FIRMWARE + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED + SOURCE_HAL
|
2024-04-12 20:39:30 +00:00
|
|
|
obj_program = []
|
|
|
|
obj_program.extend(env.Object(source=SOURCE_MOD))
|
2024-04-15 15:55:24 +00:00
|
|
|
obj_program.extend(env.Object(source=SOURCE_MOD_CRYPTO, CCFLAGS='$CCFLAGS -ftrivial-auto-var-init=zero'))
|
2024-04-12 20:39:30 +00:00
|
|
|
if FEATURE_FLAGS["SECP256K1_ZKP"]:
|
2024-08-02 15:41:01 +00:00
|
|
|
obj_program.extend(env.Object(source=SOURCE_MOD_SECP256K1_ZKP, CCFLAGS='$CCFLAGS -Wno-unused-function'))
|
2024-04-12 20:39:30 +00:00
|
|
|
source_files.extend(SOURCE_MOD_SECP256K1_ZKP)
|
|
|
|
obj_program.extend(env.Object(source=SOURCE_FIRMWARE))
|
|
|
|
obj_program.extend(env.Object(source=SOURCE_MICROPYTHON))
|
|
|
|
obj_program.extend(env.Object(source=SOURCE_MICROPYTHON_SPEED, COPT='-O3'))
|
|
|
|
obj_program.extend(env.Object(source=SOURCE_HAL))
|
|
|
|
if FROZEN:
|
|
|
|
obj_program.extend(env.Object(source=source_mpyc))
|
|
|
|
|
|
|
|
env.Replace(
|
|
|
|
ALLSOURCES=source_files,
|
|
|
|
ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT'] + [f"PRODUCTION={int(PRODUCTION)}", f"BOOTLOADER_QA={int(BOOTLOADER_QA)}", f"PYOPT={PYOPT}", f"BITCOIN_ONLY={BITCOIN_ONLY}"]))
|
|
|
|
|
|
|
|
|
|
|
|
cmake_gen = env.Command(
|
|
|
|
target='CMakeLists.txt',
|
|
|
|
source='',
|
|
|
|
action='$MAKECMAKELISTS --sources $ALLSOURCES --dirs $CPPPATH --defs $ALLDEFS',
|
|
|
|
)
|
|
|
|
|
2021-03-23 12:14:33 +00:00
|
|
|
#
|
|
|
|
# Rust library
|
|
|
|
#
|
|
|
|
|
2021-06-07 08:57:33 +00:00
|
|
|
protobuf_blobs = env.Command(
|
|
|
|
target=[
|
2022-08-16 14:51:10 +00:00
|
|
|
'rust/proto_enums.data',
|
|
|
|
'rust/proto_msgs.data',
|
|
|
|
'rust/proto_names.data',
|
|
|
|
'rust/proto_wire.data',
|
2021-06-07 08:57:33 +00:00
|
|
|
],
|
|
|
|
source=PROTO_SOURCES,
|
|
|
|
action='$PB2PY --bitcoin-only=%s --blob-outdir ${TARGET.dir} $SOURCES --qstr-defs build/firmware/genhdr/qstrdefs.generated.h' % BITCOIN_ONLY,
|
|
|
|
)
|
|
|
|
env.Depends(protobuf_blobs, qstr_generated)
|
|
|
|
|
2021-03-23 12:14:33 +00:00
|
|
|
RUST_PROFILE = 'release'
|
|
|
|
RUST_LIB = 'trezor_lib'
|
2023-06-23 14:50:13 +00:00
|
|
|
RUST_LIBDIR = f'build/firmware/rust/{env.get("ENV")["RUST_TARGET"]}/{RUST_PROFILE}'
|
2021-03-23 12:14:33 +00:00
|
|
|
RUST_LIBPATH = f'{RUST_LIBDIR}/lib{RUST_LIB}.a'
|
|
|
|
|
|
|
|
def cargo_build():
|
|
|
|
# Determine the profile build flags.
|
|
|
|
if RUST_PROFILE == 'release':
|
|
|
|
profile = '--release'
|
|
|
|
else:
|
|
|
|
profile = ''
|
2022-06-08 08:31:23 +00:00
|
|
|
|
2024-09-26 10:03:59 +00:00
|
|
|
features = ['micropython', 'protobuf']
|
2024-03-07 12:27:41 +00:00
|
|
|
if EVERYTHING:
|
|
|
|
features.append('universal_fw')
|
2024-09-26 10:03:59 +00:00
|
|
|
features.extend(RUST_UI_FEATURES)
|
2022-10-20 12:26:06 +00:00
|
|
|
features.append('ui')
|
2023-08-11 15:57:32 +00:00
|
|
|
features.append('translations')
|
2024-04-16 13:52:17 +00:00
|
|
|
|
2022-10-20 12:26:06 +00:00
|
|
|
if PYOPT == '0':
|
2024-02-12 15:45:59 +00:00
|
|
|
features.append('debug')
|
2024-04-16 13:52:17 +00:00
|
|
|
features.append('ui_debug')
|
2024-06-10 07:22:25 +00:00
|
|
|
|
2023-03-27 14:44:01 +00:00
|
|
|
features.extend(FEATURES_AVAILABLE)
|
|
|
|
|
2022-08-18 11:24:46 +00:00
|
|
|
cargo_opts = [
|
2023-06-23 14:50:13 +00:00
|
|
|
f'--target={env.get("ENV")["RUST_TARGET"]}',
|
2022-08-18 11:24:46 +00:00
|
|
|
f'--target-dir=../../build/firmware/rust',
|
|
|
|
'--no-default-features',
|
|
|
|
'--features ' + ','.join(features),
|
|
|
|
'-Z build-std=core',
|
|
|
|
'-Z build-std-features=panic_immediate_abort',
|
|
|
|
]
|
|
|
|
|
2022-10-14 10:43:37 +00:00
|
|
|
env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL
|
|
|
|
|
2024-04-25 14:44:42 +00:00
|
|
|
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
|
2024-08-08 15:18:32 +00:00
|
|
|
build_dir = str(Dir('.').abspath)
|
2024-04-25 14:44:42 +00:00
|
|
|
|
2024-08-08 15:18:32 +00:00
|
|
|
return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts)
|
2021-03-23 12:14:33 +00:00
|
|
|
|
|
|
|
rust = env.Command(
|
|
|
|
target=RUST_LIBPATH,
|
|
|
|
source='',
|
|
|
|
action=cargo_build(), )
|
2021-06-07 08:57:33 +00:00
|
|
|
env.Depends(rust, protobuf_blobs)
|
2024-03-15 10:56:00 +00:00
|
|
|
env.Depends(rust, TRANSLATION_DATA)
|
2021-03-23 12:14:33 +00:00
|
|
|
|
|
|
|
env.Append(LINKFLAGS=f' -L{RUST_LIBDIR}')
|
|
|
|
env.Append(LINKFLAGS=f' -l{RUST_LIB}')
|
|
|
|
|
2023-01-30 14:36:22 +00:00
|
|
|
|
2024-04-14 10:28:57 +00:00
|
|
|
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
|
2023-05-31 12:47:22 +00:00
|
|
|
BOOTLOADER_SUFFIX = MODEL_IDENTIFIER
|
2024-07-15 13:24:01 +00:00
|
|
|
if BOOTLOADER_QA or BOOTLOADER_DEVEL:
|
2023-10-17 12:47:31 +00:00
|
|
|
BOOTLOADER_SUFFIX += '_qa'
|
|
|
|
|
|
|
|
# select vendor header
|
|
|
|
if BOOTLOADER_QA or BOOTLOADER_DEVEL:
|
|
|
|
vendor = "dev_DO_NOT_SIGN_signed_dev"
|
|
|
|
elif not PRODUCTION:
|
|
|
|
vendor = "unsafe_signed_prod"
|
2023-03-02 15:31:25 +00:00
|
|
|
else:
|
2023-10-17 12:47:31 +00:00
|
|
|
if TREZOR_MODEL in ('T',):
|
|
|
|
vendor = "satoshilabs_signed_prod"
|
|
|
|
elif BITCOIN_ONLY == '1':
|
|
|
|
vendor = "trezor_btconly_signed_prod"
|
|
|
|
else:
|
|
|
|
vendor = "trezor_signed_prod"
|
|
|
|
|
2024-07-16 12:42:39 +00:00
|
|
|
VENDORHEADER = f'embed/models/{MODEL_IDENTIFIER}/vendorheader/vendorheader_{vendor}.bin'
|
2018-01-31 13:45:02 +00:00
|
|
|
|
2024-09-25 09:34:10 +00:00
|
|
|
tools.embed_raw_binary(
|
|
|
|
obj_program,
|
|
|
|
env,
|
|
|
|
'vendorheader',
|
|
|
|
'embed/firmware/vendorheader.o',
|
|
|
|
VENDORHEADER,
|
|
|
|
)
|
2024-09-16 12:12:51 +00:00
|
|
|
|
|
|
|
tools.embed_raw_binary(
|
|
|
|
obj_program,
|
|
|
|
env,
|
|
|
|
'kernel',
|
|
|
|
'build/kernel/kernel.o',
|
|
|
|
f'build/kernel/kernel.bin',
|
|
|
|
)
|
2017-08-03 22:45:32 +00:00
|
|
|
|
2023-09-26 14:28:38 +00:00
|
|
|
|
2019-02-18 15:59:06 +00:00
|
|
|
|
2017-08-03 18:46:40 +00:00
|
|
|
env.Depends(obj_program, qstr_generated)
|
2017-08-01 16:50:28 +00:00
|
|
|
|
2024-09-04 09:17:11 +00:00
|
|
|
linkerscript_gen = env.Command(
|
|
|
|
target='memory.ld',
|
|
|
|
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='firmware')],
|
|
|
|
action='$CAT $SOURCES > $TARGET',
|
|
|
|
)
|
|
|
|
|
2017-08-03 18:46:40 +00:00
|
|
|
program_elf = env.Command(
|
2017-08-01 16:50:28 +00:00
|
|
|
target='firmware.elf',
|
2017-08-03 18:46:40 +00:00
|
|
|
source=obj_program,
|
2017-08-01 16:50:28 +00:00
|
|
|
action=
|
2021-03-23 12:14:33 +00:00
|
|
|
'$LINK -o $TARGET $CCFLAGS $CFLAGS $SOURCES $LINKFLAGS -lc_nano -lm -lgcc',
|
2017-08-01 16:50:28 +00:00
|
|
|
)
|
|
|
|
|
2024-09-04 09:17:11 +00:00
|
|
|
env.Depends(program_elf, linkerscript_gen)
|
|
|
|
|
2023-01-30 14:36:22 +00:00
|
|
|
if CMAKELISTS != 0:
|
|
|
|
env.Depends(program_elf, cmake_gen)
|
2021-03-23 12:14:33 +00:00
|
|
|
env.Depends(program_elf, rust)
|
|
|
|
|
2024-09-16 12:12:51 +00:00
|
|
|
BINARY_NAME = f"build/firmware/firmware-{MODEL_IDENTIFIER}"
|
2023-02-17 17:06:48 +00:00
|
|
|
if not EVERYTHING:
|
2023-01-10 21:28:57 +00:00
|
|
|
BINARY_NAME += "-btconly"
|
|
|
|
BINARY_NAME += "-" + tools.get_version('embed/firmware/version.h')
|
|
|
|
BINARY_NAME += "-" + tools.get_git_revision_short_hash()
|
|
|
|
BINARY_NAME += "-dirty" if tools.get_git_modified() else ""
|
|
|
|
BINARY_NAME += ".bin"
|
|
|
|
|
|
|
|
|
2024-09-16 12:12:51 +00:00
|
|
|
if 'STM32F427xx' in CPPDEFINES_HAL or 'STM32F429xx' in CPPDEFINES_HAL:
|
2018-09-20 14:37:36 +00:00
|
|
|
action_bin=[
|
2024-09-16 12:12:51 +00:00
|
|
|
'$OBJCOPY -O binary -j .vendorheader -j .header -j .flash -j .data -j .confidential --pad-to 0x08100000 $SOURCE ${TARGET}.p1',
|
|
|
|
'$OBJCOPY -O binary -j .flash2 $SOURCE ${TARGET}.p2',
|
|
|
|
'$CAT ${TARGET}.p1 ${TARGET}.p2 > $TARGET',
|
|
|
|
'$HEADERTOOL -h $TARGET ' + ('-D' if not PRODUCTION else ''),
|
|
|
|
'$DD if=$TARGET of=${TARGET}.p1 skip=0 bs=128k count=6',
|
2023-01-10 21:28:57 +00:00
|
|
|
'$CP $TARGET ' + BINARY_NAME,
|
2018-09-20 14:37:36 +00:00
|
|
|
]
|
2024-09-16 12:12:51 +00:00
|
|
|
elif 'STM32U5A9xx' in CPPDEFINES_HAL or 'STM32U585xx' in CPPDEFINES_HAL:
|
|
|
|
action_bin=[
|
|
|
|
'$OBJCOPY -O binary -j .vendorheader -j .header -j .flash -j .data -j .confidential $SOURCE ${TARGET}',
|
|
|
|
'$HEADERTOOL -h $TARGET ' + ('-D' if not PRODUCTION else ''),
|
|
|
|
'$CP $TARGET ' + BINARY_NAME,
|
2023-06-28 08:51:30 +00:00
|
|
|
]
|
2024-09-16 12:12:51 +00:00
|
|
|
else:
|
|
|
|
raise Exception("Unknown MCU")
|
2018-09-20 14:37:36 +00:00
|
|
|
|
|
|
|
program_bin = env.Command(
|
|
|
|
target='firmware.bin',
|
|
|
|
source=program_elf,
|
|
|
|
action=action_bin,
|
|
|
|
)
|