2022-06-26 15:00:03 +03:00
|
|
|
from SCons.Action import Action
|
2023-05-03 08:48:49 +03:00
|
|
|
from SCons.Builder import Builder
|
2022-06-28 16:03:49 +03:00
|
|
|
from SCons.Defaults import Touch
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
|
2023-02-20 18:55:53 +03:00
|
|
|
def GetProjectDirName(env, project=None):
|
2022-06-26 15:00:03 +03:00
|
|
|
parts = [f"f{env['TARGET_HW']}"]
|
|
|
|
if project:
|
|
|
|
parts.append(project)
|
|
|
|
|
|
|
|
suffix = ""
|
|
|
|
if env["DEBUG"]:
|
|
|
|
suffix += "D"
|
|
|
|
if env["COMPACT"]:
|
|
|
|
suffix += "C"
|
|
|
|
if suffix:
|
|
|
|
parts.append(suffix)
|
|
|
|
|
|
|
|
return "-".join(parts)
|
|
|
|
|
|
|
|
|
|
|
|
def create_fw_build_targets(env, configuration_name):
|
2023-02-20 18:55:53 +03:00
|
|
|
flavor = GetProjectDirName(env, configuration_name)
|
2022-11-05 14:47:59 +03:00
|
|
|
build_dir = env.Dir("build").Dir(flavor)
|
2022-06-26 15:00:03 +03:00
|
|
|
return env.SConscript(
|
|
|
|
"firmware.scons",
|
|
|
|
variant_dir=build_dir,
|
|
|
|
duplicate=0,
|
|
|
|
exports={
|
|
|
|
"ENV": env,
|
|
|
|
"fw_build_meta": {
|
|
|
|
"type": configuration_name,
|
|
|
|
"flavor": flavor,
|
|
|
|
"build_dir": build_dir,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def AddFwProject(env, base_env, fw_type, fw_env_key):
|
|
|
|
project_env = env[fw_env_key] = create_fw_build_targets(base_env, fw_type)
|
|
|
|
env.Append(
|
|
|
|
DIST_PROJECTS=[
|
|
|
|
project_env["FW_FLAVOR"],
|
|
|
|
],
|
|
|
|
DIST_DEPENDS=[
|
|
|
|
project_env["FW_ARTIFACTS"],
|
|
|
|
],
|
|
|
|
)
|
2022-06-30 19:06:12 +03:00
|
|
|
|
2023-02-20 18:55:53 +03:00
|
|
|
env.Replace(DIST_DIR=env.GetProjectDirName())
|
2022-06-26 15:00:03 +03:00
|
|
|
return project_env
|
|
|
|
|
|
|
|
|
2023-08-22 21:33:10 +03:00
|
|
|
def AddFwFlashTarget(env, targetenv, **kw):
|
|
|
|
fwflash_target = env.FwFlash(
|
|
|
|
"#build/flash.flag",
|
|
|
|
targetenv["FW_ELF"],
|
2022-07-04 19:53:04 +03:00
|
|
|
**kw,
|
2022-06-26 15:00:03 +03:00
|
|
|
)
|
2023-08-22 21:33:10 +03:00
|
|
|
env.Alias(targetenv.subst("${FIRMWARE_BUILD_CFG}_flash"), fwflash_target)
|
2022-08-02 16:46:43 +03:00
|
|
|
if env["FORCE"]:
|
2023-08-22 21:33:10 +03:00
|
|
|
env.AlwaysBuild(fwflash_target)
|
|
|
|
return fwflash_target
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
|
2022-08-02 16:46:43 +03:00
|
|
|
def AddJFlashTarget(env, targetenv, **kw):
|
|
|
|
jflash_target = env.JFlash(
|
|
|
|
"#build/jflash-${BUILD_CFG}-flash.flag",
|
|
|
|
targetenv["FW_BIN"],
|
|
|
|
JFLASHADDR=targetenv.subst("$IMAGE_BASE_ADDRESS"),
|
|
|
|
BUILD_CFG=targetenv.subst("${FIRMWARE_BUILD_CFG}"),
|
|
|
|
**kw,
|
|
|
|
)
|
|
|
|
env.Alias(targetenv.subst("${FIRMWARE_BUILD_CFG}_jflash"), jflash_target)
|
|
|
|
if env["FORCE"]:
|
|
|
|
env.AlwaysBuild(jflash_target)
|
|
|
|
return jflash_target
|
|
|
|
|
|
|
|
|
|
|
|
def AddUsbFlashTarget(env, file_flag, extra_deps, **kw):
|
|
|
|
usb_update = env.UsbInstall(
|
|
|
|
file_flag,
|
|
|
|
(
|
|
|
|
env["DIST_DEPENDS"],
|
|
|
|
*extra_deps,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
if env["FORCE"]:
|
|
|
|
env.AlwaysBuild(usb_update)
|
|
|
|
return usb_update
|
|
|
|
|
|
|
|
|
2022-06-30 19:06:12 +03:00
|
|
|
def DistCommand(env, name, source, **kw):
|
|
|
|
target = f"dist_{name}"
|
|
|
|
command = env.Command(
|
|
|
|
target,
|
|
|
|
source,
|
2023-10-30 18:17:30 +03:00
|
|
|
action=Action(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
"${PYTHON3}",
|
|
|
|
"${DIST_SCRIPT}",
|
|
|
|
"copy",
|
|
|
|
"-p",
|
|
|
|
"${DIST_PROJECTS}",
|
|
|
|
"-s",
|
|
|
|
"${DIST_SUFFIX}",
|
|
|
|
"${DIST_EXTRA}",
|
|
|
|
]
|
|
|
|
],
|
|
|
|
"${DISTCOMSTR}",
|
|
|
|
),
|
2022-06-30 19:06:12 +03:00
|
|
|
**kw,
|
|
|
|
)
|
|
|
|
env.Pseudo(target)
|
|
|
|
env.Alias(name, command)
|
|
|
|
return command
|
|
|
|
|
|
|
|
|
2022-06-26 15:00:03 +03:00
|
|
|
def generate(env):
|
2023-04-22 20:32:41 +03:00
|
|
|
if not env["VERBOSE"]:
|
2023-10-30 18:17:30 +03:00
|
|
|
env.SetDefault(
|
|
|
|
COPROCOMSTR="\tCOPRO\t${TARGET}",
|
|
|
|
DISTCOMSTR="\tDIST\t${TARGET}",
|
|
|
|
)
|
2022-06-26 15:00:03 +03:00
|
|
|
env.AddMethod(AddFwProject)
|
2022-06-30 19:06:12 +03:00
|
|
|
env.AddMethod(DistCommand)
|
2023-08-22 21:33:10 +03:00
|
|
|
env.AddMethod(AddFwFlashTarget)
|
2023-02-20 18:55:53 +03:00
|
|
|
env.AddMethod(GetProjectDirName)
|
2022-08-02 16:46:43 +03:00
|
|
|
env.AddMethod(AddJFlashTarget)
|
|
|
|
env.AddMethod(AddUsbFlashTarget)
|
2022-07-04 19:53:04 +03:00
|
|
|
|
2022-06-26 15:00:03 +03:00
|
|
|
env.SetDefault(
|
|
|
|
COPRO_MCU_FAMILY="STM32WB5x",
|
2022-11-02 18:15:40 +03:00
|
|
|
SELFUPDATE_SCRIPT="${FBT_SCRIPT_DIR}/selfupdate.py",
|
|
|
|
DIST_SCRIPT="${FBT_SCRIPT_DIR}/sconsdist.py",
|
|
|
|
COPRO_ASSETS_SCRIPT="${FBT_SCRIPT_DIR}/assets.py",
|
2023-08-22 21:33:10 +03:00
|
|
|
FW_FLASH_SCRIPT="${FBT_SCRIPT_DIR}/fwflash.py",
|
2022-06-26 15:00:03 +03:00
|
|
|
)
|
2022-06-30 19:06:12 +03:00
|
|
|
|
2022-06-26 15:00:03 +03:00
|
|
|
env.Append(
|
|
|
|
BUILDERS={
|
2023-08-22 21:33:10 +03:00
|
|
|
"FwFlash": Builder(
|
|
|
|
action=[
|
|
|
|
[
|
|
|
|
"${PYTHON3}",
|
|
|
|
"${FW_FLASH_SCRIPT}",
|
|
|
|
"-d" if env["VERBOSE"] else "",
|
|
|
|
"--interface=${SWD_TRANSPORT}",
|
|
|
|
"--serial=${SWD_TRANSPORT_SERIAL}",
|
|
|
|
"${SOURCE}",
|
2024-03-01 14:58:15 +03:00
|
|
|
"${ARGS}",
|
2023-08-22 21:33:10 +03:00
|
|
|
],
|
|
|
|
Touch("${TARGET}"),
|
|
|
|
]
|
|
|
|
),
|
2022-06-28 16:03:49 +03:00
|
|
|
"UsbInstall": Builder(
|
|
|
|
action=[
|
2023-08-22 21:33:10 +03:00
|
|
|
[
|
|
|
|
"${PYTHON3}",
|
|
|
|
"${SELFUPDATE_SCRIPT}",
|
|
|
|
"-p",
|
|
|
|
"${FLIP_PORT}",
|
|
|
|
"${UPDATE_BUNDLE_DIR}/update.fuf",
|
2024-03-01 14:58:15 +03:00
|
|
|
"${ARGS}",
|
2023-08-22 21:33:10 +03:00
|
|
|
],
|
2022-06-28 16:03:49 +03:00
|
|
|
Touch("${TARGET}"),
|
|
|
|
]
|
|
|
|
),
|
2022-06-26 15:00:03 +03:00
|
|
|
"CoproBuilder": Builder(
|
|
|
|
action=Action(
|
|
|
|
[
|
2023-08-22 21:33:10 +03:00
|
|
|
[
|
|
|
|
"${PYTHON3}",
|
|
|
|
"${COPRO_ASSETS_SCRIPT}",
|
|
|
|
"copro",
|
|
|
|
"${COPRO_CUBE_DIR}",
|
|
|
|
"${TARGET}",
|
|
|
|
"${COPRO_MCU_FAMILY}",
|
|
|
|
"--cube_ver=${COPRO_CUBE_VERSION}",
|
|
|
|
"--stack_type=${COPRO_STACK_TYPE}",
|
|
|
|
"--stack_file=${COPRO_STACK_BIN}",
|
|
|
|
"--stack_addr=${COPRO_STACK_ADDR}",
|
2024-03-01 14:58:15 +03:00
|
|
|
"${ARGS}",
|
2023-08-22 21:33:10 +03:00
|
|
|
]
|
2022-06-26 15:00:03 +03:00
|
|
|
],
|
2023-08-22 21:33:10 +03:00
|
|
|
"${COPROCOMSTR}",
|
2022-06-26 15:00:03 +03:00
|
|
|
)
|
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
return True
|