-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f05c5f
commit 960ea6e
Showing
4 changed files
with
31 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import gzip | ||
import shutil | ||
import os | ||
Import("env") | ||
|
||
|
||
def compress_firmware(source, target, env): | ||
""" Compress ESP8266 firmware using gzip for 'compressed OTA upload' """ | ||
SOURCE_FILE = env.subst("$BUILD_DIR") + os.sep + env.subst("$PROGNAME") + ".bin" | ||
if not os.path.exists(SOURCE_FILE+'.bak'): | ||
print("Compressing firmware for upload...") | ||
shutil.move(SOURCE_FILE, SOURCE_FILE + '.bak') | ||
with open(SOURCE_FILE + '.bak', 'rb') as f_in: | ||
with gzip.open(SOURCE_FILE + '.gz', 'wb') as f_out: | ||
shutil.copyfileobj(f_in, f_out) | ||
shutil.move(SOURCE_FILE + '.bak', SOURCE_FILE) | ||
|
||
ORG_FIRMWARE_SIZE = os.stat(SOURCE_FILE).st_size | ||
GZ_FIRMWARE_SIZE = os.stat(SOURCE_FILE + '.gz').st_size | ||
|
||
print("Compression reduced firmware size to {:.0f}% of original (was {} bytes, now {} bytes)".format((GZ_FIRMWARE_SIZE / ORG_FIRMWARE_SIZE) * 100, ORG_FIRMWARE_SIZE, GZ_FIRMWARE_SIZE)) | ||
|
||
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [compress_firmware]) |