forked from m5stack/uiflow-micropython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
314 lines (268 loc) · 9.93 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
#
# SPDX-License-Identifier: MIT
# Makefile for MicroPython on ESP32.
#
# This is a simple, convenience wrapper around idf.py (which uses cmake).
-include .workenv
BOARD ?= M5STACK_AtomS3
boards := \
M5STACK_AtomS3:atoms3 \
M5STACK_AtomS3_Lite:atoms3-lite \
M5STACK_StampS3:stamps3 \
M5STACK_CoreS3:cores3 \
M5STACK_AtomS3U:atoms3u \
M5STACK_Core2:core2 \
M5STACK_Tough:tough \
M5STACK_StickC_PLUS2:stickcplus2 \
M5STACK_StickC_PLUS:stickcplus \
M5STACK_Fire:fire \
M5STACK_NanoC6:nanoc6 \
M5STACK_Basic:basic \
M5STACK_Basic_4MB:basic \
M5STACK_Capsule:capsule \
M5STACK_CoreInk:coreink \
M5STACK_AirQ:airq \
M5STACK_Dial:dial \
M5STACK_Cardputer:cardputer \
M5STACK_Paper:paper \
M5STACK_PaperS3:papers3 \
M5STACK_DinMeter:dinmeter \
M5STACK_StickC:stickc \
M5STACK_Station:station \
M5STACK_Atom_Lite:atom-lite \
M5STACK_Stamp_PICO:stamppico \
M5STACK_Atom_Matrix:atommatrix \
M5STACK_AtomU:atomu \
M5STACK_Atom_Echo:atomecho \
M5STACK_AtomS3R:atoms3r
define find_board
$(if $(filter $(1):%,$(boards)),$(word 2,$(subst :, ,$(filter $(1):%,$(boards)))),none)
endef
# Board type list
BOARD_TYPE_DEF := \
none \
atoms3 \
atoms3-lite \
stamps3 \
cores3 \
atoms3u \
core2 \
tough \
stickcplus2 \
stickcplus \
fire \
nanoc6 \
basic \
capsule \
coreink \
airq \
dial \
cardputer \
paper \
papers3 \
dinmeter \
stickc \
station \
atom-lite \
stamppico \
atommatrix \
atomu \
atomecho \
atoms3r
# Select the board type to build, default is None
# This value affects which folder in the "./fs/system/" directory is pack into "fs-system.bin"
# If use default value, it means no directory will pack into "fs-system.bin"
BOARD_TYPE ?= $(call find_board,$(BOARD))
ifneq ($(filter $(BOARD_TYPE),$(BOARD_TYPE_DEF)),)
else
$(error Board type $(BOARD_TYPE) does not exist in list [$(BOARD_TYPE_DEF)])
endif
TINY_BOARD_TYPE_DEF = \
M5STACK_StickC_PLUS \
M5STACK_Basic_4MB \
M5STACK_CoreInk \
M5STACK_StickC \
M5STACK_Atom_Lite \
M5STACK_Stamp_PICO \
M5STACK_Atom_Matrix \
M5STACK_AtomU \
M5STACK_Atom_Echo \
M5STACK_NanoC6
ifneq ($(filter $(BOARD),$(TINY_BOARD_TYPE_DEF)),)
TINY_FLAG ?= 1
else
TINY_FLAG ?= 0
endif
# esp32c3's bootloader is different with esp32
ifeq (C3, $(findstring C3,${BOARD}))
CHIP ?= esp32c3
else ifeq (S3, $(findstring S3,${BOARD}))
CHIP ?= esp32s3
else
CHIP ?= esp32
endif
# If the build directory is not given, make it reflect the board name.
BUILD ?= build-$(BOARD)
# Device serial settings.
PORT ?= /dev/ttyUSB0
BAUD ?= 1500000
PYTHON ?= python3
GIT_SUBMODULES = lib/berkeley-db-1.xx lib/micropython-lib
MAKEFILE_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
USER_C_MODULES = $(MAKEFILE_DIR)cmodules/cmodules.cmake
CMAKE_ARGS =
ifdef USER_C_MODULES
CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES}
endif
IDFPY_FLAGS += -DMICROPY_BOARD=$(BOARD) -DBUILD_WITH_LVGL=$(LVGL) -B$(BUILD) $(CMAKE_ARGS)
IDFPY_FLAGS += -DBOARD_TYPE=$(BOARD_TYPE)
ifdef FROZEN_MANIFEST
IDFPY_FLAGS += -D MICROPY_FROZEN_MANIFEST=$(FROZEN_MANIFEST)
endif
LVGL_FLAG = 0
ifdef LVGL
LVGL_FLAG = 1
endif
GIT_VERSION := $(shell git rev-parse --short HEAD)
include ./include/files.mk
define pack_fw
$(1) makeimg.py \
$(BUILD)/sdkconfig \
$(BUILD)/bootloader/bootloader.bin \
$(BUILD)/partition_table/partition-table.bin \
$(BUILD)/nvs.bin \
$(BUILD)/micropython.bin \
$(BUILD)/fs-system.bin \
$(2) \
$(BOARD_TYPE) \
$(LVGL_FLAG) \
$(BUILD)/uiflow-$(GIT_VERSION).bin \
$(BUILD)/uiflow-Sx-$(GIT_VERSION).uf2
endef
export ADF_PATH=$(abspath ../esp-adf)
.PHONY: all menu build deploy flash flash_all clean erase nvs fs pack pack_all littlefs mpy-cross submodules FORCE
all: nvs fs pack
@echo ""
@echo "Done, default packed firmware don't include vfs filesystem, if need vfs filesystem, please use 'make pack_all' command."
$(BUILD)/bootloader/bootloader.bin $(BUILD)/partition_table/partition-table.bin $(BUILD)/micropython.bin: FORCE
# Config menu
menu:
idf.py $(IDFPY_FLAGS) menuconfig
# Show the size summary
size:
idf.py $(IDFPY_FLAGS) size
# Build the MicroPython firmware
build: nvs
idf.py $(IDFPY_FLAGS) build
# Deploy the MicroPython firmware
deploy: build
idf.py $(IDFPY_FLAGS) -p $(PORT) -b $(BAUD) flash
# Deploy the MicroPython and system filesystem
flash: pack
esptool.py --chip $(CHIP) --port $(PORT) --baud $(BAUD) write_flash 0x0 $(BUILD)/uiflow-$(GIT_VERSION).bin
# Deploy the MicroPython, system filesystem and user filesystem
flash_all: pack_all
esptool.py --chip $(CHIP) --port $(PORT) --baud $(BAUD) write_flash 0x0 $(BUILD)/uiflow-$(GIT_VERSION).bin
# Clean the build directory
clean:
idf.py $(IDFPY_FLAGS) fullclean
# Erase the flash chip
erase:
idf.py $(IDFPY_FLAGS) -p $(PORT) -b $(BAUD) erase_flash
# Run the serial monitor
monitor:
idf.py $(IDFPY_FLAGS) -p $(PORT) -b $(BAUD) monitor
# Build the NVS partition firmware
# fixed size 0x6000
nvs:
@$(PYTHON) ./../tools/nvs_partition_gen.py generate partition_nvs.csv $(BUILD)/nvs.bin 0x6000
# Build the system and user filesystem firmware
ifeq ($(TINY_FLAG),1)
fs: build
@if [ ! -d $(BUILD)/base-files ]; then \
mkdir -p $(BUILD)/base-files; \
fi
$(call base-files/install,$(BOARD_TYPE),$(BUILD)/base-files)
@$(PYTHON) \
./../tools/fs_packed.py \
./../tools/littlefs/prebuilt/littlefs2 \
$(BOARD_TYPE) \
$(BUILD)/base-files \
$(BUILD)/fs-user.bin \
$(BUILD)/partition_table/partition-table.bin
else
fs: build
@$(PYTHON) \
./../tools/fs_packed.py \
./../tools/littlefs/prebuilt/littlefs2 \
$(BOARD_TYPE) \
./fs/system \
$(BUILD)/fs-system.bin \
$(BUILD)/partition_table/partition-table.bin
@$(PYTHON) \
./../tools/fs_packed.py \
./../tools/littlefs/prebuilt/littlefs2 \
$(BOARD_TYPE) \
./fs/user \
$(BUILD)/fs-user.bin \
$(BUILD)/partition_table/partition-table.bin
endif
# Pack the firmware into a single binary without user filesystem.
# Released firmware needn't user filesystem.
pack: fs
$(call pack_fw,$(PYTHON),none)
# Pack the firmware into a single binary with user filesystem.
pack_all: fs
$(call pack_fw,$(PYTHON),$(BUILD)/fs-user.bin)
# Build littlefs tool
littlefs:
cd ./../tools/littlefs && rm -rf ./build && mkdir build && cd build && cmake .. && make -j && cp ./littlefs2 ./../prebuilt/
# Build mpy-cross compiler
mpy-cross:
make -C ../micropython/mpy-cross
# Running the build with ECHO_SUBMODULES set will trigger py/mkrules.cmake to
# print out the value of the GIT_SUBMODULES variable, prefixed with
# "GIT_SUBMODULES", and then abort. This extracts out that line from the idf.py
# output and passes the list of submodules to py/mkrules.mk which does the
# `git submodule init` on each.
submodules:
git submodule update --init ../tools/littlefs/mbed-littlefs
git submodule update --init ./components/esp32-camera
git submodule update --init ./components/esp_dl
git submodule update --init ./components/esp-code-scanner
git submodule update --init ./components/epdiy
git submodule update --init ./components/M5Unified/M5GFX
git submodule update --init ./components/M5Unified/M5Unified
git submodule update --init --recursive ./components/lv_bindings
git submodule update --init ../micropython
git submodule update --init ../esp-adf
cd ../esp-adf && \
git submodule update --init components/esp-adf-libs && \
git submodule update --init components/esp-sr && \
cd -
cd ../micropython && \
git submodule update --init lib/berkeley-db-1.xx && \
git submodule update --init lib/tinyusb && \
git submodule update --init lib/micropython-lib && \
cd -
# Apply patches
patch:
$(call Package/patche,$(abspath ./components/lv_bindings),$(abspath ./patches/0002_avoid_lv_bindings_compile_error.patch))
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0004-micropython-1.24-machine-adc-v5.x.diff))
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0005-micropython-fix-SDCard-16223.patch))
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0006-modtime-add-timezone-method.patch))
$(call Package/patche,$(abspath $(IDF_PATH)),$(abspath ./patches/1003-WIP-Compatible-with-esp-adf-v2.7.diff))
$(call Package/patche,$(abspath ./components/M5Unified/M5Unified),$(abspath ./patches/2003-Support-LTR553.patch))
$(call Package/patche,$(abspath $(ADF_PATH)),$(abspath ./patches/3002-Modify-i2s_stream_idf5.patch))
$(call Package/patche,$(abspath ./components/epdiy),$(abspath ./patches/4001-Avoid-epdiy-compilation-failure-on-esp32-c6.patch))
# Unapply patches
unpatch:
$(call Package/unpatche,$(abspath ./components/lv_bindings),$(abspath ./patches/0002_avoid_lv_bindings_compile_error.patch))
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0006-modtime-add-timezone-method.patch))
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0005-micropython-fix-SDCard-16223.patch))
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0004-micropython-1.24-machine-adc-v5.x.diff))
$(call Package/unpatche,$(abspath $(IDF_PATH)),$(abspath ./patches/1003-WIP-Compatible-with-esp-adf-v2.7.diff))
$(call Package/unpatche,$(abspath ./components/M5Unified/M5Unified),$(abspath ./patches/2003-Support-LTR553.patch))
$(call Package/unpatche,$(abspath $(ADF_PATH)),$(abspath ./patches/3002-Modify-i2s_stream_idf5.patch))
$(call Package/unpatche,$(abspath ./components/epdiy),$(abspath ./patches/4001-Avoid-epdiy-compilation-failure-on-esp32-c6.patch))