unleashed-firmware/firmware.scons

257 lines
6.6 KiB
Text
Raw Normal View History

Import("ENV", "fw_build_meta")
import os
from fbt.util import (
should_gen_cdb_and_link_dir,
link_elf_dir_as_latest,
)
# Building initial C environment for libs
env = ENV.Clone(
tools=[
("compilation_db", {"COMPILATIONDB_COMSTR": "\tCDB\t${TARGET}"}),
"fwbin",
"fbt_apps",
],
COMPILATIONDB_USE_ABSPATH=False,
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=[
"#/furi",
"#/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
},
# for furi_check to respect build type
"furi": {
"CCFLAGS": [
"-Os",
],
"CPPDEFINES": [
"NDEBUG",
"FURI_DEBUG" if ENV["DEBUG"] else "FURI_NDEBUG",
],
},
},
)
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}",
)
if env["IS_BASE_FIRMWARE"]:
env.Append(
FIRMWARE_BUILD_CFG="firmware",
RAM_EXEC=False,
)
else:
env.Append(
FIRMWARE_BUILD_CFG="updater",
RAM_EXEC=True,
CPPDEFINES=[
"FURI_RAM_EXEC",
],
)
# Invoke child SConscripts to populate global `env` + build their own part of the code
lib_targets = env.BuildModules(
[
"lib",
"assets",
"firmware",
"furi",
],
)
# 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"):
fwenv.Append(APPS=extra_int_apps.split(","))
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"]),
)
# Adding dependency on manifest files so apps.c is rebuilt when any manifest is changed
fwenv.Depends(apps_c, fwenv.GlobRecursive("*.fam", "#/applications"))
sources = [apps_c]
# Gather sources only from app folders in current configuration
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",
"-n",
"-Xlinker",
"-Map=${TARGET}.map",
],
)
# Debug
# print(fwenv.Dump())
# Full firmware definition
fwelf = fwenv["FW_ELF"] = fwenv.Program(
"${FIRMWARE_BUILD_CFG}",
sources,
LIBS=[
"print",
"flipper${TARGET_HW}",
"furi",
"freertos",
"stm32cubewb",
"hwdrivers",
"fatfs",
"littlefs",
"subghz",
"flipperformat",
"toolbox",
[FL-2605] NFC new design (#1364) * nfc: add new read scene * lib: refactore nfc library * mifare desfire: add read card fuction * lib nfc: add auto read worker * nfc: add supported cards * nfc: add mifare classic read success scene * nfc: add troyka support * submodule: update protobuf * nfc: mifare classic keys cache * nfc: rework mifare classic key cache * Correct spelling * nfc: add user dictionary * nfc: introduce block read map in fff * nfc: rework dict attack * nfc: improve dict attack * nfc: rework mifare classic format * nfc: rework MFC read with Reader * nfc: add gui for MFC read success scene * nfc: fix dict attack view gui * nfc: add retry and exit confirm scenes * nfc: add retry and exit scenes navigation * nfc: check user dictionary * nfc: remove unused scenes * nfc: rename functions in nfc worker * nfc: rename mf_classic_dict_attack -> dict_attack * nfc: change scenes names * nfc: remove scene tick events * nfc: rework dict calls with buffer streams * nfc: fix notifications * nfc: fix mf desfire navigation * nfc: remove notification from mf classic read success * nfc: fix read sectors calculation * nfc: add fallback for unknown card * nfc: show file name while emulating * nfc: fix build * nfc: fix memory leak * nfc: fix desfire read * nfc: add no dict found navigation * nfc: add read views * nfc: update card fix * nfc: fix access bytes save * nfc: add exit and retry confirm to mf ultralight read success * nfc: introduce detect reader * nfc: change record open arg to macros * nfc: fix start from archive Co-authored-by: Astra <astra@astrra.space> Co-authored-by: あく <alleteam@gmail.com>
2022-07-26 15:30:49 +00:00
"nfc",
"microtar",
"usb_stm32",
"st25rfal002",
"infrared",
"appframe",
"assets",
"misc",
"mbedtls",
"loclass",
# 2nd round
"flipperformat",
"toolbox",
],
)
# Firmware depends on everything child builders returned
Depends(fwelf, lib_targets)
# Output extra details after building firmware
AddPostAction(fwelf, fwenv["APPBUILD_DUMP"])
AddPostAction(fwelf, Action("@$SIZECOM"))
# Produce extra firmware files
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)
fw_artifacts = fwenv["FW_ARTIFACTS"] = [
fwhex,
fwbin,
fwdfu,
fwenv["FW_VERSION_JSON"],
]
# 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}*"))
AlwaysBuild(fwcdb)
Alias(fwenv["FIRMWARE_BUILD_CFG"] + "_cdb", fwcdb)
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)
Return("fwenv")