mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-19 05:58:09 +00:00
refactor(core): migrate coreapp into firmware
[no changelog]
This commit is contained in:
parent
0c98f578ad
commit
dfd17578b6
@ -19,7 +19,6 @@ BOOTLOADER_EMU_BUILD_DIR = $(BUILD_DIR)/bootloader_emu
|
||||
PRODTEST_BUILD_DIR = $(BUILD_DIR)/prodtest
|
||||
REFLASH_BUILD_DIR = $(BUILD_DIR)/reflash
|
||||
KERNEL_BUILD_DIR = $(BUILD_DIR)/kernel
|
||||
COREAPP_BUILD_DIR = $(BUILD_DIR)/coreapp
|
||||
FIRMWARE_BUILD_DIR = $(BUILD_DIR)/firmware
|
||||
UNIX_BUILD_DIR = $(BUILD_DIR)/unix
|
||||
RUST_BUILD_DIR = $(BUILD_DIR)/rust
|
||||
@ -81,8 +80,6 @@ FLASH_START = $(shell layout_parser ${TREZOR_MODEL} FLASH_START)
|
||||
BOARDLOADER_START = $(shell layout_parser ${TREZOR_MODEL} BOARDLOADER_START)
|
||||
BOOTLOADER_START = $(shell layout_parser ${TREZOR_MODEL} BOOTLOADER_START)
|
||||
KERNEL_START = $(shell layout_parser ${TREZOR_MODEL} KERNEL_START)
|
||||
COREAPP_START = $(shell layout_parser ${TREZOR_MODEL} COREAPP_START)
|
||||
COREAPP_P2_START = $(shell layout_parser ${TREZOR_MODEL} COREAPP_P2_START)
|
||||
FIRMWARE_START = $(shell layout_parser ${TREZOR_MODEL} FIRMWARE_START)
|
||||
FIRMWARE_P2_START = $(shell layout_parser ${TREZOR_MODEL} FIRMWARE_P2_START)
|
||||
STORAGE_1_OFFSET = $(shell layout_parser ${TREZOR_MODEL} STORAGE_1_OFFSET)
|
||||
@ -281,15 +278,7 @@ build_kernel: ## build kernel image
|
||||
BOOTLOADER_QA="$(BOOTLOADER_QA)" BOOTLOADER_DEVEL="$(BOOTLOADER_DEVEL)" \
|
||||
$(KERNEL_BUILD_DIR)/kernel.bin
|
||||
|
||||
build_coreapp: templates build_cross build_kernel ## build coreapp with frozen modules
|
||||
$(SCONS) CFLAGS="$(CFLAGS)" PRODUCTION="$(PRODUCTION)" \
|
||||
TREZOR_MODEL="$(TREZOR_MODEL)" CMAKELISTS="$(CMAKELISTS)" \
|
||||
PYOPT="$(PYOPT)" BITCOIN_ONLY="$(BITCOIN_ONLY)" \
|
||||
BOOTLOADER_QA="$(BOOTLOADER_QA)" BOOTLOADER_DEVEL="$(BOOTLOADER_DEVEL)" \
|
||||
DISABLE_OPTIGA="$(DISABLE_OPTIGA)" THP="$(THP)" NEW_RENDERING="$(NEW_RENDERING)" \
|
||||
$(COREAPP_BUILD_DIR)/coreapp.bin
|
||||
|
||||
build_firmware: templates build_cross ## build firmware with frozen modules
|
||||
build_firmware: templates build_cross build_kernel ## build firmware with frozen modules
|
||||
$(SCONS) CFLAGS="$(CFLAGS)" PRODUCTION="$(PRODUCTION)" \
|
||||
TREZOR_MODEL="$(TREZOR_MODEL)" CMAKELISTS="$(CMAKELISTS)" \
|
||||
PYOPT="$(PYOPT)" BITCOIN_ONLY="$(BITCOIN_ONLY)" \
|
||||
@ -344,9 +333,6 @@ clean_reflash: ## clean reflash build
|
||||
clean_kernel: ## clean kernel build
|
||||
rm -rf $(KERNEL_BUILD_DIR)
|
||||
|
||||
clean_coreapp: ## clean coreapp build
|
||||
rm -rf $(COREAPP_BUILD_DIR) $(RUST_BUILD_DIR)
|
||||
|
||||
clean_firmware: ## clean firmware build
|
||||
rm -rf $(FIRMWARE_BUILD_DIR) $(RUST_BUILD_DIR)
|
||||
|
||||
@ -372,14 +358,6 @@ flash_bootloader_ci: $(BOOTLOADER_CI_BUILD_DIR)/bootloader.bin ## flash CI bootl
|
||||
flash_prodtest: $(PRODTEST_BUILD_DIR)/prodtest.bin ## flash prodtest using OpenOCD
|
||||
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(FIRMWARE_START); exit"
|
||||
|
||||
flash_coreapp: $(COREAPP_BUILD_DIR)/coreapp.bin ## flash coreapp using OpenOCD
|
||||
ifeq ($(MCU),$(filter $(MCU),STM32F4))
|
||||
$(OPENOCD) -c "init; reset halt; flash write_image erase $<.p1 $(FIRMWARE_START); flash write_image erase $<.p2 $(FIRMWARE_P2_START); exit"
|
||||
|
||||
else
|
||||
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(FIRMWARE_START); exit"
|
||||
endif
|
||||
|
||||
flash_firmware: $(FIRMWARE_BUILD_DIR)/firmware.bin ## flash firmware using OpenOCD
|
||||
ifeq ($(MCU),$(filter $(MCU),STM32F4))
|
||||
$(OPENOCD) -c "init; reset halt; flash write_image erase $<.p1 $(FIRMWARE_START); flash write_image erase $<.p2 $(FIRMWARE_P2_START); exit"
|
||||
|
@ -1,948 +0,0 @@
|
||||
# pylint: disable=E0602
|
||||
# fmt: off
|
||||
|
||||
import os
|
||||
import tools, models
|
||||
|
||||
BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0')
|
||||
PRODUCTION = ARGUMENTS.get('PRODUCTION', '0') == '1'
|
||||
BOOTLOADER_QA = ARGUMENTS.get('BOOTLOADER_QA', '0') == '1'
|
||||
BOOTLOADER_DEVEL = ARGUMENTS.get('BOOTLOADER_DEVEL', '0') == '1'
|
||||
EVERYTHING = BITCOIN_ONLY != '1'
|
||||
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
|
||||
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
|
||||
PYOPT = ARGUMENTS.get('PYOPT', '1')
|
||||
DISABLE_OPTIGA = ARGUMENTS.get('DISABLE_OPTIGA', '0') == '1'
|
||||
HW_REVISION = ARGUMENTS.get('HW_REVISION', None)
|
||||
THP = ARGUMENTS.get('THP', '0') == '1' # Trezor-Host Protocol
|
||||
NEW_RENDERING = ARGUMENTS.get('NEW_RENDERING', '1') == '1' or TREZOR_MODEL in ('T3T1',)
|
||||
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
|
||||
|
||||
FEATURE_FLAGS = {
|
||||
"RDI": True,
|
||||
"SECP256K1_ZKP": True, # required for trezor.crypto.curve.bip340 (BIP340/Taproot)
|
||||
"AES_GCM": False,
|
||||
}
|
||||
|
||||
FEATURES_WANTED = ["input", "sbu", "sd_card", "rgb_led", "dma2d", "consumption_mask", "usb" ,"optiga", "haptic"]
|
||||
if DISABLE_OPTIGA and PYOPT == '0':
|
||||
FEATURES_WANTED.remove("optiga")
|
||||
if NEW_RENDERING:
|
||||
FEATURES_WANTED.append("new_rendering")
|
||||
|
||||
CCFLAGS_MOD = ''
|
||||
CPPPATH_MOD = []
|
||||
CPPDEFINES_MOD = []
|
||||
SOURCE_MOD = []
|
||||
SOURCE_MOD_CRYPTO = []
|
||||
CPPDEFINES_HAL = []
|
||||
SOURCE_HAL = []
|
||||
PATH_HAL = []
|
||||
|
||||
FROZEN = True
|
||||
|
||||
if TREZOR_MODEL in ('1', 'R', 'T3B1'):
|
||||
FONT_NORMAL='Font_PixelOperator_Regular_8'
|
||||
FONT_DEMIBOLD='Font_Unifont_Bold_16'
|
||||
FONT_BOLD='Font_PixelOperator_Bold_8'
|
||||
FONT_MONO='Font_PixelOperatorMono_Regular_8'
|
||||
FONT_BIG='Font_Unifont_Regular_16'
|
||||
FONT_NORMAL_UPPER='Font_PixelOperator_Regular_8_upper'
|
||||
FONT_BOLD_UPPER='Font_PixelOperator_Bold_8_upper'
|
||||
FONT_SUB=None
|
||||
elif TREZOR_MODEL in ('T', 'DISC1', 'DISC2'):
|
||||
FONT_NORMAL='Font_TTHoves_Regular_21'
|
||||
FONT_DEMIBOLD='Font_TTHoves_DemiBold_21'
|
||||
FONT_BOLD=None
|
||||
FONT_MONO='Font_RobotoMono_Medium_20'
|
||||
FONT_BIG=None
|
||||
FONT_NORMAL_UPPER=None
|
||||
FONT_BOLD_UPPER='Font_TTHoves_Bold_17_upper'
|
||||
FONT_SUB=None
|
||||
elif TREZOR_MODEL in ('T3T1',):
|
||||
FONT_NORMAL='Font_TTSatoshi_DemiBold_21'
|
||||
FONT_DEMIBOLD='Font_TTSatoshi_DemiBold_21'
|
||||
FONT_BOLD='Font_TTSatoshi_DemiBold_21'
|
||||
FONT_MONO='Font_RobotoMono_Medium_21'
|
||||
FONT_BIG='Font_TTSatoshi_DemiBold_42'
|
||||
FONT_NORMAL_UPPER=None
|
||||
FONT_BOLD_UPPER=None
|
||||
FONT_SUB='Font_TTSatoshi_DemiBold_18'
|
||||
|
||||
# modtrezorconfig
|
||||
CPPPATH_MOD += [
|
||||
'embed/extmod/modtrezorconfig',
|
||||
'vendor/trezor-storage',
|
||||
]
|
||||
SOURCE_MOD += [
|
||||
'embed/extmod/modtrezorconfig/modtrezorconfig.c',
|
||||
'vendor/trezor-storage/norcow.c',
|
||||
'vendor/trezor-storage/storage.c',
|
||||
'vendor/trezor-storage/storage_utils.c',
|
||||
'vendor/trezor-storage/flash_area.c',
|
||||
]
|
||||
|
||||
# modtrezorcrypto
|
||||
CCFLAGS_MOD += '-Wno-sequence-point '
|
||||
CPPPATH_MOD += [
|
||||
'vendor/trezor-crypto',
|
||||
]
|
||||
CPPDEFINES_MOD += [
|
||||
'AES_128',
|
||||
'AES_192',
|
||||
('USE_BIP32_CACHE', '0'),
|
||||
('USE_KECCAK', '1'),
|
||||
('USE_ETHEREUM', '1' if EVERYTHING else '0'),
|
||||
('USE_MONERO', '1' if EVERYTHING else '0'),
|
||||
('USE_CARDANO', '1' if EVERYTHING else '0'),
|
||||
('USE_NEM', '1' if (EVERYTHING and TREZOR_MODEL == "T") else '0'),
|
||||
('USE_EOS', '1' if (EVERYTHING and TREZOR_MODEL == "T") else '0'),
|
||||
]
|
||||
SOURCE_MOD += [
|
||||
'embed/extmod/trezorobj.c',
|
||||
'embed/extmod/modtrezorcrypto/crc.c',
|
||||
'embed/extmod/modtrezorcrypto/modtrezorcrypto.c',
|
||||
'embed/extmod/modtrezorcrypto/rand.c',
|
||||
]
|
||||
SOURCE_MOD_CRYPTO += [
|
||||
'vendor/trezor-crypto/address.c',
|
||||
'vendor/trezor-crypto/aes/aes_modes.c',
|
||||
'vendor/trezor-crypto/aes/aesccm.c',
|
||||
'vendor/trezor-crypto/aes/aescrypt.c',
|
||||
'vendor/trezor-crypto/aes/aeskey.c',
|
||||
'vendor/trezor-crypto/aes/aestab.c',
|
||||
'vendor/trezor-crypto/base32.c',
|
||||
'vendor/trezor-crypto/base58.c',
|
||||
'vendor/trezor-crypto/bignum.c',
|
||||
'vendor/trezor-crypto/bip32.c',
|
||||
'vendor/trezor-crypto/bip39.c',
|
||||
'vendor/trezor-crypto/bip39_english.c',
|
||||
'vendor/trezor-crypto/blake256.c',
|
||||
'vendor/trezor-crypto/blake2b.c',
|
||||
'vendor/trezor-crypto/blake2s.c',
|
||||
'vendor/trezor-crypto/buffer.c',
|
||||
'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',
|
||||
'vendor/trezor-crypto/chacha_drbg.c',
|
||||
'vendor/trezor-crypto/curves.c',
|
||||
'vendor/trezor-crypto/der.c',
|
||||
'vendor/trezor-crypto/ecdsa.c',
|
||||
'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',
|
||||
'vendor/trezor-crypto/ed25519-donna/ed25519.c',
|
||||
'vendor/trezor-crypto/ed25519-donna/modm-donna-32bit.c',
|
||||
'vendor/trezor-crypto/groestl.c',
|
||||
'vendor/trezor-crypto/hasher.c',
|
||||
'vendor/trezor-crypto/hmac.c',
|
||||
'vendor/trezor-crypto/hmac_drbg.c',
|
||||
'vendor/trezor-crypto/memzero.c',
|
||||
'vendor/trezor-crypto/nem.c',
|
||||
'vendor/trezor-crypto/nist256p1.c',
|
||||
'vendor/trezor-crypto/pbkdf2.c',
|
||||
'vendor/trezor-crypto/rand.c',
|
||||
'vendor/trezor-crypto/rfc6979.c',
|
||||
'vendor/trezor-crypto/ripemd160.c',
|
||||
'vendor/trezor-crypto/secp256k1.c',
|
||||
'vendor/trezor-crypto/segwit_addr.c',
|
||||
'vendor/trezor-crypto/sha2.c',
|
||||
'vendor/trezor-crypto/sha3.c',
|
||||
'vendor/trezor-crypto/shamir.c',
|
||||
'vendor/trezor-crypto/slip39.c',
|
||||
'vendor/trezor-crypto/slip39_english.c',
|
||||
'vendor/trezor-crypto/tls_prf.c',
|
||||
]
|
||||
if EVERYTHING:
|
||||
SOURCE_MOD_CRYPTO += [
|
||||
'vendor/trezor-crypto/cardano.c',
|
||||
'vendor/trezor-crypto/monero/base58.c',
|
||||
'vendor/trezor-crypto/monero/serialize.c',
|
||||
'vendor/trezor-crypto/monero/xmr.c',
|
||||
]
|
||||
|
||||
# libsecp256k1-zkp
|
||||
if FEATURE_FLAGS["SECP256K1_ZKP"]:
|
||||
CPPPATH_MOD += [
|
||||
'vendor/secp256k1-zkp',
|
||||
'vendor/secp256k1-zkp/src',
|
||||
'vendor/secp256k1-zkp/include',
|
||||
]
|
||||
CPPDEFINES_MOD += [
|
||||
'USE_SECP256K1_ZKP',
|
||||
'USE_SECP256K1_ZKP_ECDSA',
|
||||
('SECP256K1_CONTEXT_SIZE', '180'),
|
||||
'USE_ASM_ARM',
|
||||
'USE_EXTERNAL_ASM',
|
||||
'USE_EXTERNAL_DEFAULT_CALLBACKS',
|
||||
('ECMULT_GEN_PREC_BITS', '2'),
|
||||
('ECMULT_WINDOW_SIZE', '2'),
|
||||
'ENABLE_MODULE_GENERATOR',
|
||||
'ENABLE_MODULE_RECOVERY',
|
||||
'ENABLE_MODULE_SCHNORRSIG',
|
||||
'ENABLE_MODULE_EXTRAKEYS',
|
||||
'ENABLE_MODULE_ECDH',
|
||||
]
|
||||
SOURCE_MOD_SECP256K1_ZKP = [
|
||||
'vendor/secp256k1-zkp/src/secp256k1.c',
|
||||
'vendor/secp256k1-zkp/src/precomputed_ecmult.c',
|
||||
'vendor/secp256k1-zkp/src/precomputed_ecmult_gen.c',
|
||||
'vendor/secp256k1-zkp/src/asm/field_10x26_arm.s'
|
||||
]
|
||||
SOURCE_MOD_CRYPTO += [
|
||||
'vendor/trezor-crypto/zkp_context.c',
|
||||
'vendor/trezor-crypto/zkp_ecdsa.c',
|
||||
'vendor/trezor-crypto/zkp_bip340.c',
|
||||
]
|
||||
|
||||
# AES-GCM
|
||||
if FEATURE_FLAGS["AES_GCM"]:
|
||||
CPPDEFINES_MOD += [
|
||||
'USE_AES_GCM',
|
||||
'AES_VAR',
|
||||
]
|
||||
SOURCE_MOD_CRYPTO += [
|
||||
'vendor/trezor-crypto/aes/gf128mul.c',
|
||||
'vendor/trezor-crypto/aes/aesgcm.c',
|
||||
]
|
||||
|
||||
# modtrezorio
|
||||
SOURCE_MOD += [
|
||||
'embed/extmod/modtrezorio/modtrezorio.c',
|
||||
]
|
||||
|
||||
# modtrezorui
|
||||
CPPPATH_MOD += [
|
||||
'vendor/micropython/lib/uzlib',
|
||||
]
|
||||
SOURCE_MOD += [
|
||||
'embed/extmod/modtrezorui/modtrezorui.c',
|
||||
'embed/lib/buffers.c',
|
||||
'embed/lib/colors.c',
|
||||
'embed/lib/display_utils.c',
|
||||
'embed/lib/error_handling.c',
|
||||
'embed/lib/fonts/font_bitmap.c',
|
||||
'embed/lib/fonts/fonts.c',
|
||||
'embed/lib/gfx_color.c',
|
||||
'embed/lib/gfx_bitblt_rgb565.c',
|
||||
'embed/lib/gfx_bitblt_rgba8888.c',
|
||||
'embed/lib/gfx_bitblt_mono8.c',
|
||||
'embed/lib/image.c',
|
||||
'embed/lib/mini_printf.c',
|
||||
'embed/lib/rsod.c',
|
||||
'embed/lib/terminal.c',
|
||||
'embed/lib/translations.c',
|
||||
'embed/lib/unit_variant.c',
|
||||
'vendor/micropython/lib/uzlib/adler32.c',
|
||||
'vendor/micropython/lib/uzlib/crc32.c',
|
||||
'vendor/micropython/lib/uzlib/tinflate.c',
|
||||
]
|
||||
|
||||
if NEW_RENDERING:
|
||||
CPPDEFINES_MOD += ['NEW_RENDERING']
|
||||
SOURCE_MOD += [
|
||||
'embed/lib/gfx_draw.c',
|
||||
]
|
||||
else:
|
||||
SOURCE_MOD += [
|
||||
'embed/lib/display_draw.c',
|
||||
]
|
||||
|
||||
|
||||
CPPDEFINES_MOD += [
|
||||
'TREZOR_UI2',
|
||||
'TRANSLATIONS',
|
||||
]
|
||||
|
||||
if TREZOR_MODEL not in ('1', ):
|
||||
CPPDEFINES_MOD += [
|
||||
'FANCY_FATAL_ERROR',
|
||||
]
|
||||
|
||||
# modtrezorutils
|
||||
SOURCE_MOD += [
|
||||
'embed/extmod/modtrezorutils/modtrezorutils.c',
|
||||
]
|
||||
|
||||
# rust mods
|
||||
SOURCE_MOD += [
|
||||
'embed/extmod/rustmods.c',
|
||||
]
|
||||
|
||||
# modutime
|
||||
SOURCE_MOD += [
|
||||
'embed/extmod/modutime.c',
|
||||
]
|
||||
|
||||
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',
|
||||
'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',
|
||||
'vendor/micropython/shared/timeutils/timeutils.c',
|
||||
'vendor/micropython/ports/stm32/gccollect.c',
|
||||
'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',
|
||||
'vendor/micropython/py/objint.c',
|
||||
'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',
|
||||
'vendor/micropython/py/pairheap.c',
|
||||
'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',
|
||||
'vendor/micropython/py/runtime_utils.c',
|
||||
'vendor/micropython/py/scheduler.c',
|
||||
'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',
|
||||
]
|
||||
|
||||
SOURCE_MICROPYTHON_SPEED = [
|
||||
'vendor/micropython/py/gc.c',
|
||||
'vendor/micropython/py/pystack.c',
|
||||
'vendor/micropython/py/vm.c',
|
||||
]
|
||||
|
||||
CPPDEFINES_MOD += ['USE_SVC_SHUTDOWN']
|
||||
|
||||
if FEATURE_FLAGS["RDI"]:
|
||||
CPPDEFINES_MOD += ['RDI']
|
||||
|
||||
TRANSLATION_DATA = [
|
||||
"translations/en.json",
|
||||
"translations/order.json",
|
||||
]
|
||||
|
||||
if THP:
|
||||
CPPDEFINES_MOD += ['USE_THP']
|
||||
SOURCE_MOD += [
|
||||
'vendor/trezor-crypto/elligator2.c',
|
||||
]
|
||||
|
||||
# fonts
|
||||
tools.add_font('NORMAL', FONT_NORMAL, CPPDEFINES_MOD, SOURCE_MOD)
|
||||
tools.add_font('BOLD', FONT_BOLD, CPPDEFINES_MOD, SOURCE_MOD)
|
||||
tools.add_font('DEMIBOLD', FONT_DEMIBOLD, CPPDEFINES_MOD, SOURCE_MOD)
|
||||
tools.add_font('MONO', FONT_MONO, CPPDEFINES_MOD, SOURCE_MOD)
|
||||
tools.add_font('BIG', FONT_BIG, CPPDEFINES_MOD, SOURCE_MOD)
|
||||
tools.add_font('NORMAL_UPPER', FONT_NORMAL_UPPER, CPPDEFINES_MOD, SOURCE_MOD)
|
||||
tools.add_font('BOLD_UPPER', FONT_BOLD_UPPER, CPPDEFINES_MOD, SOURCE_MOD)
|
||||
tools.add_font('SUB', FONT_SUB, CPPDEFINES_MOD, SOURCE_MOD)
|
||||
|
||||
SOURCE_QSTR = SOURCE_MOD + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED
|
||||
|
||||
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=[]
|
||||
)
|
||||
|
||||
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL)
|
||||
|
||||
FILE_SUFFIX= env.get('ENV')['SUFFIX']
|
||||
|
||||
SOURCE_FIRMWARE = [
|
||||
'embed/coreapp/header.S',
|
||||
'embed/coreapp/main.c',
|
||||
'embed/coreapp/mphalport.c',
|
||||
'embed/coreapp/nlrthumb.c',
|
||||
f'embed/trezorhal/{FILE_SUFFIX}/startup_stage_4.S',
|
||||
]
|
||||
|
||||
|
||||
if TREZOR_MODEL in ('T', 'DISC1', 'DISC2'):
|
||||
UI_LAYOUT = 'UI_LAYOUT_TT'
|
||||
ui_layout_feature = 'model_tt'
|
||||
elif TREZOR_MODEL in ('1', 'R', 'T3B1'):
|
||||
UI_LAYOUT = 'UI_LAYOUT_TR'
|
||||
ui_layout_feature = 'model_tr'
|
||||
elif TREZOR_MODEL in ('T3T1',):
|
||||
UI_LAYOUT = 'UI_LAYOUT_MERCURY'
|
||||
ui_layout_feature = 'model_mercury'
|
||||
else:
|
||||
raise ValueError('Unknown Trezor model')
|
||||
|
||||
if 'sd_card' in FEATURES_AVAILABLE:
|
||||
SDCARD = True
|
||||
else:
|
||||
SDCARD = False
|
||||
|
||||
env.Tool('micropython')
|
||||
|
||||
env.Replace(
|
||||
CAT='cat',
|
||||
DD='dd',
|
||||
CP='cp',
|
||||
SED='sed',
|
||||
AS='arm-none-eabi-as',
|
||||
AR='arm-none-eabi-ar',
|
||||
CC='arm-none-eabi-gcc',
|
||||
LINK='arm-none-eabi-gcc',
|
||||
SIZE='arm-none-eabi-size',
|
||||
STRIP='arm-none-eabi-strip',
|
||||
OBJCOPY='arm-none-eabi-objcopy', )
|
||||
|
||||
env.Replace(
|
||||
TREZOR_MODEL=TREZOR_MODEL,)
|
||||
|
||||
ALLPATHS = [
|
||||
'.',
|
||||
'embed/rust',
|
||||
'embed/coreapp',
|
||||
'embed/lib',
|
||||
'embed/models',
|
||||
'embed/trezorhal',
|
||||
'embed/extmod/modtrezorui',
|
||||
'vendor/micropython',
|
||||
] + CPPPATH_MOD + PATH_HAL
|
||||
|
||||
env.Replace(
|
||||
COPT=env.get('ENV').get('OPTIMIZE', '-Os'),
|
||||
CCFLAGS='$COPT '
|
||||
'-g3 '
|
||||
'-nostdlib '
|
||||
'-std=gnu11 -Wall -Werror -Wdouble-promotion -Wpointer-arith -Wno-missing-braces -fno-common '
|
||||
'-fsingle-precision-constant -fdata-sections -ffunction-sections '
|
||||
'-ffreestanding '
|
||||
'-fstack-protector-all '
|
||||
+ env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD,
|
||||
CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB',
|
||||
LINKFLAGS='-T build/coreapp/memory.ld -Wl,--gc-sections -Wl,--print-memory-usage -Wl,-Map=build/coreapp/coreapp.map -Wl,--warn-common',
|
||||
CPPPATH=ALLPATHS,
|
||||
CPPDEFINES=[
|
||||
'FIRMWARE',
|
||||
'TREZOR_MODEL_'+TREZOR_MODEL,
|
||||
'USE_HAL_DRIVER',
|
||||
'ARM_USER_MODE',
|
||||
UI_LAYOUT,
|
||||
] + CPPDEFINES_MOD + CPPDEFINES_HAL,
|
||||
ASFLAGS=env.get('ENV')['CPU_ASFLAGS'],
|
||||
ASPPFLAGS='$CFLAGS $CCFLAGS',
|
||||
)
|
||||
|
||||
env.Replace(
|
||||
HEADERTOOL='headertool',
|
||||
PYTHON='python',
|
||||
MAKEQSTRDATA='$PYTHON vendor/micropython/py/makeqstrdata.py',
|
||||
MAKEVERSIONHDR='$PYTHON vendor/micropython/py/makeversionhdr.py',
|
||||
MAKEMODULEDEFS='$PYTHON vendor/micropython/py/makemoduledefs.py',
|
||||
MAKECMAKELISTS='$PYTHON tools/make_cmakelists.py',
|
||||
MPY_TOOL='$PYTHON vendor/micropython/tools/mpy-tool.py',
|
||||
MPY_CROSS='vendor/micropython/mpy-cross/mpy-cross -O' + PYOPT,
|
||||
PB2PY='$PYTHON ../common/protob/pb2py',
|
||||
)
|
||||
|
||||
#
|
||||
# Qstrings
|
||||
#
|
||||
|
||||
PROTO_SOURCES_DIR = '../../../common/protob/'
|
||||
PROTO_SOURCES = Glob(PROTO_SOURCES_DIR + '*.proto',
|
||||
exclude=[PROTO_SOURCES_DIR + 'messages-bootloader.proto']
|
||||
)
|
||||
qstr_protobuf = env.Command(
|
||||
target=[
|
||||
'genhdr/qstrdefs.protobuf.h',
|
||||
],
|
||||
source=PROTO_SOURCES,
|
||||
action='$PB2PY $SOURCES --qstr-out ${TARGET} --bitcoin-only=%s' % BITCOIN_ONLY,
|
||||
)
|
||||
|
||||
qstr_micropython = 'vendor/micropython/py/qstrdefs.h'
|
||||
|
||||
micropy_defines = env.MicroPyDefines(source=SOURCE_QSTR)
|
||||
|
||||
qstr_collected = env.CollectQstr(
|
||||
target='genhdr/qstrdefs.collected.h', source=micropy_defines)
|
||||
|
||||
qstr_preprocessed = env.PreprocessQstr(
|
||||
target='genhdr/qstrdefs.preprocessed.h',
|
||||
source=[qstr_micropython, qstr_protobuf, qstr_collected])
|
||||
|
||||
qstr_generated = env.GenerateQstrDefs(
|
||||
target='genhdr/qstrdefs.generated.h', source=qstr_preprocessed)
|
||||
|
||||
env.Ignore(qstr_collected, qstr_generated)
|
||||
|
||||
#
|
||||
# Micropython module declarations
|
||||
#
|
||||
|
||||
moduledefs_collected = env.CollectModules(
|
||||
target='genhdr/moduledefs.collected.h', source=micropy_defines)
|
||||
|
||||
hdr_moduledefs = env.Command(
|
||||
target='genhdr/moduledefs.h',
|
||||
source=moduledefs_collected,
|
||||
action='$MAKEMODULEDEFS $SOURCE > $TARGET', )
|
||||
|
||||
env.Ignore(micropy_defines, micropy_defines)
|
||||
env.Ignore(micropy_defines, qstr_generated)
|
||||
env.Ignore(micropy_defines, hdr_moduledefs)
|
||||
|
||||
#
|
||||
# Micropython version
|
||||
#
|
||||
|
||||
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)
|
||||
|
||||
#
|
||||
# Frozen modules
|
||||
#
|
||||
|
||||
if FROZEN:
|
||||
SOURCE_PY_DIR = 'src/'
|
||||
|
||||
SOURCE_PY = Glob(SOURCE_PY_DIR + '*.py')
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/*.py',
|
||||
exclude=[
|
||||
SOURCE_PY_DIR + 'trezor/sdcard.py',
|
||||
] if not SDCARD else []
|
||||
))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/crypto/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/*.py'))
|
||||
|
||||
# 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 []
|
||||
))
|
||||
if UI_LAYOUT == 'UI_LAYOUT_TT':
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt/*.py',
|
||||
exclude=[
|
||||
SOURCE_PY_DIR + 'trezor/ui/layouts/tt/fido.py',
|
||||
] if not EVERYTHING else []
|
||||
))
|
||||
elif UI_LAYOUT == 'UI_LAYOUT_TR':
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tr/*.py',
|
||||
exclude=[
|
||||
SOURCE_PY_DIR + 'trezor/ui/layouts/tr/fido.py',
|
||||
] if not EVERYTHING else []
|
||||
))
|
||||
elif UI_LAYOUT == 'UI_LAYOUT_MERCURY':
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/mercury/*.py',
|
||||
exclude=[
|
||||
SOURCE_PY_DIR + 'trezor/ui/layouts/mercury/fido.py',
|
||||
] if not EVERYTHING else []
|
||||
))
|
||||
else:
|
||||
raise ValueError('Unknown layout')
|
||||
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/wire/*.py'))
|
||||
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'storage/*.py',
|
||||
exclude=[
|
||||
SOURCE_PY_DIR + 'storage/sd_salt.py',
|
||||
] if not SDCARD else []
|
||||
))
|
||||
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/messages/__init__.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/*.py',
|
||||
exclude=[
|
||||
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',
|
||||
SOURCE_PY_DIR + 'trezor/enums/Solana*.py',
|
||||
SOURCE_PY_DIR + 'trezor/enums/Stellar*.py',
|
||||
SOURCE_PY_DIR + 'trezor/enums/Tezos*.py',
|
||||
SOURCE_PY_DIR + 'trezor/enums/Zcash*.py',
|
||||
])
|
||||
)
|
||||
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/common/*.py',
|
||||
exclude=[
|
||||
SOURCE_PY_DIR + 'apps/common/sdcard.py',
|
||||
] if not SDCARD else []
|
||||
))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/debug/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/homescreen/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*.py',
|
||||
exclude=[
|
||||
SOURCE_PY_DIR + 'apps/management/sd_protect.py',
|
||||
] if not SDCARD else [])
|
||||
)
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*/*.py'))
|
||||
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',
|
||||
exclude=[
|
||||
SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/decred.py',
|
||||
SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/bitcoinlike.py',
|
||||
SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/zcash_v4.py',
|
||||
])
|
||||
)
|
||||
|
||||
if EVERYTHING:
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/binance/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Binance*.py'))
|
||||
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/cardano/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/cardano/*/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Cardano*.py'))
|
||||
|
||||
if TREZOR_MODEL == "T":
|
||||
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'))
|
||||
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/ethereum/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Ethereum*.py'))
|
||||
|
||||
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'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/DebugMonero*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Monero*.py'))
|
||||
|
||||
if TREZOR_MODEL == "T":
|
||||
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'))
|
||||
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/ripple/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Ripple*.py'))
|
||||
|
||||
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'))
|
||||
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/stellar/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/stellar/*/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Stellar*.py'))
|
||||
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/tezos/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Tezos*.py'))
|
||||
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/zcash/*.py'))
|
||||
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/webauthn/*.py'))
|
||||
|
||||
if TREZOR_MODEL == "T":
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/decred.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/bitcoinlike.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/zcash_v4.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Zcash*.py'))
|
||||
|
||||
source_mpy = env.FrozenModule(
|
||||
source=SOURCE_PY,
|
||||
source_dir=SOURCE_PY_DIR,
|
||||
bitcoin_only=BITCOIN_ONLY,
|
||||
backlight='backlight' in FEATURES_AVAILABLE,
|
||||
optiga='optiga' in FEATURES_AVAILABLE,
|
||||
ui_layout=UI_LAYOUT,
|
||||
thp=THP,
|
||||
)
|
||||
|
||||
source_mpyc = env.FrozenCFile(
|
||||
target='frozen_mpy.c', source=source_mpy, qstr_header=qstr_preprocessed)
|
||||
|
||||
env.Depends(source_mpyc, qstr_generated)
|
||||
|
||||
|
||||
#
|
||||
# Program objects
|
||||
#
|
||||
|
||||
source_files = SOURCE_MOD + SOURCE_MOD_CRYPTO + SOURCE_FIRMWARE + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED + SOURCE_HAL
|
||||
obj_program = []
|
||||
obj_program.extend(env.Object(source=SOURCE_MOD))
|
||||
obj_program.extend(env.Object(source=SOURCE_MOD_CRYPTO, CCFLAGS='$CCFLAGS -ftrivial-auto-var-init=zero'))
|
||||
if FEATURE_FLAGS["SECP256K1_ZKP"]:
|
||||
obj_program.extend(env.Object(source=SOURCE_MOD_SECP256K1_ZKP, CCFLAGS='$CCFLAGS -Wno-unused-function'))
|
||||
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',
|
||||
)
|
||||
|
||||
#
|
||||
# Rust library
|
||||
#
|
||||
|
||||
protobuf_blobs = env.Command(
|
||||
target=[
|
||||
'rust/proto_enums.data',
|
||||
'rust/proto_msgs.data',
|
||||
'rust/proto_names.data',
|
||||
'rust/proto_wire.data',
|
||||
],
|
||||
source=PROTO_SOURCES,
|
||||
action='$PB2PY --bitcoin-only=%s --blob-outdir ${TARGET.dir} $SOURCES --qstr-defs build/coreapp/genhdr/qstrdefs.generated.h' % BITCOIN_ONLY,
|
||||
)
|
||||
env.Depends(protobuf_blobs, qstr_generated)
|
||||
|
||||
RUST_PROFILE = 'release'
|
||||
RUST_LIB = 'trezor_lib'
|
||||
RUST_LIBDIR = f'build/coreapp/rust/{env.get("ENV")["RUST_TARGET"]}/{RUST_PROFILE}'
|
||||
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 = ''
|
||||
|
||||
features = ['micropython', 'protobuf', ui_layout_feature]
|
||||
if EVERYTHING:
|
||||
features.append('universal_fw')
|
||||
features.append('ui')
|
||||
features.append('translations')
|
||||
|
||||
if NEW_RENDERING:
|
||||
features.append('new_rendering')
|
||||
|
||||
if PYOPT == '0':
|
||||
features.append('debug')
|
||||
features.append('ui_debug')
|
||||
if TREZOR_MODEL in ('T', 'T3T1', 'DISC1', 'DISC2'):
|
||||
features.append('ui_blurring')
|
||||
features.append('ui_jpeg_decoder')
|
||||
|
||||
if NEW_RENDERING and TREZOR_MODEL in ('T3T1', 'DISC2'):
|
||||
features.append('ui_image_buffer')
|
||||
features.append('ui_overlay')
|
||||
|
||||
features.extend(FEATURES_AVAILABLE)
|
||||
|
||||
cargo_opts = [
|
||||
f'--target={env.get("ENV")["RUST_TARGET"]}',
|
||||
f'--target-dir=../../build/coreapp/rust',
|
||||
'--no-default-features',
|
||||
'--features ' + ','.join(features),
|
||||
'-Z build-std=core',
|
||||
'-Z build-std-features=panic_immediate_abort',
|
||||
]
|
||||
|
||||
env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL
|
||||
|
||||
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
|
||||
build_dir = str(Dir('.').abspath)
|
||||
|
||||
return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts)
|
||||
|
||||
rust = env.Command(
|
||||
target=RUST_LIBPATH,
|
||||
source='',
|
||||
action=cargo_build(), )
|
||||
env.Depends(rust, protobuf_blobs)
|
||||
env.Depends(rust, TRANSLATION_DATA)
|
||||
|
||||
env.Append(LINKFLAGS=f' -L{RUST_LIBDIR}')
|
||||
env.Append(LINKFLAGS=f' -l{RUST_LIB}')
|
||||
|
||||
|
||||
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
|
||||
BOOTLOADER_SUFFIX = MODEL_IDENTIFIER
|
||||
if BOOTLOADER_QA or BOOTLOADER_DEVEL:
|
||||
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"
|
||||
else:
|
||||
if TREZOR_MODEL in ('T',):
|
||||
vendor = "satoshilabs_signed_prod"
|
||||
elif BITCOIN_ONLY == '1':
|
||||
vendor = "trezor_btconly_signed_prod"
|
||||
else:
|
||||
vendor = "trezor_signed_prod"
|
||||
|
||||
VENDORHEADER = f'embed/models/{MODEL_IDENTIFIER}/vendorheader/vendorheader_{vendor}.bin'
|
||||
|
||||
|
||||
obj_program.extend(
|
||||
env.Command(
|
||||
target='embed/coreapp/vendorheader.o',
|
||||
source=VENDORHEADER,
|
||||
action='$OBJCOPY -I binary -O elf32-littlearm -B arm'
|
||||
' --rename-section .data=.vendorheader,alloc,load,readonly,contents'
|
||||
' $SOURCE $TARGET', ))
|
||||
|
||||
|
||||
tools.embed_raw_binary(
|
||||
obj_program,
|
||||
env,
|
||||
'kernel',
|
||||
'build/kernel/kernel.o',
|
||||
f'build/kernel/kernel.bin',
|
||||
)
|
||||
|
||||
|
||||
|
||||
env.Depends(obj_program, qstr_generated)
|
||||
|
||||
linkerscript_gen = env.Command(
|
||||
target='memory.ld',
|
||||
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='coreapp')],
|
||||
action='$CAT $SOURCES > $TARGET',
|
||||
)
|
||||
|
||||
program_elf = env.Command(
|
||||
target='coreapp.elf',
|
||||
source=obj_program,
|
||||
action=
|
||||
'$LINK -o $TARGET $CCFLAGS $CFLAGS $SOURCES $LINKFLAGS -lc_nano -lm -lgcc',
|
||||
)
|
||||
|
||||
env.Depends(program_elf, linkerscript_gen)
|
||||
|
||||
if CMAKELISTS != 0:
|
||||
env.Depends(program_elf, cmake_gen)
|
||||
env.Depends(program_elf, rust)
|
||||
|
||||
BINARY_NAME = f"build/coreapp/coreapp-{MODEL_IDENTIFIER}"
|
||||
if not EVERYTHING:
|
||||
BINARY_NAME += "-btconly"
|
||||
BINARY_NAME += "-" + tools.get_version('embed/coreapp/version.h')
|
||||
BINARY_NAME += "-" + tools.get_git_revision_short_hash()
|
||||
BINARY_NAME += "-dirty" if tools.get_git_modified() else ""
|
||||
BINARY_NAME += ".bin"
|
||||
|
||||
|
||||
if 'STM32F427xx' in CPPDEFINES_HAL or 'STM32F429xx' in CPPDEFINES_HAL:
|
||||
action_bin=[
|
||||
'$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',
|
||||
'$CP $TARGET ' + BINARY_NAME,
|
||||
]
|
||||
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,
|
||||
]
|
||||
else:
|
||||
raise Exception("Unknown MCU")
|
||||
|
||||
program_bin = env.Command(
|
||||
target='coreapp.bin',
|
||||
source=program_elf,
|
||||
action=action_bin,
|
||||
)
|
@ -16,12 +16,11 @@ DISABLE_OPTIGA = ARGUMENTS.get('DISABLE_OPTIGA', '0') == '1'
|
||||
HW_REVISION = ARGUMENTS.get('HW_REVISION', None)
|
||||
THP = ARGUMENTS.get('THP', '0') == '1' # Trezor-Host Protocol
|
||||
NEW_RENDERING = ARGUMENTS.get('NEW_RENDERING', '1') == '1'
|
||||
|
||||
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
|
||||
|
||||
FEATURE_FLAGS = {
|
||||
"RDI": True,
|
||||
"SECP256K1_ZKP": True, # required for trezor.crypto.curve.bip340 (BIP340/Taproot)
|
||||
"SYSTEM_VIEW": False,
|
||||
"AES_GCM": False,
|
||||
}
|
||||
|
||||
@ -85,7 +84,6 @@ CPPPATH_MOD += [
|
||||
'vendor/trezor-crypto',
|
||||
]
|
||||
CPPDEFINES_MOD += [
|
||||
'KERNEL_MODE',
|
||||
'AES_128',
|
||||
'AES_192',
|
||||
('USE_BIP32_CACHE', '0'),
|
||||
@ -221,12 +219,10 @@ CPPPATH_MOD += [
|
||||
]
|
||||
SOURCE_MOD += [
|
||||
'embed/extmod/modtrezorui/modtrezorui.c',
|
||||
'embed/lib/bl_check.c',
|
||||
'embed/lib/buffers.c',
|
||||
'embed/lib/colors.c',
|
||||
'embed/lib/display_utils.c',
|
||||
'embed/lib/error_handling.c',
|
||||
'embed/lib/flash_utils.c',
|
||||
'embed/lib/fonts/font_bitmap.c',
|
||||
'embed/lib/fonts/fonts.c',
|
||||
'embed/lib/gfx_color.c',
|
||||
@ -401,22 +397,6 @@ CPPDEFINES_MOD += ['USE_SVC_SHUTDOWN']
|
||||
if FEATURE_FLAGS["RDI"]:
|
||||
CPPDEFINES_MOD += ['RDI']
|
||||
|
||||
if FEATURE_FLAGS["SYSTEM_VIEW"]:
|
||||
SOURCE_FIRMWARE += [
|
||||
'embed/segger/SEGGER/SEGGER_SYSVIEW_Config_NoOS.c',
|
||||
'embed/segger/SEGGER/SEGGER_SYSVIEW.c',
|
||||
'embed/segger/SEGGER/SEGGER_RTT.c',
|
||||
'embed/segger/SEGGER/SEGGER_RTT_ASM_ARMv7M.S',
|
||||
'embed/segger/SEGGER/Syscalls/SEGGER_RTT_Syscalls_GCC.c',
|
||||
'embed/firmware/systemview.c',
|
||||
]
|
||||
CPPPATH_MOD += [
|
||||
'embed/segger/SEGGER/',
|
||||
'embed/segger/Config/',
|
||||
]
|
||||
CPPDEFINES_MOD += ['SYSTEM_VIEW']
|
||||
CCFLAGS_MOD += '-DSYSTEM_VIEW '
|
||||
|
||||
TRANSLATION_DATA = [
|
||||
"translations/en.json",
|
||||
"translations/order.json",
|
||||
@ -451,7 +431,6 @@ FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_
|
||||
FILE_SUFFIX= env.get('ENV')['SUFFIX']
|
||||
|
||||
SOURCE_FIRMWARE = [
|
||||
'embed/firmware/delay.c',
|
||||
'embed/firmware/header.S',
|
||||
'embed/firmware/main.c',
|
||||
'embed/firmware/mphalport.c',
|
||||
@ -891,8 +870,7 @@ else:
|
||||
VENDORHEADER = f'embed/models/{MODEL_IDENTIFIER}/vendorheader/vendorheader_{vendor}.bin'
|
||||
|
||||
|
||||
if TREZOR_MODEL not in ('1',):
|
||||
obj_program.extend(
|
||||
obj_program.extend(
|
||||
env.Command(
|
||||
target='embed/firmware/vendorheader.o',
|
||||
source=VENDORHEADER,
|
||||
@ -900,17 +878,17 @@ if TREZOR_MODEL not in ('1',):
|
||||
' --rename-section .data=.vendorheader,alloc,load,readonly,contents'
|
||||
' $SOURCE $TARGET', ))
|
||||
|
||||
if TREZOR_MODEL not in ('DISC1', 'DISC2'):
|
||||
tools.embed_compressed_binary(
|
||||
|
||||
tools.embed_raw_binary(
|
||||
obj_program,
|
||||
env,
|
||||
'bootloader',
|
||||
'embed/bootloaders/bootloader.o',
|
||||
f'embed/models/{MODEL_IDENTIFIER}/bootloaders/bootloader_{BOOTLOADER_SUFFIX}.bin',
|
||||
'firmware'
|
||||
'kernel',
|
||||
'build/kernel/kernel.o',
|
||||
f'build/kernel/kernel.bin',
|
||||
)
|
||||
|
||||
|
||||
|
||||
env.Depends(obj_program, qstr_generated)
|
||||
|
||||
linkerscript_gen = env.Command(
|
||||
@ -932,7 +910,7 @@ if CMAKELISTS != 0:
|
||||
env.Depends(program_elf, cmake_gen)
|
||||
env.Depends(program_elf, rust)
|
||||
|
||||
BINARY_NAME = f"build/firmware/firmware-{models.get_model_identifier(TREZOR_MODEL)}"
|
||||
BINARY_NAME = f"build/firmware/firmware-{MODEL_IDENTIFIER}"
|
||||
if not EVERYTHING:
|
||||
BINARY_NAME += "-btconly"
|
||||
BINARY_NAME += "-" + tools.get_version('embed/firmware/version.h')
|
||||
@ -941,14 +919,7 @@ BINARY_NAME += "-dirty" if tools.get_git_modified() else ""
|
||||
BINARY_NAME += ".bin"
|
||||
|
||||
|
||||
if TREZOR_MODEL in ('1'):
|
||||
action_bin=[
|
||||
'$OBJCOPY -O binary -j .header -j .flash -j .data -j .confidential $SOURCE $TARGET',
|
||||
'../legacy/bootloader/firmware_sign.py -f $TARGET',
|
||||
'$CP $TARGET ' + BINARY_NAME,
|
||||
]
|
||||
else:
|
||||
if 'STM32F427xx' in CPPDEFINES_HAL or 'STM32F429xx' in CPPDEFINES_HAL:
|
||||
if 'STM32F427xx' in CPPDEFINES_HAL or 'STM32F429xx' in CPPDEFINES_HAL:
|
||||
action_bin=[
|
||||
'$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',
|
||||
@ -957,13 +928,13 @@ else:
|
||||
'$DD if=$TARGET of=${TARGET}.p1 skip=0 bs=128k count=6',
|
||||
'$CP $TARGET ' + BINARY_NAME,
|
||||
]
|
||||
elif 'STM32U5A9xx' in CPPDEFINES_HAL or 'STM32U585xx' in CPPDEFINES_HAL:
|
||||
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,
|
||||
]
|
||||
else:
|
||||
else:
|
||||
raise Exception("Unknown MCU")
|
||||
|
||||
program_bin = env.Command(
|
||||
|
@ -8,7 +8,6 @@ SConscript('SConscript.bootloader', variant_dir='build/bootloader', duplicate=Fa
|
||||
SConscript('SConscript.bootloader_ci', variant_dir='build/bootloader_ci', duplicate=False)
|
||||
SConscript('SConscript.bootloader_emu', variant_dir='build/bootloader_emu', duplicate=False)
|
||||
SConscript('SConscript.kernel', variant_dir='build/kernel', duplicate=False)
|
||||
SConscript('SConscript.coreapp', variant_dir='build/coreapp', duplicate=False)
|
||||
SConscript('SConscript.firmware', variant_dir='build/firmware', duplicate=False)
|
||||
SConscript('SConscript.prodtest', variant_dir='build/prodtest', duplicate=False)
|
||||
SConscript('SConscript.reflash', variant_dir='build/reflash', duplicate=False)
|
||||
|
@ -1,54 +0,0 @@
|
||||
.syntax unified
|
||||
|
||||
#include "version.h"
|
||||
|
||||
.section .header, "a"
|
||||
|
||||
.type g_header, %object
|
||||
.size g_header, .-g_header
|
||||
|
||||
// Firmware header for both Trezor One and Trezor T.
|
||||
// Trezor One must have bootloader version >= 1.8.0 (before that version the hdrlen used to be reset vector)
|
||||
|
||||
g_header:
|
||||
.byte 'T','R','Z','F' // magic
|
||||
.word g_header_end - g_header // hdrlen
|
||||
#ifdef TREZOR_MODEL_T
|
||||
.word 0 // expiry
|
||||
#else
|
||||
.word 1 // expiry
|
||||
#endif
|
||||
.word _codelen // codelen
|
||||
.byte VERSION_MAJOR // vmajor
|
||||
.byte VERSION_MINOR // vminor
|
||||
.byte VERSION_PATCH // vpatch
|
||||
.byte VERSION_BUILD // vbuild
|
||||
.byte FIX_VERSION_MAJOR // fix_vmajor
|
||||
.byte FIX_VERSION_MINOR // fix_vminor
|
||||
.byte FIX_VERSION_PATCH // fix_vpatch
|
||||
.byte FIX_VERSION_BUILD // fix_vbuild
|
||||
.word HW_MODEL // type of the designated hardware
|
||||
.byte HW_REVISION // revision of the designated hardware
|
||||
.byte VERSION_MONOTONIC // monotonic version of the binary
|
||||
. = . + 2 // reserved
|
||||
. = . + 512 // hash1 ... hash16
|
||||
|
||||
#if !defined TREZOR_MODEL_1
|
||||
// trezor-core header style
|
||||
. = . + 415 // reserved
|
||||
.byte 0 // sigmask
|
||||
. = . + 64 // sig
|
||||
#else
|
||||
// model 1 compatibility header
|
||||
. = . + 64 // sig1
|
||||
. = . + 64 // sig2
|
||||
. = . + 64 // sig3
|
||||
.byte 0 // sigindex1
|
||||
.byte 0 // sigindex2
|
||||
.byte 0 // sigindex3
|
||||
. = . + 220 // reserved
|
||||
. = . + 65 // reserved
|
||||
#endif
|
||||
|
||||
g_header_end:
|
||||
|
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include STM32_HAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/builtin.h"
|
||||
#include "py/compile.h"
|
||||
#include "py/gc.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/repl.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stackctrl.h"
|
||||
#include "shared/runtime/pyexec.h"
|
||||
|
||||
#include "ports/stm32/gccollect.h"
|
||||
#include "ports/stm32/pendsv.h"
|
||||
|
||||
#include "error_handling.h"
|
||||
#include "rsod.h"
|
||||
#include "rust_ui_common.h"
|
||||
#include "secbool.h"
|
||||
#include "systask.h"
|
||||
#include "system.h"
|
||||
|
||||
#ifdef USE_SECP256K1_ZKP
|
||||
#include "zkp_context.h"
|
||||
#endif
|
||||
|
||||
int main(uint32_t cmd, void *arg) {
|
||||
if (cmd == 1) {
|
||||
systask_postmortem_t *info = (systask_postmortem_t *)arg;
|
||||
rsod_gui(info);
|
||||
system_exit(0);
|
||||
}
|
||||
|
||||
screen_boot_stage_2();
|
||||
|
||||
// uint32_t *p = 0;
|
||||
// *p = 0;
|
||||
|
||||
#ifdef USE_SECP256K1_ZKP
|
||||
ensure(sectrue * (zkp_context_init() == 0), NULL);
|
||||
#endif
|
||||
|
||||
printf("CORE: Preparing stack\n");
|
||||
// Stack limit should be less than real stack size, so we have a chance
|
||||
// to recover from limit hit.
|
||||
mp_stack_set_top(&_estack);
|
||||
mp_stack_set_limit((char *)&_estack - (char *)&_sstack - 1024);
|
||||
|
||||
#if MICROPY_ENABLE_PYSTACK
|
||||
static mp_obj_t pystack[1024];
|
||||
mp_pystack_init(pystack, &pystack[MP_ARRAY_SIZE(pystack)]);
|
||||
#endif
|
||||
|
||||
// GC init
|
||||
printf("CORE: Starting GC\n");
|
||||
gc_init(&_heap_start, &_heap_end);
|
||||
|
||||
// Interpreter init
|
||||
printf("CORE: Starting interpreter\n");
|
||||
mp_init();
|
||||
mp_obj_list_init(mp_sys_argv, 0);
|
||||
mp_obj_list_init(mp_sys_path, 0);
|
||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen));
|
||||
|
||||
// Execute the main script
|
||||
printf("CORE: Executing main script\n");
|
||||
pyexec_frozen_module("main.py");
|
||||
|
||||
// Clean up
|
||||
printf("CORE: Main script finished, cleaning up\n");
|
||||
mp_deinit();
|
||||
|
||||
// Python code shouldn't ever exit, avoid black screen if it does
|
||||
error_shutdown("(PE)");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// MicroPython default exception handler
|
||||
|
||||
void __attribute__((noreturn)) nlr_jump_fail(void *val) {
|
||||
error_shutdown("(UE)");
|
||||
}
|
||||
|
||||
// MicroPython builtin stubs
|
||||
|
||||
mp_import_stat_t mp_import_stat(const char *path) {
|
||||
return MP_IMPORT_STAT_NO_EXIST;
|
||||
}
|
||||
|
||||
mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
@ -1,224 +0,0 @@
|
||||
// clang-format off
|
||||
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2017 Damien P. George
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Options to control how MicroPython is built for this port,
|
||||
// overriding defaults in py/mpconfig.h.
|
||||
|
||||
#pragma once
|
||||
#ifndef __INCLUDED_MPCONFIGPORT_H
|
||||
#define __INCLUDED_MPCONFIGPORT_H
|
||||
|
||||
// frozen modules
|
||||
#define MICROPY_MODULE_FROZEN_MPY (1)
|
||||
#define MICROPY_QSTR_EXTRA_POOL (mp_qstr_frozen_const_pool)
|
||||
|
||||
// memory allocation policies
|
||||
#define MICROPY_ALLOC_PATH_MAX (128)
|
||||
#define MICROPY_ENABLE_PYSTACK (1)
|
||||
#define MICROPY_LOADED_MODULES_DICT_SIZE (160)
|
||||
|
||||
// emitters
|
||||
#define MICROPY_PERSISTENT_CODE_LOAD (0)
|
||||
#define MICROPY_EMIT_THUMB (0)
|
||||
#define MICROPY_EMIT_INLINE_THUMB (0)
|
||||
|
||||
// compiler configuration
|
||||
#define MICROPY_ENABLE_COMPILER (0)
|
||||
#define MICROPY_COMP_MODULE_CONST (1)
|
||||
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1)
|
||||
#define MICROPY_COMP_RETURN_IF_EXPR (1)
|
||||
|
||||
// optimisations
|
||||
#define MICROPY_OPT_COMPUTED_GOTO (1)
|
||||
#define MICROPY_OPT_MPZ_BITWISE (1)
|
||||
#define MICROPY_OPT_MATH_FACTORIAL (0)
|
||||
#define MICROPY_OPT_LOAD_ATTR_FAST_PATH (1)
|
||||
#define MICROPY_OPT_MAP_LOOKUP_CACHE (1)
|
||||
|
||||
#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES)
|
||||
|
||||
// Python internal features
|
||||
#define MICROPY_READER_VFS (0)
|
||||
#define MICROPY_ENABLE_GC (1)
|
||||
#define MICROPY_ENABLE_FINALISER (1)
|
||||
#define MICROPY_STACK_CHECK (1)
|
||||
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
|
||||
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0)
|
||||
#define MICROPY_KBD_EXCEPTION (1)
|
||||
#define MICROPY_HELPER_REPL (1)
|
||||
#define MICROPY_REPL_EMACS_KEYS (1)
|
||||
#define MICROPY_REPL_AUTO_INDENT (1)
|
||||
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
|
||||
#define MICROPY_ENABLE_SOURCE_LINE (1)
|
||||
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
|
||||
#define MICROPY_STREAMS_NON_BLOCK (1)
|
||||
#define MICROPY_MODULE_WEAK_LINKS (1)
|
||||
#define MICROPY_CAN_OVERRIDE_BUILTINS (0)
|
||||
#define MICROPY_USE_INTERNAL_ERRNO (1)
|
||||
#define MICROPY_ENABLE_SCHEDULER (0)
|
||||
#define MICROPY_SCHEDULER_DEPTH (0)
|
||||
#define MICROPY_VFS (0)
|
||||
|
||||
// control over Python builtins
|
||||
#define MICROPY_PY_FUNCTION_ATTRS (1)
|
||||
#define MICROPY_PY_DESCRIPTORS (0)
|
||||
#define MICROPY_PY_DELATTR_SETATTR (0)
|
||||
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
|
||||
#define MICROPY_PY_BUILTINS_STR_CENTER (1)
|
||||
#define MICROPY_PY_BUILTINS_STR_PARTITION (1)
|
||||
#define MICROPY_PY_BUILTINS_STR_SPLITLINES (0)
|
||||
#define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
|
||||
#define MICROPY_PY_BUILTINS_FROZENSET (0)
|
||||
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
|
||||
#define MICROPY_PY_BUILTINS_SLICE_INDICES (0)
|
||||
#define MICROPY_PY_BUILTINS_ROUND_INT (0)
|
||||
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
|
||||
#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
|
||||
#define MICROPY_PY_BUILTINS_COMPILE (MICROPY_ENABLE_COMPILER)
|
||||
#define MICROPY_PY_BUILTINS_EXECFILE (MICROPY_ENABLE_COMPILER)
|
||||
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
|
||||
#define MICROPY_PY_BUILTINS_INPUT (0)
|
||||
#define MICROPY_PY_BUILTINS_POW3 (0)
|
||||
#define MICROPY_PY_BUILTINS_HELP (0)
|
||||
#define MICROPY_PY_BUILTINS_HELP_TEXT stm32_help_text
|
||||
#define MICROPY_PY_BUILTINS_HELP_MODULES (0)
|
||||
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
|
||||
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
|
||||
#define MICROPY_PY_COLLECTIONS (0)
|
||||
#define MICROPY_PY_COLLECTIONS_DEQUE (0)
|
||||
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
|
||||
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
|
||||
#define MICROPY_PY_MATH_ISCLOSE (0)
|
||||
#define MICROPY_PY_MATH_FACTORIAL (0)
|
||||
#define MICROPY_PY_CMATH (0)
|
||||
#define MICROPY_PY_IO (0)
|
||||
#define MICROPY_PY_IO_IOBASE (0)
|
||||
#define MICROPY_PY_IO_FILEIO (MICROPY_VFS_FAT) // because mp_type_fileio/textio point to fatfs impl
|
||||
#define MICROPY_PY_SYS_MAXSIZE (0)
|
||||
#define MICROPY_PY_SYS_EXIT (0)
|
||||
#define MICROPY_PY_SYS_STDFILES (0)
|
||||
#define MICROPY_PY_SYS_STDIO_BUFFER (0)
|
||||
#define MICROPY_PY_SYS_PLATFORM "trezor"
|
||||
#define MICROPY_PY_UERRNO (0)
|
||||
#define MICROPY_PY_THREAD (0)
|
||||
#define MICROPY_PY_FSTRINGS (1)
|
||||
|
||||
// extended modules
|
||||
#define MICROPY_PY_UCTYPES (1)
|
||||
#define MICROPY_PY_UZLIB (0)
|
||||
#define MICROPY_PY_UJSON (0)
|
||||
#define MICROPY_PY_UOS (0)
|
||||
#define MICROPY_PY_URE (0)
|
||||
#define MICROPY_PY_URE_SUB (0)
|
||||
#define MICROPY_PY_UHEAPQ (0)
|
||||
#define MICROPY_PY_UHASHLIB (0)
|
||||
#define MICROPY_PY_UHASHLIB_MD5 (0)
|
||||
#define MICROPY_PY_UHASHLIB_SHA1 (0)
|
||||
#define MICROPY_PY_UCRYPTOLIB (0)
|
||||
#define MICROPY_PY_UBINASCII (1)
|
||||
#define MICROPY_PY_UBINASCII_CRC32 (0)
|
||||
#define MICROPY_PY_URANDOM (0)
|
||||
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
|
||||
#define MICROPY_PY_USELECT (0)
|
||||
#define MICROPY_PY_UTIME (1)
|
||||
#define MICROPY_PY_UTIMEQ (1)
|
||||
#define MICROPY_PY_UTIME_MP_HAL (1)
|
||||
#define MICROPY_PY_OS_DUPTERM (0)
|
||||
#define MICROPY_PY_LWIP_SOCK_RAW (0)
|
||||
#define MICROPY_PY_MACHINE (0)
|
||||
#define MICROPY_PY_UWEBSOCKET (0)
|
||||
#define MICROPY_PY_WEBREPL (0)
|
||||
#define MICROPY_PY_FRAMEBUF (0)
|
||||
#define MICROPY_PY_USOCKET (0)
|
||||
#define MICROPY_PY_NETWORK (0)
|
||||
|
||||
#define MICROPY_PY_TREZORCONFIG (1)
|
||||
#define MICROPY_PY_TREZORCRYPTO (1)
|
||||
#define MICROPY_PY_TREZORIO (1)
|
||||
#define MICROPY_PY_TREZORUI (1)
|
||||
#define MICROPY_PY_TREZORUTILS (1)
|
||||
#define MICROPY_PY_TREZORPROTO (1)
|
||||
#define MICROPY_PY_TREZORTRANSLATE (1)
|
||||
#define MICROPY_PY_TREZORUI2 (1)
|
||||
|
||||
#ifdef SYSTEM_VIEW
|
||||
#define MP_PLAT_PRINT_STRN(str, len) segger_print(str, len)
|
||||
// uncomment DEST_RTT and comment DEST_SYSTEMVIEW
|
||||
// if you want to print to RTT instead of SystemView
|
||||
// OpenOCD supports only the RTT output method
|
||||
// #define SYSTEMVIEW_DEST_RTT (1)
|
||||
#define SYSTEMVIEW_DEST_SYSTEMVIEW (1)
|
||||
#endif
|
||||
|
||||
#define MP_STATE_PORT MP_STATE_VM
|
||||
|
||||
// ============= this ends common config section ===================
|
||||
|
||||
|
||||
// type definitions for the specific machine
|
||||
|
||||
#define BYTES_PER_WORD (4)
|
||||
|
||||
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1))
|
||||
|
||||
#define MP_SSIZE_MAX (0x0fffffff)
|
||||
|
||||
typedef int mp_int_t; // must be pointer size
|
||||
typedef unsigned int mp_uint_t; // must be pointer size
|
||||
typedef long mp_off_t;
|
||||
|
||||
#include "irq.h"
|
||||
|
||||
#define MICROPY_BEGIN_ATOMIC_SECTION() irq_lock()
|
||||
#define MICROPY_END_ATOMIC_SECTION(state) irq_unlock(state)
|
||||
#define MICROPY_EVENT_POLL_HOOK \
|
||||
do { \
|
||||
extern void mp_handle_pending(bool); \
|
||||
mp_handle_pending(true); \
|
||||
__WFI(); \
|
||||
} while (0);
|
||||
|
||||
#define MICROPY_HW_BOARD_NAME "TREZORv2"
|
||||
#define MICROPY_HW_MCU_NAME "STM32F427xx"
|
||||
#define MICROPY_HW_HAS_SDCARD 1
|
||||
|
||||
// There is no classical C heap in bare-metal ports, only Python
|
||||
// garbage-collected heap. For completeness, emulate C heap via
|
||||
// GC heap. Note that MicroPython core never uses malloc() and friends,
|
||||
// so these defines are mostly to help extension module writers.
|
||||
#define malloc(n) m_malloc(n)
|
||||
#define free(p) m_free(p)
|
||||
#define realloc(p, n) m_realloc(p, n)
|
||||
|
||||
#define MICROPY_PORT_ROOT_POINTERS \
|
||||
mp_obj_t trezorconfig_ui_wait_callback; \
|
||||
|
||||
// We need to provide a declaration/definition of alloca()
|
||||
#include <alloca.h>
|
||||
|
||||
#endif // __INCLUDED_MPCONFIGPORT_H
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "py/mphal.h"
|
||||
|
||||
#include "systick.h"
|
||||
#include "usb.h"
|
||||
|
||||
static int vcp_iface_num = -1;
|
||||
|
||||
int mp_hal_stdin_rx_chr(void) {
|
||||
ensure(sectrue * (vcp_iface_num >= 0), "vcp stdio is not configured");
|
||||
uint8_t c = 0;
|
||||
int r = usb_vcp_read_blocking(vcp_iface_num, &c, 1, -1);
|
||||
(void)r;
|
||||
return c;
|
||||
}
|
||||
|
||||
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
||||
if (vcp_iface_num >= 0) {
|
||||
// The write timeout is set to 0, because otherwise when the VCP receive
|
||||
// buffer on the host gets full, the timeout will block device operation.
|
||||
int r = usb_vcp_write_blocking(vcp_iface_num, (const uint8_t *)str, len, 0);
|
||||
(void)r;
|
||||
}
|
||||
}
|
||||
|
||||
void mp_hal_set_vcp_iface(int iface_num) { vcp_iface_num = iface_num; }
|
||||
|
||||
// Dummy implementation required by ports/stm32/gccollect.c.
|
||||
// The normal version requires MICROPY_ENABLE_SCHEDULER which we don't use.
|
||||
void soft_timer_gc_mark_all(void) {}
|
||||
|
||||
void mp_hal_delay_ms(mp_uint_t Delay) { systick_delay_ms(Delay); }
|
||||
|
||||
void mp_hal_delay_us(mp_uint_t usec) { systick_delay_us(usec); }
|
||||
|
||||
mp_uint_t mp_hal_ticks_ms(void) { return systick_ms(); }
|
||||
|
||||
mp_uint_t mp_hal_ticks_us(void) { return systick_ms() * 1000; }
|
@ -1,24 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
|
||||
static inline mp_uint_t mp_hal_ticks_cpu(void) { return 0; }
|
||||
|
||||
void mp_hal_set_vcp_iface(int iface_num);
|
@ -1,166 +0,0 @@
|
||||
// clang-format off
|
||||
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2016 Damien P. George
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma GCC optimize("no-stack-protector") // applies to all functions in this file
|
||||
|
||||
#include "py/mpstate.h"
|
||||
#include "py/nlr.h"
|
||||
|
||||
#if (!defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP) && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
|
||||
|
||||
#undef nlr_push
|
||||
|
||||
// We only need the functions here if we are on arm/thumb, and we are not
|
||||
// using setjmp/longjmp.
|
||||
//
|
||||
// For reference, arm/thumb callee save regs are:
|
||||
// r4-r11, r13=sp
|
||||
|
||||
__attribute__((naked)) unsigned int nlr_push(nlr_buf_t *nlr) {
|
||||
|
||||
__asm volatile (
|
||||
"str r4, [r0, #12] \n" // store r4 into nlr_buf
|
||||
"str r5, [r0, #16] \n" // store r5 into nlr_buf
|
||||
"str r6, [r0, #20] \n" // store r6 into nlr_buf
|
||||
"str r7, [r0, #24] \n" // store r7 into nlr_buf
|
||||
|
||||
#if defined(__ARM_ARCH_6M__)
|
||||
"mov r1, r8 \n"
|
||||
"str r1, [r0, #28] \n" // store r8 into nlr_buf
|
||||
"mov r1, r9 \n"
|
||||
"str r1, [r0, #32] \n" // store r9 into nlr_buf
|
||||
"mov r1, r10 \n"
|
||||
"str r1, [r0, #36] \n" // store r10 into nlr_buf
|
||||
"mov r1, r11 \n"
|
||||
"str r1, [r0, #40] \n" // store r11 into nlr_buf
|
||||
"mov r1, r13 \n"
|
||||
"str r1, [r0, #44] \n" // store r13=sp into nlr_buf
|
||||
"mov r1, lr \n"
|
||||
"str r1, [r0, #8] \n" // store lr into nlr_buf
|
||||
#else
|
||||
"str r8, [r0, #28] \n" // store r8 into nlr_buf
|
||||
"str r9, [r0, #32] \n" // store r9 into nlr_buf
|
||||
"str r10, [r0, #36] \n" // store r10 into nlr_buf
|
||||
"str r11, [r0, #40] \n" // store r11 into nlr_buf
|
||||
"str r13, [r0, #44] \n" // store r13=sp into nlr_buf
|
||||
"str lr, [r0, #8] \n" // store lr into nlr_buf
|
||||
#endif
|
||||
|
||||
#if defined(__ARM_ARCH_6M__)
|
||||
"ldr r1, nlr_push_tail_var \n"
|
||||
"bx r1 \n" // do the rest in C
|
||||
".align 2 \n"
|
||||
"nlr_push_tail_var: .word nlr_push_tail \n"
|
||||
#else
|
||||
"b nlr_push_tail \n" // do the rest in C
|
||||
#endif
|
||||
);
|
||||
|
||||
return 0; // needed to silence compiler warning
|
||||
}
|
||||
|
||||
__attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr) {
|
||||
nlr_buf_t **top = &MP_STATE_THREAD(nlr_top);
|
||||
nlr->prev = *top;
|
||||
*top = nlr;
|
||||
return 0; // normal return
|
||||
}
|
||||
|
||||
void nlr_pop(void) {
|
||||
nlr_buf_t **top = &MP_STATE_THREAD(nlr_top);
|
||||
*top = (*top)->prev;
|
||||
}
|
||||
|
||||
NORETURN __attribute__((naked)) void nlr_jump(void *val) {
|
||||
nlr_buf_t **top_ptr = &MP_STATE_THREAD(nlr_top);
|
||||
nlr_buf_t *top = *top_ptr;
|
||||
if (top == NULL) {
|
||||
nlr_jump_fail(val);
|
||||
}
|
||||
|
||||
top->ret_val = val;
|
||||
*top_ptr = top->prev;
|
||||
|
||||
__asm volatile (
|
||||
"mov r0, %0 \n" // r0 points to nlr_buf
|
||||
"ldr r4, [r0, #12] \n" // load r4 from nlr_buf
|
||||
"ldr r5, [r0, #16] \n" // load r5 from nlr_buf
|
||||
"ldr r6, [r0, #20] \n" // load r6 from nlr_buf
|
||||
"ldr r7, [r0, #24] \n" // load r7 from nlr_buf
|
||||
|
||||
#if defined(__ARM_ARCH_6M__)
|
||||
"ldr r1, [r0, #28] \n" // load r8 from nlr_buf
|
||||
"mov r8, r1 \n"
|
||||
"ldr r1, [r0, #32] \n" // load r9 from nlr_buf
|
||||
"mov r9, r1 \n"
|
||||
"ldr r1, [r0, #36] \n" // load r10 from nlr_buf
|
||||
"mov r10, r1 \n"
|
||||
"ldr r1, [r0, #40] \n" // load r11 from nlr_buf
|
||||
"mov r11, r1 \n"
|
||||
"ldr r1, [r0, #44] \n" // load r13=sp from nlr_buf
|
||||
"mov r13, r1 \n"
|
||||
"ldr r1, [r0, #8] \n" // load lr from nlr_buf
|
||||
"mov lr, r1 \n"
|
||||
#else
|
||||
"ldr r8, [r0, #28] \n" // load r8 from nlr_buf
|
||||
"ldr r9, [r0, #32] \n" // load r9 from nlr_buf
|
||||
"ldr r10, [r0, #36] \n" // load r10 from nlr_buf
|
||||
"ldr r11, [r0, #40] \n" // load r11 from nlr_buf
|
||||
"ldr r13, [r0, #44] \n" // load r13=sp from nlr_buf
|
||||
"ldr lr, [r0, #8] \n" // load lr from nlr_buf
|
||||
#endif
|
||||
"movs r0, #1 \n" // return 1, non-local return
|
||||
"bx lr \n" // return
|
||||
: // output operands
|
||||
: "r"(top) // input operands
|
||||
: // clobbered registers
|
||||
);
|
||||
|
||||
for (;;); // needed to silence compiler warning
|
||||
}
|
||||
|
||||
#endif // (!defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP) && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
|
@ -1,11 +0,0 @@
|
||||
#define VERSION_MAJOR 2
|
||||
#define VERSION_MINOR 8
|
||||
#define VERSION_PATCH 2
|
||||
#define VERSION_BUILD 0
|
||||
|
||||
#define FIX_VERSION_MAJOR 2
|
||||
#define FIX_VERSION_MINOR 8
|
||||
#define FIX_VERSION_PATCH 0
|
||||
#define FIX_VERSION_BUILD 0
|
||||
|
||||
#define VERSION_MONOTONIC 1
|
@ -1,101 +0,0 @@
|
||||
// clang-format off
|
||||
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013, 2014 Damien P. George
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "irq.h"
|
||||
#include "systick.h"
|
||||
|
||||
extern __IO uint32_t uwTick;
|
||||
|
||||
// Core delay function that does an efficient sleep and may switch thread context.
|
||||
// If IRQs are enabled then we must have the GIL.
|
||||
void mp_hal_delay_ms(mp_uint_t Delay) {
|
||||
if (IS_IRQ_ENABLED(query_irq())) {
|
||||
// IRQs enabled, so can use systick counter to do the delay
|
||||
uint32_t start = uwTick;
|
||||
// Wraparound of tick is taken care of by 2's complement arithmetic.
|
||||
while (uwTick - start < Delay) {
|
||||
// This macro will execute the necessary idle behaviour. It may
|
||||
// raise an exception, switch threads or enter sleep mode (waiting for
|
||||
// (at least) the SysTick interrupt).
|
||||
MICROPY_EVENT_POLL_HOOK
|
||||
}
|
||||
} else {
|
||||
// IRQs disabled, so need to use a busy loop for the delay.
|
||||
// To prevent possible overflow of the counter we use a double loop.
|
||||
const uint32_t count_1ms = HAL_RCC_GetSysClockFreq() / 4000;
|
||||
for (int i = 0; i < Delay; i++) {
|
||||
for (uint32_t count = 0; ++count <= count_1ms;) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// delay for given number of microseconds
|
||||
void mp_hal_delay_us(mp_uint_t usec) {
|
||||
if (IS_IRQ_ENABLED(query_irq())) {
|
||||
// IRQs enabled, so can use systick counter to do the delay
|
||||
uint32_t start = mp_hal_ticks_us();
|
||||
while (mp_hal_ticks_us() - start < usec) {
|
||||
}
|
||||
} else {
|
||||
// IRQs disabled, so need to use a busy loop for the delay
|
||||
// sys freq is always a multiple of 2MHz, so division here won't lose precision
|
||||
const uint32_t ucount = HAL_RCC_GetSysClockFreq() / 2000000 * usec / 2;
|
||||
for (uint32_t count = 0; ++count <= ucount;) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp_uint_t mp_hal_ticks_ms(void) {
|
||||
return systick_ms();
|
||||
}
|
||||
|
||||
mp_uint_t mp_hal_ticks_us(void) {
|
||||
return systick_ms() * 1000;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
device stm32f427vi
|
||||
if swd
|
||||
speed 50000
|
||||
loadbin build/firmware/firmware.bin.p1.bin 0x08040000
|
||||
loadbin build/firmware/firmware.bin.p2.bin 0x08120000
|
||||
r
|
||||
g
|
||||
exit
|
@ -1,7 +0,0 @@
|
||||
device STM32F205RG
|
||||
if swd
|
||||
speed 50000
|
||||
loadbin build/firmware/firmware.bin 0x08010000
|
||||
r
|
||||
g
|
||||
exit
|
@ -36,204 +36,26 @@
|
||||
#include "ports/stm32/gccollect.h"
|
||||
#include "ports/stm32/pendsv.h"
|
||||
|
||||
#include "bl_check.h"
|
||||
#include "board_capabilities.h"
|
||||
#include "common.h"
|
||||
#include "compiler_traits.h"
|
||||
#include "display.h"
|
||||
#include "entropy.h"
|
||||
#include "flash.h"
|
||||
#include "image.h"
|
||||
#include "memzero.h"
|
||||
#include "model.h"
|
||||
#include "mpu.h"
|
||||
#include "random_delays.h"
|
||||
#include "error_handling.h"
|
||||
#include "rsod.h"
|
||||
#include "rust_ui.h"
|
||||
#include "secure_aes.h"
|
||||
#include "rust_ui_common.h"
|
||||
#include "secbool.h"
|
||||
#include "systask.h"
|
||||
#include "system.h"
|
||||
#include "systimer.h"
|
||||
|
||||
#include TREZOR_BOARD
|
||||
|
||||
#ifdef USE_RGB_LED
|
||||
#include "rgb_led.h"
|
||||
#endif
|
||||
#ifdef USE_CONSUMPTION_MASK
|
||||
#include "consumption_mask.h"
|
||||
#endif
|
||||
#ifdef USE_DMA2D
|
||||
#ifdef NEW_RENDERING
|
||||
#include "dma2d_bitblt.h"
|
||||
#else
|
||||
#include "dma2d.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_BUTTON
|
||||
#include "button.h"
|
||||
#endif
|
||||
#ifdef USE_TOUCH
|
||||
#include "touch.h"
|
||||
#endif
|
||||
#ifdef USE_SD_CARD
|
||||
#include "sdcard.h"
|
||||
#endif
|
||||
#ifdef USE_HASH_PROCESSOR
|
||||
#include "hash_processor.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_OPTIGA
|
||||
#include "optiga_commands.h"
|
||||
#include "optiga_transport.h"
|
||||
#endif
|
||||
#if defined USE_OPTIGA | defined STM32U5
|
||||
#include "secret.h"
|
||||
#endif
|
||||
|
||||
#include "unit_variant.h"
|
||||
|
||||
#ifdef SYSTEM_VIEW
|
||||
#include "systemview.h"
|
||||
#endif
|
||||
#include "platform.h"
|
||||
#include "rng.h"
|
||||
#ifdef USE_SECP256K1_ZKP
|
||||
#include "zkp_context.h"
|
||||
#endif
|
||||
#ifdef USE_HAPTIC
|
||||
#include "haptic.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_OPTIGA
|
||||
#if !PYOPT
|
||||
#include <inttypes.h>
|
||||
#if 1 // color log
|
||||
#define OPTIGA_LOG_FORMAT \
|
||||
"%" PRIu32 " \x1b[35moptiga\x1b[0m \x1b[32mDEBUG\x1b[0m %s: "
|
||||
#else
|
||||
#define OPTIGA_LOG_FORMAT "%" PRIu32 " optiga DEBUG %s: "
|
||||
#endif
|
||||
static void optiga_log_hex(const char *prefix, const uint8_t *data,
|
||||
size_t data_size) {
|
||||
printf(OPTIGA_LOG_FORMAT, hal_ticks_ms() * 1000, prefix);
|
||||
for (size_t i = 0; i < data_size; i++) {
|
||||
printf("%02x", data[i]);
|
||||
int main(uint32_t cmd, void *arg) {
|
||||
if (cmd == 1) {
|
||||
systask_postmortem_t *info = (systask_postmortem_t *)arg;
|
||||
rsod_gui(info);
|
||||
system_exit(0);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
system_init(&rsod_gui);
|
||||
|
||||
rdi_init();
|
||||
|
||||
#ifdef RDI
|
||||
rdi_start();
|
||||
#endif
|
||||
|
||||
// reinitialize HAL for Trezor One
|
||||
#if defined TREZOR_MODEL_1
|
||||
HAL_Init();
|
||||
#endif
|
||||
|
||||
#ifdef SYSTEM_VIEW
|
||||
enable_systemview();
|
||||
#endif
|
||||
|
||||
#ifdef USE_HASH_PROCESSOR
|
||||
hash_processor_init();
|
||||
#endif
|
||||
|
||||
#ifdef USE_DMA2D
|
||||
dma2d_init();
|
||||
#endif
|
||||
|
||||
display_init(DISPLAY_JUMP_BEHAVIOR);
|
||||
|
||||
#ifdef STM32U5
|
||||
check_oem_keys();
|
||||
#endif
|
||||
|
||||
screen_boot_stage_2();
|
||||
|
||||
#if !defined TREZOR_MODEL_1
|
||||
parse_boardloader_capabilities();
|
||||
|
||||
unit_variant_init();
|
||||
|
||||
#ifdef STM32U5
|
||||
secure_aes_init();
|
||||
#endif
|
||||
|
||||
#ifdef USE_OPTIGA
|
||||
uint8_t secret[SECRET_OPTIGA_KEY_LEN] = {0};
|
||||
secbool secret_ok = secret_optiga_get(secret);
|
||||
#endif
|
||||
|
||||
entropy_init();
|
||||
|
||||
#if PRODUCTION || BOOTLOADER_QA
|
||||
check_and_replace_bootloader();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// Init peripherals
|
||||
|
||||
#if defined TREZOR_MODEL_T
|
||||
set_core_clock(CLOCK_180_MHZ);
|
||||
#endif
|
||||
|
||||
#ifdef USE_BUTTON
|
||||
button_init();
|
||||
#endif
|
||||
|
||||
#ifdef USE_RGB_LED
|
||||
rgb_led_init();
|
||||
#endif
|
||||
|
||||
#ifdef USE_CONSUMPTION_MASK
|
||||
consumption_mask_init();
|
||||
#endif
|
||||
|
||||
#ifdef USE_TOUCH
|
||||
touch_init();
|
||||
#endif
|
||||
|
||||
#ifdef USE_SD_CARD
|
||||
sdcard_init();
|
||||
#endif
|
||||
|
||||
#ifdef USE_HAPTIC
|
||||
haptic_init();
|
||||
#endif
|
||||
|
||||
#ifdef USE_OPTIGA
|
||||
|
||||
#if !PYOPT
|
||||
// command log is relatively quiet so we enable it in debug builds
|
||||
optiga_command_set_log_hex(optiga_log_hex);
|
||||
// transport log can be spammy, uncomment if you want it:
|
||||
// optiga_transport_set_log_hex(optiga_log_hex);
|
||||
#endif
|
||||
|
||||
optiga_init();
|
||||
if (sectrue == secret_ok) {
|
||||
// If the shielded connection cannot be established, reset Optiga and
|
||||
// continue without it. In this case, OID_KEY_FIDO and OID_KEY_DEV cannot be
|
||||
// used, which means device and FIDO attestation will not work.
|
||||
if (optiga_sec_chan_handshake(secret, sizeof(secret)) != OPTIGA_SUCCESS) {
|
||||
optiga_soft_reset();
|
||||
}
|
||||
}
|
||||
memzero(secret, sizeof(secret));
|
||||
ensure(sectrue * (optiga_open_application() == OPTIGA_SUCCESS),
|
||||
"Cannot initialize optiga.");
|
||||
#endif
|
||||
|
||||
#ifdef USE_SECP256K1_ZKP
|
||||
ensure(sectrue * (zkp_context_init() == 0), NULL);
|
||||
#endif
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "py/mphal.h"
|
||||
|
||||
#include "systick.h"
|
||||
#include "usb.h"
|
||||
|
||||
static int vcp_iface_num = -1;
|
||||
@ -45,3 +47,11 @@ void mp_hal_set_vcp_iface(int iface_num) { vcp_iface_num = iface_num; }
|
||||
// Dummy implementation required by ports/stm32/gccollect.c.
|
||||
// The normal version requires MICROPY_ENABLE_SCHEDULER which we don't use.
|
||||
void soft_timer_gc_mark_all(void) {}
|
||||
|
||||
void mp_hal_delay_ms(mp_uint_t Delay) { systick_delay_ms(Delay); }
|
||||
|
||||
void mp_hal_delay_us(mp_uint_t usec) { systick_delay_us(usec); }
|
||||
|
||||
mp_uint_t mp_hal_ticks_ms(void) { return systick_ms(); }
|
||||
|
||||
mp_uint_t mp_hal_ticks_us(void) { return systick_ms() * 1000; }
|
||||
|
@ -1,69 +0,0 @@
|
||||
.syntax unified
|
||||
|
||||
.text
|
||||
|
||||
.global reset_handler
|
||||
.type reset_handler, STT_FUNC
|
||||
reset_handler:
|
||||
|
||||
// The following loading of VTOR address only works if T1 bootloader was built with PRODUCTION=0
|
||||
// or the firmware was properly signed. All other variants end up in hard fault due to MPU
|
||||
// (cf mpu_config_firmware in legacy bootloader)
|
||||
|
||||
#if defined TREZOR_MODEL_1
|
||||
cpsid if
|
||||
ldr r0, =0xE000ED08 // r0 = VTOR address
|
||||
ldr r1, =0x08010400 // r1 = FLASH_APP_START
|
||||
str r1, [r0] // assign
|
||||
|
||||
ldr r0, =_estack // r0 = stack pointer
|
||||
msr msp, r0 // set stack pointer
|
||||
dsb
|
||||
isb
|
||||
#endif
|
||||
|
||||
// setup environment for subsequent stage of code
|
||||
ldr r0, =ccmram_start // r0 - point to beginning of CCMRAM
|
||||
ldr r1, =ccmram_end // r1 - point to byte after the end of CCMRAM
|
||||
ldr r2, =0 // r2 - the word-sized value to be written
|
||||
bl memset_reg
|
||||
|
||||
ldr r0, =boot_args_start // r0 - point to beginning of BOOT_ARGS
|
||||
ldr r1, =boot_args_end // r1 - point to byte after the end of BOOT_ARGS
|
||||
ldr r2, =0 // r2 - the word-sized value to be written
|
||||
bl memset_reg
|
||||
|
||||
ldr r0, =sram_start // r0 - point to beginning of SRAM
|
||||
ldr r1, =sram_end // r1 - point to byte after the end of SRAM
|
||||
ldr r2, =0 // r2 - the word-sized value to be written
|
||||
bl memset_reg
|
||||
|
||||
// copy data in from flash
|
||||
ldr r0, =data_vma // dst addr
|
||||
ldr r1, =data_lma // src addr
|
||||
ldr r2, =data_size // size in bytes
|
||||
bl memcpy
|
||||
|
||||
// setup the stack protector (see build script "-fstack-protector-all") with an unpredictable value
|
||||
bl rng_get
|
||||
ldr r1, = __stack_chk_guard
|
||||
str r0, [r1]
|
||||
|
||||
// re-enable exceptions
|
||||
// according to "ARM Cortex-M Programming Guide to Memory Barrier Instructions" Application Note 321, section 4.7:
|
||||
// "If it is not necessary to ensure that a pended interrupt is recognized immediately before
|
||||
// subsequent operations, it is not necessary to insert a memory barrier instruction."
|
||||
#if defined STM32F405xx
|
||||
cpsie if
|
||||
#elif defined STM32F427xx || defined STM32F429xx
|
||||
cpsie f
|
||||
#else
|
||||
#error "Unknown MCU"
|
||||
#endif
|
||||
|
||||
// enter the application code
|
||||
bl main
|
||||
|
||||
b shutdown_privileged
|
||||
|
||||
.end
|
@ -1,72 +0,0 @@
|
||||
.syntax unified
|
||||
|
||||
.text
|
||||
|
||||
.global reset_handler
|
||||
.type reset_handler, STT_FUNC
|
||||
reset_handler:
|
||||
// set the stack protection
|
||||
ldr r0, =_sstack
|
||||
add r0, r0, #128 // safety margin for the exception frame
|
||||
msr MSPLIM, r0
|
||||
|
||||
// setup environment for subsequent stage of code
|
||||
ldr r2, =0 // r2 - the word-sized value to be written
|
||||
|
||||
ldr r0, =sram1_start // r0 - point to beginning of SRAM
|
||||
ldr r1, =sram1_end // r1 - point to byte after the end of SRAM
|
||||
bl memset_reg
|
||||
|
||||
ldr r0, =sram2_start // r0 - point to beginning of SRAM
|
||||
ldr r1, =sram2_end // r1 - point to byte after the end of SRAM
|
||||
bl memset_reg
|
||||
|
||||
ldr r0, =sram4_start // r0 - point to beginning of SRAM
|
||||
ldr r1, =sram4_end // r1 - point to byte after the end of SRAM
|
||||
bl memset_reg
|
||||
|
||||
ldr r0, =sram6_start // r0 - point to beginning of SRAM
|
||||
ldr r1, =sram6_end // r1 - point to byte after the end of SRAM
|
||||
bl memset_reg
|
||||
|
||||
ldr r0, =boot_args_start // r0 - point to beginning of boot args
|
||||
ldr r1, =boot_args_end // r1 - point to byte after the end of boot args
|
||||
bl memset_reg
|
||||
|
||||
ldr r0, =sram3_start // r0 - point to beginning of SRAM
|
||||
ldr r1, =__fb_start // r1 - point to beginning of framebuffer
|
||||
bl memset_reg
|
||||
|
||||
ldr r0, =__fb_end // r0 - point to end of framebuffer
|
||||
ldr r1, =sram5_end // r1 - point to byte after the end of SRAM
|
||||
bl memset_reg
|
||||
|
||||
// copy data in from flash
|
||||
ldr r0, =data_vma // dst addr
|
||||
ldr r1, =data_lma // src addr
|
||||
ldr r2, =data_size // size in bytes
|
||||
bl memcpy
|
||||
|
||||
// copy confidential data in from flash
|
||||
ldr r0, =confidential_vma // dst addr
|
||||
ldr r1, =confidential_lma // src addr
|
||||
ldr r2, =confidential_size // size in bytes
|
||||
bl memcpy
|
||||
|
||||
// setup the stack protector (see build script "-fstack-protector-all") with an unpredictable value
|
||||
bl rng_get
|
||||
ldr r1, = __stack_chk_guard
|
||||
str r0, [r1]
|
||||
|
||||
// re-enable exceptions
|
||||
// according to "ARM Cortex-M Programming Guide to Memory Barrier Instructions" Application Note 321, section 4.7:
|
||||
// "If it is not necessary to ensure that a pended interrupt is recognized immediately before
|
||||
// subsequent operations, it is not necessary to insert a memory barrier instruction."
|
||||
cpsie f
|
||||
|
||||
// enter the application code
|
||||
bl main
|
||||
|
||||
b shutdown_privileged
|
||||
|
||||
.end
|
@ -1,99 +0,0 @@
|
||||
INCLUDE "./embed/trezorhal/stm32f4/linker/memory.ld";
|
||||
|
||||
ENTRY(reset_handler)
|
||||
|
||||
MEMORY {
|
||||
FLASH (rx) : ORIGIN = FIRMWARE_START, LENGTH = FIRMWARE_P1_IMAGE_MAXSIZE
|
||||
FLASH2 (r) : ORIGIN = FIRMWARE_P2_START, LENGTH = FIRMWARE_P2_IMAGE_MAXSIZE
|
||||
CCMRAM (wal) : ORIGIN = MCU_CCMRAM + KERNEL_STACK_SIZE, LENGTH = MCU_CCMRAM_SIZE - KERNEL_CCMRAM_SIZE - KERNEL_FRAMEBUFFER_SIZE - KERNEL_STACK_SIZE
|
||||
SRAM (wal) : ORIGIN = MCU_SRAM, LENGTH = MCU_SRAM_SIZE - KERNEL_SRAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ORIGIN(SRAM) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ORIGIN(SRAM);
|
||||
_estack = main_stack_base;
|
||||
_stack_size = SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
data_vma = ADDR(.data);
|
||||
data_size = SIZEOF(.data);
|
||||
|
||||
bss_start = ADDR(.bss);
|
||||
bss_end = ADDR(.bss) + SIZEOF(.bss);
|
||||
|
||||
_codelen = LENGTH(FLASH) - SIZEOF(.vendorheader) - SIZEOF(.header) + SIZEOF(.flash2);
|
||||
_flash_start = ORIGIN(FLASH);
|
||||
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
|
||||
_heap_start = ADDR(.heap);
|
||||
_heap_end = ADDR(.heap) + SIZEOF(.heap);
|
||||
|
||||
SECTIONS {
|
||||
.vendorheader : ALIGN(4) {
|
||||
KEEP(*(.vendorheader))
|
||||
} >FLASH AT>FLASH
|
||||
|
||||
.header : ALIGN(4) {
|
||||
KEEP(*(.header));
|
||||
} >FLASH AT>FLASH
|
||||
|
||||
.flash2 : ALIGN(CODE_ALIGNMENT) {
|
||||
build/coreapp/frozen_mpy.o(.rodata*);
|
||||
build/coreapp/vendor/secp256k1-zkp/src/secp256k1.o(.rodata*);
|
||||
build/coreapp/vendor/secp256k1-zkp/src/precomputed_ecmult.o(.rodata*);
|
||||
build/coreapp/vendor/secp256k1-zkp/src/precomputed_ecmult_gen.o(.rodata*);
|
||||
build/coreapp/vendor/trezor-crypto/aes/aestab.o(.rodata*);
|
||||
. = ALIGN(4);
|
||||
*/libtrezor_lib.a:(.text*);
|
||||
. = ALIGN(4);
|
||||
*/libtrezor_lib.a:(.rodata*);
|
||||
. = ALIGN(512);
|
||||
} >FLASH2 AT>FLASH2
|
||||
|
||||
.flash : ALIGN(512) {
|
||||
KEEP(*(.kernel));
|
||||
. = ALIGN(512);
|
||||
KEEP(*(.vector_table));
|
||||
. = ALIGN(4);
|
||||
*(.text*);
|
||||
. = ALIGN(4);
|
||||
*(.rodata*);
|
||||
. = ALIGN(4);
|
||||
. = ALIGN(512);
|
||||
} >FLASH AT>FLASH
|
||||
|
||||
.stack : ALIGN(8) {
|
||||
. = 16K; /* Exactly 16K allocated for stack. Overflow causes MemManage fault (when using MPU). */
|
||||
} >SRAM
|
||||
|
||||
.data : ALIGN(4) {
|
||||
*(.data*);
|
||||
. = ALIGN(512);
|
||||
} >SRAM AT>FLASH
|
||||
|
||||
.bss : ALIGN(4) {
|
||||
*(.bss*);
|
||||
. = ALIGN(4);
|
||||
} >SRAM
|
||||
|
||||
.buf : ALIGN(4) {
|
||||
*(.buf*);
|
||||
. = ALIGN(4);
|
||||
} >SRAM
|
||||
|
||||
.heap : ALIGN(4) {
|
||||
. = 37K; /* this acts as a build time assertion that at least this much memory is available for heap use */
|
||||
. = ABSOLUTE(ORIGIN(SRAM) + LENGTH(SRAM)); /* this explicitly sets the end of the heap */
|
||||
} >SRAM
|
||||
|
||||
.data_ccm : ALIGN(4) {
|
||||
*(.no_dma_buffers*);
|
||||
. = ALIGN(4);
|
||||
} >CCMRAM
|
||||
|
||||
|
||||
/DISCARD/ : {
|
||||
*(.ARM.exidx*);
|
||||
}
|
||||
|
||||
}
|
@ -5,36 +5,23 @@ ENTRY(reset_handler)
|
||||
MEMORY {
|
||||
FLASH (rx) : ORIGIN = FIRMWARE_START, LENGTH = FIRMWARE_P1_IMAGE_MAXSIZE
|
||||
FLASH2 (r) : ORIGIN = FIRMWARE_P2_START, LENGTH = FIRMWARE_P2_IMAGE_MAXSIZE
|
||||
CCMRAM (wal) : ORIGIN = MCU_CCMRAM, LENGTH = MCU_CCMRAM_SIZE - BOOTARGS_SIZE
|
||||
BOOT_ARGS (wal) : ORIGIN = MCU_CCMRAM + MCU_CCMRAM_SIZE - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
|
||||
SRAM (wal) : ORIGIN = MCU_SRAM, LENGTH = MCU_SRAM_SIZE
|
||||
CCMRAM (wal) : ORIGIN = MCU_CCMRAM + KERNEL_STACK_SIZE, LENGTH = MCU_CCMRAM_SIZE - KERNEL_CCMRAM_SIZE - KERNEL_FRAMEBUFFER_SIZE - KERNEL_STACK_SIZE
|
||||
SRAM (wal) : ORIGIN = MCU_SRAM, LENGTH = MCU_SRAM_SIZE - KERNEL_SRAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ORIGIN(SRAM) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ORIGIN(SRAM);
|
||||
_estack = main_stack_base;
|
||||
_stack_size = SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
data_vma = ADDR(.data);
|
||||
data_size = SIZEOF(.data);
|
||||
|
||||
bss_start = ADDR(.bss);
|
||||
bss_end = ADDR(.bss) + SIZEOF(.bss);
|
||||
|
||||
/* used by the startup code to wipe memory */
|
||||
ccmram_start = ORIGIN(CCMRAM);
|
||||
ccmram_end = ORIGIN(CCMRAM) + LENGTH(CCMRAM);
|
||||
|
||||
/* reserve 256 bytes for bootloader arguments */
|
||||
boot_args_start = ORIGIN(BOOT_ARGS);
|
||||
boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
|
||||
|
||||
/* used by the startup code to wipe memory */
|
||||
sram_start = ORIGIN(SRAM);
|
||||
sram_end = ORIGIN(SRAM) + LENGTH(SRAM);
|
||||
_ram_start = sram_start;
|
||||
_ram_end = sram_end;
|
||||
|
||||
_codelen = LENGTH(FLASH) - SIZEOF(.vendorheader) - SIZEOF(.header) + SIZEOF(.flash2);
|
||||
_flash_start = ORIGIN(FLASH);
|
||||
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
|
||||
@ -50,7 +37,7 @@ SECTIONS {
|
||||
KEEP(*(.header));
|
||||
} >FLASH AT>FLASH
|
||||
|
||||
.flash2 : ALIGN(512) {
|
||||
.flash2 : ALIGN(CODE_ALIGNMENT) {
|
||||
build/firmware/frozen_mpy.o(.rodata*);
|
||||
build/firmware/vendor/secp256k1-zkp/src/secp256k1.o(.rodata*);
|
||||
build/firmware/vendor/secp256k1-zkp/src/precomputed_ecmult.o(.rodata*);
|
||||
@ -63,15 +50,15 @@ SECTIONS {
|
||||
. = ALIGN(512);
|
||||
} >FLASH2 AT>FLASH2
|
||||
|
||||
.flash : ALIGN(CODE_ALIGNMENT) {
|
||||
.flash : ALIGN(512) {
|
||||
KEEP(*(.kernel));
|
||||
. = ALIGN(512);
|
||||
KEEP(*(.vector_table));
|
||||
. = ALIGN(4);
|
||||
*(.text*);
|
||||
. = ALIGN(4);
|
||||
*(.rodata*);
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.bootloader));
|
||||
*(.bootloader*);
|
||||
. = ALIGN(512);
|
||||
} >FLASH AT>FLASH
|
||||
|
||||
@ -96,7 +83,7 @@ SECTIONS {
|
||||
|
||||
.heap : ALIGN(4) {
|
||||
. = 37K; /* this acts as a build time assertion that at least this much memory is available for heap use */
|
||||
. = ABSOLUTE(sram_end); /* this explicitly sets the end of the heap */
|
||||
. = ABSOLUTE(ORIGIN(SRAM) + LENGTH(SRAM)); /* this explicitly sets the end of the heap */
|
||||
} >SRAM
|
||||
|
||||
.data_ccm : ALIGN(4) {
|
||||
@ -104,8 +91,9 @@ SECTIONS {
|
||||
. = ALIGN(4);
|
||||
} >CCMRAM
|
||||
|
||||
.boot_args : ALIGN(8) {
|
||||
*(.boot_args*);
|
||||
. = ALIGN(8);
|
||||
} >BOOT_ARGS
|
||||
|
||||
/DISCARD/ : {
|
||||
*(.ARM.exidx*);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,92 +0,0 @@
|
||||
INCLUDE "./embed/trezorhal/stm32u5/linker/u58/memory.ld";
|
||||
|
||||
ENTRY(reset_handler)
|
||||
|
||||
MEMORY {
|
||||
FLASH (rx) : ORIGIN = KERNEL_START, LENGTH = FIRMWARE_IMAGE_MAXSIZE
|
||||
SRAM1 (wal) : ORIGIN = MCU_SRAM1, LENGTH = MCU_SRAM1_SIZE - KERNEL_SRAM1_SIZE
|
||||
SRAM2 (wal) : ORIGIN = MCU_SRAM2 + KERNEL_SRAM2_SIZE, LENGTH = MCU_SRAM2_SIZE - KERNEL_SRAM2_SIZE
|
||||
SRAM3 (wal) : ORIGIN = MCU_SRAM3 + KERNEL_SRAM3_SIZE, LENGTH = MCU_SRAM3_SIZE - KERNEL_SRAM3_SIZE
|
||||
SRAM5 (wal) : ORIGIN = MCU_SRAM5, LENGTH = 0K /* SRAM5 is not available */
|
||||
SRAM6 (wal) : ORIGIN = MCU_SRAM6, LENGTH = 0K /* SRAM6 is not available */
|
||||
SRAM4 (wal) : ORIGIN = MCU_SRAM4, LENGTH = 0K /* not allocated to coreapp */
|
||||
}
|
||||
|
||||
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ORIGIN(SRAM2);
|
||||
_estack = main_stack_base;
|
||||
_stack_size = SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
data_vma = ADDR(.data);
|
||||
data_size = SIZEOF(.data);
|
||||
bss_start = ADDR(.bss);
|
||||
bss_end = ADDR(.bss) + SIZEOF(.bss);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
confidential_lma = LOADADDR(.confidential);
|
||||
confidential_vma = ADDR(.confidential);
|
||||
confidential_size = SIZEOF(.confidential);
|
||||
|
||||
_codelen = SIZEOF(.flash) + SIZEOF(.data) + SIZEOF(.confidential);
|
||||
_flash_start = ORIGIN(FLASH);
|
||||
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
|
||||
_heap_start = ADDR(.heap);
|
||||
_heap_end = ADDR(.heap) + SIZEOF(.heap);
|
||||
|
||||
SECTIONS {
|
||||
.vendorheader : ALIGN(4) {
|
||||
KEEP(*(.vendorheader))
|
||||
} >FLASH AT>FLASH
|
||||
|
||||
.header : ALIGN(4) {
|
||||
KEEP(*(.header));
|
||||
. = ALIGN(CODE_ALIGNMENT);
|
||||
} >FLASH AT>FLASH
|
||||
|
||||
.flash : ALIGN(CODE_ALIGNMENT) {
|
||||
KEEP(*(.kernel));
|
||||
. = ALIGN(512);
|
||||
KEEP(*(.vector_table));
|
||||
. = ALIGN(4);
|
||||
*(.text*);
|
||||
. = ALIGN(4);
|
||||
*(.rodata*);
|
||||
. = ALIGN(512);
|
||||
} >FLASH AT>FLASH
|
||||
|
||||
.data : ALIGN(4) {
|
||||
*(.data*);
|
||||
. = ALIGN(512);
|
||||
} >SRAM1 AT>FLASH
|
||||
|
||||
/DISCARD/ : {
|
||||
*(.ARM.exidx*);
|
||||
}
|
||||
|
||||
.bss : ALIGN(4) {
|
||||
*(.no_dma_buffers*);
|
||||
*(.bss*);
|
||||
. = ALIGN(4);
|
||||
} >SRAM1
|
||||
|
||||
.stack : ALIGN(8) {
|
||||
. = 32K; /* Overflow causes UsageFault */
|
||||
} >SRAM2
|
||||
|
||||
.confidential : ALIGN(512) {
|
||||
*(.confidential*);
|
||||
. = ALIGN(512);
|
||||
} >SRAM2 AT>FLASH
|
||||
|
||||
.buf : ALIGN(4) {
|
||||
*(.buf*);
|
||||
. = ALIGN(4);
|
||||
} >SRAM3
|
||||
|
||||
.heap : ALIGN(4) {
|
||||
. = 37K; /* this acts as a build time assertion that at least this much memory is available for heap use */
|
||||
. = ABSOLUTE(ORIGIN(SRAM3) + LENGTH(SRAM3)); /* this explicitly sets the end of the heap */
|
||||
} >SRAM3
|
||||
}
|
@ -3,19 +3,19 @@ INCLUDE "./embed/trezorhal/stm32u5/linker/u58/memory.ld";
|
||||
ENTRY(reset_handler)
|
||||
|
||||
MEMORY {
|
||||
FLASH (rx) : ORIGIN = FIRMWARE_START, LENGTH = FIRMWARE_IMAGE_MAXSIZE
|
||||
SRAM1 (wal) : ORIGIN = MCU_SRAM1, LENGTH = MCU_SRAM1_SIZE - BOOTARGS_SIZE
|
||||
BOOT_ARGS (wal) : ORIGIN = MCU_SRAM2 - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
|
||||
SRAM2 (wal) : ORIGIN = MCU_SRAM2, LENGTH = MCU_SRAM2_SIZE
|
||||
SRAM3 (wal) : ORIGIN = MCU_SRAM3, LENGTH = MCU_SRAM3_SIZE
|
||||
SRAM5 (wal) : ORIGIN = MCU_SRAM5, LENGTH = MCU_SRAM5_SIZE /* SRAM5 is not available */
|
||||
SRAM6 (wal) : ORIGIN = MCU_SRAM6, LENGTH = MCU_SRAM6_SIZE /* SRAM6 is not available */
|
||||
SRAM4 (wal) : ORIGIN = MCU_SRAM4, LENGTH = MCU_SRAM4_SIZE
|
||||
FLASH (rx) : ORIGIN = KERNEL_START, LENGTH = FIRMWARE_IMAGE_MAXSIZE
|
||||
SRAM1 (wal) : ORIGIN = MCU_SRAM1, LENGTH = MCU_SRAM1_SIZE - KERNEL_SRAM1_SIZE
|
||||
SRAM2 (wal) : ORIGIN = MCU_SRAM2 + KERNEL_SRAM2_SIZE, LENGTH = MCU_SRAM2_SIZE - KERNEL_SRAM2_SIZE
|
||||
SRAM3 (wal) : ORIGIN = MCU_SRAM3 + KERNEL_SRAM3_SIZE, LENGTH = MCU_SRAM3_SIZE - KERNEL_SRAM3_SIZE
|
||||
SRAM5 (wal) : ORIGIN = MCU_SRAM5, LENGTH = 0K /* SRAM5 is not available */
|
||||
SRAM6 (wal) : ORIGIN = MCU_SRAM6, LENGTH = 0K /* SRAM6 is not available */
|
||||
SRAM4 (wal) : ORIGIN = MCU_SRAM4, LENGTH = 0K /* not allocated to coreapp */
|
||||
}
|
||||
|
||||
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ORIGIN(SRAM2);
|
||||
_estack = main_stack_base;
|
||||
_stack_size = SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
@ -29,29 +29,6 @@ confidential_lma = LOADADDR(.confidential);
|
||||
confidential_vma = ADDR(.confidential);
|
||||
confidential_size = SIZEOF(.confidential);
|
||||
|
||||
/* used by the startup/jump code to wipe memory */
|
||||
_handoff_clear_ram_0_start = ORIGIN(SRAM1);
|
||||
_handoff_clear_ram_0_end = ORIGIN(BOOT_ARGS);
|
||||
_handoff_clear_ram_1_start = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
|
||||
_handoff_clear_ram_1_end = ORIGIN(SRAM6)+ LENGTH(SRAM6);
|
||||
_handoff_clear_ram_2_start = ORIGIN(SRAM4);
|
||||
_handoff_clear_ram_2_end = ORIGIN(SRAM4) + LENGTH(SRAM4);
|
||||
|
||||
/* used by the shutdown code to wipe memory */
|
||||
_shutdown_clear_ram_0_start = ORIGIN(SRAM1);
|
||||
_shutdown_clear_ram_0_end = ORIGIN(SRAM6)+ LENGTH(SRAM6);
|
||||
_shutdown_clear_ram_1_start = ORIGIN(SRAM4);
|
||||
_shutdown_clear_ram_1_end = ORIGIN(SRAM4) + LENGTH(SRAM4);
|
||||
_shutdown_clear_ram_2_start = 0;
|
||||
_shutdown_clear_ram_2_end = 0;
|
||||
_shutdown_clear_ram_3_start = 0;
|
||||
_shutdown_clear_ram_3_end = 0;
|
||||
|
||||
|
||||
/* reserve 256 bytes for bootloader arguments */
|
||||
boot_args_start = ORIGIN(BOOT_ARGS);
|
||||
boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
|
||||
|
||||
_codelen = SIZEOF(.flash) + SIZEOF(.data) + SIZEOF(.confidential);
|
||||
_flash_start = ORIGIN(FLASH);
|
||||
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
|
||||
@ -65,17 +42,17 @@ SECTIONS {
|
||||
|
||||
.header : ALIGN(4) {
|
||||
KEEP(*(.header));
|
||||
. = ALIGN(CODE_ALIGNMENT);
|
||||
} >FLASH AT>FLASH
|
||||
|
||||
.flash : ALIGN(CODE_ALIGNMENT) {
|
||||
KEEP(*(.kernel));
|
||||
. = ALIGN(512);
|
||||
KEEP(*(.vector_table));
|
||||
. = ALIGN(4);
|
||||
*(.text*);
|
||||
. = ALIGN(4);
|
||||
*(.rodata*);
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.bootloader));
|
||||
*(.bootloader*);
|
||||
. = ALIGN(512);
|
||||
} >FLASH AT>FLASH
|
||||
|
||||
@ -103,14 +80,6 @@ SECTIONS {
|
||||
. = ALIGN(512);
|
||||
} >SRAM2 AT>FLASH
|
||||
|
||||
.fb : ALIGN(4) {
|
||||
__fb_start = .;
|
||||
*(.fb1*);
|
||||
*(.fb2*);
|
||||
__fb_end = .;
|
||||
. = ALIGN(4);
|
||||
} >SRAM3
|
||||
|
||||
.buf : ALIGN(4) {
|
||||
*(.buf*);
|
||||
. = ALIGN(4);
|
||||
@ -118,13 +87,6 @@ SECTIONS {
|
||||
|
||||
.heap : ALIGN(4) {
|
||||
. = 37K; /* this acts as a build time assertion that at least this much memory is available for heap use */
|
||||
. = ABSOLUTE(sram3_end); /* this explicitly sets the end of the heap */
|
||||
. = ABSOLUTE(ORIGIN(SRAM3) + LENGTH(SRAM3)); /* this explicitly sets the end of the heap */
|
||||
} >SRAM3
|
||||
|
||||
.boot_args : ALIGN(8) {
|
||||
*(.boot_command*);
|
||||
. = ALIGN(8);
|
||||
*(.boot_args*);
|
||||
. = ALIGN(8);
|
||||
} >BOOT_ARGS
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user