10
10
OFFSET_PARTITIONS_DEFAULT = 0x8000
11
11
12
12
13
- def load_sdkconfig_hex_value (filename , value , default ):
13
+ def load_sdkconfig_value (filename , value , default ):
14
14
value = "CONFIG_" + value + "="
15
15
with open (filename , "r" ) as f :
16
16
for line in f :
17
17
if line .startswith (value ):
18
- return int ( line .split ("=" , 1 )[1 ], 16 )
18
+ return line .split ("=" , 1 )[1 ]
19
19
return default
20
20
21
21
22
+ def load_sdkconfig_hex_value (filename , value , default ):
23
+ value = load_sdkconfig_value (filename , value , None )
24
+ if value is None :
25
+ return default
26
+ return int (value , 16 )
27
+
28
+
29
+ def load_sdkconfig_str_value (filename , value , default ):
30
+ value = load_sdkconfig_value (filename , value , None )
31
+ if value is None :
32
+ return default
33
+ return value .strip ().strip ('"' )
34
+
35
+
22
36
def load_partition_table (filename ):
23
37
with open (filename , "rb" ) as f :
24
38
return gen_esp32part .PartitionTable .from_binary (f .read ())
@@ -30,8 +44,10 @@ def load_partition_table(filename):
30
44
arg_partitions_bin = sys .argv [3 ]
31
45
arg_application_bin = sys .argv [4 ]
32
46
arg_output_bin = sys .argv [5 ]
47
+ arg_output_uf2 = sys .argv [6 ]
33
48
34
49
# Load required sdkconfig values.
50
+ idf_target = load_sdkconfig_str_value (arg_sdkconfig , "IDF_TARGET" , "" ).upper ()
35
51
offset_bootloader = load_sdkconfig_hex_value (
36
52
arg_sdkconfig , "BOOTLOADER_OFFSET_IN_FLASH" , OFFSET_BOOTLOADER_DEFAULT
37
53
)
@@ -85,3 +101,14 @@ def load_partition_table(filename):
85
101
)
86
102
sys .exit (1 )
87
103
print ("%-22s% 8d" % ("total" , cur_offset ))
104
+
105
+ # Generate .uf2 file if the SoC has native USB.
106
+ if idf_target in ("ESP32S2" , "ESP32S3" ):
107
+ sys .path .append (os .path .join (os .path .dirname (__file__ ), "../../tools" ))
108
+ import uf2conv
109
+
110
+ families = uf2conv .load_families ()
111
+ uf2conv .appstartaddr = 0
112
+ uf2conv .familyid = families [idf_target ]
113
+ with open (arg_application_bin , "rb" ) as fin , open (arg_output_uf2 , "wb" ) as fout :
114
+ fout .write (uf2conv .convert_to_uf2 (fin .read ()))
0 commit comments