mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
md5 check for upload bin files #637
This commit is contained in:
@@ -2,6 +2,7 @@ import shutil
|
||||
import re
|
||||
import os
|
||||
Import("env")
|
||||
import hashlib
|
||||
|
||||
OUTPUT_DIR = "build{}".format(os.path.sep)
|
||||
|
||||
@@ -18,7 +19,6 @@ def bin_copy(source, target, env):
|
||||
bag[var] = m.group(1)
|
||||
|
||||
app_version = bag.get('app_version')
|
||||
|
||||
platform = "ESP32"
|
||||
chip_target = env.get('PIOENV').upper()
|
||||
|
||||
@@ -33,14 +33,13 @@ def bin_copy(source, target, env):
|
||||
|
||||
# alternatively take platform from the pio target
|
||||
# platform = str(target[0]).split(os.path.sep)[2]
|
||||
chip_target = env.get('PIOENV').upper()
|
||||
|
||||
print("app version: " + app_version)
|
||||
print("platform: " + platform)
|
||||
print("chip_target: " + chip_target)
|
||||
|
||||
# convert . to _ so Windows doesn't complain
|
||||
variant = "EMS-ESP-" + chip_target + "-" + app_version.replace(".", "_")
|
||||
variant = "EMS-ESP-" + app_version.replace(".", "_") + "-" + chip_target.replace("CI","ESP32")
|
||||
|
||||
# check if output directories exist and create if necessary
|
||||
if not os.path.isdir(OUTPUT_DIR):
|
||||
@@ -52,15 +51,29 @@ def bin_copy(source, target, env):
|
||||
|
||||
# create string with location and file names based on variant
|
||||
bin_file = "{}firmware{}{}.bin".format(OUTPUT_DIR, os.path.sep, variant)
|
||||
md5_file = "{}firmware{}{}.md5".format(OUTPUT_DIR, os.path.sep, variant)
|
||||
|
||||
# check if new target files exist and remove if necessary
|
||||
for f in [bin_file]:
|
||||
if os.path.isfile(f):
|
||||
os.remove(f)
|
||||
|
||||
# check if new target files exist and remove if necessary
|
||||
for f in [md5_file]:
|
||||
if os.path.isfile(f):
|
||||
os.remove(f)
|
||||
|
||||
print("Renaming file to "+bin_file)
|
||||
|
||||
# copy firmware.bin to firmware/<variant>.bin
|
||||
shutil.copy(str(target[0]), bin_file)
|
||||
|
||||
with open(bin_file,"rb") as f:
|
||||
result = hashlib.md5(f.read())
|
||||
print("Calculating MD5: "+result.hexdigest())
|
||||
file1 = open(md5_file, 'w')
|
||||
file1.write(result.hexdigest())
|
||||
file1.close()
|
||||
|
||||
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_copy])
|
||||
env.AddPostAction("$BUILD_DIR/${PROGNAME}.md5", [bin_copy])
|
||||
|
||||
Reference in New Issue
Block a user