2021-08-16 11:37:38 +01:00
|
|
|
Import("env")
|
2022-12-22 16:50:40 +00:00
|
|
|
|
2023-05-03 10:04:10 +01:00
|
|
|
import os
|
2019-11-16 12:57:07 +00:00
|
|
|
import shutil
|
2021-08-16 11:37:38 +01:00
|
|
|
import pathlib
|
|
|
|
import tasmotapiolib
|
2023-05-03 10:04:10 +01:00
|
|
|
from os.path import join
|
2019-11-16 19:16:39 +00:00
|
|
|
|
|
|
|
|
2021-08-16 11:37:38 +01:00
|
|
|
def bin_map_copy(source, target, env):
|
|
|
|
firsttarget = pathlib.Path(target[0].path)
|
2019-11-16 19:16:39 +00:00
|
|
|
|
2021-08-16 11:37:38 +01:00
|
|
|
# get locations and file names based on variant
|
|
|
|
map_file = tasmotapiolib.get_final_map_path(env)
|
|
|
|
bin_file = tasmotapiolib.get_final_bin_path(env)
|
2023-05-31 20:54:59 +01:00
|
|
|
one_bin_file = bin_file
|
2023-10-22 16:10:59 +01:00
|
|
|
firmware_name = env.subst("$BUILD_DIR/${PROGNAME}.bin")
|
2019-11-16 19:16:39 +00:00
|
|
|
|
2022-01-05 22:14:49 +00:00
|
|
|
if env["PIOPLATFORM"] == "espressif32":
|
2023-10-22 16:10:59 +01:00
|
|
|
if("safeboot" not in firmware_name):
|
|
|
|
factory_tmp = pathlib.Path(firsttarget).with_suffix("")
|
|
|
|
factory = factory_tmp.with_suffix(factory_tmp.suffix + ".factory.bin")
|
|
|
|
one_bin_tmp = pathlib.Path(bin_file).with_suffix("")
|
|
|
|
one_bin_file = one_bin_tmp.with_suffix(one_bin_tmp.suffix + ".factory.bin")
|
2022-01-05 22:14:49 +00:00
|
|
|
|
2019-11-16 19:16:39 +00:00
|
|
|
# check if new target files exist and remove if necessary
|
2023-05-31 20:54:59 +01:00
|
|
|
for f in [map_file, bin_file, one_bin_file]:
|
2021-08-16 11:37:38 +01:00
|
|
|
if f.is_file():
|
|
|
|
f.unlink()
|
|
|
|
|
|
|
|
# copy firmware.bin and map to final destination
|
|
|
|
shutil.copy(firsttarget, bin_file)
|
2022-01-05 22:14:49 +00:00
|
|
|
if env["PIOPLATFORM"] == "espressif32":
|
2023-10-26 17:04:34 +01:00
|
|
|
# the map file is needed later for firmware-metrics.py
|
2023-04-21 15:56:27 +01:00
|
|
|
shutil.copy(tasmotapiolib.get_source_map_path(env), map_file)
|
2023-10-22 16:10:59 +01:00
|
|
|
if("safeboot" not in firmware_name):
|
|
|
|
shutil.copy(factory, one_bin_file)
|
2023-04-21 15:56:27 +01:00
|
|
|
else:
|
2023-05-03 10:04:10 +01:00
|
|
|
map_firm = join(env.subst("$BUILD_DIR")) + os.sep + "firmware.map"
|
|
|
|
shutil.copy(tasmotapiolib.get_source_map_path(env), map_firm)
|
2023-04-21 15:56:27 +01:00
|
|
|
shutil.move(tasmotapiolib.get_source_map_path(env), map_file)
|
2023-04-20 19:26:07 +01:00
|
|
|
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", bin_map_copy)
|