@@ -141,6 +141,31 @@ def add_crc(out):
141
141
with open (out , "wb" ) as binfile :
142
142
binfile .write (raw )
143
143
144
+ def gzip_bin (mode , out ):
145
+ import gzip
146
+
147
+ firmware_path = out
148
+ gzip_path = firmware_path + '.gz'
149
+ orig_path = firmware_path + '.orig'
150
+ if os .path .exists (gzip_path ):
151
+ os .remove (gzip_path )
152
+ print ('GZipping firmware ' + firmware_path )
153
+ with open (firmware_path , 'rb' ) as firmware_file , \
154
+ gzip .open (gzip_path , 'wb' ) as dest :
155
+ data = firmware_file .read ()
156
+ dest .write (data )
157
+ orig_size = os .stat (firmware_path ).st_size
158
+ gzip_size = os .stat (gzip_path ).st_size
159
+ print ("New FW size {:d} bytes vs old {:d} bytes" .format (
160
+ gzip_size , orig_size ))
161
+
162
+ if mode == "PIO" :
163
+ if os .path .exists (orig_path ):
164
+ os .remove (orig_path )
165
+ print ('Moving original firmware to ' + orig_path )
166
+ os .rename (firmware_path , orig_path )
167
+ os .rename (gzip_path , firmware_path )
168
+
144
169
def main ():
145
170
parser = argparse .ArgumentParser (description = 'Create a BIN file from eboot.elf and Arduino sketch.elf for upload by esptool.py' )
146
171
parser .add_argument ('-e' , '--eboot' , action = 'store' , required = True , help = 'Path to the Arduino eboot.elf bootloader' )
@@ -150,6 +175,7 @@ def main():
150
175
parser .add_argument ('-s' , '--flash_size' , action = 'store' , required = True , choices = ['256K' , '512K' , '1M' , '2M' , '4M' , '8M' , '16M' ], help = 'SPI flash size' )
151
176
parser .add_argument ('-o' , '--out' , action = 'store' , required = True , help = 'Output BIN filename' )
152
177
parser .add_argument ('-p' , '--path' , action = 'store' , required = True , help = 'Path to Xtensa toolchain binaries' )
178
+ parser .add_argument ('-g' , '--gzip' , choices = ['PIO' , 'Arduino' ], help = 'PIO - generate gzipped BIN file, Arduino - generate BIN and BIN.gz' )
153
179
154
180
args = parser .parse_args ()
155
181
@@ -175,6 +201,9 @@ def wrapper(**kwargs):
175
201
# Because the CRC includes both eboot and app, can only calculate it after the entire BIN generated
176
202
add_crc (args .out )
177
203
204
+ if args .gzip :
205
+ gzip_bin (args .gzip , args .out )
206
+
178
207
return 0
179
208
180
209
0 commit comments