Skip to content

Commit 71b3ce3

Browse files
committed
esp32: Create .uf2 binaries for S2 and S3 chips.
The name of the filesystem partition is updated to support "ffat", as used by TinyUF2. Signed-off-by: Damien George <[email protected]>
1 parent 59b6099 commit 71b3ce3

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

ports/esp32/Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ all:
3636
$(BUILD)/sdkconfig \
3737
$(BUILD)/bootloader/bootloader.bin \
3838
$(BUILD)/partition_table/partition-table.bin \
39-
$(BUILD)/micropython.bin \
40-
$(BUILD)/firmware.bin
39+
$(BUILD)/micropython.bin \
40+
$(BUILD)/firmware.bin \
41+
$(BUILD)/micropython.uf2
4142

4243
$(BUILD)/bootloader/bootloader.bin $(BUILD)/partition_table/partition-table.bin $(BUILD)/micropython.bin: FORCE
4344

ports/esp32/makeimg.py

+29-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,29 @@
1010
OFFSET_PARTITIONS_DEFAULT = 0x8000
1111

1212

13-
def load_sdkconfig_hex_value(filename, value, default):
13+
def load_sdkconfig_value(filename, value, default):
1414
value = "CONFIG_" + value + "="
1515
with open(filename, "r") as f:
1616
for line in f:
1717
if line.startswith(value):
18-
return int(line.split("=", 1)[1], 16)
18+
return line.split("=", 1)[1]
1919
return default
2020

2121

22+
def load_sdkconfig_hex_value(filename, value, default):
23+
value = load_sdkconfig_value(filename, value, None)
24+
if value is None:
25+
return default
26+
return int(value, 16)
27+
28+
29+
def load_sdkconfig_str_value(filename, value, default):
30+
value = load_sdkconfig_value(filename, value, None)
31+
if value is None:
32+
return default
33+
return value.strip().strip('"')
34+
35+
2236
def load_partition_table(filename):
2337
with open(filename, "rb") as f:
2438
return gen_esp32part.PartitionTable.from_binary(f.read())
@@ -30,8 +44,10 @@ def load_partition_table(filename):
3044
arg_partitions_bin = sys.argv[3]
3145
arg_application_bin = sys.argv[4]
3246
arg_output_bin = sys.argv[5]
47+
arg_output_uf2 = sys.argv[6]
3348

3449
# Load required sdkconfig values.
50+
idf_target = load_sdkconfig_str_value(arg_sdkconfig, "IDF_TARGET", "").upper()
3551
offset_bootloader = load_sdkconfig_hex_value(
3652
arg_sdkconfig, "BOOTLOADER_OFFSET_IN_FLASH", OFFSET_BOOTLOADER_DEFAULT
3753
)
@@ -85,3 +101,14 @@ def load_partition_table(filename):
85101
)
86102
sys.exit(1)
87103
print("%-22s% 8d" % ("total", cur_offset))
104+
105+
# Generate .uf2 file if the SoC has native USB.
106+
if idf_target in ("ESP32S2", "ESP32S3"):
107+
sys.path.append(os.path.join(os.path.dirname(__file__), "../../tools"))
108+
import uf2conv
109+
110+
families = uf2conv.load_families()
111+
uf2conv.appstartaddr = 0
112+
uf2conv.familyid = families[idf_target]
113+
with open(arg_application_bin, "rb") as fin, open(arg_output_uf2, "wb") as fout:
114+
fout.write(uf2conv.convert_to_uf2(fin.read()))

ports/esp32/modules/flashbdev.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from esp32 import Partition
22

3+
# MicroPython's partition table uses "vfs", TinyUF2 uses "ffat".
34
bdev = Partition.find(Partition.TYPE_DATA, label="vfs")
5+
if not bdev:
6+
bdev = Partition.find(Partition.TYPE_DATA, label="ffat")
47
bdev = bdev[0] if bdev else None

0 commit comments

Comments
 (0)