Skip to content

Commit ce598b9

Browse files
committed
still messing with the partition size
1 parent f94c4a9 commit ce598b9

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

builder/esp32.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,15 @@ def get_app_size(self) -> int:
6464
return self.factory
6565

6666
def set_app_size(self, size):
67-
if int((self.factory + size) / 0x1000) * 0x1000 == self.factory + size:
68-
self.factory += size
69-
else:
70-
self.factory = (int((self.factory + size) / 0x1000) + 1) * 0x1000
67+
if int(size / 0x1000) * 0x1000 != size:
68+
size = (int(size / 0x1000) + 1) * 0x1000
69+
70+
if self.factory == size:
71+
return False
72+
73+
self.factory = size
74+
75+
return True
7176

7277
def save(self):
7378
offset = self.first_offset
@@ -937,16 +942,17 @@ def compile(*args): # NOQA
937942
sys.exit(ret_code)
938943

939944
if not skip_partition_resize and partition_size == -1:
940-
if 'partition is too small ' in output:
945+
if 'Error: app partition is too small' in output:
941946
sys.stdout.write(
942947
'\n\033[31;1m***** Resizing Partition *****\033[0m\n'
943948
)
944949
sys.stdout.flush()
945950

946-
end = output.split('(overflow ', 1)[-1]
947-
overflow_amount = int(end.split(')', 1)[0], 16)
951+
app_size = output.rsplit('Error: app partition is too small', 1)[1]
952+
app_size = app_size.split('micropython.bin size', 1)[1]
953+
app_size = int(app_size.split(':', 1)[0].strip(), 16)
948954

949-
partition.set_app_size(overflow_amount)
955+
partition.set_app_size(app_size)
950956
partition.save()
951957

952958
sys.stdout.write(
@@ -960,26 +966,22 @@ def compile(*args): # NOQA
960966
if ret_code != 0:
961967
sys.exit(ret_code)
962968

963-
elif 'Project build complete.' in output:
964-
app_size = output.rsplit('micropython.bin binary size ', 1)[1]
969+
if 'Project build complete.' in output:
970+
app_size = output.rsplit('Project build complete.', 1)[0]
971+
972+
app_size = app_size.rsplit('micropython.bin binary size', 1)[1]
965973
app_size = int(
966-
app_size.split(' bytes', 1)[0].strip(),
974+
app_size.split('bytes', 1)[0].strip(),
967975
16
968976
)
969977

970-
remaining = app_size - partition.get_app_size()
971-
972-
app_size
978+
if partition.set_app_size(app_size):
979+
partition.save()
973980

974-
if abs(remaining) > 0x1000:
975981
sys.stdout.write(
976982
'\n\033[31;1m***** Resizing Partition *****\033[0m\n'
977983
)
978984
sys.stdout.flush()
979-
980-
partition.set_app_size(-remaining)
981-
partition.save()
982-
983985
sys.stdout.write(
984986
'\n\033[31;1m***** Running build again *****\033[0m\n\n'
985987
)

0 commit comments

Comments
 (0)