1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-10-31 20:39:48 +00:00

chore(vendor): bump micropython to 1.19.1

Relevant micropython commits:
  01374d941f9d7398e35990b574769b20c6779457 py/mpconfig.h: Define initial templates for "feature levels".
  7b89ad8dbf432ab51eea6d138e179bf51394c786 py/vm: Add a fast path for LOAD_ATTR on instance types.
  68219a295c75457c096ac42dbe8411b84e1e1a51 stm32: Enable LOAD_ATTR fast path, and map lookup caching on >M0.
  e0bf4611c3a8b23b3c52e6a7804aac341ac3a87d py: Only search frozen modules when '.frozen' is found in sys.path.
  f2040bfc7ee033e48acef9f289790f3b4e6b74e5 py: Rework bytecode and .mpy file format to be mostly static data.
  926b554dafffa1e9bd80aa12fea5c621221c9d79 extmod/moduos: Create general uos module to be used by all ports.
  2b409ef8a46015f8f3bd20bc44e644637dbe9bd3 unix/moduos: Convert module to use extmod version.
  47f634300c5572571816817f16836113c98814ae py: Change makemoduledefs process so it uses output of qstr extraction.
  0e7bfc88c6ac6b5d64240f91183a3cfe2ab67ade all: Use mp_obj_malloc everywhere it's applicable.
  2a6ba47110be88ff1e1f5abd1bd76c353447884c py/obj: Add static safety checks to mp_obj_is_type().
This commit is contained in:
Martin Milata 2023-01-24 21:57:27 +01:00
parent eea52174ac
commit 3fb3f108cc
30 changed files with 124 additions and 75 deletions

View File

@ -132,9 +132,9 @@ WIRETYPE_ENTRY = c.Sequence(
"msg_offset" / c.Int16ul, "msg_offset" / c.Int16ul,
) )
# QDEF(MP_QSTR_copysign, (const byte*)"\x33\x14\x08" "copysign") # QDEF(MP_QSTR_copysign, 5171, 8, "copysign")
QDEF_RE = re.compile( QDEF_RE = re.compile(
r'^QDEF\(MP_QSTR(\S+), \(const byte\*\)"(\\x..\\x..\\x..)" "(.*)"\)$' r'^QDEF\(MP_QSTR(\S+), ([0-9]+), ([0-9])+, "(.*)"\)$'
) )
@ -549,7 +549,7 @@ class RustBlobRenderer:
if not match: if not match:
continue continue
line = match.group(0) line = match.group(0)
string = match.group(3) string = match.group(4)
self.qstr_map[string] = qstr_counter self.qstr_map[string] = qstr_counter
qstr_counter += 1 qstr_counter += 1
logging.debug(f"Found {qstr_counter} Qstr defs") logging.debug(f"Found {qstr_counter} Qstr defs")

View File

@ -0,0 +1 @@
Update to MicroPython 1.19.1.

View File

@ -225,7 +225,6 @@ SOURCE_MICROPYTHON = [
'vendor/micropython/shared/timeutils/timeutils.c', 'vendor/micropython/shared/timeutils/timeutils.c',
'vendor/micropython/ports/stm32/gccollect.c', 'vendor/micropython/ports/stm32/gccollect.c',
'vendor/micropython/ports/stm32/pendsv.c', 'vendor/micropython/ports/stm32/pendsv.c',
'vendor/micropython/ports/stm32/softtimer.c',
'vendor/micropython/py/argcheck.c', 'vendor/micropython/py/argcheck.c',
'vendor/micropython/py/asmarm.c', 'vendor/micropython/py/asmarm.c',
'vendor/micropython/py/asmbase.c', 'vendor/micropython/py/asmbase.c',
@ -535,7 +534,23 @@ qstr_generated = env.GenerateQstrDefs(
env.Ignore(qstr_collected, qstr_generated) env.Ignore(qstr_collected, qstr_generated)
# #
# Micropython version and modules # Micropython module declarations
#
moduledefs_collected = env.CollectModules(
target='genhdr/moduledefs.collected.h', source=SOURCE_QSTR)
hdr_moduledefs = env.Command(
target='genhdr/moduledefs.h',
source=moduledefs_collected,
action='$MAKEMODULEDEFS $SOURCE > $TARGET', )
env.Ignore(moduledefs_collected, moduledefs_collected)
env.Ignore(moduledefs_collected, qstr_generated)
env.Ignore(moduledefs_collected, hdr_moduledefs)
#
# Micropython version
# #
hdr_version = env.Command( hdr_version = env.Command(
@ -543,11 +558,6 @@ hdr_version = env.Command(
source='', source='',
action='$MAKEVERSIONHDR $TARGET', ) action='$MAKEVERSIONHDR $TARGET', )
hdr_moduledefs = env.Command(
target='genhdr/moduledefs.h',
source=SOURCE_QSTR,
action='$MAKEMODULEDEFS --vpath="." $SOURCES > $TARGET', )
env.Ignore(hdr_moduledefs, hdr_moduledefs) env.Ignore(hdr_moduledefs, hdr_moduledefs)
env.Ignore(hdr_moduledefs, qstr_collected) env.Ignore(hdr_moduledefs, qstr_collected)
env.Ignore(hdr_moduledefs, qstr_preprocessed) env.Ignore(hdr_moduledefs, qstr_preprocessed)

View File

@ -214,11 +214,11 @@ SOURCE_MICROPYTHON = [
'vendor/micropython/extmod/modubinascii.c', 'vendor/micropython/extmod/modubinascii.c',
'vendor/micropython/extmod/moductypes.c', 'vendor/micropython/extmod/moductypes.c',
'vendor/micropython/extmod/moduheapq.c', 'vendor/micropython/extmod/moduheapq.c',
'vendor/micropython/extmod/moduos.c',
'vendor/micropython/extmod/modutimeq.c', 'vendor/micropython/extmod/modutimeq.c',
'vendor/micropython/extmod/utime_mphal.c', 'vendor/micropython/extmod/utime_mphal.c',
'vendor/micropython/shared/readline/readline.c', 'vendor/micropython/shared/readline/readline.c',
'vendor/micropython/shared/timeutils/timeutils.c', 'vendor/micropython/shared/timeutils/timeutils.c',
'vendor/micropython/ports/unix/modos.c',
'vendor/micropython/py/argcheck.c', 'vendor/micropython/py/argcheck.c',
'vendor/micropython/py/asmarm.c', 'vendor/micropython/py/asmarm.c',
'vendor/micropython/py/asmbase.c', 'vendor/micropython/py/asmbase.c',
@ -504,7 +504,24 @@ qstr_generated = env.GenerateQstrDefs(
env.Ignore(qstr_collected, qstr_generated) env.Ignore(qstr_collected, qstr_generated)
# #
# Micropython version and modules # Micropython module declarations
#
moduledefs_collected = env.CollectModules(
target='genhdr/moduledefs.collected.h', source=SOURCE_QSTR)
hdr_moduledefs = env.Command(
target='genhdr/moduledefs.h',
source=moduledefs_collected,
action='$MAKEMODULEDEFS $SOURCE > $TARGET', )
env.Ignore(moduledefs_collected, moduledefs_collected)
env.Ignore(moduledefs_collected, qstr_generated)
env.Ignore(moduledefs_collected, hdr_moduledefs)
#
# Micropython version
# #
hdr_version = env.Command( hdr_version = env.Command(
@ -512,11 +529,6 @@ hdr_version = env.Command(
source='', source='',
action='$MAKEVERSIONHDR $TARGET', ) action='$MAKEVERSIONHDR $TARGET', )
hdr_moduledefs = env.Command(
target='genhdr/moduledefs.h',
source=SOURCE_QSTR,
action='$MAKEMODULEDEFS --vpath="." $SOURCES > $TARGET', )
env.Ignore(hdr_moduledefs, hdr_moduledefs) env.Ignore(hdr_moduledefs, hdr_moduledefs)
env.Ignore(hdr_moduledefs, qstr_collected) env.Ignore(hdr_moduledefs, qstr_collected)
env.Ignore(hdr_moduledefs, qstr_preprocessed) env.Ignore(hdr_moduledefs, qstr_preprocessed)

View File

@ -446,7 +446,6 @@ const mp_obj_module_t mp_module_trezorconfig = {
.globals = (mp_obj_dict_t *)&mp_module_trezorconfig_globals, .globals = (mp_obj_dict_t *)&mp_module_trezorconfig_globals,
}; };
MP_REGISTER_MODULE(MP_QSTR_trezorconfig, mp_module_trezorconfig, MP_REGISTER_MODULE(MP_QSTR_trezorconfig, mp_module_trezorconfig);
MICROPY_PY_TREZORCONFIG);
#endif // MICROPY_PY_TREZORCONFIG #endif // MICROPY_PY_TREZORCONFIG

View File

@ -129,8 +129,7 @@ const mp_obj_module_t mp_module_trezorcrypto = {
.globals = (mp_obj_dict_t *)&mp_module_trezorcrypto_globals, .globals = (mp_obj_dict_t *)&mp_module_trezorcrypto_globals,
}; };
MP_REGISTER_MODULE(MP_QSTR_trezorcrypto, mp_module_trezorcrypto, MP_REGISTER_MODULE(MP_QSTR_trezorcrypto, mp_module_trezorcrypto);
MICROPY_PY_TREZORCRYPTO);
#ifdef USE_SECP256K1_ZKP #ifdef USE_SECP256K1_ZKP
void secp256k1_default_illegal_callback_fn(const char *str, void *data) { void secp256k1_default_illegal_callback_fn(const char *str, void *data) {

View File

@ -386,8 +386,8 @@ STATIC mp_obj_t mod_trezorio_fatfs_open(mp_obj_t path, mp_obj_t flags) {
if (res != FR_OK) { if (res != FR_OK) {
FATFS_RAISE(FatFSError, res); FATFS_RAISE(FatFSError, res);
} }
mp_obj_FatFSFile_t *f = m_new_obj(mp_obj_FatFSFile_t); mp_obj_FatFSFile_t *f =
f->base.type = &mod_trezorio_FatFSFile_type; mp_obj_malloc(mp_obj_FatFSFile_t, &mod_trezorio_FatFSFile_type);
f->fp = fp; f->fp = fp;
return f; return f;
} }
@ -407,8 +407,8 @@ STATIC mp_obj_t mod_trezorio_fatfs_listdir(mp_obj_t path) {
if (res != FR_OK) { if (res != FR_OK) {
FATFS_RAISE(FatFSError, res); FATFS_RAISE(FatFSError, res);
} }
mp_obj_FatFSDir_t *d = m_new_obj(mp_obj_FatFSDir_t); mp_obj_FatFSDir_t *d =
d->base.type = &mod_trezorio_FatFSDir_type; mp_obj_malloc(mp_obj_FatFSDir_t, &mod_trezorio_FatFSDir_type);
d->dp = dp; d->dp = dp;
return d; return d;
} }

View File

@ -37,8 +37,7 @@ STATIC mp_obj_t mod_trezorio_FlashOTP_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_FlashOTP_t *o = m_new_obj(mp_obj_FlashOTP_t); mp_obj_FlashOTP_t *o = mp_obj_malloc(mp_obj_FlashOTP_t, type);
o->base.type = type;
return MP_OBJ_FROM_PTR(o); return MP_OBJ_FROM_PTR(o);
} }

View File

@ -94,8 +94,7 @@ STATIC mp_obj_t mod_trezorio_HID_make_new(const mp_obj_type_t *type,
CHECK_PARAM_RANGE(polling_interval, 1, 255) CHECK_PARAM_RANGE(polling_interval, 1, 255)
CHECK_PARAM_RANGE(max_packet_len, 64, 64) CHECK_PARAM_RANGE(max_packet_len, 64, 64)
mp_obj_HID_t *o = m_new_obj(mp_obj_HID_t); mp_obj_HID_t *o = mp_obj_malloc(mp_obj_HID_t, type);
o->base.type = type;
o->info.rx_buffer = m_new(uint8_t, max_packet_len); o->info.rx_buffer = m_new(uint8_t, max_packet_len);
o->info.report_desc = report_desc.buf; o->info.report_desc = report_desc.buf;

View File

@ -35,8 +35,7 @@ STATIC mp_obj_t mod_trezorio_SBU_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_SBU_t *o = m_new_obj(mp_obj_SBU_t); mp_obj_SBU_t *o = mp_obj_malloc(mp_obj_SBU_t, type);
o->base.type = type;
sbu_init(); sbu_init();
return MP_OBJ_FROM_PTR(o); return MP_OBJ_FROM_PTR(o);
} }

View File

@ -85,8 +85,7 @@ STATIC mp_obj_t mod_trezorio_VCP_make_new(const mp_obj_type_t *type,
const size_t vcp_buffer_len = 1024; const size_t vcp_buffer_len = 1024;
const size_t vcp_packet_len = 64; const size_t vcp_packet_len = 64;
mp_obj_VCP_t *o = m_new_obj(mp_obj_VCP_t); mp_obj_VCP_t *o = mp_obj_malloc(mp_obj_VCP_t, type);
o->base.type = type;
o->info.tx_packet = m_new(uint8_t, vcp_packet_len); o->info.tx_packet = m_new(uint8_t, vcp_packet_len);
o->info.tx_buffer = m_new(uint8_t, vcp_buffer_len); o->info.tx_buffer = m_new(uint8_t, vcp_buffer_len);

View File

@ -84,8 +84,7 @@ STATIC mp_obj_t mod_trezorio_WebUSB_make_new(const mp_obj_type_t *type,
CHECK_PARAM_RANGE(polling_interval, 1, 255) CHECK_PARAM_RANGE(polling_interval, 1, 255)
CHECK_PARAM_RANGE(max_packet_len, 64, 64) CHECK_PARAM_RANGE(max_packet_len, 64, 64)
mp_obj_WebUSB_t *o = m_new_obj(mp_obj_WebUSB_t); mp_obj_WebUSB_t *o = mp_obj_malloc(mp_obj_WebUSB_t, type);
o->base.type = type;
o->info.rx_buffer = m_new(uint8_t, max_packet_len); o->info.rx_buffer = m_new(uint8_t, max_packet_len);
o->info.iface_num = (uint8_t)(iface_num); o->info.iface_num = (uint8_t)(iface_num);

View File

@ -127,6 +127,6 @@ const mp_obj_module_t mp_module_trezorio = {
.globals = (mp_obj_dict_t*)&mp_module_trezorio_globals, .globals = (mp_obj_dict_t*)&mp_module_trezorio_globals,
}; };
MP_REGISTER_MODULE(MP_QSTR_trezorio, mp_module_trezorio, MICROPY_PY_TREZORIO); MP_REGISTER_MODULE(MP_QSTR_trezorio, mp_module_trezorio);
#endif // MICROPY_PY_TREZORIO #endif // MICROPY_PY_TREZORIO

View File

@ -43,8 +43,7 @@ STATIC mp_obj_t mod_trezorui_Display_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, size_t n_args, size_t n_kw,
const mp_obj_t *args) { const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_Display_t *o = m_new_obj(mp_obj_Display_t); mp_obj_Display_t *o = mp_obj_malloc(mp_obj_Display_t, type);
o->base.type = type;
return MP_OBJ_FROM_PTR(o); return MP_OBJ_FROM_PTR(o);
} }

View File

@ -41,6 +41,6 @@ const mp_obj_module_t mp_module_trezorui = {
.globals = (mp_obj_dict_t*)&mp_module_trezorui_globals, .globals = (mp_obj_dict_t*)&mp_module_trezorui_globals,
}; };
MP_REGISTER_MODULE(MP_QSTR_trezorui, mp_module_trezorui, MICROPY_PY_TREZORUI); MP_REGISTER_MODULE(MP_QSTR_trezorui, mp_module_trezorui);
#endif // MICROPY_PY_TREZORUI #endif // MICROPY_PY_TREZORUI

View File

@ -253,17 +253,21 @@ void dump_dict_inner(FILE *out, const mp_obj_dict_t *dict) {
void dump_function(FILE *out, const mp_obj_fun_bc_t *func) { void dump_function(FILE *out, const mp_obj_fun_bc_t *func) {
print_type(out, "function", NULL, func, false); print_type(out, "function", NULL, func, false);
fprintf(out, ",\n\"globals\": \"%p\"", func->globals);
fprintf(out, ",\n\"code_alloc\": %ld", find_allocated_size(func->bytecode)); fprintf(out, ",\n\"code_alloc\": %ld", find_allocated_size(func->bytecode));
fprintf(out, ",\n\"code_ptr\": \"%p\"", func->bytecode); fprintf(out, ",\n\"code_ptr\": \"%p\"", func->bytecode);
fprintf(out, ",\n\"const_table_alloc\": %ld",
find_allocated_size(func->const_table));
fprintf(out, ",\n\"const_table_ptr\": \"%p\"", func->const_table);
mark(func->bytecode); mark(func->bytecode);
mark(func->const_table); fprintf(out, ",\n\"context_ptr\": \"%p\"", func->context);
fprintf(out, ",\n\"qstr_table_ptr\": \"%p\"",
func->context->constants.qstr_table);
fprintf(out, ",\n\"qstr_table_alloc\": \"%ld\"",
find_allocated_size(func->context->constants.qstr_table));
// obj_table uses the same allocation as qstr_table
fprintf(out, "},\n"); fprintf(out, "},\n");
dump_value(out, func->globals); // mp_module_context_t has mp_obj_module_t value at the beginning,
// dump_value will handle it as a module. The two pointers in
// mp_module_constants_t are handled above.
dump_value(out, &func->context);
} }
typedef struct _mp_obj_bound_meth_t { typedef struct _mp_obj_bound_meth_t {
@ -672,10 +676,11 @@ void dump_value(FILE *out, mp_const_obj_t value) {
dump_value_opt(out, value, false); dump_value_opt(out, value, false);
} }
void dump_qstr_pool(FILE *out, qstr_pool_t *pool) { void dump_qstr_pool(FILE *out, const qstr_pool_t *pool) {
print_type(out, "qstrpool", NULL, pool, false); print_type(out, "qstrpool", NULL, pool, false);
fprintf(out, ", \"qstrs\": [\n"); fprintf(out, ", \"qstrs\": [\n");
for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; for (const char *const *q = pool->qstrs, *const *q_top =
pool->qstrs + pool->len;
q < q_top; q++) { q < q_top; q++) {
if (q < (q_top - 1)) if (q < (q_top - 1))
fprintf(out, "\"%s\",\n", Q_GET_DATA(*q)); fprintf(out, "\"%s\",\n", Q_GET_DATA(*q));
@ -683,7 +688,8 @@ void dump_qstr_pool(FILE *out, qstr_pool_t *pool) {
fprintf(out, "\"%s\"]\n", Q_GET_DATA(*q)); fprintf(out, "\"%s\"]\n", Q_GET_DATA(*q));
} }
fprintf(out, "},\n"); fprintf(out, "},\n");
for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; for (const char *const *q = pool->qstrs, *const *q_top =
pool->qstrs + pool->len;
q < q_top; q++) { q < q_top; q++) {
print_type(out, "qstrdata", NULL, *q, false); print_type(out, "qstrdata", NULL, *q, false);
fprintf(out, ", \"pool\": \"%p\"},\n", pool); fprintf(out, ", \"pool\": \"%p\"},\n", pool);
@ -691,9 +697,10 @@ void dump_qstr_pool(FILE *out, qstr_pool_t *pool) {
} }
void dump_qstrdata(FILE *out) { void dump_qstrdata(FILE *out) {
qstr_pool_t *pool = MP_STATE_VM(last_pool); const qstr_pool_t *pool = MP_STATE_VM(last_pool);
while (pool != NULL) { while (pool != NULL) {
for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; for (const char *const *q = pool->qstrs, *const *q_top =
pool->qstrs + pool->len;
q < q_top; q++) { q < q_top; q++) {
if ((void *)*q > (void *)mp_state_ctx.mem.gc_pool_start) { if ((void *)*q > (void *)mp_state_ctx.mem.gc_pool_start) {
print_type(out, "qstrdata", NULL, q, false); print_type(out, "qstrdata", NULL, q, false);
@ -757,7 +764,7 @@ STATIC mp_obj_t mod_trezorutils_meminfo(mp_obj_t filename) {
dump_value(out, MP_STATE_VM(trezorconfig_ui_wait_callback)); dump_value(out, MP_STATE_VM(trezorconfig_ui_wait_callback));
fprintf(out, "\"qstr_pools\",\n"); fprintf(out, "\"qstr_pools\",\n");
qstr_pool_t *pool = MP_STATE_VM(last_pool); const qstr_pool_t *pool = MP_STATE_VM(last_pool);
while (VERIFY_PTR((void *)pool)) { while (VERIFY_PTR((void *)pool)) {
dump_qstr_pool(out, pool); dump_qstr_pool(out, pool);
pool = pool->prev; pool = pool->prev;

View File

@ -287,7 +287,6 @@ const mp_obj_module_t mp_module_trezorutils = {
.globals = (mp_obj_dict_t *)&mp_module_trezorutils_globals, .globals = (mp_obj_dict_t *)&mp_module_trezorutils_globals,
}; };
MP_REGISTER_MODULE(MP_QSTR_trezorutils, mp_module_trezorutils, MP_REGISTER_MODULE(MP_QSTR_trezorutils, mp_module_trezorutils);
MICROPY_PY_TREZORUTILS);
#endif // MICROPY_PY_TREZORUTILS #endif // MICROPY_PY_TREZORUTILS

View File

@ -69,4 +69,4 @@ const mp_obj_module_t mp_module_utime = {
.globals = (mp_obj_dict_t*)&time_module_globals, .globals = (mp_obj_dict_t*)&time_module_globals,
}; };
MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime, MICROPY_PY_UTIME); MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime);

View File

@ -80,7 +80,6 @@ const mp_obj_module_t mp_module_trezorproto = {
.globals = (mp_obj_dict_t *)&mp_module_trezorproto_globals, .globals = (mp_obj_dict_t *)&mp_module_trezorproto_globals,
}; };
MP_REGISTER_MODULE(MP_QSTR_trezorproto, mp_module_trezorproto, MP_REGISTER_MODULE(MP_QSTR_trezorproto, mp_module_trezorproto);
MICROPY_PY_TREZORPROTO);
#endif // MICROPY_PY_TREZORPROTO #endif // MICROPY_PY_TREZORPROTO

View File

@ -23,7 +23,6 @@
#include "librust.h" #include "librust.h"
MP_REGISTER_MODULE(MP_QSTR_trezorui2, mp_module_trezorui2, MP_REGISTER_MODULE(MP_QSTR_trezorui2, mp_module_trezorui2);
MICROPY_PY_TREZORUI2);
#endif // MICROPY_PY_TREZORUI2 #endif // MICROPY_PY_TREZORUI2

View File

@ -54,7 +54,7 @@ bool trezor_obj_get_ll_checked(mp_obj_t obj, long long *value) {
*value = MP_OBJ_SMALL_INT_VALUE(obj); *value = MP_OBJ_SMALL_INT_VALUE(obj);
return true; return true;
} else if (mp_obj_is_type(obj, &mp_type_int)) { } else if (mp_obj_is_int(obj)) {
// Value is not fitting into small int range, but is an integer. // Value is not fitting into small int range, but is an integer.
mp_obj_int_t *self = MP_OBJ_TO_PTR(obj); mp_obj_int_t *self = MP_OBJ_TO_PTR(obj);
// Try to get the long long value out of the MPZ struct. // Try to get the long long value out of the MPZ struct.

View File

@ -23,6 +23,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "py/builtin.h"
#include "py/compile.h" #include "py/compile.h"
#include "py/gc.h" #include "py/gc.h"
#include "py/mperrno.h" #include "py/mperrno.h"
@ -173,9 +174,7 @@ int main(void) {
mp_init(); mp_init();
mp_obj_list_init(mp_sys_argv, 0); mp_obj_list_init(mp_sys_argv, 0);
mp_obj_list_init(mp_sys_path, 0); mp_obj_list_init(mp_sys_path, 0);
mp_obj_list_append( mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen));
mp_sys_path,
MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
// Execute the main script // Execute the main script
printf("CORE: Executing main script\n"); printf("CORE: Executing main script\n");

View File

@ -55,9 +55,12 @@
// optimisations // optimisations
#define MICROPY_OPT_COMPUTED_GOTO (1) #define MICROPY_OPT_COMPUTED_GOTO (1)
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
#define MICROPY_OPT_MPZ_BITWISE (1) #define MICROPY_OPT_MPZ_BITWISE (1)
#define MICROPY_OPT_MATH_FACTORIAL (0) #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 // Python internal features
#define MICROPY_READER_VFS (0) #define MICROPY_READER_VFS (0)
@ -129,6 +132,7 @@
#define MICROPY_PY_UCTYPES (1) #define MICROPY_PY_UCTYPES (1)
#define MICROPY_PY_UZLIB (0) #define MICROPY_PY_UZLIB (0)
#define MICROPY_PY_UJSON (0) #define MICROPY_PY_UJSON (0)
#define MICROPY_PY_UOS (0)
#define MICROPY_PY_URE (0) #define MICROPY_PY_URE (0)
#define MICROPY_PY_URE_SUB (0) #define MICROPY_PY_URE_SUB (0)
#define MICROPY_PY_UHEAPQ (0) #define MICROPY_PY_UHEAPQ (0)

View File

@ -41,3 +41,7 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) {
} }
void mp_hal_set_vcp_iface(int iface_num) { vcp_iface_num = iface_num; } 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) {}

View File

@ -1,5 +1,5 @@
enum Qstr { enum Qstr {
#define QDEF(id, str) id, #define QDEF(id, hash, len, str) id,
#include "genhdr/qstrdefs.generated.h" #include "genhdr/qstrdefs.generated.h"
#undef QDEF #undef QDEF
}; };

View File

@ -501,7 +501,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
#ifdef MICROPY_PY_SYS_PATH_DEFAULT #ifdef MICROPY_PY_SYS_PATH_DEFAULT
path = MICROPY_PY_SYS_PATH_DEFAULT; path = MICROPY_PY_SYS_PATH_DEFAULT;
#else #else
path = "~/.micropython/lib:/usr/lib/micropython"; path = ".frozen:~/.micropython/lib:/usr/lib/micropython";
#endif #endif
} }
size_t path_num = 1; // [0] is for current dir (or base dir of the script) size_t path_num = 1; // [0] is for current dir (or base dir of the script)
@ -724,3 +724,5 @@ void nlr_jump_fail(void *val) {
printf("FATAL: uncaught NLR %p\n", val); printf("FATAL: uncaught NLR %p\n", val);
exit(1); exit(1);
} }
MP_REGISTER_MODULE(MP_QSTR_uos, mp_module_uos);

View File

@ -60,9 +60,12 @@
// optimisations // optimisations
#define MICROPY_OPT_COMPUTED_GOTO (1) #define MICROPY_OPT_COMPUTED_GOTO (1)
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
#define MICROPY_OPT_MPZ_BITWISE (1) #define MICROPY_OPT_MPZ_BITWISE (1)
#define MICROPY_OPT_MATH_FACTORIAL (0) #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 // Python internal features
#define MICROPY_READER_VFS (0) #define MICROPY_READER_VFS (0)
@ -137,6 +140,13 @@
#define MICROPY_PY_UCTYPES (1) #define MICROPY_PY_UCTYPES (1)
#define MICROPY_PY_UZLIB (0) #define MICROPY_PY_UZLIB (0)
#define MICROPY_PY_UJSON (0) #define MICROPY_PY_UJSON (0)
#define MICROPY_PY_UOS (1)
#define MICROPY_PY_UOS_INCLUDEFILE "ports/unix/moduos.c"
#define MICROPY_PY_UOS_ERRNO (1)
#define MICROPY_PY_UOS_GETENV_PUTENV_UNSETENV (1)
#define MICROPY_PY_UOS_SEP (1)
#define MICROPY_PY_UOS_SYSTEM (1)
#define MICROPY_PY_UOS_URANDOM (1)
#define MICROPY_PY_URE (0) #define MICROPY_PY_URE (0)
#define MICROPY_PY_URE_SUB (0) #define MICROPY_PY_URE_SUB (0)
#define MICROPY_PY_UHEAPQ (0) #define MICROPY_PY_UHEAPQ (0)
@ -208,13 +218,6 @@ extern const struct _mp_print_t mp_stderr_print;
// ============= this ends common config section =================== // ============= this ends common config section ===================
// extra built in modules to add to the list of known ones
extern const struct _mp_obj_module_t mp_module_os;
#define MICROPY_PORT_BUILTIN_MODULES \
{ MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_os) },
// For size_t and ssize_t // For size_t and ssize_t
#include <unistd.h> #include <unistd.h>

View File

@ -4,7 +4,8 @@ import SCons.Builder
def generate(env): def generate(env):
env.SetDefault( env.SetDefault(
QSTRCOL='site_scons/site_tools/micropython/qstrdefs.py', ) QSTRCOL='site_scons/site_tools/micropython/qstrdefs.py',
MODULECOL='site_scons/site_tools/micropython/moduledefs.py', )
env['BUILDERS']['CollectQstr'] = SCons.Builder.Builder( env['BUILDERS']['CollectQstr'] = SCons.Builder.Builder(
action='$CC -E $CCFLAGS_QSTR $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES' action='$CC -E $CCFLAGS_QSTR $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES'
@ -19,6 +20,10 @@ def generate(env):
env['BUILDERS']['GenerateQstrDefs'] = SCons.Builder.Builder( env['BUILDERS']['GenerateQstrDefs'] = SCons.Builder.Builder(
action='$MAKEQSTRDATA $SOURCE > $TARGET', ) action='$MAKEQSTRDATA $SOURCE > $TARGET', )
env['BUILDERS']['CollectModules'] = SCons.Builder.Builder(
action='$CC -E $CCFLAGS_QSTR $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES'
' | $PYTHON $MODULECOL > $TARGET')
def generate_frozen_module(source, target, env, for_signature): def generate_frozen_module(source, target, env, for_signature):
target = str(target[0]) target = str(target[0])
source = str(source[0]) source = str(source[0])

View File

@ -0,0 +1,13 @@
import re
import sys
def process(source, target):
re_module = re.compile(r"MP_REGISTER_MODULE\(.*?,\s*.*?\);")
for line in source:
for match in re_module.findall(line):
target.write(f"{match}\n")
if __name__ == "__main__":
process(sys.stdin, sys.stdout)

2
vendor/micropython vendored

@ -1 +1 @@
Subproject commit fce614cbe213e3f6c9e1a2a9634d2c1edae7c57b Subproject commit 2e06e072519194ba76d3f11298c76a2733dd95ec