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 <damien@micropython.org>
This commit is contained in:
parent
59b6099508
commit
71b3ce3ace
|
@ -36,8 +36,9 @@ all:
|
||||||
$(BUILD)/sdkconfig \
|
$(BUILD)/sdkconfig \
|
||||||
$(BUILD)/bootloader/bootloader.bin \
|
$(BUILD)/bootloader/bootloader.bin \
|
||||||
$(BUILD)/partition_table/partition-table.bin \
|
$(BUILD)/partition_table/partition-table.bin \
|
||||||
$(BUILD)/micropython.bin \
|
$(BUILD)/micropython.bin \
|
||||||
$(BUILD)/firmware.bin
|
$(BUILD)/firmware.bin \
|
||||||
|
$(BUILD)/micropython.uf2
|
||||||
|
|
||||||
$(BUILD)/bootloader/bootloader.bin $(BUILD)/partition_table/partition-table.bin $(BUILD)/micropython.bin: FORCE
|
$(BUILD)/bootloader/bootloader.bin $(BUILD)/partition_table/partition-table.bin $(BUILD)/micropython.bin: FORCE
|
||||||
|
|
||||||
|
|
|
@ -10,15 +10,29 @@ OFFSET_BOOTLOADER_DEFAULT = 0x1000
|
||||||
OFFSET_PARTITIONS_DEFAULT = 0x8000
|
OFFSET_PARTITIONS_DEFAULT = 0x8000
|
||||||
|
|
||||||
|
|
||||||
def load_sdkconfig_hex_value(filename, value, default):
|
def load_sdkconfig_value(filename, value, default):
|
||||||
value = "CONFIG_" + value + "="
|
value = "CONFIG_" + value + "="
|
||||||
with open(filename, "r") as f:
|
with open(filename, "r") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
if line.startswith(value):
|
if line.startswith(value):
|
||||||
return int(line.split("=", 1)[1], 16)
|
return line.split("=", 1)[1]
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
def load_sdkconfig_hex_value(filename, value, default):
|
||||||
|
value = load_sdkconfig_value(filename, value, None)
|
||||||
|
if value is None:
|
||||||
|
return default
|
||||||
|
return int(value, 16)
|
||||||
|
|
||||||
|
|
||||||
|
def load_sdkconfig_str_value(filename, value, default):
|
||||||
|
value = load_sdkconfig_value(filename, value, None)
|
||||||
|
if value is None:
|
||||||
|
return default
|
||||||
|
return value.strip().strip('"')
|
||||||
|
|
||||||
|
|
||||||
def load_partition_table(filename):
|
def load_partition_table(filename):
|
||||||
with open(filename, "rb") as f:
|
with open(filename, "rb") as f:
|
||||||
return gen_esp32part.PartitionTable.from_binary(f.read())
|
return gen_esp32part.PartitionTable.from_binary(f.read())
|
||||||
|
@ -30,8 +44,10 @@ arg_bootloader_bin = sys.argv[2]
|
||||||
arg_partitions_bin = sys.argv[3]
|
arg_partitions_bin = sys.argv[3]
|
||||||
arg_application_bin = sys.argv[4]
|
arg_application_bin = sys.argv[4]
|
||||||
arg_output_bin = sys.argv[5]
|
arg_output_bin = sys.argv[5]
|
||||||
|
arg_output_uf2 = sys.argv[6]
|
||||||
|
|
||||||
# Load required sdkconfig values.
|
# Load required sdkconfig values.
|
||||||
|
idf_target = load_sdkconfig_str_value(arg_sdkconfig, "IDF_TARGET", "").upper()
|
||||||
offset_bootloader = load_sdkconfig_hex_value(
|
offset_bootloader = load_sdkconfig_hex_value(
|
||||||
arg_sdkconfig, "BOOTLOADER_OFFSET_IN_FLASH", OFFSET_BOOTLOADER_DEFAULT
|
arg_sdkconfig, "BOOTLOADER_OFFSET_IN_FLASH", OFFSET_BOOTLOADER_DEFAULT
|
||||||
)
|
)
|
||||||
|
@ -85,3 +101,14 @@ with open(file_out, "wb") as fout:
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
print("%-22s% 8d" % ("total", cur_offset))
|
print("%-22s% 8d" % ("total", cur_offset))
|
||||||
|
|
||||||
|
# Generate .uf2 file if the SoC has native USB.
|
||||||
|
if idf_target in ("ESP32S2", "ESP32S3"):
|
||||||
|
sys.path.append(os.path.join(os.path.dirname(__file__), "../../tools"))
|
||||||
|
import uf2conv
|
||||||
|
|
||||||
|
families = uf2conv.load_families()
|
||||||
|
uf2conv.appstartaddr = 0
|
||||||
|
uf2conv.familyid = families[idf_target]
|
||||||
|
with open(arg_application_bin, "rb") as fin, open(arg_output_uf2, "wb") as fout:
|
||||||
|
fout.write(uf2conv.convert_to_uf2(fin.read()))
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
from esp32 import Partition
|
from esp32 import Partition
|
||||||
|
|
||||||
|
# MicroPython's partition table uses "vfs", TinyUF2 uses "ffat".
|
||||||
bdev = Partition.find(Partition.TYPE_DATA, label="vfs")
|
bdev = Partition.find(Partition.TYPE_DATA, label="vfs")
|
||||||
|
if not bdev:
|
||||||
|
bdev = Partition.find(Partition.TYPE_DATA, label="ffat")
|
||||||
bdev = bdev[0] if bdev else None
|
bdev = bdev[0] if bdev else None
|
||||||
|
|
Loading…
Reference in New Issue