formatting

This commit is contained in:
proddy
2024-09-25 17:32:31 +02:00
parent e802812fc6
commit 5cba925717
13 changed files with 169 additions and 89 deletions

View File

@@ -1,11 +1,12 @@
import hashlib
import shutil
import re
import os
Import("env")
import hashlib
OUTPUT_DIR = "build{}".format(os.path.sep)
def bin_copy(source, target, env):
# get the application version from version.h
@@ -19,14 +20,14 @@ def bin_copy(source, target, env):
bag[var] = m.group(1)
app_version = bag.get('app_version')
# print(env.Dump())
# get the chip type, in uppercase
mcu = env.get('BOARD_MCU').upper()
# alternatively take platform from the pio target
# platform = str(target[0]).split(os.path.sep)[2]
# work out the flash memory from the PIO env name (sloppy but works)
# unfortunately the board_upload.flash_size is not passed down
flash_mem = "4MB"
@@ -37,21 +38,21 @@ def bin_copy(source, target, env):
index = -2
else:
index = -1
# if doesn't have an M at the end
# if doesn't have an M at the end
if parts[index].endswith("M"):
flash_mem = parts[index] + "B"
# find if BOARD_HAS_PSRAM is in the cppdefines
cppdefines = env.get("CPPDEFINES")
if 'BOARD_HAS_PSRAM' in cppdefines:
psram = True
else:
psram = False
print("*********************************************")
print("EMS-ESP version: " + app_version)
# show psram as Yes or No
psram_status = "Yes" if psram else "No"
print("Has PSRAM: " + psram_status)
@@ -60,7 +61,9 @@ def bin_copy(source, target, env):
# convert . to _ so Windows doesn't complain
# Format is EMS-ESP-<version>-<mcu>-<flash> with + at the end if it has PSRAM
variant = "EMS-ESP-" + app_version.replace(".", "_") + "-" + mcu + "-" + flash_mem + ("+" if psram else "")
variant = "EMS-ESP-" + \
app_version.replace(".", "_") + "-" + mcu + "-" + \
flash_mem + ("+" if psram else "")
# check if output directories exist and create if necessary
if not os.path.isdir(OUTPUT_DIR):
@@ -89,13 +92,13 @@ def bin_copy(source, target, env):
# copy firmware.bin to firmware/<variant>.bin
shutil.copy(str(target[0]), bin_file)
with open(bin_file,"rb") as f:
with open(bin_file, "rb") as f:
result = hashlib.md5(f.read())
print("MD5: "+result.hexdigest())
file1 = open(md5_file, 'w')
file1.write(result.hexdigest())
file1.close()
# make a copy using the old 3.6.x filename format for backwards compatibility with the WebUI version check, e.g.
# create a EMS-ESP-<version>-ESP32_S3.bin if target is ci_s3_16M_P (16MB, PSRAM)
# create a EMS-ESP-<version>-ESP32.bin if target is ci_s_4M (4MB, no PSRAM)
@@ -105,24 +108,28 @@ def bin_copy(source, target, env):
#
extra_variant = ""
if env.get('PIOENV') == "ci_s3_16M_P":
extra_variant = "EMS-ESP-" + app_version.replace(".", "_") + "-ESP32_S3"
extra_variant = "EMS-ESP-" + \
app_version.replace(".", "_") + "-ESP32_S3"
elif env.get('PIOENV') == "ci_s_4M":
extra_variant = "EMS-ESP-" + app_version.replace(".", "_") + "-ESP32"
if extra_variant:
extra_bin_file = "{}firmware{}{}.bin".format(OUTPUT_DIR, os.path.sep, extra_variant)
if extra_variant:
extra_bin_file = "{}firmware{}{}.bin".format(
OUTPUT_DIR, os.path.sep, extra_variant)
if os.path.isfile(extra_bin_file):
os.remove(extra_bin_file)
extra_md5_file = "{}firmware{}{}.md5".format(OUTPUT_DIR, os.path.sep, extra_variant)
extra_md5_file = "{}firmware{}{}.md5".format(
OUTPUT_DIR, os.path.sep, extra_variant)
if os.path.isfile(extra_md5_file):
os.remove(extra_md5_file)
os.remove(extra_md5_file)
shutil.copy(bin_file, extra_bin_file)
shutil.copy(md5_file, extra_md5_file)
print("Filename copy for 3.6.x: "+extra_bin_file)
print("*********************************************")
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_copy])
env.AddPostAction("$BUILD_DIR/${PROGNAME}.md5", [bin_copy])