From c357692a43b2a707652cc304ae114cada92b6706 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Thu, 3 Aug 2017 20:46:40 +0200 Subject: [PATCH] scons: add SConscript.unix --- SConscript => SConscript.firmware | 52 +-- SConscript.unix | 326 ++++++++++++++++++ SConstruct | 3 +- embed/unix/mpconfigport.h | 21 +- site_scons/site_tools/micropython/__init__.py | 2 +- 5 files changed, 366 insertions(+), 38 deletions(-) rename SConscript => SConscript.firmware (96%) create mode 100644 SConscript.unix diff --git a/SConscript b/SConscript.firmware similarity index 96% rename from SConscript rename to SConscript.firmware index 0d2844c71..c3792b4b9 100644 --- a/SConscript +++ b/SConscript.firmware @@ -455,7 +455,11 @@ SOURCE_PY = [ 'src/trezor/workflow.py', ] -env = Environment( +env = Environment() + +env.Tool('micropython') + +env.Replace( SED='sed', AS='arm-none-eabi-as', AR='arm-none-eabi-ar', @@ -463,7 +467,9 @@ env = Environment( LINK='arm-none-eabi-ld', SIZE='arm-none-eabi-size', STRIP='arm-none-eabi-strip', - OBJCOPY='arm-none-eabi-objcopy', + OBJCOPY='arm-none-eabi-objcopy', ) + +env.Replace( CCFLAGS='-Os ' '-g3 ' '-nostdlib ' @@ -492,7 +498,9 @@ env = Environment( 'STM32F405xx', 'TREZOR_STM32', 'MCU_SERIES_F4', - ] + CPPDEFINES_MOD, + ] + CPPDEFINES_MOD, ) + +env.Replace( PYTHON='python', PYTHONPATH='vendor/micropython/py', MAKEQSTRDEFS='$PYTHON vendor/micropython/py/makeqstrdefs.py', @@ -500,9 +508,7 @@ env = Environment( MAKEVERSIONHDR='$PYTHON vendor/micropython/py/makeversionhdr.py', MPY_CROSS='vendor/micropython/mpy-cross/mpy-cross', MPY_TOOL='$PYTHON vendor/micropython/tools/mpy-tool.py', - MAKE_FROZEN='$PYTHON vendor/micropython/tools/make-frozen.py') - -env.Tool('micropython') + MAKE_FROZEN='$PYTHON vendor/micropython/tools/make-frozen.py', ) # # Micropython version @@ -520,16 +526,14 @@ hdr_version = env.Command( qstr_micropython = 'vendor/micropython/py/qstrdefs.h' qstr_collected = env.CollectQstr( - target='genhdr/qstrdefs.collected.h', - source=SOURCE_QSTR) + target='genhdr/qstrdefs.collected.h', source=SOURCE_QSTR) qstr_preprocessed = env.PreprocessQstr( target='genhdr/qstrdefs.preprocessed.h', source=[qstr_micropython, qstr_collected]) qstr_generated = env.GenerateQstrDefs( - target='genhdr/qstrdefs.generated.h', - source=qstr_preprocessed) + target='genhdr/qstrdefs.generated.h', source=qstr_preprocessed) env.Ignore(qstr_collected, qstr_generated) @@ -540,9 +544,7 @@ env.Ignore(qstr_collected, qstr_generated) source_mpy = env.FrozenModule(source=SOURCE_PY) source_mpyc = env.FrozenCFile( - target='frozen_mpy.c', - source=source_mpy, - qstr_header=qstr_preprocessed) + target='frozen_mpy.c', source=source_mpy, qstr_header=qstr_preprocessed) env.Depends(source_mpyc, qstr_generated) @@ -550,25 +552,25 @@ env.Depends(source_mpyc, qstr_generated) # Program objects # -obj_firmware = [] -obj_firmware += env.Object(source=SOURCE_MOD) -obj_firmware += env.Object(source=SOURCE_FIRMWARE) -obj_firmware += env.Object(source=SOURCE_MICROPYTHON) -obj_firmware += env.Object(source=SOURCE_STMHAL) -obj_firmware += env.Object(source=SOURCE_TREZORHAL) -obj_firmware += env.Object(source=source_mpyc) +obj_program = [] +obj_program += env.Object(source=SOURCE_MOD) +obj_program += env.Object(source=SOURCE_FIRMWARE) +obj_program += env.Object(source=SOURCE_MICROPYTHON) +obj_program += env.Object(source=SOURCE_STMHAL) +obj_program += env.Object(source=SOURCE_TREZORHAL) +obj_program += env.Object(source=source_mpyc) -env.Depends(obj_firmware, qstr_generated) +env.Depends(obj_program, qstr_generated) -env.Command( +program_elf = env.Command( target='firmware.elf', - source=obj_firmware, + source=obj_program, action= '$LINK -o $TARGET $LINKFLAGS $SOURCES `$CC $CFLAGS $CCFLAGS $_CCCOMCOM -print-libgcc-file-name`', ) -env.Command( +program_bin = env.Command( target='firmware.bin', - source='firmware.elf', + source=program_elf, action='$OBJCOPY -O binary -j .header -j .flash -j .data $SOURCE $TARGET', ) diff --git a/SConscript.unix b/SConscript.unix new file mode 100644 index 000000000..aa3a4e903 --- /dev/null +++ b/SConscript.unix @@ -0,0 +1,326 @@ +# pylint: disable=E0602 + +CCFLAGS_MOD = '' +CPPPATH_MOD = [] +CPPDEFINES_MOD = [] +SOURCE_MOD = [] +LIBS_MOD = [] + +# modtrezorconfig +SOURCE_MOD += [ + 'embed/extmod/modtrezorconfig/modtrezorconfig.c', + 'embed/extmod/modtrezorconfig/norcow.c', +] + +# modtrezorcrypto +CCFLAGS_MOD += '-Wno-sequence-point ' +CPPPATH_MOD += [ + 'embed/extmod/modtrezorcrypto/trezor-crypto', + 'embed/extmod/modtrezorcrypto/trezor-crypto/aes', + 'embed/extmod/modtrezorcrypto/trezor-crypto/ed25519-donna', +] +CPPDEFINES_MOD += [ + 'AES_128', + 'AES_192', + 'USE_KECCAK', +] +SOURCE_MOD += [ + 'embed/extmod/modtrezorcrypto/modtrezorcrypto.c', + 'embed/extmod/modtrezorcrypto/rand.c', + 'embed/extmod/modtrezorcrypto/ssss.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/address.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/aes/aescrypt.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/aes/aeskey.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/aes/aes_modes.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/aes/aestab.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/base58.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/bignum.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/bip32.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/bip39.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/blake2b.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/blake2s.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/curves.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/ecdsa.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/ed25519-donna/ed25519.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/hmac.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/nist256p1.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/pbkdf2.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/ripemd160.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/secp256k1.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/sha2.c', + 'embed/extmod/modtrezorcrypto/trezor-crypto/sha3.c', +] + +# modtrezorio +SOURCE_MOD += [ + 'embed/extmod/modtrezorio/modtrezorio.c', +] + +# modtrezormsg +SOURCE_MOD += [ + 'embed/unix/touch.c', + 'embed/extmod/modtrezormsg/modtrezormsg.c', +] + +# modtrezorui +CPPDEFINES_MOD += [('QR_MAX_VERSION', '0')] +SOURCE_MOD += [ + 'embed/extmod/modtrezorui/display.c', + 'embed/extmod/modtrezorui/inflate.c', + 'embed/extmod/modtrezorui/font_bitmap.c', + 'embed/extmod/modtrezorui/font_roboto_bold_20.c', + 'embed/extmod/modtrezorui/font_roboto_regular_20.c', + 'embed/extmod/modtrezorui/font_robotomono_regular_20.c', + 'embed/extmod/modtrezorui/modtrezorui.c', + 'embed/extmod/modtrezorui/trezor-qrenc/qr_encode.c', +] +LIBS_MOD += ['SDL2', 'SDL2_image'] + +# modtrezorutils +SOURCE_MOD += [ + 'embed/extmod/modtrezorutils/modtrezorutils.c', +] + +# modutime +# SOURCE_MOD += [ +# 'embed/firmware/modutime.c', +# ] + +SOURCE_MICROPYTHON = [ + 'vendor/micropython/extmod/modubinascii.c', + 'vendor/micropython/extmod/moductypes.c', + 'vendor/micropython/extmod/moduheapq.c', + 'vendor/micropython/extmod/modujson.c', + 'vendor/micropython/extmod/modure.c', + 'vendor/micropython/extmod/modutimeq.c', + 'vendor/micropython/extmod/moduzlib.c', + 'vendor/micropython/extmod/utime_mphal.c', + 'vendor/micropython/lib/mp-readline/readline.c', + 'vendor/micropython/lib/timeutils/timeutils.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/gc.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/modcmath.c', + 'vendor/micropython/py/modcollections.c', + 'vendor/micropython/py/modgc.c', + 'vendor/micropython/py/modio.c', + 'vendor/micropython/py/modmath.c', + 'vendor/micropython/py/modmicropython.c', + 'vendor/micropython/py/modstruct.c', + 'vendor/micropython/py/modsys.c', + 'vendor/micropython/py/modthread.c', + 'vendor/micropython/py/moduerrno.c', + 'vendor/micropython/py/mpprint.c', + 'vendor/micropython/py/mpstate.c', + 'vendor/micropython/py/mpz.c', + 'vendor/micropython/py/nativeglue.c', + 'vendor/micropython/py/nlrsetjmp.c', + 'vendor/micropython/py/nlrthumb.c', + 'vendor/micropython/py/nlrx64.c', + 'vendor/micropython/py/nlrx86.c', + 'vendor/micropython/py/nlrxtensa.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_longlong.c', + 'vendor/micropython/py/objint_mpz.c', + 'vendor/micropython/py/objint.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/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_utils.c', + 'vendor/micropython/py/runtime.c', + 'vendor/micropython/py/scope.c', + 'vendor/micropython/py/scheduler.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/vm.c', + 'vendor/micropython/py/vstr.c', + 'vendor/micropython/py/warning.c', +] + +SOURCE_UNIX = [ + 'vendor/micropython/unix/main.c', + 'vendor/micropython/unix/gccollect.c', + 'vendor/micropython/unix/unix_mphal.c', + 'vendor/micropython/unix/mpthreadport.c', + 'vendor/micropython/unix/input.c', + 'vendor/micropython/unix/file.c', + 'vendor/micropython/unix/modos.c', + 'vendor/micropython/unix/modtime.c', + 'vendor/micropython/unix/moduselect.c', + 'vendor/micropython/unix/alloc.c', + 'embed/unix/common.c', +] + +SOURCE_EMIT_NATIVE = ['vendor/micropython/py/emitnative.c'] + +SOURCE_QSTR = SOURCE_MOD + SOURCE_MICROPYTHON + SOURCE_UNIX + SOURCE_EMIT_NATIVE + +env = Environment() + +env.Tool('micropython') + +env.Replace( + SED='sed', + AS='as', + AR='ar', + CC='gcc', + LINK='ld', + SIZE='size', + STRIP='strip', + OBJCOPY='objcopy', ) + +env.Replace( + CCFLAGS='-Os ' + '-g3 ' + '-std=gnu99 -Wall -Werror -Wuninitialized ' + '-fdata-sections -ffunction-sections ' + CCFLAGS_MOD, + CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB -DN_ARM -DN_XTENSA', + LIBS=LIBS_MOD, + CPPPATH=[ + '.', + 'embed/unix', + 'embed/extmod/modtrezorui', + 'vendor/micropython', + 'vendor/micropython/unix', + 'vendor/micropython/lib/mp-readline', + ] + CPPPATH_MOD, + CPPDEFINES=[ + 'MICROPY_USE_READLINE', + 'TREZOR_UNIX', + 'UNIX', + ('MP_CONFIGFILE', '\\"embed/unix/mpconfigport.h\\"'), + ] + CPPDEFINES_MOD, ) + +env.Replace( + PYTHON='python', + PYTHONPATH='vendor/micropython/py', + MAKEQSTRDEFS='$PYTHON vendor/micropython/py/makeqstrdefs.py', + MAKEQSTRDATA='$PYTHON vendor/micropython/py/makeqstrdata.py', + MAKEVERSIONHDR='$PYTHON vendor/micropython/py/makeversionhdr.py', + MPY_CROSS='vendor/micropython/mpy-cross/mpy-cross', + MPY_TOOL='$PYTHON vendor/micropython/tools/mpy-tool.py', + MAKE_FROZEN='$PYTHON vendor/micropython/tools/make-frozen.py', ) + +# +# Micropython version +# + +hdr_version = env.Command( + target='genhdr/mpversion.h', + source='', + action='$MAKEVERSIONHDR $TARGET', ) + +# +# Qstrings +# + +qstr_micropython = 'vendor/micropython/py/qstrdefs.h' + +qstr_collected = env.CollectQstr( + target='genhdr/qstrdefs.collected.h', source=SOURCE_QSTR) + +qstr_preprocessed = env.PreprocessQstr( + target='genhdr/qstrdefs.preprocessed.h', + source=[qstr_micropython, qstr_collected]) + +qstr_generated = env.GenerateQstrDefs( + target='genhdr/qstrdefs.generated.h', source=qstr_preprocessed) + +env.Ignore(qstr_collected, qstr_generated) + +# +# Program objects +# + +obj_program = [] +obj_program += env.Object(source=SOURCE_MOD) +obj_program += env.Object(source=SOURCE_MICROPYTHON) +obj_program += env.Object(source=SOURCE_UNIX) + +obj_program += env.Object( + source=SOURCE_EMIT_NATIVE, + target='vendor/micropython/py/emitnx64.o', + CPPDEFINES=[env['CPPDEFINES'], 'N_X64'], ) + +obj_program += env.Object( + source=SOURCE_EMIT_NATIVE, + target='vendor/micropython/py/emitnx86.o', + CPPDEFINES=[env['CPPDEFINES'], 'N_X86'], ) + +obj_program += env.Object( + source=SOURCE_EMIT_NATIVE, + target='vendor/micropython/py/emitnthumb.o', + CPPDEFINES=[env['CPPDEFINES'], 'N_THUMB'], ) + +env.Depends(obj_program, qstr_generated) + +program = env.Command( + target='micropython', + source=obj_program, + action='$CC -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS $LINKFLAGS', ) diff --git a/SConstruct b/SConstruct index f6535843f..34202f49c 100644 --- a/SConstruct +++ b/SConstruct @@ -1,3 +1,4 @@ # pylint: disable=E0602 -SConscript('SConscript', variant_dir='build/firmware', src='.', duplicate=False) +SConscript('SConscript.firmware', variant_dir='build/firmware', duplicate=False) +SConscript('SConscript.unix', variant_dir='build/unix', duplicate=False) diff --git a/embed/unix/mpconfigport.h b/embed/unix/mpconfigport.h index e682645b8..f0c4dd134 100644 --- a/embed/unix/mpconfigport.h +++ b/embed/unix/mpconfigport.h @@ -102,9 +102,9 @@ #endif #define MICROPY_PY_CMATH (1) #define MICROPY_PY_IO_FILEIO (1) -#define MICROPY_PY_IO_RESOURCE_STREAM (1) +#define MICROPY_PY_IO_RESOURCE_STREAM (0) #define MICROPY_PY_GC_COLLECT_RETVAL (1) -#define MICROPY_MODULE_FROZEN_STR (1) +#define MICROPY_MODULE_FROZEN_STR (0) #define MICROPY_STACKLESS (0) #define MICROPY_STACKLESS_STRICT (0) @@ -119,19 +119,19 @@ #define MICROPY_PY_URE (1) #define MICROPY_PY_UHEAPQ (1) #define MICROPY_PY_UTIMEQ (1) -#define MICROPY_PY_UHASHLIB (1) +#define MICROPY_PY_UHASHLIB (0) #if MICROPY_PY_USSL && MICROPY_SSL_AXTLS -#define MICROPY_PY_UHASHLIB_SHA1 (1) +#define MICROPY_PY_UHASHLIB_SHA1 (0) #endif #define MICROPY_PY_UBINASCII (1) #define MICROPY_PY_UBINASCII_CRC32 (1) -#define MICROPY_PY_URANDOM (1) +#define MICROPY_PY_URANDOM (0) #ifndef MICROPY_PY_USELECT_POSIX -#define MICROPY_PY_USELECT_POSIX (1) +#define MICROPY_PY_USELECT_POSIX (0) #endif -#define MICROPY_PY_WEBSOCKET (1) -#define MICROPY_PY_MACHINE (1) -#define MICROPY_PY_MACHINE_PULSE (1) +#define MICROPY_PY_WEBSOCKET (0) +#define MICROPY_PY_MACHINE (0) +#define MICROPY_PY_MACHINE_PULSE (0) #define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr #define MICROPY_MACHINE_MEM_GET_WRITE_ADDR mod_machine_mem_get_addr @@ -146,6 +146,7 @@ #define MICROPY_FATFS_RPATH (2) #define MICROPY_FATFS_MAX_SS (4096) #define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */ +#define MICROPY_VFS (0) #define MICROPY_VFS_FAT (0) // Define to MICROPY_ERROR_REPORTING_DETAILED to get function, etc. @@ -169,7 +170,6 @@ #define MICROPY_KBD_EXCEPTION (1) #define MICROPY_ASYNC_KBD_INTR (1) -extern const struct _mp_obj_module_t mp_module_machine; extern const struct _mp_obj_module_t mp_module_os; extern const struct _mp_obj_module_t mp_module_uos_vfs; extern const struct _mp_obj_module_t mp_module_uselect; @@ -258,7 +258,6 @@ extern const struct _mp_obj_module_t mp_module_trezorutils; MICROPY_PY_JNI_DEF \ MICROPY_PY_UTIME_DEF \ MICROPY_PY_SOCKET_DEF \ - { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \ { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_os) }, \ MICROPY_PY_UOS_VFS_DEF \ MICROPY_PY_USELECT_DEF \ diff --git a/site_scons/site_tools/micropython/__init__.py b/site_scons/site_tools/micropython/__init__.py index 35c332f76..1c64500d4 100644 --- a/site_scons/site_tools/micropython/__init__.py +++ b/site_scons/site_tools/micropython/__init__.py @@ -20,7 +20,7 @@ def generate(env): action='$MAKEQSTRDATA $SOURCE > $TARGET', ) env['BUILDERS']['FrozenModule'] = SCons.Builder.Builder( - action='$MPY_CROSS -o $TARGET -s $SOURCE $SOURCE', + action='$MPY_CROSS -o $TARGET $SOURCE', suffix='.mpy', single_source=True, )