Files
lbuque 4b8dbf65b9 all: Add copyright information.
Signed-off-by: lbuque <1102390310@qq.com>
2024-03-21 12:21:51 +08:00

59 lines
1.5 KiB
Python

# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
#
# SPDX-License-Identifier: MIT
# Combine bootloader, partition table and application into a final binary.
import cmd
import os, sys
sys.path.append(os.getenv("IDF_PATH") + "/components/partition_table")
import gen_esp32part
def load_partition_table(filename):
with open(filename, "rb") as f:
return gen_esp32part.PartitionTable.from_binary(f.read())
# Extract command-line arguments.
arg_littlefs2_exec = sys.argv[1]
arg_board_type_in = sys.argv[2]
arg_filesystem_in = sys.argv[3]
arg_filesystem_out = sys.argv[4]
arg_partitions_bin = sys.argv[5]
# Load the partition table.
partition_table = load_partition_table(arg_partitions_bin)
max_size_filesystem = None
# Inspect the partition table to find offsets and maximum sizes.
for part in partition_table:
if (
part.type == gen_esp32part.DATA_TYPE
and part.name == "sys"
and "system" in arg_filesystem_out
):
max_size_filesystem = part.size
elif (
part.type == gen_esp32part.DATA_TYPE
and part.name == "vfs"
and "user" in arg_filesystem_out
):
max_size_filesystem = part.size
# print("fs partition size: 0x%x bytes" % max_size_filesystem)
if max_size_filesystem is not None:
cmd_line = "{} -c -b {} -i {} -o {} -s {}".format(
arg_littlefs2_exec,
arg_board_type_in,
arg_filesystem_in,
arg_filesystem_out,
hex(max_size_filesystem),
)
os.system(cmd_line)