Skip to content

Added GZipped OTA support in elf2bin and PlatformIO #7727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tools/elf2bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,31 @@ def add_crc(out):
with open(out, "wb") as binfile:
binfile.write(raw)

def gzip_bin(mode, out):
import gzip

firmware_path = out
gzip_path = firmware_path + '.gz'
orig_path = firmware_path + '.orig'
if os.path.exists(gzip_path):
os.remove(gzip_path)
print('GZipping firmware ' + firmware_path)
with open(firmware_path, 'rb') as firmware_file, \
gzip.open(gzip_path, 'wb') as dest:
data = firmware_file.read()
dest.write(data)
orig_size = os.stat(firmware_path).st_size
gzip_size = os.stat(gzip_path).st_size
print("New FW size {:d} bytes vs old {:d} bytes".format(
gzip_size, orig_size))

if mode == "PIO":
if os.path.exists(orig_path):
os.remove(orig_path)
print('Moving original firmware to ' + orig_path)
os.rename(firmware_path, orig_path)
os.rename(gzip_path, firmware_path)

def main():
parser = argparse.ArgumentParser(description='Create a BIN file from eboot.elf and Arduino sketch.elf for upload by esptool.py')
parser.add_argument('-e', '--eboot', action='store', required=True, help='Path to the Arduino eboot.elf bootloader')
Expand All @@ -150,6 +175,7 @@ def main():
parser.add_argument('-s', '--flash_size', action='store', required=True, choices=['256K', '512K', '1M', '2M', '4M', '8M', '16M'], help='SPI flash size')
parser.add_argument('-o', '--out', action='store', required=True, help='Output BIN filename')
parser.add_argument('-p', '--path', action='store', required=True, help='Path to Xtensa toolchain binaries')
parser.add_argument('-g', '--gzip', choices=['PIO', 'Arduino'], help='PIO - generate gzipped BIN file, Arduino - generate BIN and BIN.gz')

args = parser.parse_args()

Expand All @@ -175,6 +201,9 @@ def wrapper(**kwargs):
# Because the CRC includes both eboot and app, can only calculate it after the entire BIN generated
add_crc(args.out)

if args.gzip:
gzip_bin(args.gzip, args.out)

return 0


Expand Down
7 changes: 6 additions & 1 deletion tools/platformio-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ def scons_patched_match_splitext(path, suffixes=None):

env = DefaultEnvironment()
platform = env.PioPlatform()
board = env.BoardConfig()
gzip_fw = board.get("build.gzip_fw", False)
gzip_switch = []

FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif8266")
assert isdir(FRAMEWORK_DIR)

if gzip_fw:
gzip_switch = ["--gzip", "PIO"]

env.Append(
ASFLAGS=["-x", "assembler-with-cpp"],
Expand Down Expand Up @@ -145,7 +150,7 @@ def scons_patched_match_splitext(path, suffixes=None):
"--path", '"%s"' % join(
platform.get_package_dir("toolchain-xtensa"), "bin"),
"--out", "$TARGET"
]), "Building $TARGET"),
] + gzip_switch), "Building $TARGET"),
suffix=".bin"
)
)
Expand Down