fix(partition_table): Check partition size for type APP

The size of partition of type APP should be multiple of 4 KB. Partition
generation tool now make this as a mandatory requirement. This is
minimum flash erase size. If the size of the APP type partition is not
aligned to 4 KB then the last erase operation could go beyond the allocated
partition and hence may fail. This issue would only be observed when the
firmware size grows very close to the allocated partition size, and hence
causing the OTA update to fail.

For already deployed devices on-field with the size of APP partition not
aligned to flash sector boundary, it is best to ensure that firmware
size always remains within the lower 4 KB boundary of the total
allocated space. While migrating to ESP-IDF 5.3 release, partition table
for an existing project can be adjusted accordingly for the build to
succeed.

Found during discussion in https://github.com/espressif/esp-idf/pull/12460
This commit is contained in:
Harshit Malpani
2023-10-30 18:04:25 +05:30
parent 7c738c0658
commit bbbede07d0
10 changed files with 50 additions and 34 deletions

View File

@@ -98,14 +98,18 @@ def get_alignment_offset_for_type(ptype):
def get_alignment_size_for_type(ptype):
if ptype == APP_TYPE and secure == SECURE_V1:
# For secure boot v1 case, app partition must be 64K aligned
# signature block (68 bytes) lies at the very end of 64K block
return 0x10000
if ptype == APP_TYPE and secure == SECURE_V2:
# For secure boot v2 case, app partition must be 4K aligned
# signature block (4K) is kept after padding the unsigned image to 64K boundary
return 0x1000
if ptype == APP_TYPE:
if secure == SECURE_V1:
# For secure boot v1 case, app partition must be 64K aligned
# signature block (68 bytes) lies at the very end of 64K block
return 0x10000
elif secure == SECURE_V2:
# For secure boot v2 case, app partition must be 4K aligned
# signature block (4K) is kept after padding the unsigned image to 64K boundary
return 0x1000
else:
# For no secure boot enabled case, app partition must be 4K aligned (min. flash erase size)
return 0x1000
# No specific size alignement requirement as such
return 0x1
@@ -441,7 +445,7 @@ class PartitionDefinition(object):
offset_align = get_alignment_offset_for_type(self.type)
if self.offset % offset_align:
raise ValidationError(self, 'Offset 0x%x is not aligned to 0x%x' % (self.offset, offset_align))
if self.type == APP_TYPE and secure is not SECURE_NONE:
if self.type == APP_TYPE:
size_align = get_alignment_size_for_type(self.type)
if self.size % size_align:
raise ValidationError(self, 'Size 0x%x is not aligned to 0x%x' % (self.size, size_align))