2022-06-26 15:00:03 +03:00
|
|
|
Import("ENV", "fw_build_meta")
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2022-07-05 15:24:59 +03:00
|
|
|
from fbt.util import (
|
|
|
|
should_gen_cdb_and_link_dir,
|
|
|
|
link_elf_dir_as_latest,
|
|
|
|
)
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
# Building initial C environment for libs
|
|
|
|
env = ENV.Clone(
|
2022-07-04 19:53:04 +03:00
|
|
|
tools=["compilation_db", "fwbin", "fbt_apps"],
|
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"],
|
|
|
|
PLUGIN_ELF_DIR="${BUILD_DIR}",
|
|
|
|
LIB_DIST_DIR="${BUILD_DIR}/lib",
|
|
|
|
LINT_SOURCES=[
|
|
|
|
"applications",
|
|
|
|
],
|
|
|
|
LIBPATH=[
|
|
|
|
"${LIB_DIST_DIR}",
|
|
|
|
],
|
|
|
|
CPPPATH=[
|
|
|
|
"#/core",
|
|
|
|
"#/applications",
|
|
|
|
"#/firmware/targets/f${TARGET_HW}/ble_glue",
|
|
|
|
"#/firmware/targets/f${TARGET_HW}/fatfs",
|
|
|
|
"#/firmware/targets/f${TARGET_HW}/furi_hal",
|
|
|
|
"#/firmware/targets/f${TARGET_HW}/Inc",
|
|
|
|
"#/firmware/targets/furi_hal_include",
|
|
|
|
],
|
|
|
|
# Specific flags for building libraries - always do optimized builds
|
|
|
|
FW_LIB_OPTS={
|
|
|
|
"Default": {
|
|
|
|
"CCFLAGS": [
|
|
|
|
"-Os",
|
|
|
|
],
|
|
|
|
"CPPDEFINES": [
|
|
|
|
"NDEBUG",
|
|
|
|
"FURI_NDEBUG",
|
|
|
|
],
|
|
|
|
# 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
|
|
|
|
"core": {
|
|
|
|
"CCFLAGS": [
|
|
|
|
"-Os",
|
|
|
|
],
|
|
|
|
"CPPDEFINES": [
|
|
|
|
"NDEBUG",
|
|
|
|
"FURI_DEBUG" if ENV["DEBUG"] else "FURI_NDEBUG",
|
|
|
|
],
|
|
|
|
},
|
2022-06-26 15:00:03 +03:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def ApplyLibFlags(env):
|
|
|
|
flags_to_apply = env["FW_LIB_OPTS"].get(
|
|
|
|
env.get("FW_LIB_NAME"),
|
|
|
|
env["FW_LIB_OPTS"]["Default"],
|
|
|
|
)
|
|
|
|
# print("Flags for ", env.get("FW_LIB_NAME", "Default"), flags_to_apply)
|
|
|
|
env.MergeFlags(flags_to_apply)
|
|
|
|
|
|
|
|
|
|
|
|
env.AddMethod(ApplyLibFlags)
|
|
|
|
|
|
|
|
Export("env")
|
|
|
|
|
|
|
|
if not env["VERBOSE"]:
|
|
|
|
env.SetDefault(
|
|
|
|
HEXCOMSTR="\tHEX\t${TARGET}",
|
|
|
|
BINCOMSTR="\tBIN\t${TARGET}",
|
|
|
|
DFUCOMSTR="\tDFU\t${TARGET}",
|
2022-06-30 19:06:12 +03:00
|
|
|
OPENOCDCOMSTR="\tFLASH\t${SOURCE}",
|
2022-06-26 15:00:03 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
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",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Invoke child SCopscripts to populate global `env` + build their own part of the code
|
|
|
|
lib_targets = env.BuildModules(
|
|
|
|
[
|
|
|
|
"lib",
|
|
|
|
"assets",
|
|
|
|
"firmware",
|
|
|
|
"core",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Now, env is fully set up with everything to build apps
|
|
|
|
fwenv = env.Clone()
|
|
|
|
|
|
|
|
# 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"])
|
|
|
|
|
|
|
|
if extra_int_apps := GetOption("extra_int_apps"):
|
2022-06-30 19:06:12 +03:00
|
|
|
fwenv.Append(APPS=extra_int_apps.split(","))
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
fwenv.LoadApplicationManifests()
|
|
|
|
fwenv.PrepareApplicationsBuild()
|
|
|
|
|
|
|
|
# Build external apps
|
|
|
|
extapps = SConscript("applications/extapps.scons", exports={"ENV": fwenv})
|
|
|
|
|
|
|
|
|
|
|
|
# Add preprocessor definitions for current set of apps
|
|
|
|
fwenv.AppendUnique(
|
|
|
|
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",
|
|
|
|
Value(fwenv["APPS"]),
|
|
|
|
)
|
2022-07-04 19:53:04 +03:00
|
|
|
# Adding dependency on manifest files so apps.c is rebuilt when any manifest is changed
|
|
|
|
fwenv.Depends(apps_c, fwenv.GlobRecursive("*.fam", "applications"))
|
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-06-26 15:00:03 +03:00
|
|
|
for app_folder in fwenv["APPBUILD"].get_builtin_app_folders():
|
|
|
|
sources += fwenv.GlobRecursive("*.c*", os.path.join("applications", app_folder))
|
|
|
|
|
|
|
|
|
|
|
|
fwenv.AppendUnique(
|
|
|
|
LINKFLAGS=[
|
|
|
|
"-specs=nano.specs",
|
|
|
|
"-specs=nosys.specs",
|
|
|
|
"-Wl,--start-group",
|
|
|
|
"-lstdc++",
|
|
|
|
"-lsupc++",
|
|
|
|
"-Wl,--end-group",
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
"-Wl,--undefined=uxTopUsedPriority",
|
|
|
|
"-Wl,--wrap,_malloc_r",
|
|
|
|
"-Wl,--wrap,_free_r",
|
|
|
|
"-Wl,--wrap,_calloc_r",
|
|
|
|
"-Wl,--wrap,_realloc_r",
|
|
|
|
"-u",
|
|
|
|
"_printf_float",
|
|
|
|
"-n",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Debug
|
|
|
|
# print(fwenv.Dump())
|
|
|
|
|
|
|
|
# Full firmware definition
|
|
|
|
|
|
|
|
fwelf = fwenv["FW_ELF"] = fwenv.Program(
|
|
|
|
"${FIRMWARE_BUILD_CFG}",
|
|
|
|
sources,
|
|
|
|
LIBS=[
|
|
|
|
"flipper${TARGET_HW}",
|
|
|
|
"core",
|
|
|
|
"freertos",
|
|
|
|
"stm32cubewb",
|
|
|
|
"hwdrivers",
|
|
|
|
"fatfs",
|
|
|
|
"littlefs",
|
|
|
|
"subghz",
|
|
|
|
"flipperformat",
|
|
|
|
"toolbox",
|
|
|
|
"microtar",
|
|
|
|
"usb_stm32",
|
|
|
|
"st25rfal002",
|
|
|
|
"infrared",
|
|
|
|
"appframe",
|
|
|
|
"assets",
|
|
|
|
"misc",
|
2022-07-05 15:24:59 +03:00
|
|
|
"mbedtls",
|
|
|
|
"loclass",
|
2022-06-26 15:00:03 +03:00
|
|
|
# 2nd round
|
|
|
|
"flipperformat",
|
|
|
|
"toolbox",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2022-07-14 19:24:26 +03:00
|
|
|
# Make it depend on everything child builders returned
|
2022-07-05 15:24:59 +03:00
|
|
|
# Firmware depends on everything child builders returned
|
2022-06-26 15:00:03 +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-06-28 15:28:55 +03:00
|
|
|
AddPostAction(fwelf, Action("@$SIZECOM"))
|
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}")
|
|
|
|
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-07-05 15:24:59 +03:00
|
|
|
fw_artifacts = fwenv["FW_ARTIFACTS"] = [
|
2022-06-30 19:06:12 +03:00
|
|
|
fwhex,
|
|
|
|
fwbin,
|
|
|
|
fwdfu,
|
2022-07-05 15:24:59 +03:00
|
|
|
fwenv["FW_VERSION_JSON"],
|
2022-06-30 19:06:12 +03:00
|
|
|
]
|
2022-06-26 15:00:03 +03:00
|
|
|
|
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):
|
|
|
|
fwcdb = fwenv.CompilationDatabase()
|
|
|
|
# without filtering, both updater & firmware commands would be generated
|
|
|
|
fwenv.Replace(COMPILATIONDB_PATH_FILTER=fwenv.subst("*${FW_FLAVOR}*"))
|
|
|
|
Depends(fwcdb, fwelf)
|
|
|
|
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
|
|
|
|
2022-06-30 19:06:12 +03:00
|
|
|
|
2022-06-26 15:00:03 +03:00
|
|
|
Return("fwenv")
|