|
|
@@ -114,6 +114,16 @@ class PartitionTable(list):
|
|
|
raise InputError("Partition at 0x%x overlaps 0x%x-0x%x" % (p.offset, last.offset, last.offset+last.size-1))
|
|
|
last = p
|
|
|
|
|
|
+ def flash_size(self):
|
|
|
+ """ Return the size that partitions will occupy in flash
|
|
|
+ (ie the offset the last partition ends at)
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ last = sorted(self, reverse=True)[0]
|
|
|
+ except IndexError:
|
|
|
+ return 0 # empty table!
|
|
|
+ return last.offset + last.size
|
|
|
+
|
|
|
@classmethod
|
|
|
def from_binary(cls, b):
|
|
|
md5 = hashlib.md5();
|
|
|
@@ -350,6 +360,8 @@ def main():
|
|
|
global md5sum
|
|
|
parser = argparse.ArgumentParser(description='ESP32 partition table utility')
|
|
|
|
|
|
+ parser.add_argument('--flash-size', help='Optional flash size limit, checks partition table fits in flash',
|
|
|
+ nargs='?', choices=[ '1MB', '2MB', '4MB', '8MB', '16MB' ])
|
|
|
parser.add_argument('--disable-md5sum', help='Disable md5 checksum for the partition table', default=False, action='store_true')
|
|
|
parser.add_argument('--verify', '-v', help='Verify partition table fields', default=True, action='store_false')
|
|
|
parser.add_argument('--quiet', '-q', help="Don't print status messages to stderr", action='store_true')
|
|
|
@@ -377,6 +389,14 @@ def main():
|
|
|
status("Verifying table...")
|
|
|
table.verify()
|
|
|
|
|
|
+ if args.flash_size:
|
|
|
+ size_mb = int(args.flash_size.replace("MB", ""))
|
|
|
+ size = size_mb * 1024 * 1024 # flash memory uses honest megabytes!
|
|
|
+ table_size = table.flash_size()
|
|
|
+ if size < table_size:
|
|
|
+ raise InputError("Partitions defined in '%s' occupy %.1fMB of flash (%d bytes) which does not fit in configured flash size %dMB. Change the flash size in menuconfig under the 'Serial Flasher Config' menu." %
|
|
|
+ (args.input.name, table_size / 1024.0 / 1024.0, table_size, size_mb))
|
|
|
+
|
|
|
if input_is_binary:
|
|
|
output = table.to_csv()
|
|
|
with sys.stdout if args.output == '-' else open(args.output, 'w') as f:
|