@@ -144,12 +144,27 @@ def _update_max_upload_size(env):
144
144
if p ["type" ] in ("0" , "app" )
145
145
}
146
146
147
- # One of the `factory` or `ota_0` partitions is used to determine available memory
148
- # size. If both partitions are set, we should prefer the `factory`, but there are
149
- # cases (e.g. Adafruit's `partitions-4MB-tinyuf2.csv`) that uses the `factory`
150
- # partition for their UF2 bootloader. So let's use the first match
147
+ partitions = {p ["name" ]: p for p in _parse_partitions (env )}
148
+
149
+ # User-specified partition name has the highest priority
150
+ custom_app_partition_name = board .get ("build.app_partition_name" , "" )
151
+ if custom_app_partition_name :
152
+ selected_partition = partitions .get (custom_app_partition_name , {})
153
+ if selected_partition :
154
+ board .update ("upload.maximum_size" , _parse_size (selected_partition ["size" ]))
155
+ return
156
+ else :
157
+ print (
158
+ "Warning! Selected partition `%s` is not available in the partition " \
159
+ "table! Default partition will be used!" % custom_app_partition_name
160
+ )
161
+
162
+ # Otherwise, one of the `factory` or `ota_0` partitions is used to determine
163
+ # available memory size. If both partitions are set, we should prefer the `factory`,
164
+ # but there are cases (e.g. Adafruit's `partitions-4MB-tinyuf2.csv`) that uses the
165
+ # `factory` partition for their UF2 bootloader. So let's use the first match
151
166
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#subtype
152
- for p in _parse_partitions ( env ):
167
+ for p in partitions . values ( ):
153
168
if p ["type" ] in ("0" , "app" ) and p ["subtype" ] in ("factory" , "ota_0" ):
154
169
board .update ("upload.maximum_size" , _parse_size (p ["size" ]))
155
170
break
0 commit comments