@@ -29,91 +29,79 @@ def get_partition_file_name(otp):
29
29
30
30
31
31
PARTITION_HEADER = '''\
32
- # Notes: the offset of the partition table itself is set in
33
- # $IDF_PATH/components/partition_table/Kconfig.projbuild.
34
32
# Name, Type, SubType, Offset, Size, Flags
35
33
'''
36
34
35
+ # OTA boards
36
+ # ARDUINO_NANO_ESP32
37
+ # SIL_WESP32
38
+
37
39
38
40
class Partition :
39
41
40
- def __init__ (self , file_path ):
41
- self .load_file_path = file_path
42
+ def __init__ (self ):
42
43
self .save_file_path = f'"{ SCRIPT_DIR } /build/partitions-{ flash_size } MiB.csv"'
43
- self ._saved_data = None
44
- self .csv_data = self .read_csv ()
45
- last_partition = self .csv_data [- 1 ]
46
-
47
- self .total_space = last_partition [- 2 ] + last_partition [- 3 ]
48
-
49
- def get_app_size (self ) -> int :
50
- for part in self .csv_data :
51
- if part [1 ] in ('app' , 'factory' ):
52
- return part [4 ]
44
+ self .first_offset = 0x9000
45
+ self .nvs = 0x6000
46
+ self .phy_init = 0x1000
47
+ self .factory = 1 * 1024 * 1024
53
48
54
- def set_app_size (self , size ):
55
- next_offset = 0
56
- app_size = 0
57
-
58
- for i , part in enumerate (self .csv_data ):
59
- if next_offset == 0 :
60
- next_offset = part [3 ]
49
+ if ota :
50
+ self .otadata = 0x2000
51
+ else :
52
+ self .otadata = 0x0
61
53
62
- if part [3 ] != next_offset :
63
- part [3 ] = next_offset # NOQA
54
+ def build_file (self ):
55
+ offset = self .first_offset
56
+ data = [f'nvs,data, nvs,0x{ offset :X} ,0x{ self .nvs :X} ' ]
57
+ offset += self .nvs
64
58
65
- if part [1 ] in ('app' , 'factory' ):
66
- factor = ((part [4 ] + size ) / 4096.0 ) + 1
67
- part [4 ] = int (int (factor ) * 4096 ) # NOQA
68
- app_size += part [4 ]
69
- elif app_size != 0 :
70
- part [4 ] = self .total_space - next_offset # NOQA
59
+ if ota :
60
+ data .append (f'otadata,data,ota,0x{ offset :X} ,0x{ self .otadata :X} ' )
61
+ offset += self .otadata
71
62
72
- next_offset += part [4 ]
63
+ data .append (f'phy_init,data,phy,0x{ offset :X} ,0x{ self .phy_init :X} ' )
64
+ offset += self .phy_init
73
65
74
- if next_offset > self .total_space :
75
- raise RuntimeError (
76
- f'Board does not have enough space, overflow of '
77
- f'{ next_offset - self .total_space } bytes ({ self .load_file_path } )\n '
78
- )
66
+ if ota :
67
+ data .append (f'ota_0,app,ota_0,0x{ offset :X} ,0x{ self .factory :X} ' )
68
+ offset += self .factory
69
+ data .append (f'ota_1,app,ota_1,0x{ offset :X} ,0x{ self .factory :X} ' )
70
+ offset += self .factory
71
+ else :
72
+ data .append (f'factory,app,factory,0x{ offset :X} ,0x{ self .factory :X} ' )
73
+ offset += self .factory
74
+
75
+ vfs = (flash_size * 1024 * 1024 ) - sum ([
76
+ self .first_offset ,
77
+ self .nvs ,
78
+ self .otadata ,
79
+ self .phy_init ,
80
+ self .factory
81
+ ])
79
82
80
- def save ( self ) :
81
- otp = []
83
+ if ota :
84
+ vfs -= self . factory
82
85
83
- def convert_to_hex (itm ):
84
- if isinstance (itm , int ):
85
- itm = hex (itm )
86
- return itm
86
+ if vfs < 0 :
87
+ raise RuntimeError ('There is not enough flash to store the firmware' )
87
88
88
- for line in self .csv_data :
89
- otp .append (',' .join (convert_to_hex (item ) for item in line ))
89
+ data .append (f'vfs,data,fat,0x{ offset :X} ,0x{ vfs :X} ' )
90
90
91
91
with open (self .save_file_path , 'w' ) as f :
92
92
f .write (PARTITION_HEADER )
93
- f .write ('\n ' .join (otp ))
94
-
95
- def read_csv (self ):
96
- with open (self .load_file_path , 'r' ) as f :
97
- csv_data = f .read ()
98
-
99
- self ._saved_data = csv_data
93
+ f .write ('\n ' .join (data ))
94
+ f .write ('\n ' )
100
95
101
- csv_data = [
102
- line .strip ()
103
- for line in csv_data .split ('\n ' )
104
- if line .strip () and not line .startswith ('#' )
105
- ]
106
-
107
- def convert_to_int (elem ):
108
- if elem .startswith ('0' ):
109
- elem = int (elem , 16 )
110
- return elem
96
+ def get_app_size (self ) -> int :
97
+ return self .factory
111
98
112
- for j , line in enumerate ( csv_data ):
113
- line = [ convert_to_int ( item . strip ()) for item in line . split ( ',' )]
114
- csv_data [ j ] = line
99
+ def set_app_size ( self , size ):
100
+ factor = (( self . factory + size ) / 4096.0 ) + 1
101
+ self . factory = int ( factor * 4096 )
115
102
116
- return csv_data
103
+ def save (self ):
104
+ self .build_file ()
117
105
118
106
119
107
def get_espidf ():
@@ -159,6 +147,8 @@ def get_espidf():
159
147
disable_OTG = True
160
148
onboard_mem_speed = 80
161
149
flash_mode = 'QIO'
150
+ optimize_size = False
151
+ ota = False
162
152
163
153
164
154
def common_args (extra_args ):
@@ -170,6 +160,25 @@ def common_args(extra_args):
170
160
global skip_partition_resize
171
161
global partition_size
172
162
global flash_size
163
+ global board_variant
164
+ global optimize_size
165
+ global ota
166
+
167
+ if board == 'ARDUINO_NANO_ESP32' :
168
+ raise RuntimeError ('Board is not currently supported' )
169
+
170
+ if board in (
171
+ 'UM_NANOS3' , 'ESP32_GENERIC_S3' ,
172
+ 'UM_TINYS3' , 'UM_TINYWATCHS3'
173
+ ):
174
+ def_flash_size = 8
175
+ elif board in (
176
+ 'UM_FEATHERS2' , 'SIL_WESP32' ,
177
+ 'UM_PROS3' , 'UM_FEATHERS3' ,
178
+ ):
179
+ def_flash_size = 16
180
+ else :
181
+ def_flash_size = 4
173
182
174
183
esp_argParser = ArgumentParser (prefix_chars = '-BPd' )
175
184
esp_argParser .add_argument (
@@ -191,30 +200,32 @@ def common_args(extra_args):
191
200
default = False ,
192
201
action = 'store_true'
193
202
)
194
-
195
203
esp_argParser .add_argument (
196
204
'--skip-partition-resize' ,
197
205
dest = 'skip_partition_resize' ,
198
206
help = 'clean the build' ,
199
207
default = False ,
200
208
action = 'store_true'
201
209
)
202
-
203
210
esp_argParser .add_argument (
204
211
'--partition-size' ,
205
212
dest = 'partition_size' ,
206
213
default = - 1 ,
207
214
type = int ,
208
215
action = 'store'
209
216
)
210
-
217
+ esp_argParser .add_argument (
218
+ '--optimize-size' ,
219
+ dest = 'optimize_size' ,
220
+ default = False ,
221
+ action = 'store_true'
222
+ )
211
223
esp_argParser .add_argument (
212
224
'--debug' ,
213
225
dest = 'debug' ,
214
226
default = False ,
215
227
action = 'store_true'
216
228
)
217
-
218
229
esp_argParser .add_argument (
219
230
'--ccache' ,
220
231
dest = 'ccache' ,
@@ -227,10 +238,16 @@ def common_args(extra_args):
227
238
dest = 'flash_size' ,
228
239
help = 'flash size' ,
229
240
choices = (4 , 8 , 16 , 32 , 64 , 128 ),
230
- default = 4 ,
241
+ default = def_flash_size ,
231
242
type = int ,
232
243
action = 'store'
233
244
)
245
+ esp_argParser .add_argument (
246
+ '--ota' ,
247
+ dest = 'ota' ,
248
+ default = False ,
249
+ action = 'store_true'
250
+ )
234
251
235
252
esp_args , extra_args = esp_argParser .parse_known_args (extra_args )
236
253
@@ -242,16 +259,18 @@ def common_args(extra_args):
242
259
ccache = esp_args .ccache
243
260
DEBUG = esp_args .debug
244
261
flash_size = esp_args .flash_size
262
+ optimize_size = esp_args .optimize_size
263
+ ota = esp_args .ota
245
264
246
265
return extra_args
247
266
248
267
249
268
def esp32_s3_args (extra_args ):
250
- global board_variant
251
269
global oct_flash
252
270
global disable_OTG
253
271
global onboard_mem_speed
254
272
global flash_mode
273
+ global board_variant
255
274
256
275
esp_argParser = ArgumentParser (prefix_chars = '-B' )
257
276
@@ -261,21 +280,18 @@ def esp32_s3_args(extra_args):
261
280
default = '' ,
262
281
action = 'store'
263
282
)
264
-
265
283
esp_argParser .add_argument (
266
284
'--USB-OTG' ,
267
285
dest = 'usb_otg' ,
268
286
default = False ,
269
287
action = 'store_true'
270
288
)
271
-
272
289
esp_argParser .add_argument (
273
290
'--octal-flash' ,
274
291
help = 'octal spi flash' ,
275
292
dest = 'oct_flash' ,
276
293
action = 'store_true'
277
294
)
278
-
279
295
esp_argParser .add_argument (
280
296
'--onboard-mem-speed' ,
281
297
dest = 'onboard_mem_speed' ,
@@ -284,7 +300,6 @@ def esp32_s3_args(extra_args):
284
300
type = int ,
285
301
action = 'store'
286
302
)
287
-
288
303
esp_argParser .add_argument (
289
304
'--flash-mode' ,
290
305
dest = 'flash_mode' ,
@@ -324,9 +339,9 @@ def esp32_s2_args(extra_args):
324
339
325
340
def esp32_args (extra_args ):
326
341
global board_variant
342
+ global ota
327
343
328
- esp_argParser = ArgumentParser (prefix_chars = '-B' )
329
-
344
+ esp_argParser = ArgumentParser (prefix_chars = 'B' )
330
345
esp_argParser .add_argument (
331
346
'BOARD_VARIANT' ,
332
347
dest = 'board_variant' ,
@@ -337,8 +352,16 @@ def esp32_args(extra_args):
337
352
esp_args , extra_args = esp_argParser .parse_known_args (extra_args )
338
353
board_variant = esp_args .board_variant
339
354
340
- return extra_args
355
+ if board_variant == 'OTA' :
356
+ board_variant = ''
357
+ ota = True
341
358
359
+ elif board_variant == 'D2WD' :
360
+ raise RuntimeError (
361
+ 'board variant not supported, Not enough flash capacity'
362
+ )
363
+
364
+ return extra_args
342
365
343
366
def parse_args (extra_args , lv_cflags , brd ):
344
367
global board
@@ -655,6 +678,7 @@ def submodules():
655
678
656
679
def compile (): # NOQA
657
680
global PORT
681
+ global flash_size
658
682
659
683
env , cmds = setup_idf_environ ()
660
684
@@ -679,7 +703,10 @@ def compile(): # NOQA
679
703
'CONFIG_ESPTOOLPY_FLASHSIZE_16MB=n' ,
680
704
'CONFIG_ESPTOOLPY_FLASHSIZE_32MB=n' ,
681
705
'CONFIG_ESPTOOLPY_FLASHSIZE_64MB=n' ,
682
- 'CONFIG_ESPTOOLPY_FLASHSIZE_128MB=n'
706
+ 'CONFIG_ESPTOOLPY_FLASHSIZE_128MB=n' ,
707
+ 'CONFIG_COMPILER_OPTIMIZATION_SIZE=n' ,
708
+ 'CONFIG_COMPILER_OPTIMIZATION_PERF=n' ,
709
+ 'CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y'
683
710
]
684
711
685
712
if DEBUG :
@@ -718,6 +745,11 @@ def compile(): # NOQA
718
745
f'"{ SCRIPT_DIR } /build/partitions-{ flash_size } MiB.csv"'
719
746
]))
720
747
748
+ if optimize_size :
749
+ base_config .append ('CONFIG_COMPILER_OPTIMIZATION_SIZE=y' )
750
+ else :
751
+ base_config .append ('CONFIG_COMPILER_OPTIMIZATION_PERF=y' )
752
+
721
753
base_config .append ('CONFIG_ESPTOOLPY_FLASHFREQ_{onboard_mem_speed}M=y' )
722
754
base_config .append ('CONFIG_SPIRAM_SPEED_{onboard_mem_speed}M=y' )
723
755
@@ -750,6 +782,9 @@ def compile(): # NOQA
750
782
'../../../../build/sdkconfig.board)'
751
783
)
752
784
785
+ partition = Partition ()
786
+ partition .save ()
787
+
753
788
if sdkconfig not in data :
754
789
data += '\n ' + sdkconfig + '\n '
755
790
@@ -826,12 +861,6 @@ def compile(): # NOQA
826
861
sys .stdout .write ('\n \033 [31;1m***** Resizing Partition *****\033 [0m\n ' )
827
862
sys .stdout .flush ()
828
863
829
- partition_file_name = get_partition_file_name (output )
830
- partition_file_name = (
831
- os .path .join ('lib/micropython/ports/esp32' , partition_file_name )
832
- )
833
- partition = Partition (partition_file_name )
834
-
835
864
if partition_size != - 1 :
836
865
overflow_amount = partition_size - partition .get_app_size ()
837
866
else :
@@ -854,13 +883,6 @@ def compile(): # NOQA
854
883
855
884
elif not skip_partition_resize :
856
885
if 'build complete' in output :
857
- partition_file_name = get_partition_file_name (output )
858
- partition_file_name = os .path .join (
859
- 'lib/micropython/ports/esp32' ,
860
- partition_file_name
861
- )
862
- partition = Partition (partition_file_name )
863
-
864
886
remaining = output .rsplit ('application' )[- 1 ]
865
887
remaining = int (
866
888
remaining .split ('(' , 1 )[- 1 ].split ('remaining' )[0 ].strip ()
0 commit comments