2022-09-14 19:11:38 +03:00
|
|
|
import itertools
|
2022-06-26 15:00:03 +03:00
|
|
|
|
2023-09-05 14:49:39 +03:00
|
|
|
from fbt.sdk.cache import LazySdkVersionLoader
|
2023-10-30 18:17:30 +03:00
|
|
|
from fbt.version import get_git_commit_unix_timestamp
|
|
|
|
from fbt_extra.util import link_elf_dir_as_latest, should_gen_cdb_and_link_dir
|
|
|
|
from SCons.Errors import UserError
|
|
|
|
from SCons.Node import FS
|
2023-09-05 14:49:39 +03:00
|
|
|
|
2023-05-03 08:48:49 +03:00
|
|
|
Import("ENV", "fw_build_meta")
|
|
|
|
|
2022-06-26 15:00:03 +03:00
|
|
|
# Building initial C environment for libs
|
|
|
|
env = ENV.Clone(
|
2022-08-02 16:46:43 +03:00
|
|
|
tools=[
|
|
|
|
("compilation_db", {"COMPILATIONDB_COMSTR": "\tCDB\t${TARGET}"}),
|
|
|
|
"fwbin",
|
|
|
|
"fbt_apps",
|
2023-01-17 15:55:49 +03:00
|
|
|
"pvsstudio",
|
2023-02-07 19:33:05 +03:00
|
|
|
"fbt_hwtarget",
|
2023-05-29 19:40:56 +03:00
|
|
|
"fbt_envhooks",
|
2023-10-30 18:17:30 +03:00
|
|
|
"fbt_resources",
|
2022-08-02 16:46:43 +03:00
|
|
|
],
|
2022-07-05 15:24:59 +03:00
|
|
|
COMPILATIONDB_USE_ABSPATH=False,
|
2022-06-26 15:00:03 +03:00
|
|
|
BUILD_DIR=fw_build_meta["build_dir"],
|
|
|
|
IS_BASE_FIRMWARE=fw_build_meta["type"] == "firmware",
|
|
|
|
FW_FLAVOR=fw_build_meta["flavor"],
|
2022-11-05 14:47:59 +03:00
|
|
|
LIB_DIST_DIR=fw_build_meta["build_dir"].Dir("lib"),
|
2023-10-30 18:17:30 +03:00
|
|
|
RESOURCES_ROOT=fw_build_meta["build_dir"].Dir("resources"),
|
|
|
|
TARGETS_ROOT=Dir("#/targets"),
|
2022-06-26 15:00:03 +03:00
|
|
|
LINT_SOURCES=[
|
2022-11-12 13:03:22 +03:00
|
|
|
Dir("applications"),
|
2022-06-26 15:00:03 +03:00
|
|
|
],
|
|
|
|
LIBPATH=[
|
|
|
|
"${LIB_DIST_DIR}",
|
|
|
|
],
|
|
|
|
CPPPATH=[
|
2022-07-20 13:56:33 +03:00
|
|
|
"#/furi",
|
2022-09-14 19:11:38 +03:00
|
|
|
*(f"#/{app_dir[0]}" for app_dir in ENV["APPDIRS"] if app_dir[1]),
|
2023-10-30 18:17:30 +03:00
|
|
|
"#/targets/furi_hal_include",
|
2022-06-26 15:00:03 +03:00
|
|
|
],
|
|
|
|
# Specific flags for building libraries - always do optimized builds
|
|
|
|
FW_LIB_OPTS={
|
|
|
|
"Default": {
|
|
|
|
"CCFLAGS": [
|
2022-11-10 14:55:11 +03:00
|
|
|
"-Og" if ENV["LIB_DEBUG"] else "-Os",
|
2022-06-26 15:00:03 +03:00
|
|
|
],
|
|
|
|
"CPPDEFINES": [
|
|
|
|
"NDEBUG",
|
2022-11-10 14:55:11 +03:00
|
|
|
"FURI_DEBUG" if ENV["LIB_DEBUG"] else "FURI_NDEBUG",
|
2022-06-26 15:00:03 +03:00
|
|
|
],
|
|
|
|
# You can add other entries named after libraries
|
|
|
|
# If they are present, they have precedence over Default
|
2022-06-28 15:28:55 +03:00
|
|
|
},
|
|
|
|
# for furi_check to respect build type
|
2022-07-20 13:56:33 +03:00
|
|
|
"furi": {
|
2022-06-28 15:28:55 +03:00
|
|
|
"CCFLAGS": [
|
|
|
|
"-Os",
|
|
|
|
],
|
|
|
|
"CPPDEFINES": [
|
|
|
|
"NDEBUG",
|
|
|
|
"FURI_DEBUG" if ENV["DEBUG"] else "FURI_NDEBUG",
|
|
|
|
],
|
|
|
|
},
|
2022-09-14 19:11:38 +03:00
|
|
|
"flipper_application": {
|
|
|
|
"CCFLAGS": [
|
|
|
|
"-Og",
|
|
|
|
],
|
|
|
|
"CPPDEFINES": [
|
|
|
|
"NDEBUG",
|
|
|
|
"FURI_DEBUG" if ENV["DEBUG"] else "FURI_NDEBUG",
|
|
|
|
],
|
|
|
|
},
|
2022-06-26 15:00:03 +03:00
|
|
|
},
|
2023-04-06 05:44:37 +03:00
|
|
|
FW_API_TABLE=None,
|
2023-01-17 15:55:49 +03:00
|
|
|
_APP_ICONS=None,
|
2023-09-05 14:49:39 +03:00
|
|
|
APPS=_.split(",") if (_ := GetOption("extra_int_apps")) else [],
|
|
|
|
EXTRA_EXT_APPS=_.split(",") if (_ := GetOption("extra_ext_apps")) else [],
|
2022-06-26 15:00:03 +03:00
|
|
|
)
|
|
|
|
|
2023-05-29 19:40:56 +03:00
|
|
|
env.PreConfigureFwEnvionment()
|
|
|
|
|
2022-07-05 15:24:59 +03:00
|
|
|
if env["IS_BASE_FIRMWARE"]:
|
|
|
|
env.Append(
|
|
|
|
FIRMWARE_BUILD_CFG="firmware",
|
|
|
|
RAM_EXEC=False,
|
|
|
|
)
|
|
|
|
else:
|
2022-06-26 15:00:03 +03:00
|
|
|
env.Append(
|
|
|
|
FIRMWARE_BUILD_CFG="updater",
|
|
|
|
RAM_EXEC=True,
|
|
|
|
CPPDEFINES=[
|
|
|
|
"FURI_RAM_EXEC",
|
|
|
|
],
|
|
|
|
)
|
2023-09-11 16:34:41 +03:00
|
|
|
env.AppendUnique(CPPDEFINES=["FW_CFG_${FIRMWARE_APP_SET}"])
|
2022-06-26 15:00:03 +03:00
|
|
|
|
2023-02-07 19:33:05 +03:00
|
|
|
env.ConfigureForTarget(env.subst("${TARGET_HW}"))
|
|
|
|
|
|
|
|
Export("env")
|
|
|
|
|
|
|
|
# Invoke child SCopscripts to populate global `env` + build their own part of the code
|
2022-06-26 15:00:03 +03:00
|
|
|
lib_targets = env.BuildModules(
|
|
|
|
[
|
|
|
|
"lib",
|
|
|
|
"assets",
|
2023-10-30 18:17:30 +03:00
|
|
|
"targets",
|
2022-07-20 13:56:33 +03:00
|
|
|
"furi",
|
2022-06-26 15:00:03 +03:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2023-05-29 19:40:56 +03:00
|
|
|
# Configure firmware origin definitions
|
|
|
|
env.Append(
|
|
|
|
CPPDEFINES=[
|
|
|
|
env.subst("FW_ORIGIN_${FIRMWARE_ORIGIN}"),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
# Now, env is fully set up with everything to build apps
|
2022-11-02 18:15:40 +03:00
|
|
|
fwenv = env.Clone(FW_ARTIFACTS=[])
|
|
|
|
|
|
|
|
fw_artifacts = fwenv["FW_ARTIFACTS"]
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
# Set up additional app-specific build flags
|
|
|
|
SConscript("site_scons/firmwareopts.scons", exports={"ENV": fwenv})
|
|
|
|
|
|
|
|
# Set up app configuration
|
|
|
|
if env["IS_BASE_FIRMWARE"]:
|
|
|
|
fwenv.Append(APPS=fwenv["FIRMWARE_APPS"].get(fwenv.subst("$FIRMWARE_APP_SET")))
|
|
|
|
else:
|
|
|
|
fwenv.Append(APPS=["updater"])
|
|
|
|
|
2022-10-12 19:12:05 +03:00
|
|
|
|
2023-02-07 19:33:05 +03:00
|
|
|
for app_dir, _ in fwenv["APPDIRS"]:
|
2022-11-02 18:15:40 +03:00
|
|
|
app_dir_node = env.Dir("#").Dir(app_dir)
|
|
|
|
|
|
|
|
for entry in app_dir_node.glob("*"):
|
|
|
|
if isinstance(entry, FS.Dir) and not str(entry).startswith("."):
|
|
|
|
fwenv.LoadAppManifest(entry)
|
|
|
|
|
2022-06-26 15:00:03 +03:00
|
|
|
fwenv.PrepareApplicationsBuild()
|
|
|
|
|
2022-11-05 14:47:59 +03:00
|
|
|
# Build external apps + configure SDK
|
2022-10-26 01:15:02 +03:00
|
|
|
if env["IS_BASE_FIRMWARE"]:
|
2023-09-21 15:56:00 +03:00
|
|
|
fwenv.SetDefault(FBT_FAP_DEBUG_ELF_ROOT=fwenv["BUILD_DIR"].Dir(".extapps"))
|
2023-10-30 18:17:30 +03:00
|
|
|
fw_extapps = fwenv["FW_EXTAPPS"] = SConscript(
|
2022-11-05 14:47:59 +03:00
|
|
|
"site_scons/extapps.scons",
|
|
|
|
exports={"ENV": fwenv},
|
2022-10-26 01:15:02 +03:00
|
|
|
)
|
2023-10-30 18:17:30 +03:00
|
|
|
fw_artifacts.append(fw_extapps.sdk_tree)
|
|
|
|
|
2023-10-31 14:27:58 +03:00
|
|
|
# Resources & manifest for SD card
|
2023-10-30 18:17:30 +03:00
|
|
|
manifest = fwenv.ManifestBuilder(
|
|
|
|
"${RESOURCES_ROOT}/Manifest",
|
|
|
|
GIT_UNIX_TIMESTAMP=get_git_commit_unix_timestamp(),
|
2023-10-31 14:27:58 +03:00
|
|
|
_EXTRA_DIST=[fwenv["DOLPHIN_EXTERNAL_OUT_DIR"]],
|
2023-10-30 18:17:30 +03:00
|
|
|
)
|
|
|
|
fwenv.Replace(FW_RESOURCES_MANIFEST=manifest)
|
|
|
|
fwenv.Alias("resources", manifest)
|
2022-06-26 15:00:03 +03:00
|
|
|
|
2023-10-30 18:17:30 +03:00
|
|
|
# API getter
|
2023-09-05 14:49:39 +03:00
|
|
|
fwenv.Append(FBT_API_VERSION=LazySdkVersionLoader(fwenv.subst("$SDK_DEFINITION")))
|
|
|
|
fwenv.PhonyTarget(
|
|
|
|
"get_apiversion",
|
|
|
|
"@echo $( ${FBT_API_VERSION} $)",
|
|
|
|
)
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
# Add preprocessor definitions for current set of apps
|
2022-09-14 19:11:38 +03:00
|
|
|
fwenv.Append(
|
2022-06-26 15:00:03 +03:00
|
|
|
CPPDEFINES=fwenv["APPBUILD"].get_apps_cdefs(),
|
|
|
|
)
|
|
|
|
|
|
|
|
# Build applications.c for selected services & apps
|
|
|
|
# Depends on virtual value-only node, so it only gets rebuilt when set of apps changes
|
|
|
|
apps_c = fwenv.ApplicationsC(
|
|
|
|
"applications/applications.c",
|
2022-08-13 01:17:11 +03:00
|
|
|
[Value(fwenv["APPS"]), Value(fwenv["LOADER_AUTOSTART"])],
|
2022-06-26 15:00:03 +03:00
|
|
|
)
|
2022-09-14 19:11:38 +03:00
|
|
|
|
2022-07-04 19:53:04 +03:00
|
|
|
# Adding dependency on manifest files so apps.c is rebuilt when any manifest is changed
|
2022-09-14 19:11:38 +03:00
|
|
|
for app_dir, _ in env["APPDIRS"]:
|
|
|
|
app_dir_node = env.Dir("#").Dir(app_dir)
|
2022-10-06 16:55:57 +03:00
|
|
|
fwenv.Depends(apps_c, app_dir_node.glob("*/application.fam"))
|
|
|
|
|
|
|
|
# Sanity check - certain external apps are using features that are not available in base firmware
|
|
|
|
if advanced_faps := list(
|
|
|
|
filter(
|
|
|
|
lambda app: app.fap_extbuild or app.fap_private_libs or app.fap_icon_assets,
|
|
|
|
fwenv["APPBUILD"].get_builtin_apps(),
|
|
|
|
)
|
|
|
|
):
|
|
|
|
raise UserError(
|
|
|
|
"An Application that is using fap-specific features cannot be built into base firmware."
|
|
|
|
f" Offending app(s): {', '.join(app.appid for app in advanced_faps)}"
|
|
|
|
)
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
sources = [apps_c]
|
2022-07-05 15:24:59 +03:00
|
|
|
# Gather sources only from app folders in current configuration
|
2022-09-14 19:11:38 +03:00
|
|
|
sources.extend(
|
|
|
|
itertools.chain.from_iterable(
|
2023-11-01 07:21:31 +03:00
|
|
|
fwenv.GatherSources([source_type, "!lib"], appdir.relpath)
|
2022-09-14 19:11:38 +03:00
|
|
|
for appdir, source_type in fwenv["APPBUILD"].get_builtin_app_folders()
|
|
|
|
)
|
|
|
|
)
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
# Debug
|
|
|
|
# print(fwenv.Dump())
|
|
|
|
|
|
|
|
# Full firmware definition
|
|
|
|
fwelf = fwenv["FW_ELF"] = fwenv.Program(
|
|
|
|
"${FIRMWARE_BUILD_CFG}",
|
|
|
|
sources,
|
2023-02-07 19:33:05 +03:00
|
|
|
LIBS=fwenv["TARGET_CFG"].linker_dependencies,
|
2022-06-26 15:00:03 +03:00
|
|
|
)
|
|
|
|
|
2022-07-05 15:24:59 +03:00
|
|
|
# Firmware depends on everything child builders returned
|
2023-02-07 19:33:05 +03:00
|
|
|
# Depends(fwelf, lib_targets)
|
2022-07-05 15:24:59 +03:00
|
|
|
# Output extra details after building firmware
|
2022-06-26 15:00:03 +03:00
|
|
|
AddPostAction(fwelf, fwenv["APPBUILD_DUMP"])
|
2022-08-13 01:17:11 +03:00
|
|
|
AddPostAction(
|
|
|
|
fwelf,
|
2022-11-02 18:15:40 +03:00
|
|
|
Action(
|
2023-11-15 19:27:35 +03:00
|
|
|
[["${PYTHON3}", "${BIN_SIZE_SCRIPT}", "elf", "${TARGET}"]],
|
2022-11-02 18:15:40 +03:00
|
|
|
"Firmware size",
|
|
|
|
),
|
2022-08-13 01:17:11 +03:00
|
|
|
)
|
2022-06-26 15:00:03 +03:00
|
|
|
|
2022-07-05 15:24:59 +03:00
|
|
|
# Produce extra firmware files
|
2022-06-26 15:00:03 +03:00
|
|
|
fwhex = fwenv["FW_HEX"] = fwenv.HEXBuilder("${FIRMWARE_BUILD_CFG}")
|
|
|
|
fwbin = fwenv["FW_BIN"] = fwenv.BINBuilder("${FIRMWARE_BUILD_CFG}")
|
2022-08-13 01:17:11 +03:00
|
|
|
AddPostAction(
|
|
|
|
fwbin,
|
2023-11-15 19:27:35 +03:00
|
|
|
Action([["@${PYTHON3}", "${BIN_SIZE_SCRIPT}", "bin", "${TARGET}"]]),
|
2022-08-13 01:17:11 +03:00
|
|
|
)
|
|
|
|
|
2022-06-26 15:00:03 +03:00
|
|
|
fwdfu = fwenv["FW_DFU"] = fwenv.DFUBuilder("${FIRMWARE_BUILD_CFG}")
|
|
|
|
Alias(fwenv["FIRMWARE_BUILD_CFG"] + "_dfu", fwdfu)
|
|
|
|
|
|
|
|
fwdump = fwenv.ObjDump("${FIRMWARE_BUILD_CFG}")
|
|
|
|
Alias(fwenv["FIRMWARE_BUILD_CFG"] + "_list", fwdump)
|
|
|
|
|
|
|
|
|
2022-11-02 18:15:40 +03:00
|
|
|
fw_artifacts.extend(
|
|
|
|
[
|
|
|
|
fwhex,
|
|
|
|
fwbin,
|
|
|
|
fwdfu,
|
|
|
|
fwenv["FW_VERSION_JSON"],
|
|
|
|
]
|
|
|
|
)
|
2022-06-26 15:00:03 +03:00
|
|
|
|
2022-10-06 16:55:57 +03:00
|
|
|
|
2024-01-12 11:58:37 +03:00
|
|
|
fwcdb = fwenv["FW_CDB"] = fwenv.CompilationDatabase()
|
2022-10-06 16:55:57 +03:00
|
|
|
# without filtering, both updater & firmware commands would be generated in same file
|
2022-11-07 17:54:41 +03:00
|
|
|
fwenv.Replace(
|
|
|
|
COMPILATIONDB_PATH_FILTER=fwenv.subst("*${FW_FLAVOR}*"),
|
|
|
|
COMPILATIONDB_SRCPATH_FILTER="*.c*",
|
|
|
|
)
|
2022-10-06 16:55:57 +03:00
|
|
|
AlwaysBuild(fwcdb)
|
|
|
|
Precious(fwcdb)
|
|
|
|
NoClean(fwcdb)
|
|
|
|
Alias(fwenv["FIRMWARE_BUILD_CFG"] + "_cdb", fwcdb)
|
|
|
|
|
2023-01-17 15:55:49 +03:00
|
|
|
pvscheck = fwenv.PVSCheck("pvsreport.log", fwcdb)
|
|
|
|
Depends(
|
|
|
|
pvscheck,
|
|
|
|
[
|
|
|
|
fwenv["FW_VERSION_JSON"],
|
|
|
|
fwenv["FW_ASSETS_HEADERS"],
|
2023-04-06 05:44:37 +03:00
|
|
|
fwenv["FW_API_TABLE"],
|
2023-01-17 15:55:49 +03:00
|
|
|
fwenv["_APP_ICONS"],
|
|
|
|
],
|
|
|
|
)
|
|
|
|
Alias(fwenv["FIRMWARE_BUILD_CFG"] + "_pvscheck", pvscheck)
|
|
|
|
AlwaysBuild(pvscheck)
|
|
|
|
Precious(pvscheck)
|
|
|
|
|
|
|
|
pvsreport = fwenv.PVSReport(None, pvscheck, REPORT_DIR=Dir("pvsreport"))
|
|
|
|
Alias(fwenv["FIRMWARE_BUILD_CFG"] + "_pvs", pvsreport)
|
|
|
|
AlwaysBuild(pvsreport)
|
|
|
|
|
2022-07-05 15:24:59 +03:00
|
|
|
# If current configuration was explicitly requested, generate compilation database
|
|
|
|
# and link its directory as build/latest
|
|
|
|
if should_gen_cdb_and_link_dir(fwenv, BUILD_TARGETS):
|
|
|
|
fw_artifacts.append(fwcdb)
|
|
|
|
|
|
|
|
# Adding as a phony target, so folder link is updated even if elf didn't change
|
|
|
|
link_dir_command = fwenv.PhonyTarget(
|
|
|
|
fwenv.subst("${FIRMWARE_BUILD_CFG}_latest"),
|
|
|
|
Action(
|
|
|
|
lambda source, target, env: link_elf_dir_as_latest(env, source[0]),
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
source=fwelf,
|
|
|
|
)
|
|
|
|
fw_artifacts.append(link_dir_command)
|
|
|
|
|
|
|
|
Alias(fwenv["FIRMWARE_BUILD_CFG"] + "_all", fw_artifacts)
|
2022-06-26 15:00:03 +03:00
|
|
|
|
2023-05-29 19:40:56 +03:00
|
|
|
env.PostConfigureFwEnvionment()
|
2022-06-30 19:06:12 +03:00
|
|
|
|
2022-06-26 15:00:03 +03:00
|
|
|
Return("fwenv")
|