]> granicus.if.org Git - esp-idf/commitdiff
gen_esp32part.py: Correctly error out for non-64KB aligned app partitions
authorAngus Gratton <angus@espressif.com>
Fri, 12 May 2017 02:07:59 +0000 (12:07 +1000)
committerAngus Gratton <gus@projectgus.com>
Fri, 12 May 2017 02:27:53 +0000 (12:27 +1000)
Also clean up error handling for verification errors in general.

Ref https://esp32.com/viewtopic.php?f=13&t=1838&p=8685#p8659

components/partition_table/gen_esp32part.py
components/partition_table/tests/gen_esp32part_tests.py

index d1c5aac63e921926b6acb5bb3184af4e9380944f..2600ac214dbb5d61c3f1ecb5415c5b71c408fa4d 100755 (executable)
@@ -155,7 +155,7 @@ class PartitionDefinition(object):
     MAGIC_BYTES = b"\xAA\x50"
 
     ALIGNMENT = {
-        APP_TYPE : 0x1000,
+        APP_TYPE : 0x10000,
         DATA_TYPE : 0x04,
     }
 
@@ -241,16 +241,16 @@ class PartitionDefinition(object):
 
     def verify(self):
         if self.type is None:
-            raise ValidationError("Type field is not set")
+            raise ValidationError(self, "Type field is not set")
         if self.subtype is None:
-            raise ValidationError("Subtype field is not set")
+            raise ValidationError(self, "Subtype field is not set")
         if self.offset is None:
-            raise ValidationError("Offset field is not set")
+            raise ValidationError(self, "Offset field is not set")
         align = self.ALIGNMENT.get(self.type, 4)
         if self.offset % align:
-            raise ValidationError("%s offset 0x%x is not aligned to 0x%x" % (self.name, self.offset, align))
+            raise ValidationError(self, "Offset 0x%x is not aligned to 0x%x" % (self.offset, align))
         if self.size is None:
-            raise ValidationError("Size field is not set")
+            raise ValidationError(self, "Size field is not set")
 
     STRUCT_FORMAT = "<2sBBLL16sL"
 
@@ -311,9 +311,6 @@ class PartitionDefinition(object):
                           addr_format(self.size, True),
                           generate_text_flags()])
 
-class InputError(RuntimeError):
-    def __init__(self, e):
-        super(InputError, self).__init__(e)
 
 def parse_int(v, keywords={}):
     """Generic parser for integer fields - int(x,0) with provision for
@@ -370,6 +367,18 @@ def main():
         with sys.stdout.buffer if args.output == '-' else open(args.output, 'wb') as f:
             f.write(output)
 
+
+class InputError(RuntimeError):
+    def __init__(self, e):
+        super(InputError, self).__init__(e)
+
+
+class ValidationError(InputError):
+    def __init__(self, partition, message):
+        super(ValidationError, self).__init__(
+            "Partition %s invalid: %s" % (partition.name, message))
+
+
 if __name__ == '__main__':
     try:
         main()
index 1591c3012216a0e49991284bfdbd493c951dd20a..46fe45c228516b8b0560b2d1e8013ec84709d67b 100755 (executable)
@@ -111,11 +111,11 @@ myota_status, data, ota,, 0x100000
     def test_unit_suffixes(self):
         csv = """
 # Name, Type, Subtype, Offset, Size
-one_megabyte, app, factory, 32k, 1M
+one_megabyte, app, factory, 64k, 1M
 """
         t = PartitionTable.from_csv(csv)
         t.verify()
-        self.assertEqual(t[0].offset, 32*1024)
+        self.assertEqual(t[0].offset, 64*1024)
         self.assertEqual(t[0].size, 1*1024*1024)
 
     def test_default_offsets(self):
@@ -337,5 +337,18 @@ class CommandLineTests(unittest.TestCase):
                     pass
 
 
+class VerificationTests(unittest.TestCase):
+
+    def test_bad_alignment(self):
+        csv = """
+# Name,Type, SubType,Offset,Size
+app,app, factory, 32K, 1M
+"""
+        with self.assertRaisesRegexp(ValidationError,
+                                     r"Offset.+not aligned"):
+            t = PartitionTable.from_csv(csv)
+            t.verify()
+
+
 if __name__ =="__main__":
     unittest.main()