From 6bc7b4b5e27f72250718152121215e99f9d09291 Mon Sep 17 00:00:00 2001 From: Matus Fabo Date: Thu, 3 Mar 2022 00:16:11 +0100 Subject: [PATCH] change: misaligned partitions now raise an exception change: alignment for data partitions is now 4kB instead of 4B remove: STRICT_DATA_ALIGNMENT variable remove: warning tests for misaligned partitions add: assertion test for misaligned partitions add: breaking change documentation --- components/partition_table/gen_esp32part.py | 10 +------- .../gen_esp32part_tests.py | 24 +++++++++---------- docs/en/migration-guides/storage.rst | 5 ++++ 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/components/partition_table/gen_esp32part.py b/components/partition_table/gen_esp32part.py index ba6ba6c5da..2917d95ab2 100755 --- a/components/partition_table/gen_esp32part.py +++ b/components/partition_table/gen_esp32part.py @@ -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: diff --git a/components/partition_table/test_gen_esp32part_host/gen_esp32part_tests.py b/components/partition_table/test_gen_esp32part_host/gen_esp32part_tests.py index 7ba1878151..c82b26df66 100755 --- a/components/partition_table/test_gen_esp32part_host/gen_esp32part_tests.py +++ b/components/partition_table/test_gen_esp32part_host/gen_esp32part_tests.py @@ -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__ diff --git a/docs/en/migration-guides/storage.rst b/docs/en/migration-guides/storage.rst index 8705ab3293..3603152606 100644 --- a/docs/en/migration-guides/storage.rst +++ b/docs/en/migration-guides/storage.rst @@ -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. \ No newline at end of file