mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
gen_esp32part.py: Correctly error out for non-64KB aligned app partitions
Also clean up error handling for verification errors in general. Ref https://esp32.com/viewtopic.php?f=13&t=1838&p=8685#p8659
This commit is contained in:
parent
c9969ab996
commit
7eb0b3c2d7
@ -155,7 +155,7 @@ class PartitionDefinition(object):
|
|||||||
MAGIC_BYTES = b"\xAA\x50"
|
MAGIC_BYTES = b"\xAA\x50"
|
||||||
|
|
||||||
ALIGNMENT = {
|
ALIGNMENT = {
|
||||||
APP_TYPE : 0x1000,
|
APP_TYPE : 0x10000,
|
||||||
DATA_TYPE : 0x04,
|
DATA_TYPE : 0x04,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,16 +241,16 @@ class PartitionDefinition(object):
|
|||||||
|
|
||||||
def verify(self):
|
def verify(self):
|
||||||
if self.type is None:
|
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:
|
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:
|
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)
|
align = self.ALIGNMENT.get(self.type, 4)
|
||||||
if self.offset % align:
|
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:
|
if self.size is None:
|
||||||
raise ValidationError("Size field is not set")
|
raise ValidationError(self, "Size field is not set")
|
||||||
|
|
||||||
STRUCT_FORMAT = "<2sBBLL16sL"
|
STRUCT_FORMAT = "<2sBBLL16sL"
|
||||||
|
|
||||||
@ -311,9 +311,6 @@ class PartitionDefinition(object):
|
|||||||
addr_format(self.size, True),
|
addr_format(self.size, True),
|
||||||
generate_text_flags()])
|
generate_text_flags()])
|
||||||
|
|
||||||
class InputError(RuntimeError):
|
|
||||||
def __init__(self, e):
|
|
||||||
super(InputError, self).__init__(e)
|
|
||||||
|
|
||||||
def parse_int(v, keywords={}):
|
def parse_int(v, keywords={}):
|
||||||
"""Generic parser for integer fields - int(x,0) with provision for
|
"""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:
|
with sys.stdout.buffer if args.output == '-' else open(args.output, 'wb') as f:
|
||||||
f.write(output)
|
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__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
main()
|
main()
|
||||||
|
@ -111,11 +111,11 @@ myota_status, data, ota,, 0x100000
|
|||||||
def test_unit_suffixes(self):
|
def test_unit_suffixes(self):
|
||||||
csv = """
|
csv = """
|
||||||
# Name, Type, Subtype, Offset, Size
|
# Name, Type, Subtype, Offset, Size
|
||||||
one_megabyte, app, factory, 32k, 1M
|
one_megabyte, app, factory, 64k, 1M
|
||||||
"""
|
"""
|
||||||
t = PartitionTable.from_csv(csv)
|
t = PartitionTable.from_csv(csv)
|
||||||
t.verify()
|
t.verify()
|
||||||
self.assertEqual(t[0].offset, 32*1024)
|
self.assertEqual(t[0].offset, 64*1024)
|
||||||
self.assertEqual(t[0].size, 1*1024*1024)
|
self.assertEqual(t[0].size, 1*1024*1024)
|
||||||
|
|
||||||
def test_default_offsets(self):
|
def test_default_offsets(self):
|
||||||
@ -337,5 +337,18 @@ class CommandLineTests(unittest.TestCase):
|
|||||||
pass
|
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__":
|
if __name__ =="__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user