Skip to content

Commit 3b7a6b6

Browse files
committed
still working on application partitions sizes.
1 parent 74162a8 commit 3b7a6b6

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

builder/esp32.py

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ def get_partition_file_name(otp):
3939

4040
class Partition:
4141

42-
def __init__(self):
42+
def __init__(self, size):
4343
if not os.path.exists('build'):
4444
os.mkdir('build')
4545

4646
self.save_file_path = f'{SCRIPT_DIR}/build/partitions-{flash_size}MiB.csv'
4747
self.first_offset = 0x9000
4848
self.nvs = 0x6000
4949
self.phy_init = 0x1000
50-
self.factory = 0x279000
50+
51+
if size == int(size / 0x1000) * 0x1000:
52+
self.factory = size
53+
else:
54+
self.factory = (int(size / 0x1000) + 1) * 0x1000
5155

5256
if ota:
5357
self.otadata = 0x2000
@@ -58,7 +62,10 @@ def get_app_size(self) -> int:
5862
return self.factory
5963

6064
def set_app_size(self, size):
61-
self.factory += size
65+
if int((self.factory + size) / 0x1000) * 0x1000 == self.factory + size:
66+
self.factory += size
67+
else:
68+
self.factory = (int((self.factory + size) / 0x1000) + 1) * 0x1000
6269

6370
def save(self):
6471
offset = self.first_offset
@@ -779,7 +786,12 @@ def compile(): # NOQA
779786
'../../../../build/sdkconfig.board)'
780787
)
781788

782-
partition = Partition()
789+
if partition_size == -1:
790+
p_size = 0x27A000
791+
else:
792+
p_size = partition_size
793+
794+
partition = Partition(p_size)
783795
partition.save()
784796

785797
if sdkconfig not in data:
@@ -855,14 +867,15 @@ def compile(): # NOQA
855867
):
856868
sys.exit(ret_code)
857869

870+
if partition_size != -1:
871+
872+
sys.exit(ret_code)
873+
858874
sys.stdout.write('\n\033[31;1m***** Resizing Partition *****\033[0m\n')
859875
sys.stdout.flush()
860876

861-
if partition_size != -1:
862-
overflow_amount = partition_size - partition.get_app_size()
863-
else:
864-
end = output.split('(overflow ', 1)[-1]
865-
overflow_amount = int(end.split(')', 1)[0], 16)
877+
end = output.split('(overflow ', 1)[-1]
878+
overflow_amount = int(end.split(')', 1)[0], 16)
866879

867880
partition.set_app_size(overflow_amount)
868881
partition.save()
@@ -878,35 +891,19 @@ def compile(): # NOQA
878891
if ret_code != 0:
879892
sys.exit(ret_code)
880893

881-
elif not skip_partition_resize:
894+
elif not skip_partition_resize and partition_size == -1:
882895
if 'build complete' in output:
883896
remaining = output.rsplit('application')[-1]
884897
remaining = int(
885898
remaining.split('(', 1)[-1].split('remaining')[0].strip()
886899
)
887900

888-
if remaining > 4096 or partition_size != -1:
901+
if remaining > 0x1000:
889902
sys.stdout.write(
890903
'\n\033[31;1m***** Resizing Partition *****\033[0m\n'
891904
)
892905
sys.stdout.flush()
893906

894-
if partition_size != -1:
895-
part_size = partition.get_app_size()
896-
resize = abs(part_size - partition_size)
897-
898-
if part_size < partition_size:
899-
resize = -resize
900-
901-
partition.set_app_size(-resize)
902-
partition.save()
903-
904-
sys.stdout.write(
905-
'\n\033[31;1m***** Running build again *****\033[0m\n\n'
906-
)
907-
sys.stdout.flush()
908-
909-
elif remaining > 4096:
910907
partition.set_app_size(-remaining)
911908
partition.save()
912909

@@ -915,7 +912,6 @@ def compile(): # NOQA
915912
)
916913
sys.stdout.flush()
917914

918-
if remaining > 4096 or partition_size != -1:
919915
compile_cmd[4] = 'SECOND_BUILD=1'
920916

921917
ret_code, output = spawn(cmds, env=env, cmpl=True)

0 commit comments

Comments
 (0)