2022-06-26 12:00:03 +00:00
|
|
|
from SCons.Builder import Builder
|
|
|
|
from SCons.Action import Action
|
|
|
|
from SCons.Script import Mkdir
|
2022-06-28 13:03:49 +00:00
|
|
|
from SCons.Defaults import Touch
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_variant_dirname(env, project=None):
|
|
|
|
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):
|
|
|
|
flavor = get_variant_dirname(env, configuration_name)
|
|
|
|
build_dir = env.Dir("build").Dir(flavor).abspath
|
|
|
|
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 16:06:12 +00:00
|
|
|
|
2022-06-28 13:03:49 +00:00
|
|
|
env.Replace(DIST_DIR=get_variant_dirname(env))
|
2022-06-26 12:00:03 +00:00
|
|
|
return project_env
|
|
|
|
|
|
|
|
|
2022-07-04 16:53:04 +00:00
|
|
|
def AddOpenOCDFlashTarget(env, targetenv, **kw):
|
|
|
|
openocd_target = env.OpenOCDFlash(
|
|
|
|
"#build/oocd-${BUILD_CFG}-flash.flag",
|
|
|
|
targetenv["FW_BIN"],
|
|
|
|
OPENOCD_COMMAND=[
|
|
|
|
"-c",
|
|
|
|
"program ${SOURCE.posix} reset exit ${BASE_ADDRESS}",
|
|
|
|
],
|
|
|
|
BUILD_CFG=targetenv.subst("$FIRMWARE_BUILD_CFG"),
|
|
|
|
BASE_ADDRESS=targetenv.subst("$IMAGE_BASE_ADDRESS"),
|
|
|
|
**kw,
|
2022-06-26 12:00:03 +00:00
|
|
|
)
|
2022-07-04 16:53:04 +00:00
|
|
|
env.Alias(targetenv.subst("${FIRMWARE_BUILD_CFG}_flash"), openocd_target)
|
2022-08-02 13:46:43 +00:00
|
|
|
if env["FORCE"]:
|
|
|
|
env.AlwaysBuild(openocd_target)
|
2022-07-04 16:53:04 +00:00
|
|
|
return openocd_target
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
|
2022-08-02 13:46:43 +00: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 16:06:12 +00:00
|
|
|
def DistCommand(env, name, source, **kw):
|
|
|
|
target = f"dist_{name}"
|
|
|
|
command = env.Command(
|
|
|
|
target,
|
|
|
|
source,
|
2022-07-25 21:31:34 +00:00
|
|
|
'@${PYTHON3} "${ROOT_DIR.abspath}/scripts/sconsdist.py" copy -p ${DIST_PROJECTS} -s "${DIST_SUFFIX}" ${DIST_EXTRA}',
|
2022-06-30 16:06:12 +00:00
|
|
|
**kw,
|
|
|
|
)
|
|
|
|
env.Pseudo(target)
|
|
|
|
env.Alias(name, command)
|
|
|
|
return command
|
|
|
|
|
|
|
|
|
2022-06-26 12:00:03 +00:00
|
|
|
def generate(env):
|
|
|
|
env.AddMethod(AddFwProject)
|
2022-06-30 16:06:12 +00:00
|
|
|
env.AddMethod(DistCommand)
|
2022-07-04 16:53:04 +00:00
|
|
|
env.AddMethod(AddOpenOCDFlashTarget)
|
2022-08-02 13:46:43 +00:00
|
|
|
env.AddMethod(AddJFlashTarget)
|
|
|
|
env.AddMethod(AddUsbFlashTarget)
|
2022-07-04 16:53:04 +00:00
|
|
|
|
2022-06-26 12:00:03 +00:00
|
|
|
env.SetDefault(
|
|
|
|
COPRO_MCU_FAMILY="STM32WB5x",
|
|
|
|
)
|
2022-06-30 16:06:12 +00:00
|
|
|
|
2022-06-26 12:00:03 +00:00
|
|
|
env.Append(
|
|
|
|
BUILDERS={
|
2022-06-28 13:03:49 +00:00
|
|
|
"UsbInstall": Builder(
|
|
|
|
action=[
|
|
|
|
Action(
|
2022-07-25 21:31:34 +00:00
|
|
|
'${PYTHON3} "${ROOT_DIR.abspath}/scripts/selfupdate.py" dist/${DIST_DIR}/f${TARGET_HW}-update-${DIST_SUFFIX}/update.fuf'
|
2022-06-28 13:03:49 +00:00
|
|
|
),
|
|
|
|
Touch("${TARGET}"),
|
|
|
|
]
|
|
|
|
),
|
2022-06-26 12:00:03 +00:00
|
|
|
"CoproBuilder": Builder(
|
|
|
|
action=Action(
|
|
|
|
[
|
|
|
|
Mkdir("$TARGET"),
|
2022-07-25 21:31:34 +00:00
|
|
|
'${PYTHON3} "${ROOT_DIR.abspath}/scripts/assets.py" '
|
2022-06-26 12:00:03 +00:00
|
|
|
"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} ",
|
|
|
|
],
|
|
|
|
"",
|
|
|
|
)
|
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
return True
|