Merge branch 'partition/not_aligned_is_error' into 'master'

gen_esp32part.py: misaligned partitions now raise an exception

Closes IDF-3742

See merge request espressif/esp-idf!17368
This commit is contained in:
Ivan Grokhotkov 2022-03-23 18:34:55 +08:00
commit d17220fc66
3 changed files with 17 additions and 22 deletions

View File

@ -84,13 +84,10 @@ def get_subtype_as_int(ptype, subtype):
ALIGNMENT = {
APP_TYPE: 0x10000,
DATA_TYPE: 0x4,
DATA_TYPE: 0x1000,
}
STRICT_DATA_ALIGNMENT = 0x1000
def get_alignment_for_type(ptype):
return ALIGNMENT.get(ptype, ALIGNMENT[DATA_TYPE])
@ -400,11 +397,6 @@ class PartitionDefinition(object):
align = get_alignment_for_type(self.type)
if self.offset % align:
raise ValidationError(self, 'Offset 0x%x is not aligned to 0x%x' % (self.offset, align))
# The alignment requirement for non-app partition is 4 bytes, but it should be 4 kB.
# Print a warning for now, make it an error in IDF 5.0 (IDF-3742).
if self.type != APP_TYPE and self.offset % STRICT_DATA_ALIGNMENT:
critical('WARNING: Partition %s not aligned to 0x%x.'
'This is deprecated and will be considered an error in the future release.' % (self.name, STRICT_DATA_ALIGNMENT))
if self.size % align and secure and self.type == APP_TYPE:
raise ValidationError(self, 'Size 0x%x is not aligned to 0x%x' % (self.size, align))
if self.size is None:

View File

@ -393,6 +393,17 @@ class VerificationTests(Py23TestCase):
csv = """
# Name,Type, SubType,Offset,Size
app,app, factory, 32K, 1M
"""
with self.assertRaisesRegex(gen_esp32part.ValidationError, r'Offset.+not aligned'):
t = gen_esp32part.PartitionTable.from_csv(csv)
t.verify()
csv = """
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9420, 0x6000,
phy_init, data, phy, , 0x1000,
factory, app, factory, , 1M,
"""
with self.assertRaisesRegex(gen_esp32part.ValidationError, r'Offset.+not aligned'):
t = gen_esp32part.PartitionTable.from_csv(csv)
@ -453,19 +464,6 @@ ota_1, 0, ota_1, , 1M,
self.assertIn('WARNING', sys.stderr.getvalue())
self.assertIn('partition subtype', sys.stderr.getvalue())
sys.stderr = io.StringIO()
csv_3 = 'nvs, data, nvs, 0x8800, 32k'
gen_esp32part.PartitionTable.from_csv(csv_3).verify()
self.assertIn('WARNING', sys.stderr.getvalue())
self.assertIn('not aligned to 0x1000', sys.stderr.getvalue())
sys.stderr = io.StringIO()
csv_4 = 'factory, app, factory, 0x10000, 0x100100\n' \
'nvs, data, nvs, , 32k'
gen_esp32part.PartitionTable.from_csv(csv_4).verify()
self.assertIn('WARNING', sys.stderr.getvalue())
self.assertIn('not aligned to 0x1000', sys.stderr.getvalue())
finally:
sys.stderr = sys.__stderr__

View File

@ -8,3 +8,8 @@ f_mkfs() signature change in FATFS v0.14
----------------------------------------
New signature is ``FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len);`` which now uses ``MKFS_PARM`` struct as a second argument.
Partition table generation no longer supports misaligned partitions
-------------------------------------------------------------------
When generating a partiton table, ``esp-idf`` will no longer accept partitions which offset does not align to 4kB. This change only affects generating new partition tables, reading and writing to already existing partitions remains unchanged.