unix: fix unix build

pull/25/head
Pavol Rusnak 7 years ago
parent 462f6bab7f
commit 433bc8138b
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -14,7 +14,7 @@ script:
- make build_trezorhal
- make build_unix TREZORUI_NOUI=1
- make build_unix MICROPY_PY_TREZORUI_NOUI=1
- make test

@ -27,10 +27,10 @@ build_trezorhal_debug: vendor res build_cross ## build trezorhal port with froze
$(MAKE) -f Makefile.firmware $(TREZORHAL_PORT_OPTS) DEBUG=1
build_unix: vendor ## build unix port
$(MAKE) -C vendor/micropython/unix $(UNIX_PORT_OPTS)
$(MAKE) -f ../../../micropython/unix/Makefile -C vendor/micropython/unix $(UNIX_PORT_OPTS)
build_unix_debug: vendor ## build unix port with debug symbols
$(MAKE) -C vendor/micropython/unix $(UNIX_PORT_OPTS) DEBUG=1
$(MAKE) -f ../../../micropython/unix/Makefile -C vendor/micropython/unix $(UNIX_PORT_OPTS) DEBUG=1
build_cross: vendor ## build mpy-cross port
$(MAKE) -C vendor/micropython/mpy-cross $(CROSS_PORT_OPTS)
@ -47,7 +47,7 @@ clean_trezorhal: ## clean trezorhal build
$(MAKE) -f Makefile.firmware clean $(TREZORHAL_PORT_OPTS)
clean_unix: ## clean unix build
$(MAKE) -C vendor/micropython/unix clean $(UNIX_PORT_OPTS)
$(MAKE) -f ../../../micropython/unix/Makefile -C vendor/micropython/unix clean $(UNIX_PORT_OPTS)
clean_cross: ## clean mpy-cross build
$(MAKE) -C vendor/micropython/mpy-cross clean $(CROSS_PORT_OPTS)

@ -1,78 +0,0 @@
--- a/py/py.mk
+++ b/py/py.mk
@@ -101,6 +101,75 @@ CFLAGS_MOD += -DMICROPY_PY_BTREE=1
$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter
endif
+ifeq ($(MICROPY_PY_TREZORCONFIG),1)
+SRC_MOD += extmod/modtrezorconfig/modtrezorconfig.c
+SRC_MOD += extmod/modtrezorconfig/norcow.c
+endif
+
+ifeq ($(MICROPY_PY_TREZORCRYPTO),1)
+CFLAGS_MOD += -I../extmod/modtrezorcrypto/trezor-crypto
+CFLAGS_MOD += -I../extmod/modtrezorcrypto/trezor-crypto/curve25519-donna
+CFLAGS_MOD += -I../extmod/modtrezorcrypto/trezor-crypto/ed25519-donna
+CFLAGS_MOD += -DED25519_CUSTOMRANDOM=1
+CFLAGS_MOD += -DED25519_CUSTOMHASH=1
+CFLAGS_MOD += -DED25519_NO_INLINE_ASM
+CFLAGS_MOD += -DED25519_FORCE_32BIT=1
+CFLAGS_MOD += -DAES_128
+CFLAGS_MOD += -DAES_192
+CFLAGS_MOD += -DUSE_KECCAK=1
+CFLAGS_MOD += -Wno-sequence-point
+SRC_MOD += \
+ extmod/modtrezorcrypto/modtrezorcrypto.c \
+ extmod/modtrezorcrypto/rand.c \
+ extmod/modtrezorcrypto/ssss.c \
+ extmod/modtrezorcrypto/trezor-crypto/address.c \
+ extmod/modtrezorcrypto/trezor-crypto/aescrypt.c \
+ extmod/modtrezorcrypto/trezor-crypto/aeskey.c \
+ extmod/modtrezorcrypto/trezor-crypto/aes_modes.c \
+ extmod/modtrezorcrypto/trezor-crypto/aestab.c \
+ extmod/modtrezorcrypto/trezor-crypto/base58.c \
+ extmod/modtrezorcrypto/trezor-crypto/bignum.c \
+ extmod/modtrezorcrypto/trezor-crypto/bip32.c \
+ extmod/modtrezorcrypto/trezor-crypto/bip39.c \
+ extmod/modtrezorcrypto/trezor-crypto/blake2s.c \
+ extmod/modtrezorcrypto/trezor-crypto/curve25519-donna/curve25519.c \
+ extmod/modtrezorcrypto/trezor-crypto/curves.c \
+ extmod/modtrezorcrypto/trezor-crypto/ecdsa.c \
+ extmod/modtrezorcrypto/trezor-crypto/ed25519-donna/ed25519.c \
+ extmod/modtrezorcrypto/trezor-crypto/hmac.c \
+ extmod/modtrezorcrypto/trezor-crypto/nist256p1.c \
+ extmod/modtrezorcrypto/trezor-crypto/pbkdf2.c \
+ extmod/modtrezorcrypto/trezor-crypto/ripemd160.c \
+ extmod/modtrezorcrypto/trezor-crypto/secp256k1.c \
+ extmod/modtrezorcrypto/trezor-crypto/sha2.c \
+ extmod/modtrezorcrypto/trezor-crypto/sha3.c
+endif
+
+ifeq ($(MICROPY_PY_TREZORDEBUG),1)
+SRC_MOD += extmod/modtrezordebug/modtrezordebug.c
+endif
+
+ifeq ($(MICROPY_PY_TREZORMSG),1)
+SRC_MOD += extmod/modtrezormsg/modtrezormsg.c
+endif
+
+ifeq ($(MICROPY_PY_TREZORUI),1)
+CFLAGS_MOD += -DQR_MAX_VERSION=0
+SRC_MOD += \
+ extmod/modtrezorui/display.c \
+ extmod/modtrezorui/inflate.c \
+ extmod/modtrezorui/font_bitmap.c \
+ extmod/modtrezorui/font_roboto_bold_20.c \
+ extmod/modtrezorui/font_roboto_regular_20.c \
+ extmod/modtrezorui/font_robotomono_regular_20.c \
+ extmod/modtrezorui/modtrezorui.c \
+ extmod/modtrezorui/trezor-qrenc/qr_encode.c
+endif
+
+ifeq ($(MICROPY_PY_TREZORUTILS),1)
+SRC_MOD += extmod/modtrezorutils/modtrezorutils.c
+endif
+
# py object files
PY_O_BASENAME = \
mpstate.o \

@ -1,43 +0,0 @@
--- a/stmhal/mpconfigport.h
+++ b/stmhal/mpconfigport.h
@@ -130,6 +130,14 @@
#define MICROPY_PY_MACHINE_SPI_MIN_DELAY (0)
#define MICROPY_PY_MACHINE_SPI_MAX_BAUDRATE (HAL_RCC_GetSysClockFreq() / 48)
#define MICROPY_PY_FRAMEBUF (1)
+
+#define MICROPY_PY_TREZORCONFIG (1)
+#define MICROPY_PY_TREZORCRYPTO (1)
+#define MICROPY_PY_TREZORDEBUG (1)
+#define MICROPY_PY_TREZORMSG (1)
+#define MICROPY_PY_TREZORUI (1)
+#define MICROPY_PY_TREZORUTILS (1)
+
#ifndef MICROPY_PY_USOCKET
#define MICROPY_PY_USOCKET (1)
#endif
@@ -172,6 +180,12 @@ extern const struct _mp_obj_module_t mp_module_uos;
extern const struct _mp_obj_module_t mp_module_utime;
extern const struct _mp_obj_module_t mp_module_usocket;
extern const struct _mp_obj_module_t mp_module_network;
+extern const struct _mp_obj_module_t mp_module_TrezorConfig;
+extern const struct _mp_obj_module_t mp_module_TrezorCrypto;
+extern const struct _mp_obj_module_t mp_module_TrezorDebug;
+extern const struct _mp_obj_module_t mp_module_TrezorMsg;
+extern const struct _mp_obj_module_t mp_module_TrezorUi;
+extern const struct _mp_obj_module_t mp_module_TrezorUtils;
#if MICROPY_PY_USOCKET
#define SOCKET_BUILTIN_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_usocket },
@@ -213,6 +227,12 @@ extern const struct _mp_obj_module_t mp_module_network;
{ MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&mp_module_ustruct }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&machine_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_errno), (mp_obj_t)&mp_module_uerrno }, \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_TrezorConfig), (mp_obj_t)&mp_module_TrezorConfig }, \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_TrezorCrypto), (mp_obj_t)&mp_module_TrezorCrypto }, \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_TrezorDebug), (mp_obj_t)&mp_module_TrezorDebug }, \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_TrezorMsg), (mp_obj_t)&mp_module_TrezorMsg }, \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_TrezorUi), (mp_obj_t)&mp_module_TrezorUi }, \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_TrezorUtils), (mp_obj_t)&mp_module_TrezorUtils }, \
// extra constants
#define MICROPY_PORT_CONSTANTS \

@ -1,18 +0,0 @@
--- a/stmhal/mpconfigport.mk
+++ b/stmhal/mpconfigport.mk
@@ -5,3 +5,15 @@ MICROPY_PY_WIZNET5K ?= 0
# cc3k module for wifi support
MICROPY_PY_CC3K ?= 0
+
+MICROPY_PY_TREZORCONFIG = 1
+
+MICROPY_PY_TREZORCRYPTO = 1
+
+MICROPY_PY_TREZORDEBUG = 1
+
+MICROPY_PY_TREZORMSG = 1
+
+MICROPY_PY_TREZORUI = 1
+
+MICROPY_PY_TREZORUTILS = 1

@ -1,16 +0,0 @@
--- a/unix/Makefile
+++ b/unix/Makefile
@@ -103,6 +103,13 @@ ifeq ($(MICROPY_PY_THREAD),1)
CFLAGS_MOD += -DMICROPY_PY_THREAD=1 -DMICROPY_PY_THREAD_GIL=0
LDFLAGS_MOD += -lpthread
endif
+ifeq ($(MICROPY_PY_TREZORUI),1)
+ifeq ($(TREZORUI_NOUI),1)
+CFLAGS_MOD += -DTREZORUI_NOUI=1
+else
+LDFLAGS_MOD += -lSDL2 -lSDL2_image
+endif
+endif
ifeq ($(MICROPY_PY_FFI),1)

@ -1,80 +0,0 @@
--- a/unix/mpconfigport.h
+++ b/unix/mpconfigport.h
@@ -131,6 +131,12 @@
#define MICROPY_PY_MACHINE_PULSE (1)
#define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr
#define MICROPY_MACHINE_MEM_GET_WRITE_ADDR mod_machine_mem_get_addr
+#define MICROPY_PY_TREZORCONFIG (1)
+#define MICROPY_PY_TREZORCRYPTO (1)
+#define MICROPY_PY_TREZORDEBUG (1)
+#define MICROPY_PY_TREZORMSG (1)
+#define MICROPY_PY_TREZORUI (1)
+#define MICROPY_PY_TREZORUTILS (1)
#define MICROPY_FATFS_ENABLE_LFN (1)
#define MICROPY_FATFS_RPATH (2)
@@ -167,6 +173,12 @@ extern const struct _mp_obj_module_t mp_module_termios;
extern const struct _mp_obj_module_t mp_module_socket;
extern const struct _mp_obj_module_t mp_module_ffi;
extern const struct _mp_obj_module_t mp_module_jni;
+extern const struct _mp_obj_module_t mp_module_TrezorConfig;
+extern const struct _mp_obj_module_t mp_module_TrezorCrypto;
+extern const struct _mp_obj_module_t mp_module_TrezorDebug;
+extern const struct _mp_obj_module_t mp_module_TrezorMsg;
+extern const struct _mp_obj_module_t mp_module_TrezorUi;
+extern const struct _mp_obj_module_t mp_module_TrezorUtils;
#if MICROPY_PY_UOS_VFS
#define MICROPY_PY_UOS_VFS_DEF { MP_ROM_QSTR(MP_QSTR_uos_vfs), MP_ROM_PTR(&mp_module_uos_vfs) },
@@ -203,6 +215,38 @@ extern const struct _mp_obj_module_t mp_module_jni;
#else
#define MICROPY_PY_USELECT_DEF
#endif
+#if MICROPY_PY_TREZORCONFIG
+#define MICROPY_PY_TREZORCONFIG_DEF { MP_ROM_QSTR(MP_QSTR_TrezorConfig), MP_ROM_PTR(&mp_module_TrezorConfig) },
+#else
+#define MICROPY_PY_TREZORCONFIG_DEF
+#endif
+#if MICROPY_PY_TREZORCRYPTO
+#define MICROPY_PY_TREZORCRYPTO_DEF { MP_ROM_QSTR(MP_QSTR_TrezorCrypto), MP_ROM_PTR(&mp_module_TrezorCrypto) },
+#else
+#define MICROPY_PY_TREZORCRYPTO_DEF
+#endif
+#if MICROPY_PY_TREZORDEBUG
+#define MICROPY_PY_TREZORDEBUG_DEF { MP_ROM_QSTR(MP_QSTR_TrezorDebug), MP_ROM_PTR(&mp_module_TrezorDebug) },
+#else
+#define MICROPY_PY_TREZORDEBUGI_DEF
+#endif
+#if MICROPY_PY_TREZORMSG
+#define MICROPY_PY_TREZORMSG_DEF { MP_ROM_QSTR(MP_QSTR_TrezorMsg), MP_ROM_PTR(&mp_module_TrezorMsg) },
+#else
+#define MICROPY_PY_TREZORMSG_DEF
+#endif
+#if MICROPY_PY_TREZORUI
+#define MICROPY_PY_TREZORUI_DEF { MP_ROM_QSTR(MP_QSTR_TrezorUi), MP_ROM_PTR(&mp_module_TrezorUi) },
+#else
+#define MICROPY_PY_TREZORUI_DEF
+#endif
+#if MICROPY_PY_TREZORUTILS
+#define MICROPY_PY_TREZORUTILS_DEF { MP_ROM_QSTR(MP_QSTR_TrezorUtils), MP_ROM_PTR(&mp_module_TrezorUtils) },
+#else
+#define MICROPY_PY_TREZORUTILS_DEF
+#endif
+
+
#define MICROPY_PORT_BUILTIN_MODULES \
MICROPY_PY_FFI_DEF \
@@ -214,6 +258,12 @@ extern const struct _mp_obj_module_t mp_module_jni;
MICROPY_PY_UOS_VFS_DEF \
MICROPY_PY_USELECT_DEF \
MICROPY_PY_TERMIOS_DEF \
+ MICROPY_PY_TREZORCONFIG_DEF \
+ MICROPY_PY_TREZORCRYPTO_DEF \
+ MICROPY_PY_TREZORDEBUG_DEF \
+ MICROPY_PY_TREZORMSG_DEF \
+ MICROPY_PY_TREZORUI_DEF \
+ MICROPY_PY_TREZORUTILS_DEF \
// type definitions for the specific machine

@ -1,22 +0,0 @@
--- a/unix/mpconfigport.mk
+++ b/unix/mpconfigport.mk
@@ -34,6 +34,19 @@ MICROPY_SSL_MBEDTLS = 0
# jni module requires JVM/JNI
MICROPY_PY_JNI = 0
+MICROPY_PY_TREZORCONFIG = 1
+
+MICROPY_PY_TREZORCRYPTO = 1
+
+MICROPY_PY_TREZORDEBUG = 1
+
+MICROPY_PY_TREZORMSG = 1
+
+# TrezorUi module requires SDL2+SDL2_image unless TREZORUI_NOUI=1 is used
+MICROPY_PY_TREZORUI = 1
+
+MICROPY_PY_TREZORUTILS = 1
+
# Avoid using system libraries, use copies bundled with MicroPython
# as submodules (currently affects only libffi).
MICROPY_STANDALONE = 0

@ -0,0 +1,394 @@
MICROPY_PY_TREZORCONFIG = 1
MICROPY_PY_TREZORCRYPTO = 1
MICROPY_PY_TREZORDEBUG = 1
MICROPY_PY_TREZORMSG = 1
MICROPY_PY_TREZORUI = 1
MICROPY_PY_TREZORUI_NOUI = 0
MICROPY_PY_TREZORUTILS = 1
EXTMOD_DIR = ../../micropython/extmod
CFLAGS_EXTRA='-DMP_CONFIGFILE="../../../micropython/unix/mpconfigport.h"'
# OBJ micropython/extmod/modtrezorconfig
ifeq ($(MICROPY_PY_TREZORCONFIG),1)
SRC_MOD += $(EXTMOD_DIR)/modtrezorconfig/modtrezorconfig.c
SRC_MOD += $(EXTMOD_DIR)/modtrezorconfig/norcow.c
endif
# OBJ micropython/extmod/modtrezorcrypto
ifeq ($(MICROPY_PY_TREZORCRYPTO),1)
CFLAGS_MOD += -I../$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto
CFLAGS_MOD += -I../$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/curve25519-donna
CFLAGS_MOD += -I../$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/ed25519-donna
CFLAGS_MOD += -DED25519_CUSTOMRANDOM=1
CFLAGS_MOD += -DED25519_CUSTOMHASH=1
CFLAGS_MOD += -DED25519_NO_INLINE_ASM
CFLAGS_MOD += -DED25519_FORCE_32BIT=1
CFLAGS_MOD += -DAES_128
CFLAGS_MOD += -DAES_192
CFLAGS_MOD += -DUSE_KECCAK=1
CFLAGS_MOD += -Wno-sequence-point
SRC_MOD += \
$(EXTMOD_DIR)/modtrezorcrypto/modtrezorcrypto.c \
$(EXTMOD_DIR)/modtrezorcrypto/rand.c \
$(EXTMOD_DIR)/modtrezorcrypto/ssss.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/address.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/aescrypt.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/aeskey.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/aes_modes.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/aestab.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/base58.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/bignum.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/bip32.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/bip39.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/blake2b.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/blake2s.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/curve25519-donna/curve25519.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/curves.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/ecdsa.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/ed25519-donna/ed25519.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/hmac.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/nist256p1.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/pbkdf2.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/ripemd160.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/secp256k1.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/sha2.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/sha3.c
endif
# OBJ micropython/extmod/modtrezordebug
ifeq ($(MICROPY_PY_TREZORDEBUG),1)
SRC_MOD += $(EXTMOD_DIR)/modtrezordebug/modtrezordebug.c
endif
# OBJ micropython/extmod/modtrezormsg
ifeq ($(MICROPY_PY_TREZORMSG),1)
SRC_MOD += $(EXTMOD_DIR)/modtrezormsg/modtrezormsg.c
endif
# OBJ micropython/extmod/modtrezorui
ifeq ($(MICROPY_PY_TREZORUI),1)
CFLAGS_MOD += -DQR_MAX_VERSION=0
SRC_MOD += \
$(EXTMOD_DIR)/modtrezorui/display.c \
$(EXTMOD_DIR)/modtrezorui/inflate.c \
$(EXTMOD_DIR)/modtrezorui/font_bitmap.c \
$(EXTMOD_DIR)/modtrezorui/font_roboto_bold_20.c \
$(EXTMOD_DIR)/modtrezorui/font_roboto_regular_20.c \
$(EXTMOD_DIR)/modtrezorui/font_robotomono_regular_20.c \
$(EXTMOD_DIR)/modtrezorui/modtrezorui.c \
$(EXTMOD_DIR)/modtrezorui/trezor-qrenc/qr_encode.c
ifeq ($(MICROPY_PY_TREZORUI_NOUI),1)
CFLAGS_MOD += -DTREZORUI_NOUI=1
else
LDFLAGS_MOD += -lSDL2 -lSDL2_image
endif
endif
# OBJ micropython/extmod/modtrezorutils
ifeq ($(MICROPY_PY_TREZORUTILS),1)
SRC_MOD += $(EXTMOD_DIR)/modtrezorutils/modtrezorutils.c
endif
#################################################
-include mpconfigport.mk
include ../py/mkenv.mk
FROZEN_DIR = scripts
# define main target
PROG = micropython
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h
# OS name, for simple autoconfig
UNAME_S := $(shell uname -s)
# include py core make definitions
include ../py/py.mk
INC += -I.
INC += -I..
INC += -I../lib/timeutils
INC += -I$(BUILD)
# compiler settings
CWARN = -Wall -Werror
CWARN += -Wpointer-arith -Wuninitialized
CFLAGS = $(INC) $(CWARN) -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
# Debugging/Optimization
ifdef DEBUG
CFLAGS += -g
COPT = -O0
else
COPT = -Os -fdata-sections -ffunction-sections #-DNDEBUG
# _FORTIFY_SOURCE is a feature in gcc/glibc which is intended to provide extra
# security for detecting buffer overflows. Some distros (Ubuntu at the very least)
# have it enabled by default.
#
# gcc already optimizes some printf calls to call puts and/or putchar. When
# _FORTIFY_SOURCE is enabled and compiling with -O1 or greater, then some
# printf calls will also be optimized to call __printf_chk (in glibc). Any
# printfs which get redirected to __printf_chk are then no longer synchronized
# with printfs that go through mp_printf.
#
# In MicroPython, we don't want to use the runtime library's printf but rather
# go through mp_printf, so that stdout is properly tied into streams, etc.
# This means that we either need to turn off _FORTIFY_SOURCE or provide our
# own implementation of __printf_chk. We've chosen to turn off _FORTIFY_SOURCE.
# It should also be noted that the use of printf in MicroPython is typically
# quite limited anyways (primarily for debug and some error reporting, etc
# in the unix version).
#
# Information about _FORTIFY_SOURCE seems to be rather scarce. The best I could
# find was this: https://securityblog.redhat.com/2014/03/26/fortify-and-you/
# Original patchset was introduced by
# https://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html .
#
# Turning off _FORTIFY_SOURCE is only required when compiling with -O1 or greater
CFLAGS += -U _FORTIFY_SOURCE
endif
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
# The unix port of micropython on OSX must be compiled with clang,
# while cross-compile ports require gcc, so we test here for OSX and
# if necessary override the value of 'CC' set in py/mkenv.mk
ifeq ($(UNAME_S),Darwin)
ifeq ($(MICROPY_FORCE_32BIT),1)
CC = clang -m32
else
CC = clang
endif
# Use clang syntax for map file
LDFLAGS_ARCH = -Wl,-map,$@.map -Wl,-dead_strip
else
# Use gcc syntax for map file
LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref -Wl,--gc-sections
endif
LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)
ifeq ($(MICROPY_FORCE_32BIT),1)
# Note: you may need to install i386 versions of dependency packages,
# starting with linux-libc-dev:i386
ifeq ($(MICROPY_PY_FFI),1)
ifeq ($(UNAME_S),Linux)
CFLAGS_MOD += -I/usr/include/i686-linux-gnu
endif
endif
endif
ifeq ($(MICROPY_USE_READLINE),1)
INC += -I../lib/mp-readline
CFLAGS_MOD += -DMICROPY_USE_READLINE=1
LIB_SRC_C_EXTRA += mp-readline/readline.c
endif
ifeq ($(MICROPY_PY_TERMIOS),1)
CFLAGS_MOD += -DMICROPY_PY_TERMIOS=1
SRC_MOD += modtermios.c
endif
ifeq ($(MICROPY_PY_SOCKET),1)
CFLAGS_MOD += -DMICROPY_PY_SOCKET=1
SRC_MOD += modsocket.c
endif
ifeq ($(MICROPY_PY_THREAD),1)
CFLAGS_MOD += -DMICROPY_PY_THREAD=1 -DMICROPY_PY_THREAD_GIL=0
LDFLAGS_MOD += -lpthread
endif
ifeq ($(MICROPY_PY_FFI),1)
ifeq ($(MICROPY_STANDALONE),1)
LIBFFI_CFLAGS_MOD := -I$(shell ls -1d ../lib/libffi/build_dir/out/lib/libffi-*/include)
ifeq ($(MICROPY_FORCE_32BIT),1)
LIBFFI_LDFLAGS_MOD = ../lib/libffi/build_dir/out/lib32/libffi.a
else
LIBFFI_LDFLAGS_MOD = ../lib/libffi/build_dir/out/lib/libffi.a
endif
else
LIBFFI_CFLAGS_MOD := $(shell pkg-config --cflags libffi)
LIBFFI_LDFLAGS_MOD := $(shell pkg-config --libs libffi)
endif
ifeq ($(UNAME_S),Linux)
LIBFFI_LDFLAGS_MOD += -ldl
endif
CFLAGS_MOD += $(LIBFFI_CFLAGS_MOD) -DMICROPY_PY_FFI=1
LDFLAGS_MOD += $(LIBFFI_LDFLAGS_MOD)
SRC_MOD += modffi.c
endif
ifeq ($(MICROPY_PY_JNI),1)
# Path for 64-bit OpenJDK, should be adjusted for other JDKs
CFLAGS_MOD += -I/usr/lib/jvm/java-7-openjdk-amd64/include -DMICROPY_PY_JNI=1
SRC_MOD += modjni.c
endif
# source files
SRC_C = \
main.c \
gccollect.c \
unix_mphal.c \
mpthreadport.c \
input.c \
file.c \
modmachine.c \
modos.c \
moduos_vfs.c \
modtime.c \
moduselect.c \
alloc.c \
coverage.c \
fatfs_port.c \
$(SRC_MOD)
LIB_SRC_C = $(addprefix lib/,\
$(LIB_SRC_C_EXTRA) \
timeutils/timeutils.c \
)
# FatFS VFS support
LIB_SRC_C += $(addprefix lib/,\
oofatfs/ff.c \
oofatfs/option/unicode.c \
)
OBJ = $(PY_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(STMHAL_SRC_C:.c=.o))
# List of sources for qstr extraction
SRC_QSTR += $(SRC_C) $(LIB_SRC_C)
# Append any auto-generated sources that are needed by sources listed in
# SRC_QSTR
SRC_QSTR_AUTO_DEPS +=
ifneq ($(FROZEN_MPY_DIR),)
# To use frozen bytecode, put your .py files in a subdirectory (eg frozen/) and
# then invoke make with FROZEN_MPY_DIR=frozen (be sure to build from scratch).
CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
CFLAGS += -DMPZ_DIG_SIZE=16 # force 16 bits to work on both 32 and 64 bit archs
MPY_CROSS_FLAGS += -mcache-lookup-bc
endif
include ../py/mkrules.mk
.PHONY: test
test: $(PROG) ../tests/run-tests
$(eval DIRNAME=$(notdir $(CURDIR)))
cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests
# install micropython in /usr/local/bin
TARGET = micropython
PREFIX = $(DESTDIR)/usr/local
BINDIR = $(PREFIX)/bin
install: micropython
install -d $(BINDIR)
install $(TARGET) $(BINDIR)/$(TARGET)
# uninstall micropython
uninstall:
-rm $(BINDIR)/$(TARGET)
# build synthetically fast interpreter for benchmarking
fast:
$(MAKE) COPT="-O2 -DNDEBUG -fno-crossjumping" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_fast.h>"' BUILD=build-fast PROG=micropython_fast
# build a minimal interpreter
minimal:
$(MAKE) COPT="-Os -DNDEBUG" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_minimal.h>"' \
BUILD=build-minimal PROG=micropython_minimal FROZEN_DIR= \
MICROPY_PY_BTREE=0 MICROPY_PY_FFI=0 MICROPY_PY_SOCKET=0 MICROPY_PY_THREAD=0 \
MICROPY_PY_TERMIOS=0 MICROPY_PY_USSL=0 \
MICROPY_USE_READLINE=0 MICROPY_FATFS=0
# build interpreter with nan-boxing as object model
nanbox:
$(MAKE) \
CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_nanbox.h>"' \
BUILD=build-nanbox \
PROG=micropython_nanbox \
MICROPY_FORCE_32BIT=1 \
MICROPY_PY_USSL=0
freedos:
$(MAKE) \
CC=i586-pc-msdosdjgpp-gcc \
STRIP=i586-pc-msdosdjgpp-strip \
SIZE=i586-pc-msdosdjgpp-size \
CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_freedos.h>" -DMICROPY_NLR_SETJMP -Dtgamma=gamma -DMICROPY_EMIT_X86=0 -DMICROPY_NO_ALLOCA=1 -DMICROPY_PY_USELECT_POSIX=0' \
BUILD=build-freedos \
PROG=micropython_freedos \
MICROPY_PY_SOCKET=0 \
MICROPY_PY_FFI=0 \
MICROPY_PY_JNI=0 \
MICROPY_PY_BTREE=0 \
MICROPY_PY_THREAD=0 \
MICROPY_PY_USSL=0
# build an interpreter for coverage testing and do the testing
coverage:
$(MAKE) \
COPT="-O0" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_coverage.h>" \
-fprofile-arcs -ftest-coverage \
-Wdouble-promotion -Wformat -Wmissing-declarations -Wmissing-prototypes -Wsign-compare \
-Wold-style-definition -Wpointer-arith -Wshadow -Wuninitialized -Wunused-parameter \
-DMICROPY_UNIX_COVERAGE' \
LDFLAGS_EXTRA='-fprofile-arcs -ftest-coverage' \
FROZEN_DIR=coverage-frzstr FROZEN_MPY_DIR=coverage-frzmpy \
BUILD=build-coverage PROG=micropython_coverage
coverage_test: coverage
$(eval DIRNAME=$(notdir $(CURDIR)))
cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests
cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests -d thread
cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --emit native
cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --via-mpy -d basics float
gcov -o build-coverage/py ../py/*.c
gcov -o build-coverage/extmod ../extmod/*.c
# Value of configure's --host= option (required for cross-compilation).
# Deduce it from CROSS_COMPILE by default, but can be overriden.
ifneq ($(CROSS_COMPILE),)
CROSS_COMPILE_HOST = --host=$(patsubst %-,%,$(CROSS_COMPILE))
else
CROSS_COMPILE_HOST =
endif
deplibs: libffi axtls
# install-exec-recursive & install-data-am targets are used to avoid building
# docs and depending on makeinfo
libffi:
cd ../lib/libffi; git clean -d -x -f
cd ../lib/libffi; ./autogen.sh
mkdir -p ../lib/libffi/build_dir; cd ../lib/libffi/build_dir; \
../configure $(CROSS_COMPILE_HOST) --prefix=$$PWD/out --disable-structs CC="$(CC)" CXX="$(CXX)" LD="$(LD)" CFLAGS="-Os -fomit-frame-pointer -fstrict-aliasing -ffast-math -fno-exceptions"; \
make install-exec-recursive; make -C include install-data-am
axtls: $(BUILD)/libaxtls.a
$(BUILD)/libaxtls.a: ../lib/axtls/README | $(OBJ_DIRS)
cd ../lib/axtls; cp config/upyconfig config/.config
cd ../lib/axtls; make oldconfig -B
cd ../lib/axtls; make clean
cd ../lib/axtls; make all CC="$(CC)" LD="$(LD)"
cp ../lib/axtls/_stage/libaxtls.a $@
../lib/axtls/README:
@echo "You cloned without --recursive, fetching submodules for you."
(cd ..; git submodule update --init --recursive)

@ -0,0 +1,367 @@
/*
* This file is part of the Micro Python 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.
*/
// options to control how Micro Python is built
#define MICROPY_ALLOC_PATH_MAX (PATH_MAX)
#define MICROPY_PERSISTENT_CODE_LOAD (1)
#if !defined(MICROPY_EMIT_X64) && defined(__x86_64__)
#define MICROPY_EMIT_X64 (1)
#endif
#if !defined(MICROPY_EMIT_X86) && defined(__i386__)
#define MICROPY_EMIT_X86 (1)
#endif
#if !defined(MICROPY_EMIT_THUMB) && defined(__thumb2__)
#define MICROPY_EMIT_THUMB (1)
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1))
#endif
// Some compilers define __thumb2__ and __arm__ at the same time, let
// autodetected thumb2 emitter have priority.
#if !defined(MICROPY_EMIT_ARM) && defined(__arm__) && !defined(__thumb2__)
#define MICROPY_EMIT_ARM (1)
#endif
#define MICROPY_COMP_MODULE_CONST (1)
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1)
#define MICROPY_ENABLE_GC (1)
#define MICROPY_ENABLE_FINALISER (1)
#define MICROPY_STACK_CHECK (1)
#define MICROPY_MALLOC_USES_ALLOCATED_SIZE (1)
#define MICROPY_MEM_STATS (1)
#define MICROPY_DEBUG_PRINTERS (1)
// Printing debug to stderr may give tests which
// check stdout a chance to pass, etc.
#define MICROPY_DEBUG_PRINTER_DEST mp_stderr_print
#define MICROPY_READER_POSIX (1)
#define MICROPY_USE_READLINE_HISTORY (1)
#define MICROPY_HELPER_REPL (1)
#define MICROPY_REPL_EMACS_KEYS (1)
#define MICROPY_REPL_AUTO_INDENT (1)
#define MICROPY_HELPER_LEXER_UNIX (1)
#define MICROPY_ENABLE_SOURCE_LINE (1)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_STREAMS_NON_BLOCK (1)
#define MICROPY_STREAMS_POSIX_API (1)
#define MICROPY_OPT_COMPUTED_GOTO (1)
#ifndef MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (1)
#endif
#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
#define MICROPY_PY_FUNCTION_ATTRS (1)
#define MICROPY_PY_DESCRIPTORS (1)
#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 (1)
#define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
#define MICROPY_PY_BUILTINS_FROZENSET (1)
#define MICROPY_PY_BUILTINS_COMPILE (1)
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
#define MICROPY_PY_BUILTINS_POW3 (1)
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
#define MICROPY_PY_ALL_SPECIAL_METHODS (1)
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
#define MICROPY_PY_SYS_EXIT (1)
#if defined(__APPLE__) && defined(__MACH__)
#define MICROPY_PY_SYS_PLATFORM "darwin"
#else
#define MICROPY_PY_SYS_PLATFORM "linux"
#endif
#define MICROPY_PY_SYS_MAXSIZE (1)
#define MICROPY_PY_SYS_STDFILES (1)
#define MICROPY_PY_SYS_EXC_INFO (1)
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)
#ifndef MICROPY_PY_MATH_SPECIAL_FUNCTIONS
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1)
#endif
#define MICROPY_PY_CMATH (1)
#define MICROPY_PY_IO_FILEIO (1)
#define MICROPY_PY_GC_COLLECT_RETVAL (1)
#define MICROPY_MODULE_FROZEN_STR (1)
#define MICROPY_STACKLESS (0)
#define MICROPY_STACKLESS_STRICT (0)
#define MICROPY_PY_OS_STATVFS (1)
#define MICROPY_PY_UTIME (1)
#define MICROPY_PY_UTIME_MP_HAL (1)
#define MICROPY_PY_UERRNO (1)
#define MICROPY_PY_UCTYPES (1)
#define MICROPY_PY_UZLIB (1)
#define MICROPY_PY_UJSON (1)
#define MICROPY_PY_URE (1)
#define MICROPY_PY_UHEAPQ (1)
#define MICROPY_PY_UTIMEQ (1)
#define MICROPY_PY_UHASHLIB (1)
#if MICROPY_PY_USSL && MICROPY_SSL_AXTLS
#define MICROPY_PY_UHASHLIB_SHA1 (1)
#endif
#define MICROPY_PY_UBINASCII (1)
#define MICROPY_PY_UBINASCII_CRC32 (1)
#define MICROPY_PY_URANDOM (1)
#ifndef MICROPY_PY_USELECT_POSIX
#define MICROPY_PY_USELECT_POSIX (1)
#endif
#define MICROPY_PY_WEBSOCKET (1)
#define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE_PULSE (1)
#define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr
#define MICROPY_MACHINE_MEM_GET_WRITE_ADDR mod_machine_mem_get_addr
#define MICROPY_PY_TREZORCONFIG (1)
#define MICROPY_PY_TREZORCRYPTO (1)
#define MICROPY_PY_TREZORDEBUG (1)
#define MICROPY_PY_TREZORMSG (1)
#define MICROPY_PY_TREZORUI (1)
#define MICROPY_PY_TREZORUTILS (1)
#define MICROPY_FATFS_ENABLE_LFN (1)
#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_FAT (0)
// Define to MICROPY_ERROR_REPORTING_DETAILED to get function, etc.
// names in exception messages (may require more RAM).
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
#define MICROPY_WARNINGS (1)
#define MICROPY_PY_STR_BYTES_CMP_WARN (1)
// Define to 1 to use undertested inefficient GC helper implementation
// (if more efficient arch-specific one is not available).
#ifndef MICROPY_GCREGS_SETJMP
#ifdef __mips__
#define MICROPY_GCREGS_SETJMP (1)
#else
#define MICROPY_GCREGS_SETJMP (0)
#endif
#endif
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256)
#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;
extern const struct _mp_obj_module_t mp_module_time;
extern const struct _mp_obj_module_t mp_module_termios;
extern const struct _mp_obj_module_t mp_module_socket;
extern const struct _mp_obj_module_t mp_module_ffi;
extern const struct _mp_obj_module_t mp_module_jni;
extern const struct _mp_obj_module_t mp_module_TrezorConfig;
extern const struct _mp_obj_module_t mp_module_TrezorCrypto;
extern const struct _mp_obj_module_t mp_module_TrezorDebug;
extern const struct _mp_obj_module_t mp_module_TrezorMsg;
extern const struct _mp_obj_module_t mp_module_TrezorUi;
extern const struct _mp_obj_module_t mp_module_TrezorUtils;
#if MICROPY_PY_UOS_VFS
#define MICROPY_PY_UOS_VFS_DEF { MP_ROM_QSTR(MP_QSTR_uos_vfs), MP_ROM_PTR(&mp_module_uos_vfs) },
#else
#define MICROPY_PY_UOS_VFS_DEF
#endif
#if MICROPY_PY_FFI
#define MICROPY_PY_FFI_DEF { MP_ROM_QSTR(MP_QSTR_ffi), MP_ROM_PTR(&mp_module_ffi) },
#else
#define MICROPY_PY_FFI_DEF
#endif
#if MICROPY_PY_JNI
#define MICROPY_PY_JNI_DEF { MP_ROM_QSTR(MP_QSTR_jni), MP_ROM_PTR(&mp_module_jni) },
#else
#define MICROPY_PY_JNI_DEF
#endif
#if MICROPY_PY_UTIME
#define MICROPY_PY_UTIME_DEF { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_time) },
#else
#define MICROPY_PY_UTIME_DEF
#endif
#if MICROPY_PY_TERMIOS
#define MICROPY_PY_TERMIOS_DEF { MP_ROM_QSTR(MP_QSTR_termios), MP_ROM_PTR(&mp_module_termios) },
#else
#define MICROPY_PY_TERMIOS_DEF
#endif
#if MICROPY_PY_SOCKET
#define MICROPY_PY_SOCKET_DEF { MP_ROM_QSTR(MP_QSTR_usocket), MP_ROM_PTR(&mp_module_socket) },
#else
#define MICROPY_PY_SOCKET_DEF
#endif
#if MICROPY_PY_USELECT_POSIX
#define MICROPY_PY_USELECT_DEF { MP_ROM_QSTR(MP_QSTR_uselect), MP_ROM_PTR(&mp_module_uselect) },
#else
#define MICROPY_PY_USELECT_DEF
#endif
#if MICROPY_PY_TREZORCONFIG
#define MICROPY_PY_TREZORCONFIG_DEF { MP_ROM_QSTR(MP_QSTR_TrezorConfig), MP_ROM_PTR(&mp_module_TrezorConfig) },
#else
#define MICROPY_PY_TREZORCONFIG_DEF
#endif
#if MICROPY_PY_TREZORCRYPTO
#define MICROPY_PY_TREZORCRYPTO_DEF { MP_ROM_QSTR(MP_QSTR_TrezorCrypto), MP_ROM_PTR(&mp_module_TrezorCrypto) },
#else
#define MICROPY_PY_TREZORCRYPTO_DEF
#endif
#if MICROPY_PY_TREZORDEBUG
#define MICROPY_PY_TREZORDEBUG_DEF { MP_ROM_QSTR(MP_QSTR_TrezorDebug), MP_ROM_PTR(&mp_module_TrezorDebug) },
#else
#define MICROPY_PY_TREZORDEBUGI_DEF
#endif
#if MICROPY_PY_TREZORMSG
#define MICROPY_PY_TREZORMSG_DEF { MP_ROM_QSTR(MP_QSTR_TrezorMsg), MP_ROM_PTR(&mp_module_TrezorMsg) },
#else
#define MICROPY_PY_TREZORMSG_DEF
#endif
#if MICROPY_PY_TREZORUI
#define MICROPY_PY_TREZORUI_DEF { MP_ROM_QSTR(MP_QSTR_TrezorUi), MP_ROM_PTR(&mp_module_TrezorUi) },
#else
#define MICROPY_PY_TREZORUI_DEF
#endif
#if MICROPY_PY_TREZORUTILS
#define MICROPY_PY_TREZORUTILS_DEF { MP_ROM_QSTR(MP_QSTR_TrezorUtils), MP_ROM_PTR(&mp_module_TrezorUtils) },
#else
#define MICROPY_PY_TREZORUTILS_DEF
#endif
#define MICROPY_PORT_BUILTIN_MODULES \
MICROPY_PY_FFI_DEF \
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 \
MICROPY_PY_TERMIOS_DEF \
MICROPY_PY_TREZORCONFIG_DEF \
MICROPY_PY_TREZORCRYPTO_DEF \
MICROPY_PY_TREZORDEBUG_DEF \
MICROPY_PY_TREZORMSG_DEF \
MICROPY_PY_TREZORUI_DEF \
MICROPY_PY_TREZORUTILS_DEF \
// type definitions for the specific machine
// assume that if we already defined the obj repr then we also defined types
#ifndef MICROPY_OBJ_REPR
#ifdef __LP64__
typedef long mp_int_t; // must be pointer size
typedef unsigned long mp_uint_t; // must be pointer size
#else
// These are definitions for machines where sizeof(int) == sizeof(void*),
// regardless of actual size.
typedef int mp_int_t; // must be pointer size
typedef unsigned int mp_uint_t; // must be pointer size
#endif
#endif
#define BYTES_PER_WORD sizeof(mp_int_t)
// Cannot include <sys/types.h>, as it may lead to symbol name clashes
#if _FILE_OFFSET_BITS == 64 && !defined(__LP64__)
typedef long long mp_off_t;
#else
typedef long mp_off_t;
#endif
void mp_unix_alloc_exec(mp_uint_t min_size, void** ptr, mp_uint_t *size);
void mp_unix_free_exec(void *ptr, mp_uint_t size);
void mp_unix_mark_exec(void);
#define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) mp_unix_alloc_exec(min_size, ptr, size)
#define MP_PLAT_FREE_EXEC(ptr, size) mp_unix_free_exec(ptr, size)
#ifndef MICROPY_FORCE_PLAT_ALLOC_EXEC
// Use MP_PLAT_ALLOC_EXEC for any executable memory allocation, including for FFI
// (overriding libffi own implementation)
#define MICROPY_FORCE_PLAT_ALLOC_EXEC (1)
#endif
#if MICROPY_PY_OS_DUPTERM
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
#else
#include <unistd.h>
#define MP_PLAT_PRINT_STRN(str, len) do { ssize_t ret = write(1, str, len); (void)ret; } while (0)
#endif
#ifdef __linux__
// Can access physical memory using /dev/mem
#define MICROPY_PLAT_DEV_MEM (1)
#endif
// Assume that select() call, interrupted with a signal, and erroring
// with EINTR, updates remaining timeout value.
#define MICROPY_SELECT_REMAINING_TIME (1)
#ifdef __ANDROID__
#include <android/api-level.h>
#if __ANDROID_API__ < 4
// Bionic libc in Android 1.5 misses these 2 functions
#define MP_NEED_LOG2 (1)
#define nan(x) NAN
#endif
#endif
#define MICROPY_PORT_BUILTINS \
{ MP_ROM_QSTR(MP_QSTR_input), MP_ROM_PTR(&mp_builtin_input_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_PORT_ROOT_POINTERS \
const char *readline_hist[50]; \
mp_obj_t keyboard_interrupt_obj; \
void *mmap_region_head; \
// We need to provide a declaration/definition of alloca()
// unless support for it is disabled.
#if !defined(MICROPY_NO_ALLOCA) || MICROPY_NO_ALLOCA == 0
#ifdef __FreeBSD__
#include <stdlib.h>
#else
#include <alloca.h>
#endif
#endif
// From "man readdir": "Under glibc, programs can check for the availability
// of the fields [in struct dirent] not defined in POSIX.1 by testing whether
// the macros [...], _DIRENT_HAVE_D_TYPE are defined."
// Other libc's don't define it, but proactively assume that dirent->d_type
// is available on a modern *nix system.
#ifndef _DIRENT_HAVE_D_TYPE
#define _DIRENT_HAVE_D_TYPE (1)
#endif
// This macro is not provided by glibc but we need it so ports that don't have
// dirent->d_ino can disable the use of this field.
#ifndef _DIRENT_HAVE_D_INO
#define _DIRENT_HAVE_D_INO (1)
#endif
#ifndef __APPLE__
// For debugging purposes, make printf() available to any source file.
#include <stdio.h>
#endif
Loading…
Cancel
Save