diff --git a/core/Makefile b/core/Makefile index 08b172287..325659da6 100644 --- a/core/Makefile +++ b/core/Makefile @@ -105,11 +105,14 @@ build_firmware: res build_cross ## build firmware with frozen modules build_unix: res ## build unix port $(SCONS) CFLAGS="$(CFLAGS)" $(UNIX_BUILD_DIR)/micropython $(UNIX_PORT_OPTS) +build_unix_frozen: res build_cross ## build unix port with frozen modules + $(SCONS) CFLAGS="$(CFLAGS)" $(UNIX_BUILD_DIR)/micropython $(UNIX_PORT_OPTS) TREZOR_EMULATOR_FROZEN=1 + build_unix_noui: res ## build unix port without UI support $(SCONS) CFLAGS="$(CFLAGS)" $(UNIX_BUILD_DIR)/micropython $(UNIX_PORT_OPTS) TREZOR_EMULATOR_NOUI=1 build_unix_noui_frozen: res build_cross ## build unix port without UI support with frozen modules - $(SCONS) CFLAGS="$(CFLAGS)" $(UNIX_BUILD_DIR)/micropython $(UNIX_PORT_OPTS) TREZOR_EMULATOR_NOUI=1 TREZOR_FROZEN=1 + $(SCONS) CFLAGS="$(CFLAGS)" $(UNIX_BUILD_DIR)/micropython $(UNIX_PORT_OPTS) TREZOR_EMULATOR_NOUI=1 TREZOR_EMULATOR_FROZEN=1 build_unix_raspi: res ## build unix port for Raspberry Pi $(SCONS) CFLAGS="$(CFLAGS)" $(UNIX_BUILD_DIR)/micropython $(UNIX_PORT_OPTS) TREZOR_EMULATOR_RASPI=1 diff --git a/core/SConscript.unix b/core/SConscript.unix index af305ba53..1bb0409c9 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -8,6 +8,8 @@ CPPDEFINES_MOD = [] SOURCE_MOD = [] SOURCE_MOD_SECP256K1_ZKP = [] +PYOPT = '1' + # modtrezorconfig CPPPATH_MOD += [ 'embed/extmod/modtrezorconfig', @@ -134,6 +136,8 @@ if ARGUMENTS.get('TREZOR_EMULATOR_NOUI', 0): CPPDEFINES_MOD += ['TREZOR_EMULATOR_NOUI'] if ARGUMENTS.get('TREZOR_EMULATOR_RASPI', 0): CPPDEFINES_MOD += ['TREZOR_EMULATOR_RASPI'] +if ARGUMENTS.get('TREZOR_EMULATOR_FROZEN', 0): + CPPDEFINES_MOD += ['TREZOR_EMULATOR_FROZEN'] # modtrezorutils SOURCE_MOD += [ @@ -286,7 +290,7 @@ SOURCE_UNIX = [ SOURCE_QSTR = SOURCE_MOD + SOURCE_MICROPYTHON + SOURCE_UNIX -env = Environment(ENV=os.environ, CFLAGS=ARGUMENTS.get('CFLAGS', '')) +env = Environment(ENV=os.environ, CFLAGS='%s -DPYOPT=%s' % (ARGUMENTS.get('CFLAGS', ''), PYOPT)) env.Tool('micropython') @@ -313,7 +317,7 @@ env.Replace( env.Replace( COPT=env.get('OPTIMIZE', env.get('ENV').get('OPTIMIZE', '-Os')), - CCFLAGS='$COPT -DMPZ_DIG_SIZE=16 ' + CCFLAGS='$COPT ' '-g3 ' '-std=gnu99 -Wall -Werror -Wuninitialized ' '-fdata-sections -ffunction-sections ' + CCFLAGS_MOD, @@ -343,7 +347,8 @@ env.Replace( MAKEQSTRDATA='$PYTHON vendor/micropython/py/makeqstrdata.py', MAKEVERSIONHDR='$PYTHON vendor/micropython/py/makeversionhdr.py', MPY_TOOL='$PYTHON vendor/micropython/tools/mpy-tool.py', - MPY_CROSS='vendor/micropython/mpy-cross/mpy-cross', ) + MPY_CROSS='vendor/micropython/mpy-cross/mpy-cross -O' + PYOPT +) # # Micropython version @@ -376,7 +381,7 @@ env.Ignore(qstr_collected, qstr_generated) # Frozen modules # -if ARGUMENTS.get('TREZOR_FROZEN', 0): +if ARGUMENTS.get('TREZOR_EMULATOR_FROZEN', 0): if env.get('TREZOR_MODEL') == '1': SOURCE_PY_DIR = 'src1/' else: @@ -426,7 +431,7 @@ obj_program.extend(env.Object(source=SOURCE_MOD)) obj_program.extend(env.Object(source=SOURCE_MOD_SECP256K1_ZKP, CCFLAGS='$CCFLAGS -Wno-unused-function')) obj_program.extend(env.Object(source=SOURCE_MICROPYTHON)) obj_program.extend(env.Object(source=SOURCE_UNIX)) -if ARGUMENTS.get('TREZOR_FROZEN', 0): +if ARGUMENTS.get('TREZOR_EMULATOR_FROZEN', 0): obj_program.extend(env.Object(source=source_mpyc)) env.Depends(obj_program, qstr_generated) diff --git a/core/embed/unix/mpconfigport.h b/core/embed/unix/mpconfigport.h index 3ea011c1d..94179a6f0 100644 --- a/core/embed/unix/mpconfigport.h +++ b/core/embed/unix/mpconfigport.h @@ -28,6 +28,13 @@ // options to control how MicroPython is built +#ifdef TREZOR_EMULATOR_FROZEN +#define MICROPY_QSTR_EXTRA_POOL (mp_qstr_frozen_const_pool) +#define MICROPY_MODULE_FROZEN_MPY (1) +#endif + +#define MPZ_DIG_SIZE (16) + #define MICROPY_ALLOC_PATH_MAX (PATH_MAX) #define MICROPY_PERSISTENT_CODE_LOAD (1) #if !defined(MICROPY_EMIT_X64) && defined(__x86_64__)