Skip to content

Commit 51743d0

Browse files
committed
makefile: nvs, fs and flash command support
1. <make nvs> generate the nvs partition binary file 2. <make fs> pack the fs folder into fs.bin binary file 3. <make flash> flash the whole firmware file(nvs + app + fs)
1 parent b230ad4 commit 51743d0

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

m5stack/Makefile

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# Select the board to build for, defaulting to GENERIC.
66
BOARD ?= m5stack
7+
CHIP ?= esp32
78

89
# If the build directory is not given, make it reflect the board name.
910
BUILD ?= build-$(BOARD)
@@ -17,7 +18,7 @@ PYTHON ?= python3
1718

1819
GIT_SUBMODULES = lib/berkeley-db-1.xx
1920

20-
.PHONY: all clean deploy erase mpy-cross submodules FORCE
21+
.PHONY: all clean deploy erase mpy-cross submodules fs nvs FORCE
2122

2223
MAKEFILE_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
2324

@@ -35,14 +36,18 @@ ifdef FROZEN_MANIFEST
3536
IDFPY_FLAGS += -D MICROPY_FROZEN_MANIFEST=$(FROZEN_MANIFEST)
3637
endif
3738

38-
all:
39+
GIT_VERSION := $(shell git describe --abbrev=7 --dirty --always --tags)
40+
41+
all: fs nvs
3942
idf.py $(IDFPY_FLAGS) build
4043
@$(PYTHON) makeimg.py \
4144
$(BUILD)/sdkconfig \
4245
$(BUILD)/bootloader/bootloader.bin \
4346
$(BUILD)/partition_table/partition-table.bin \
44-
$(BUILD)/micropython.bin \
45-
$(BUILD)/firmware.bin
47+
$(BUILD)/nvs.bin \
48+
$(BUILD)/micropython.bin \
49+
$(BUILD)/fs.bin \
50+
$(BUILD)/uiflow-$(GIT_VERSION).bin
4651

4752
$(BUILD)/bootloader/bootloader.bin $(BUILD)/partition_table/partition-table.bin $(BUILD)/micropython.bin: FORCE
4853

@@ -58,6 +63,18 @@ monitor:
5863
erase:
5964
idf.py $(IDFPY_FLAGS) -p $(PORT) -b $(BAUD) erase_flash
6065

66+
flash: all
67+
esptool.py --chip $(CHIP) --port $(PORT) --baud $(BAUD) \
68+
write_flash 0x1000 $(BUILD)/uiflow-$(GIT_VERSION).bin
69+
70+
fs:
71+
./../tools/littlefs/prebuilt/linux/littlefs2 -c -v -i ./fs \
72+
-o $(BUILD)/fs.bin -s 0x14e000 # defined in partitions.csv
73+
74+
nvs:
75+
python ./../tools/nvs_partition_gen.py generate partition_nvs.csv \
76+
$(BUILD)/nvs.bin 0x6000 # defined in partitions.csv
77+
6178
mpy-cross:
6279
make -C ../micropython/mpy-cross
6380

@@ -66,4 +83,4 @@ mpy-cross:
6683
# berkeley-db-1.xx submodule belong to micropython submodule
6784
submodules:
6885
git submodule update --init ../micropython
69-
cd ./../micropython && git submodule update --init $(addprefix ./,$(GIT_SUBMODULES)) && cd -
86+
cd ./../micropython && git submodule update --init $(addprefix ./,$(GIT_SUBMODULES)) && cd -

m5stack/makeimg.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ def load_partition_table(filename):
2828
arg_sdkconfig = sys.argv[1]
2929
arg_bootloader_bin = sys.argv[2]
3030
arg_partitions_bin = sys.argv[3]
31-
arg_application_bin = sys.argv[4]
32-
arg_output_bin = sys.argv[5]
31+
arg_nvs_bin = sys.argv[4]
32+
arg_application_bin = sys.argv[5]
33+
arg_filesystem_bin = sys.argv[6]
34+
arg_output_bin = sys.argv[7]
3335

3436
# Load required sdkconfig values.
3537
offset_bootloader = load_sdkconfig_hex_value(
@@ -44,22 +46,34 @@ def load_partition_table(filename):
4446

4547
max_size_bootloader = offset_partitions - offset_bootloader
4648
max_size_partitions = 0
49+
offset_nvs = 0
50+
max_size_nvs = 0
4751
offset_application = 0
4852
max_size_application = 0
53+
offset_filesystem = 0
54+
max_size_filesystem = 0
4955

5056
# Inspect the partition table to find offsets and maximum sizes.
5157
for part in partition_table:
5258
if part.name == "nvs":
5359
max_size_partitions = part.offset - offset_partitions
60+
offset_nvs = part.offset
61+
max_size_nvs = part.size
5462
elif part.type == gen_esp32part.APP_TYPE and offset_application == 0:
5563
offset_application = part.offset
5664
max_size_application = part.size
65+
elif part.type == gen_esp32part.DATA_TYPE and part.name == "vfs":
66+
offset_filesystem = part.offset
67+
max_size_filesystem = part.size
68+
5769

5870
# Define the input files, their location and maximum size.
5971
files_in = [
6072
("bootloader", offset_bootloader, max_size_bootloader, arg_bootloader_bin),
6173
("partitions", offset_partitions, max_size_partitions, arg_partitions_bin),
74+
("nvs", offset_nvs, max_size_nvs, arg_nvs_bin),
6275
("application", offset_application, max_size_application, arg_application_bin),
76+
("filesystem", offset_filesystem, max_size_filesystem, arg_filesystem_bin),
6377
]
6478
file_out = arg_output_bin
6579

0 commit comments

Comments
 (0)