cmake partition_table: Check binaries fit in partition spaces at build time

- Bootloader is checked not to overlap partition table
- Apps are checked not to overlap any app partition regions

Supported for CMake build system only.

Closes https://github.com/espressif/esp-idf/pull/612
Closes https://github.com/espressif/esp-idf/issues/5043
Probable fix for https://github.com/espressif/esp-idf/issues/5456
This commit is contained in:
Angus Gratton
2020-06-24 15:52:50 +10:00
parent bc3d45026c
commit 6f6b4c3983
13 changed files with 423 additions and 46 deletions

View File

@@ -48,6 +48,18 @@ TYPES = {
'data': DATA_TYPE,
}
def get_ptype_as_int(ptype):
""" Convert a string which might be numeric or the name of a partition type to an integer """
try:
return TYPES[ptype]
except KeyError:
try:
return int(ptype, 0)
except TypeError:
return ptype
# Keep this map in sync with esp_partition_subtype_t enum in esp_partition.h
SUBTYPES = {
APP_TYPE: {
@@ -67,6 +79,18 @@ SUBTYPES = {
},
}
def get_subtype_as_int(ptype, subtype):
""" Convert a string which might be numeric or the name of a partition subtype to an integer """
try:
return SUBTYPES[get_ptype_as_int(ptype)][subtype]
except KeyError:
try:
return int(subtype, 0)
except TypeError:
return subtype
quiet = False
md5sum = True
secure = False
@@ -89,6 +113,18 @@ class PartitionTable(list):
def __init__(self):
super(PartitionTable, self).__init__(self)
@classmethod
def from_file(cls, f):
input = f.read()
input_is_binary = input[0:2] == PartitionDefinition.MAGIC_BYTES
if input_is_binary:
status('Parsing binary partition input...')
return cls.from_binary(input), True
else:
input = input.decode()
status('Parsing CSV input...')
return cls.from_csv(input), False
@classmethod
def from_csv(cls, csv_contents):
res = PartitionTable()
@@ -149,20 +185,8 @@ class PartitionTable(list):
""" Return a partition by type & subtype, returns
None if not found """
# convert ptype & subtypes names (if supplied this way) to integer values
try:
ptype = TYPES[ptype]
except KeyError:
try:
ptype = int(ptype, 0)
except TypeError:
pass
try:
subtype = SUBTYPES[int(ptype)][subtype]
except KeyError:
try:
subtype = int(subtype, 0)
except TypeError:
pass
ptype = get_ptype_as_int(ptype)
subtype = get_subtype_as_int(subtype)
for p in self:
if p.type == ptype and p.subtype == subtype:
@@ -471,15 +495,7 @@ def main():
md5sum = not args.disable_md5sum
secure = args.secure
offset_part_table = int(args.offset, 0)
input = args.input.read()
input_is_binary = input[0:2] == PartitionDefinition.MAGIC_BYTES
if input_is_binary:
status('Parsing binary partition input...')
table = PartitionTable.from_binary(input)
else:
input = input.decode()
status('Parsing CSV input...')
table = PartitionTable.from_csv(input)
table, input_is_binary = PartitionTable.from_file(args.input)
if not args.no_verify:
status('Verifying table...')