Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit db80c0e

Browse files
committed
esp8266: Enable frozen bytecode, with scripts in modules/ subdir.
To start with, the critical scripts _boot.py and flashbdev.py are frozen to improve performance and reduce RAM consumption. Saves about 1000 bytes of heap RAM for a bare boot with filesystem.
1 parent b9e3fde commit db80c0e

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

esp8266/Makefile

+18
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ MICROPY_PY_USSL = 1
88
# include py core make definitions
99
include ../py/py.mk
1010

11+
MPY_CROSS = ../mpy-cross/mpy-cross
12+
MPY_TOOL = ../tools/mpy-tool.py
1113
MAKE_FROZEN = ../tools/make-frozen.py
1214

1315
SCRIPTDIR = scripts
16+
FROZEN_MPY_DIR = modules
1417
PORT ?= /dev/ttyACM0
1518
BAUD ?= 115200
1619
CROSS_COMPILE = xtensa-lx106-elf-
@@ -131,6 +134,9 @@ DRIVERS_SRC_C = $(addprefix drivers/,\
131134
SRC_S = \
132135
gchelper.s \
133136

137+
FROZEN_MPY_PY_FILES := $(shell find $(FROZEN_MPY_DIR)/ -type f -name '*.py')
138+
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
139+
134140
OBJ =
135141
OBJ += $(PY_O)
136142
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
@@ -139,6 +145,7 @@ OBJ += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o))
139145
OBJ += $(addprefix $(BUILD)/, $(EXTMOD_SRC_C:.c=.o))
140146
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
141147
OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o))
148+
OBJ += $(BUILD)/$(BUILD)/frozen_mpy.o
142149
#OBJ += $(BUILD)/pins_$(BOARD).o
143150

144151
# List of sources for qstr extraction
@@ -163,6 +170,17 @@ $(BUILD)/frozen.c: $(wildcard $(SCRIPTDIR)/*) $(CONFVARS_FILE)
163170
$(ECHO) "Generating $@"
164171
$(Q)$(MAKE_FROZEN) $(SCRIPTDIR) > $@
165172

173+
# to build .mpy files from .py files
174+
$(BUILD)/$(FROZEN_MPY_DIR)/%.mpy: $(FROZEN_MPY_DIR)/%.py
175+
@$(ECHO) "MPY $<"
176+
$(Q)$(MKDIR) -p $(dir $@)
177+
$(Q)$(MPY_CROSS) -o $@ -s $(^:$(FROZEN_MPY_DIR)/%=%) $^
178+
179+
# to build frozen_mpy.c from all .mpy files
180+
$(BUILD)/frozen_mpy.c: $(FROZEN_MPY_MPY_FILES) $(BUILD)/genhdr/qstrdefs.generated.h
181+
@$(ECHO) "Creating $@"
182+
$(Q)$(PYTHON) $(MPY_TOOL) -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h $(FROZEN_MPY_MPY_FILES) > $@
183+
166184
.PHONY: deploy
167185

168186
deploy: $(BUILD)/firmware-combined.bin
File renamed without changes.
File renamed without changes.

esp8266/mpconfigport.h

+2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@
7474
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
7575
#define MICROPY_STREAMS_NON_BLOCK (1)
7676
#define MICROPY_MODULE_FROZEN_STR (1)
77+
#define MICROPY_MODULE_FROZEN_MPY (1)
7778
#define MICROPY_MODULE_FROZEN_LEXER mp_lexer_new_from_str32
79+
#define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool
7880

7981
#define MICROPY_FATFS_ENABLE_LFN (1)
8082
#define MICROPY_FATFS_RPATH (2)

0 commit comments

Comments
 (0)