@@ -39,15 +39,19 @@ def get_partition_file_name(otp):
39
39
40
40
class Partition :
41
41
42
- def __init__ (self ):
42
+ def __init__ (self , size ):
43
43
if not os .path .exists ('build' ):
44
44
os .mkdir ('build' )
45
45
46
46
self .save_file_path = f'{ SCRIPT_DIR } /build/partitions-{ flash_size } MiB.csv'
47
47
self .first_offset = 0x9000
48
48
self .nvs = 0x6000
49
49
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
51
55
52
56
if ota :
53
57
self .otadata = 0x2000
@@ -58,7 +62,10 @@ def get_app_size(self) -> int:
58
62
return self .factory
59
63
60
64
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
62
69
63
70
def save (self ):
64
71
offset = self .first_offset
@@ -779,7 +786,12 @@ def compile(): # NOQA
779
786
'../../../../build/sdkconfig.board)'
780
787
)
781
788
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 )
783
795
partition .save ()
784
796
785
797
if sdkconfig not in data :
@@ -855,14 +867,15 @@ def compile(): # NOQA
855
867
):
856
868
sys .exit (ret_code )
857
869
870
+ if partition_size != - 1 :
871
+
872
+ sys .exit (ret_code )
873
+
858
874
sys .stdout .write ('\n \033 [31;1m***** Resizing Partition *****\033 [0m\n ' )
859
875
sys .stdout .flush ()
860
876
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 )
866
879
867
880
partition .set_app_size (overflow_amount )
868
881
partition .save ()
@@ -878,35 +891,19 @@ def compile(): # NOQA
878
891
if ret_code != 0 :
879
892
sys .exit (ret_code )
880
893
881
- elif not skip_partition_resize :
894
+ elif not skip_partition_resize and partition_size == - 1 :
882
895
if 'build complete' in output :
883
896
remaining = output .rsplit ('application' )[- 1 ]
884
897
remaining = int (
885
898
remaining .split ('(' , 1 )[- 1 ].split ('remaining' )[0 ].strip ()
886
899
)
887
900
888
- if remaining > 4096 or partition_size != - 1 :
901
+ if remaining > 0x1000 :
889
902
sys .stdout .write (
890
903
'\n \033 [31;1m***** Resizing Partition *****\033 [0m\n '
891
904
)
892
905
sys .stdout .flush ()
893
906
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 :
910
907
partition .set_app_size (- remaining )
911
908
partition .save ()
912
909
@@ -915,7 +912,6 @@ def compile(): # NOQA
915
912
)
916
913
sys .stdout .flush ()
917
914
918
- if remaining > 4096 or partition_size != - 1 :
919
915
compile_cmd [4 ] = 'SECOND_BUILD=1'
920
916
921
917
ret_code , output = spawn (cmds , env = env , cmpl = True )
0 commit comments