2019-11-16 12:57:07 +00:00
|
|
|
Import('env')
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
2019-11-16 19:16:39 +00:00
|
|
|
OUTPUT_DIR = "build_output{}".format(os.path.sep)
|
|
|
|
|
|
|
|
def bin_map_copy(source, target, env):
|
2020-09-10 15:41:31 +01:00
|
|
|
variant = str(target[0]).split(os.path.sep)[2]
|
2019-11-16 19:16:39 +00:00
|
|
|
|
|
|
|
# check if output directories exist and create if necessary
|
|
|
|
if not os.path.isdir(OUTPUT_DIR):
|
|
|
|
os.mkdir(OUTPUT_DIR)
|
|
|
|
|
|
|
|
for d in ['firmware', 'map']:
|
|
|
|
if not os.path.isdir("{}{}".format(OUTPUT_DIR, d)):
|
|
|
|
os.mkdir("{}{}".format(OUTPUT_DIR, d))
|
|
|
|
|
|
|
|
# create string with location and file names based on variant
|
|
|
|
map_file = "{}map{}{}.map".format(OUTPUT_DIR, os.path.sep, variant)
|
|
|
|
bin_file = "{}firmware{}{}.bin".format(OUTPUT_DIR, os.path.sep, variant)
|
|
|
|
|
|
|
|
# check if new target files exist and remove if necessary
|
|
|
|
for f in [map_file, bin_file]:
|
|
|
|
if os.path.isfile(f):
|
|
|
|
os.remove(f)
|
|
|
|
|
|
|
|
# copy firmware.bin to firmware/<variant>.bin
|
|
|
|
shutil.copy(str(target[0]), bin_file)
|
|
|
|
|
|
|
|
# copy firmware.map to map/<variant>.map
|
2020-04-17 15:15:41 +01:00
|
|
|
if os.path.isfile("firmware.map"):
|
|
|
|
shutil.move("firmware.map", map_file)
|
2019-11-16 19:16:39 +00:00
|
|
|
|
|
|
|
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_map_copy])
|