Beautify console log output (#23456)

This commit is contained in:
Jason2866 2025-05-21 22:15:23 +02:00 committed by GitHub
parent 36a2d253e5
commit c8d6f723c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 68 additions and 23 deletions

View File

@ -28,7 +28,9 @@ def map_gzip(source, target, env):
if not tasmotapiolib.is_env_set(tasmotapiolib.DISABLE_MAP_GZ, env):
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [map_gzip])
silent_action = env.Action([map_gzip])
silent_action.strfunction = lambda target, source, env: '' # hack to silence scons command output
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", silent_action)
if tasmotapiolib.is_env_set(tasmotapiolib.ENABLE_ESP32_GZ, env) or env["PIOPLATFORM"] != "espressif32":
import time
@ -55,6 +57,7 @@ if tasmotapiolib.is_env_set(tasmotapiolib.ENABLE_ESP32_GZ, env) or env["PIOPLATF
ORG_FIRMWARE_SIZE = bin_file.stat().st_size
GZ_FIRMWARE_SIZE = gzip_file.stat().st_size
print()
if ORG_FIRMWARE_SIZE > 995326 and env["PIOPLATFORM"] != "espressif32":
print(Fore.RED + "!!! Tasmota firmware size is too big with {} bytes. Max size is 995326 bytes !!! ".format(
ORG_FIRMWARE_SIZE
@ -70,4 +73,6 @@ if tasmotapiolib.is_env_set(tasmotapiolib.ENABLE_ESP32_GZ, env) or env["PIOPLATF
)
if not tasmotapiolib.is_env_set(tasmotapiolib.DISABLE_BIN_GZ, env):
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_gzip])
silent_action = env.Action([bin_gzip])
silent_action.strfunction = lambda target, source, env: '' # hack to silence scons command output
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", silent_action)

View File

@ -3,12 +3,17 @@ Import("env")
import os
import tasmotapiolib
from os.path import join
import subprocess
def firm_metrics(source, target, env):
print()
if env["PIOPLATFORM"] == "espressif32":
try:
import tasmota_metrics
env.Execute("$PYTHONEXE -m tasmota_metrics \"" + str(tasmotapiolib.get_source_map_path(env).resolve()) + "\"")
map_file = str(tasmotapiolib.get_source_map_path(env).resolve())
subprocess.run([
env.subst("$PYTHONEXE"), "-m", "tasmota_metrics", map_file
], check=False)
except:
pass
elif env["PIOPLATFORM"] == "espressif8266":
@ -24,5 +29,6 @@ def firm_metrics(source, target, env):
percentage = round(used_bytes / 0x8000 * 100,1)
print("Used static IRAM:",used_bytes,"bytes (",remaining_bytes,"remain,",percentage,"% used)")
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin",firm_metrics)
silent_action = env.Action(firm_metrics)
silent_action.strfunction = lambda target, source, env: '' # hack to silence scons command output
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", silent_action)

View File

@ -47,4 +47,7 @@ def bin_map_copy(source, target, env):
map_firm = join(env.subst("$BUILD_DIR")) + os.sep + "firmware.map"
shutil.copy(tasmotapiolib.get_source_map_path(env), map_firm)
shutil.move(tasmotapiolib.get_source_map_path(env), map_file)
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", bin_map_copy)
silent_action = env.Action(bin_map_copy)
silent_action.strfunction = lambda target, source, env: '' # hack to silence scons command output
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", silent_action)

View File

@ -16,9 +16,19 @@ def obj_dump_after_elf(source, target, env):
env.Execute("xtensa-esp32s2-elf-objdump "+ "-D -C " + str(target[0]) + " > "+ "$BUILD_DIR/${PROGNAME}.asm")
if mcu == "esp32s3":
env.Execute("xtensa-esp32s3-elf-objdump "+ "-D -C " + str(target[0]) + " > "+ "$BUILD_DIR/${PROGNAME}.asm")
if mcu == "esp32c2":
env.Execute("riscv32-esp-elf-objdump "+ "-D -C " + str(target[0]) + " > "+ "$BUILD_DIR/${PROGNAME}.asm")
if mcu == "esp32c3":
env.Execute("riscv32-esp-elf-objdump "+ "-D -C " + str(target[0]) + " > "+ "$BUILD_DIR/${PROGNAME}.asm")
if mcu == "esp32c5":
env.Execute("riscv32-esp-elf-objdump "+ "-D -C " + str(target[0]) + " > "+ "$BUILD_DIR/${PROGNAME}.asm")
if mcu == "esp32c6":
env.Execute("riscv32-esp-elf-objdump "+ "-D -C " + str(target[0]) + " > "+ "$BUILD_DIR/${PROGNAME}.asm")
if mcu == "esp32p4":
env.Execute("riscv32-esp-elf-objdump "+ "-D -C " + str(target[0]) + " > "+ "$BUILD_DIR/${PROGNAME}.asm")
if mcu == "esp32h2":
env.Execute("riscv32-esp-elf-objdump "+ "-D -C " + str(target[0]) + " > "+ "$BUILD_DIR/${PROGNAME}.asm")
env.AddPostAction("$BUILD_DIR/${PROGNAME}.elf", [obj_dump_after_elf])
silent_action = env.Action([obj_dump_after_elf])
silent_action.strfunction = lambda target, source, env: '' # hack to silence scons command output
env.AddPostAction("$BUILD_DIR/${PROGNAME}.elf", silent_action)

View File

@ -150,10 +150,14 @@ def esp32_create_chip_string(chip):
def esp32_build_filesystem(fs_size):
files = env.GetProjectOption("custom_files_upload").splitlines()
num_entries = len([f for f in files if f.strip()])
filesystem_dir = join(env.subst("$BUILD_DIR"),"littlefs_data")
if not os.path.exists(filesystem_dir):
os.makedirs(filesystem_dir)
print("Creating filesystem with content:")
if num_entries > 1:
print()
print(Fore.GREEN + "Will create filesystem with the following files:")
print()
for file in files:
if "no_files" in file:
continue
@ -173,7 +177,7 @@ def esp32_build_filesystem(fs_size):
else:
shutil.copy(file, filesystem_dir)
if not os.listdir(filesystem_dir):
print("No files added -> will NOT create littlefs.bin and NOT overwrite fs partition!")
#print("No files added -> will NOT create littlefs.bin and NOT overwrite fs partition!")
return False
tool = env.subst(env["MKFSTOOL"])
cmd = (tool,"-c",filesystem_dir,"-s",fs_size,join(env.subst("$BUILD_DIR"),"littlefs.bin"))
@ -185,14 +189,15 @@ def esp32_fetch_safeboot_bin(tasmota_platform):
safeboot_fw_url = "http://ota.tasmota.com/tasmota32/release/" + tasmota_platform + "-safeboot.bin"
safeboot_fw_name = join(variants_dir, tasmota_platform + "-safeboot.bin")
if(exists(safeboot_fw_name)):
print("safeboot binary already in place.")
print(Fore.GREEN + "Safeboot binary already in place")
return True
print("Will download safeboot binary from URL:")
print(safeboot_fw_url)
print()
print(Fore.GREEN + "Will download safeboot binary from URL:")
print(Fore.BLUE + safeboot_fw_url)
try:
response = requests.get(safeboot_fw_url)
open(safeboot_fw_name, "wb").write(response.content)
print("safeboot binary written to variants dir.")
print(Fore.GREEN + "safeboot binary written to variants dir")
return True
except:
print(Fore.RED + "Download of safeboot binary failed. Please check your Internet connection.")
@ -220,7 +225,9 @@ def esp32_create_combined_bin(source, target, env):
fs_offset = -1 # error code value
with open(env.BoardConfig().get("build.partitions")) as csv_file:
print()
print("Read partitions from ",env.BoardConfig().get("build.partitions"))
print("--------------------------------------------------------------------")
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
@ -244,7 +251,7 @@ def esp32_create_combined_bin(source, target, env):
if esp32_build_filesystem(partition_size):
fs_offset = int(row[3],base=16)
print()
new_file_name = env.subst("$BUILD_DIR/${PROGNAME}.factory.bin")
firmware_name = env.subst("$BUILD_DIR/${PROGNAME}.bin")
tasmota_platform = esp32_create_chip_string(chip)
@ -282,19 +289,21 @@ def esp32_create_combined_bin(source, target, env):
if (fw_size > max_size):
raise Exception(Fore.RED + "firmware binary too large: %d > %d" % (fw_size, max_size))
print()
print(" Offset | File")
for section in sections:
sect_adr, sect_file = section.split(" ", 1)
print(f" - {sect_adr} | {sect_file}")
print(f" - {sect_adr.ljust(8)} | {sect_file}")
cmd += [sect_adr, sect_file]
# "main" firmware to app0 - mandatory, except we just built a new safeboot bin locally
if ("safeboot" not in firmware_name):
print(f" - {hex(app_offset)} | {firmware_name}")
print(f" - {hex(app_offset).ljust(8)} | {firmware_name}")
cmd += [hex(app_offset), firmware_name]
else:
print("Upload new safeboot binary only")
print()
print(Fore.GREEN + "Upload new safeboot binary only")
upload_protocol = env.subst("$UPLOAD_PROTOCOL")
if(upload_protocol == "esptool") and (fs_offset != -1):
@ -302,7 +311,8 @@ def esp32_create_combined_bin(source, target, env):
if exists(fs_bin):
before_reset = env.BoardConfig().get("upload.before_reset", "default_reset")
after_reset = env.BoardConfig().get("upload.after_reset", "hard_reset")
print(f" - {hex(fs_offset)}| {fs_bin}")
print(f" - {hex(fs_offset).ljust(8)} | {fs_bin}")
print()
cmd += [hex(fs_offset), fs_bin]
env.Replace(
UPLOADERFLAGS=[
@ -318,11 +328,22 @@ def esp32_create_combined_bin(source, target, env):
],
UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS ' + " ".join(cmd[7:])
)
print("Will use custom upload command for flashing operation to add file system defined for this build target.")
print(Fore.GREEN + "Will use custom upload command for flashing operation to add file system defined for this build target.")
print()
if("safeboot" not in firmware_name):
#print('Using esptool.py arguments: %s' % ' '.join(cmd))
with open(os.devnull, 'w') as devnull:
old_stdout = sys.stdout
old_stderr = sys.stderr
sys.stdout = devnull
sys.stderr = devnull
try:
esptool.main(cmd)
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", esp32_create_combined_bin)
silent_action = env.Action(esp32_create_combined_bin)
silent_action.strfunction = lambda target, source, env: '' # hack to silence scons command output
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", silent_action)