fix(partition_table): Ignore UTF-8 BOM bytes in csv file

This commit is contained in:
Konstantin Kondrashov
2025-05-07 17:22:45 +03:00
parent fe75355314
commit 41dd352149
7 changed files with 79 additions and 15 deletions

View File

@@ -62,6 +62,7 @@ class ParttoolTarget():
self.baud = baud
gen.offset_part_table = partition_table_offset
gen.quiet = True
def parse_esptool_args(esptool_args):
results = list()
@@ -82,17 +83,8 @@ class ParttoolTarget():
self.esptool_erase_args = parse_esptool_args(esptool_erase_args)
if partition_table_file:
partition_table = None
with open(partition_table_file, 'rb') as f:
input_is_binary = (f.read(2) == gen.PartitionDefinition.MAGIC_BYTES)
f.seek(0)
if input_is_binary:
partition_table = gen.PartitionTable.from_binary(f.read())
if partition_table is None:
with open(partition_table_file, 'r', encoding='utf-8') as f:
f.seek(0)
partition_table = gen.PartitionTable.from_csv(f.read())
partition_table, _ = gen.PartitionTable.from_file(f)
else:
temp_file = tempfile.NamedTemporaryFile(delete=False)
temp_file.close()